WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] merge with xen-unstable.hg

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] merge with xen-unstable.hg
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 09 Aug 2006 22:20:44 +0000
Delivery-date: Wed, 09 Aug 2006 15:26:29 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User awilliam@xxxxxxxxxxx
# Node ID 54550e85f25a23759e48141af48dde1626d5ae0c
# Parent  bfc69471550ed272b11df29903b268292f4857f5
# Parent  b16252dbcb1f99a22fcf4c87a015c47f6019cfd2
merge with xen-unstable.hg
---
 tools/ioemu/pc-bios/proll.patch                                  | 3836 
----------
 xen/include/xen/reboot.h                                         |    8 
 buildconfigs/linux-defconfig_xen0_ia64                           |    3 
 buildconfigs/linux-defconfig_xen0_x86_32                         |    1 
 buildconfigs/linux-defconfig_xen0_x86_64                         |    1 
 buildconfigs/linux-defconfig_xen_ia64                            |    3 
 buildconfigs/linux-defconfig_xen_x86_32                          |    1 
 buildconfigs/linux-defconfig_xen_x86_64                          |    1 
 docs/src/user.tex                                                |    2 
 linux-2.6-xen-sparse/drivers/xen/Kconfig                         |   11 
 linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c               |    9 
 linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c               |    9 
 linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c                 |   50 
 linux-2.6-xen-sparse/drivers/xen/netback/netback.c               |    4 
 linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c             |    3 
 linux-2.6-xen-sparse/drivers/xen/pciback/Makefile                |    1 
 linux-2.6-xen-sparse/drivers/xen/pciback/slot.c                  |  151 
 linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c               |    1 
 linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/mmu_context.h |    3 
 linux-2.6-xen-sparse/include/asm-i386/spinlock.h                 |    4 
 tools/Makefile                                                   |    2 
 tools/blktap/drivers/Makefile                                    |   19 
 tools/blktap/lib/Makefile                                        |   14 
 tools/examples/block                                             |   18 
 tools/examples/xend-config.sxp                                   |    2 
 tools/examples/xmexample.hvm                                     |   10 
 tools/firmware/acpi/acpi_dsdt.asl                                |  235 
 tools/firmware/acpi/acpi_dsdt.c                                  |  531 -
 tools/firmware/hvmloader/Makefile                                |    9 
 tools/firmware/hvmloader/acpi_madt.c                             |    4 
 tools/firmware/hvmloader/hvmloader.c                             |  117 
 tools/firmware/hvmloader/hypercall.h                             |  180 
 tools/firmware/hvmloader/mp_tables.c                             |    3 
 tools/firmware/hvmloader/util.c                                  |   96 
 tools/firmware/hvmloader/util.h                                  |   19 
 tools/ioemu/.CVS/Entries                                         |  190 
 tools/ioemu/.CVS/Entries.Log                                     |    7 
 tools/ioemu/.CVS/Tag                                             |    2 
 tools/ioemu/.cvsignore                                           |   13 
 tools/ioemu/Changelog                                            |   19 
 tools/ioemu/Makefile                                             |   31 
 tools/ioemu/Makefile.target                                      |   55 
 tools/ioemu/TODO                                                 |    2 
 tools/ioemu/VERSION                                              |    2 
 tools/ioemu/audio/.CVS/Entries                                   |   37 
 tools/ioemu/audio/.CVS/Tag                                       |    2 
 tools/ioemu/audio/alsaaudio.c                                    |   23 
 tools/ioemu/audio/audio.c                                        |  452 +
 tools/ioemu/audio/audio.h                                        |   46 
 tools/ioemu/audio/audio_int.h                                    |   42 
 tools/ioemu/audio/audio_template.h                               |   33 
 tools/ioemu/audio/coreaudio.c                                    |   16 
 tools/ioemu/audio/dsound_template.h                              |   20 
 tools/ioemu/audio/dsoundaudio.c                                  |    8 
 tools/ioemu/audio/fmodaudio.c                                    |   10 
 tools/ioemu/audio/noaudio.c                                      |   40 
 tools/ioemu/audio/ossaudio.c                                     |   44 
 tools/ioemu/audio/rate_template.h                                |    2 
 tools/ioemu/audio/sdlaudio.c                                     |   10 
 tools/ioemu/audio/wavaudio.c                                     |    4 
 tools/ioemu/audio/wavcapture.c                                   |  164 
 tools/ioemu/block-bochs.c                                        |    2 
 tools/ioemu/block-cloop.c                                        |    2 
 tools/ioemu/block-cow.c                                          |    9 
 tools/ioemu/block-qcow.c                                         |    9 
 tools/ioemu/block-vmdk.c                                         |    9 
 tools/ioemu/block-vpc.c                                          |    2 
 tools/ioemu/block-vvfat.c                                        |    1 
 tools/ioemu/block.c                                              |   64 
 tools/ioemu/block_int.h                                          |    1 
 tools/ioemu/cocoa.m                                              |   60 
 tools/ioemu/configure                                            |   55 
 tools/ioemu/console.c                                            |  170 
 tools/ioemu/cpu-all.h                                            |  102 
 tools/ioemu/cpu-defs.h                                           |    2 
 tools/ioemu/cpu-exec.c                                           |   49 
 tools/ioemu/disas.c                                              |    4 
 tools/ioemu/dyngen-exec.h                                        |   27 
 tools/ioemu/dyngen.c                                             |   92 
 tools/ioemu/dyngen.h                                             |    8 
 tools/ioemu/elf.h                                                |    2 
 tools/ioemu/exec-all.h                                           |    2 
 tools/ioemu/exec.c                                               |   33 
 tools/ioemu/fpu/.CVS/Entries                                     |   12 
 tools/ioemu/fpu/.CVS/Tag                                         |    2 
 tools/ioemu/fpu/softfloat-native.c                               |   13 
 tools/ioemu/gdbstub.c                                            |  131 
 tools/ioemu/hw/.CVS/Entries                                      |  159 
 tools/ioemu/hw/.CVS/Tag                                          |    2 
 tools/ioemu/hw/acpi-dsdt.dsl                                     |  559 +
 tools/ioemu/hw/acpi-dsdt.hex                                     |  278 
 tools/ioemu/hw/acpi.c                                            |  615 +
 tools/ioemu/hw/adlib.c                                           |    4 
 tools/ioemu/hw/apb_pci.c                                         |  232 
 tools/ioemu/hw/apic.c                                            |    4 
 tools/ioemu/hw/cdrom.c                                           |  156 
 tools/ioemu/hw/cuda.c                                            |    2 
 tools/ioemu/hw/es1370.c                                          |   10 
 tools/ioemu/hw/esp.c                                             |  538 -
 tools/ioemu/hw/grackle_pci.c                                     |  156 
 tools/ioemu/hw/i8259.c                                           |    2 
 tools/ioemu/hw/ide.c                                             |  135 
 tools/ioemu/hw/lsi53c895a.c                                      | 1571 ++++
 tools/ioemu/hw/m48t59.c                                          |   10 
 tools/ioemu/hw/mips_r4k.c                                        |    6 
 tools/ioemu/hw/ne2000.c                                          |    2 
 tools/ioemu/hw/pc.c                                              |   61 
 tools/ioemu/hw/pci.c                                             | 1489 ---
 tools/ioemu/hw/pci_host.h                                        |   93 
 tools/ioemu/hw/pcnet.c                                           | 1789 ++++
 tools/ioemu/hw/pcspk.c                                           |    4 
 tools/ioemu/hw/pflash_cfi02.c                                    |  624 +
 tools/ioemu/hw/piix4acpi.c                                       |  153 
 tools/ioemu/hw/piix_pci.c                                        |  435 +
 tools/ioemu/hw/pl050.c                                           |    2 
 tools/ioemu/hw/ppc_chrp.c                                        |   20 
 tools/ioemu/hw/ppc_prep.c                                        |    4 
 tools/ioemu/hw/prep_pci.c                                        |  167 
 tools/ioemu/hw/rtl8139.c                                         | 1494 ++-
 tools/ioemu/hw/sb16.c                                            |   94 
 tools/ioemu/hw/scsi-disk.c                                       |  478 +
 tools/ioemu/hw/sh7750.c                                          |    2 
 tools/ioemu/hw/slavio_intctl.c                                   |    2 
 tools/ioemu/hw/slavio_timer.c                                    |    2 
 tools/ioemu/hw/sun4m.c                                           |   14 
 tools/ioemu/hw/sun4u.c                                           |   18 
 tools/ioemu/hw/unin_pci.c                                        |  261 
 tools/ioemu/hw/usb-hid.c                                         |   14 
 tools/ioemu/hw/usb-hub.c                                         |   26 
 tools/ioemu/hw/usb-msd.c                                         |  402 +
 tools/ioemu/hw/usb-ohci.c                                        | 1190 +++
 tools/ioemu/hw/usb-uhci.c                                        |   22 
 tools/ioemu/hw/usb.h                                             |   18 
 tools/ioemu/hw/versatile_pci.c                                   |  119 
 tools/ioemu/hw/versatilepb.c                                     |  216 
 tools/ioemu/hw/vga.c                                             |  137 
 tools/ioemu/hw/vga_int.h                                         |    9 
 tools/ioemu/hw/vga_template.h                                    |  234 
 tools/ioemu/keymaps/.CVS/Entries                                 |   70 
 tools/ioemu/keymaps/.CVS/Tag                                     |    2 
 tools/ioemu/kqemu.c                                              |   11 
 tools/ioemu/loader.c                                             |    2 
 tools/ioemu/monitor.c                                            |  169 
 tools/ioemu/osdep.c                                              |   22 
 tools/ioemu/osdep.h                                              |    2 
 tools/ioemu/patches/acpi-poweroff-support                        |    8 
 tools/ioemu/patches/acpi-support                                 |  158 
 tools/ioemu/patches/acpi-timer-support                           |  226 
 tools/ioemu/patches/domain-destroy                               |   23 
 tools/ioemu/patches/domain-reset                                 |   16 
 tools/ioemu/patches/domain-timeoffset                            |   40 
 tools/ioemu/patches/hypervisor-pit                               |   18 
 tools/ioemu/patches/ide-hd-multithread                           |   24 
 tools/ioemu/patches/ioemu-ia64                                   |   43 
 tools/ioemu/patches/qemu-64bit                                   |   28 
 tools/ioemu/patches/qemu-allow-disable-sdl                       |   27 
 tools/ioemu/patches/qemu-bugfixes                                |   25 
 tools/ioemu/patches/qemu-cleanup                                 |   22 
 tools/ioemu/patches/qemu-dm                                      |  126 
 tools/ioemu/patches/qemu-fix-memset-args                         |   15 
 tools/ioemu/patches/qemu-fix-write-to-disk-synchronous           |   66 
 tools/ioemu/patches/qemu-hvm-banner                              |    4 
 tools/ioemu/patches/qemu-init-vgabios                            |    6 
 tools/ioemu/patches/qemu-logging                                 |   28 
 tools/ioemu/patches/qemu-no-apic                                 |   16 
 tools/ioemu/patches/qemu-nobios                                  |   19 
 tools/ioemu/patches/qemu-smp                                     |   20 
 tools/ioemu/patches/qemu-target-i386-dm                          |   57 
 tools/ioemu/patches/qemu-timer                                   |   14 
 tools/ioemu/patches/serial-non-block                             |    4 
 tools/ioemu/patches/series                                       |    7 
 tools/ioemu/patches/shadow-vram                                  |   12 
 tools/ioemu/patches/shared-vram                                  |   26 
 tools/ioemu/patches/support-xm-console                           |    6 
 tools/ioemu/patches/vnc-access-monitor-vt                        |   16 
 tools/ioemu/patches/vnc-cleanup                                  |   19 
 tools/ioemu/patches/vnc-fixes                                    |  101 
 tools/ioemu/patches/vnc-start-vncviewer                          |   48 
 tools/ioemu/patches/vnc-title-domain-name                        |    6 
 tools/ioemu/patches/xen-build                                    |   57 
 tools/ioemu/patches/xen-domain-name                              |   30 
 tools/ioemu/patches/xen-domid                                    |   18 
 tools/ioemu/patches/xen-mm                                       |   27 
 tools/ioemu/patches/xen-network                                  |   12 
 tools/ioemu/patches/xen-support-buffered-ioreqs                  |   77 
 tools/ioemu/patches/xenstore-block-device-config                 |  221 
 tools/ioemu/patches/xenstore-write-vnc-port                      |   27 
 tools/ioemu/pc-bios/.CVS/Entries                                 |   27 
 tools/ioemu/pc-bios/.CVS/Tag                                     |    2 
 tools/ioemu/pc-bios/README                                       |    8 
 tools/ioemu/pc-bios/bios.diff                                    |   87 
 tools/ioemu/pc-bios/vgabios.diff                                 |  825 --
 tools/ioemu/qemu-doc.texi                                        |  250 
 tools/ioemu/qemu-img.c                                           |   33 
 tools/ioemu/sdl.c                                                |   27 
 tools/ioemu/tap-win32.c                                          |    8 
 tools/ioemu/target-i386-dm/helper2.c                             |  107 
 tools/ioemu/target-i386/.CVS/Entries                             |   24 
 tools/ioemu/target-i386/.CVS/Tag                                 |    2 
 tools/ioemu/target-i386/exec.h                                   |    3 
 tools/ioemu/target-i386/helper.c                                 |   39 
 tools/ioemu/target-i386/helper2.c                                |   33 
 tools/ioemu/target-i386/op.c                                     |   15 
 tools/ioemu/target-i386/translate.c                              |   93 
 tools/ioemu/tests/.CVS/Entries                                   |   34 
 tools/ioemu/tests/.CVS/Tag                                       |    2 
 tools/ioemu/tests/Makefile                                       |    3 
 tools/ioemu/tests/test-i386.c                                    |   22 
 tools/ioemu/usb-linux.c                                          |   44 
 tools/ioemu/vl.c                                                 | 1378 ++-
 tools/ioemu/vl.h                                                 |  148 
 tools/ioemu/vnc.c                                                |  258 
 tools/ioemu/vnchextile.h                                         |   48 
 tools/ioemu/xenstore.c                                           |  215 
 tools/libxc/xc_hvm_build.c                                       |   78 
 tools/libxc/xc_linux_build.c                                     |    6 
 tools/libxc/xc_misc.c                                            |   13 
 tools/libxc/xenctrl.h                                            |    9 
 tools/misc/xend                                                  |    2 
 tools/misc/xenperf.c                                             |   60 
 tools/pygrub/src/GrubConf.py                                     |   72 
 tools/pygrub/src/pygrub                                          |  541 -
 tools/python/xen/sv/CreateDomain.py                              |    1 
 tools/python/xen/util/xmlrpclib2.py                              |    5 
 tools/python/xen/xend/XendDomain.py                              |    4 
 tools/python/xen/xend/image.py                                   |   30 
 tools/python/xen/xend/server/DevController.py                    |    2 
 tools/python/xen/xend/server/blkif.py                            |   26 
 tools/python/xen/xend/sxp.py                                     |    2 
 tools/python/xen/xend/tests/test_sxp.py                          |   21 
 tools/python/xen/xend/tests/xend-config.sxp                      |  132 
 tools/python/xen/xm/create.py                                    |   68 
 tools/python/xen/xm/main.py                                      |   10 
 tools/python/xen/xm/tests/test_create.py                         |    3 
 tools/xenstat/libxenstat/src/xenstat.c                           |  101 
 xen/arch/ia64/linux-xen/setup.c                                  |    2 
 xen/arch/ia64/vmx/vmx_support.c                                  |    3 
 xen/arch/ia64/xen/hypercall.c                                    |    2 
 xen/arch/ia64/xen/xensetup.c                                     |    3 
 xen/arch/powerpc/domain.c                                        |    2 
 xen/arch/powerpc/setup.c                                         |    2 
 xen/arch/x86/cpu/mcheck/mce.c                                    |    4 
 xen/arch/x86/domain.c                                            |    2 
 xen/arch/x86/flushtlb.c                                          |    4 
 xen/arch/x86/genapic/es7000plat.c                                |    1 
 xen/arch/x86/hvm/hvm.c                                           |  400 -
 xen/arch/x86/hvm/intercept.c                                     |   68 
 xen/arch/x86/hvm/io.c                                            |   89 
 xen/arch/x86/hvm/platform.c                                      |   82 
 xen/arch/x86/hvm/svm/svm.c                                       |   10 
 xen/arch/x86/hvm/svm/vmcb.c                                      |   34 
 xen/arch/x86/hvm/svm/x86_32/exits.S                              |    3 
 xen/arch/x86/hvm/svm/x86_64/exits.S                              |    2 
 xen/arch/x86/hvm/vlapic.c                                        |    7 
 xen/arch/x86/hvm/vmx/io.c                                        |   18 
 xen/arch/x86/hvm/vmx/vmcs.c                                      |   12 
 xen/arch/x86/hvm/vmx/vmx.c                                       |  134 
 xen/arch/x86/hvm/vmx/x86_32/exits.S                              |    3 
 xen/arch/x86/hvm/vmx/x86_64/exits.S                              |    2 
 xen/arch/x86/irq.c                                               |   87 
 xen/arch/x86/mm.c                                                |  107 
 xen/arch/x86/nmi.c                                               |   38 
 xen/arch/x86/shutdown.c                                          |   17 
 xen/arch/x86/time.c                                              |   64 
 xen/arch/x86/traps.c                                             |    2 
 xen/arch/x86/x86_32/domain_page.c                                |    3 
 xen/arch/x86/x86_32/entry.S                                      |    2 
 xen/arch/x86/x86_32/traps.c                                      |    4 
 xen/arch/x86/x86_32/xen.lds.S                                    |    3 
 xen/arch/x86/x86_64/entry.S                                      |    2 
 xen/arch/x86/x86_64/traps.c                                      |    2 
 xen/arch/x86/x86_64/xen.lds.S                                    |    3 
 xen/common/Makefile                                              |    1 
 xen/common/domain.c                                              |   38 
 xen/common/event_channel.c                                       |  108 
 xen/common/kernel.c                                              |    7 
 xen/common/keyhandler.c                                          |    2 
 xen/common/multicall.c                                           |    4 
 xen/common/perfc.c                                               |   53 
 xen/common/sched_bvt.c                                           |   16 
 xen/common/sched_credit.c                                        |   31 
 xen/common/sched_sedf.c                                          |   21 
 xen/common/schedule.c                                            |   65 
 xen/common/shutdown.c                                            |   66 
 xen/common/timer.c                                               |   86 
 xen/common/trace.c                                               |   17 
 xen/drivers/char/console.c                                       |   20 
 xen/drivers/char/serial.c                                        |    1 
 xen/include/asm-ia64/linux-xen/asm/cache.h                       |    2 
 xen/include/asm-ia64/perfc.h                                     |   16 
 xen/include/asm-powerpc/cache.h                                  |    2 
 xen/include/asm-powerpc/flushtlb.h                               |   15 
 xen/include/asm-powerpc/perfc.h                                  |   16 
 xen/include/asm-x86/cache.h                                      |    2 
 xen/include/asm-x86/current.h                                    |    2 
 xen/include/asm-x86/e820.h                                       |    1 
 xen/include/asm-x86/flushtlb.h                                   |   16 
 xen/include/asm-x86/guest_access.h                               |   25 
 xen/include/asm-x86/hvm/domain.h                                 |   10 
 xen/include/asm-x86/hvm/guest_access.h                           |   10 
 xen/include/asm-x86/hvm/hvm.h                                    |   12 
 xen/include/asm-x86/hvm/io.h                                     |    3 
 xen/include/asm-x86/hvm/support.h                                |    8 
 xen/include/asm-x86/hvm/vcpu.h                                   |    2 
 xen/include/asm-x86/hvm/vmx/vmx.h                                |  359 
 xen/include/asm-x86/perfc.h                                      |   23 
 xen/include/asm-x86/shadow.h                                     |    7 
 xen/include/public/dom0_ops.h                                    |    7 
 xen/include/public/hvm/ioreq.h                                   |   10 
 xen/include/public/hvm/params.h                                  |   24 
 xen/include/public/version.h                                     |    3 
 xen/include/public/xen.h                                         |    1 
 xen/include/xen/config.h                                         |    1 
 xen/include/xen/event.h                                          |   38 
 xen/include/xen/hypercall.h                                      |    5 
 xen/include/xen/multicall.h                                      |    5 
 xen/include/xen/percpu.h                                         |    1 
 xen/include/xen/sched-if.h                                       |   10 
 xen/include/xen/sched.h                                          |    8 
 xen/include/xen/shutdown.h                                       |   13 
 ioemu/pc-bios/video.x                                            |    0 
 321 files changed, 20015 insertions(+), 10875 deletions(-)

diff -r bfc69471550e -r 54550e85f25a buildconfigs/linux-defconfig_xen0_ia64
--- a/buildconfigs/linux-defconfig_xen0_ia64    Wed Aug 09 08:01:52 2006 -0600
+++ b/buildconfigs/linux-defconfig_xen0_ia64    Wed Aug 09 08:34:06 2006 -0600
@@ -1532,8 +1532,9 @@ CONFIG_XEN_BLKDEV_BACKEND=y
 # CONFIG_XEN_NETDEV_PIPELINED_TRANSMITTER is not set
 CONFIG_XEN_NETDEV_LOOPBACK=y
 CONFIG_XEN_PCIDEV_BACKEND=y
-CONFIG_XEN_PCIDEV_BACKEND_VPCI=y
+# CONFIG_XEN_PCIDEV_BACKEND_VPCI is not set
 # CONFIG_XEN_PCIDEV_BACKEND_PASS is not set
+CONFIG_XEN_PCIDEV_BACKEND_SLOT=y
 # CONFIG_XEN_PCIDEV_BE_DEBUG is not set
 # CONFIG_XEN_TPMDEV_BACKEND is not set
 CONFIG_XEN_BLKDEV_FRONTEND=y
diff -r bfc69471550e -r 54550e85f25a buildconfigs/linux-defconfig_xen0_x86_32
--- a/buildconfigs/linux-defconfig_xen0_x86_32  Wed Aug 09 08:01:52 2006 -0600
+++ b/buildconfigs/linux-defconfig_xen0_x86_32  Wed Aug 09 08:34:06 2006 -0600
@@ -1320,6 +1320,7 @@ CONFIG_XEN_PCIDEV_BACKEND=y
 CONFIG_XEN_PCIDEV_BACKEND=y
 # CONFIG_XEN_PCIDEV_BACKEND_VPCI is not set
 CONFIG_XEN_PCIDEV_BACKEND_PASS=y
+# CONFIG_XEN_PCIDEV_BACKEND_SLOT is not set
 # CONFIG_XEN_PCIDEV_BE_DEBUG is not set
 CONFIG_XEN_BLKDEV_BACKEND=y
 CONFIG_XEN_BLKDEV_TAP=y
diff -r bfc69471550e -r 54550e85f25a buildconfigs/linux-defconfig_xen0_x86_64
--- a/buildconfigs/linux-defconfig_xen0_x86_64  Wed Aug 09 08:01:52 2006 -0600
+++ b/buildconfigs/linux-defconfig_xen0_x86_64  Wed Aug 09 08:34:06 2006 -0600
@@ -1261,6 +1261,7 @@ CONFIG_XEN_PCIDEV_BACKEND=y
 CONFIG_XEN_PCIDEV_BACKEND=y
 # CONFIG_XEN_PCIDEV_BACKEND_VPCI is not set
 CONFIG_XEN_PCIDEV_BACKEND_PASS=y
+# CONFIG_XEN_PCIDEV_BACKEND_SLOT is not set
 # CONFIG_XEN_PCIDEV_BE_DEBUG is not set
 CONFIG_XEN_BLKDEV_BACKEND=y
 CONFIG_XEN_BLKDEV_TAP=y
diff -r bfc69471550e -r 54550e85f25a buildconfigs/linux-defconfig_xen_ia64
--- a/buildconfigs/linux-defconfig_xen_ia64     Wed Aug 09 08:01:52 2006 -0600
+++ b/buildconfigs/linux-defconfig_xen_ia64     Wed Aug 09 08:34:06 2006 -0600
@@ -1538,8 +1538,9 @@ CONFIG_XEN_BLKDEV_BACKEND=y
 # CONFIG_XEN_NETDEV_PIPELINED_TRANSMITTER is not set
 CONFIG_XEN_NETDEV_LOOPBACK=y
 CONFIG_XEN_PCIDEV_BACKEND=y
-CONFIG_XEN_PCIDEV_BACKEND_VPCI=y
+# CONFIG_XEN_PCIDEV_BACKEND_VPCI is not set
 # CONFIG_XEN_PCIDEV_BACKEND_PASS is not set
+CONFIG_XEN_PCIDEV_BACKEND_SLOT=y
 # CONFIG_XEN_PCIDEV_BE_DEBUG is not set
 # CONFIG_XEN_TPMDEV_BACKEND is not set
 CONFIG_XEN_BLKDEV_FRONTEND=y
diff -r bfc69471550e -r 54550e85f25a buildconfigs/linux-defconfig_xen_x86_32
--- a/buildconfigs/linux-defconfig_xen_x86_32   Wed Aug 09 08:01:52 2006 -0600
+++ b/buildconfigs/linux-defconfig_xen_x86_32   Wed Aug 09 08:34:06 2006 -0600
@@ -3021,6 +3021,7 @@ CONFIG_XEN_PCIDEV_BACKEND=m
 CONFIG_XEN_PCIDEV_BACKEND=m
 CONFIG_XEN_PCIDEV_BACKEND_VPCI=y
 # CONFIG_XEN_PCIDEV_BACKEND_PASS is not set
+# CONFIG_XEN_PCIDEV_BACKEND_SLOT is not set
 # CONFIG_XEN_PCIDEV_BE_DEBUG is not set
 CONFIG_XEN_BLKDEV_BACKEND=y
 CONFIG_XEN_BLKDEV_TAP=y
diff -r bfc69471550e -r 54550e85f25a buildconfigs/linux-defconfig_xen_x86_64
--- a/buildconfigs/linux-defconfig_xen_x86_64   Wed Aug 09 08:01:52 2006 -0600
+++ b/buildconfigs/linux-defconfig_xen_x86_64   Wed Aug 09 08:34:06 2006 -0600
@@ -2853,6 +2853,7 @@ CONFIG_XEN_PCIDEV_BACKEND=m
 CONFIG_XEN_PCIDEV_BACKEND=m
 # CONFIG_XEN_PCIDEV_BACKEND_VPCI is not set
 CONFIG_XEN_PCIDEV_BACKEND_PASS=y
+# CONFIG_XEN_PCIDEV_BACKEND_SLOT is not set
 # CONFIG_XEN_PCIDEV_BE_DEBUG is not set
 CONFIG_XEN_BLKDEV_BACKEND=y
 CONFIG_XEN_BLKDEV_TAP=y
diff -r bfc69471550e -r 54550e85f25a docs/src/user.tex
--- a/docs/src/user.tex Wed Aug 09 08:01:52 2006 -0600
+++ b/docs/src/user.tex Wed Aug 09 08:34:06 2006 -0600
@@ -3170,7 +3170,7 @@ editing \path{grub.conf}.
 \item [ tbuf\_size=xxx ] Set the size of the per-cpu trace buffers, in
   pages (default 0).  
 \item [ sched=xxx ] Select the CPU scheduler Xen should use.  The
-  current possibilities are `sedf' (default), `credit', and `bvt'.
+  current possibilities are `credit' (default), `sedf', and `bvt'.
 \item [ apic\_verbosity=debug,verbose ] Print more detailed
   information about local APIC and IOAPIC configuration.
 \item [ lapic ] Force use of local APIC even when left disabled by
diff -r bfc69471550e -r 54550e85f25a linux-2.6-xen-sparse/drivers/xen/Kconfig
--- a/linux-2.6-xen-sparse/drivers/xen/Kconfig  Wed Aug 09 08:01:52 2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/Kconfig  Wed Aug 09 08:34:06 2006 -0600
@@ -117,7 +117,7 @@ config XEN_PCIDEV_BACKEND_VPCI
          This PCI Backend hides the true PCI topology and makes the frontend
          think there is a single PCI bus with only the exported devices on it.
          For example, a device at 03:05.0 will be re-assigned to 00:00.0. A
-         second device at 02:1a.0 will be re-assigned to 00:01.0.
+         second device at 02:1a.1 will be re-assigned to 00:01.1.
 
 config XEN_PCIDEV_BACKEND_PASS
        bool "Passthrough"
@@ -129,6 +129,15 @@ config XEN_PCIDEV_BACKEND_PASS
          which depend on finding their hardward in certain bus/slot
          locations.
 
+config XEN_PCIDEV_BACKEND_SLOT
+       bool "Slot"
+       ---help---
+         This PCI Backend hides the true PCI topology and makes the frontend
+         think there is a single PCI bus with only the exported devices on it.
+         Contrary to the virtual PCI backend, a function becomes a new slot.
+         For example, a device at 03:05.2 will be re-assigned to 00:00.0. A
+         second device at 02:1a.1 will be re-assigned to 00:01.0.
+
 endchoice
 
 config XEN_PCIDEV_BE_DEBUG
diff -r bfc69471550e -r 54550e85f25a 
linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c
--- a/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c        Wed Aug 09 
08:01:52 2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/balloon/balloon.c        Wed Aug 09 
08:34:06 2006 -0600
@@ -563,10 +563,14 @@ struct page *balloon_alloc_empty_page_ra
                set_xen_guest_handle(reservation.extent_start, &gmfn);
                ret = HYPERVISOR_memory_op(XENMEM_decrease_reservation,
                                           &reservation);
+               if (ret == -ENOSYS)
+                       goto err;
                BUG_ON(ret != 1);
        } else {
                ret = apply_to_page_range(&init_mm, vstart, PAGE_SIZE << order,
                                          dealloc_pte_fn, NULL);
+               if (ret == -ENOSYS)
+                       goto err;
                BUG_ON(ret);
        }
        current_pages -= 1UL << order;
@@ -583,6 +587,11 @@ struct page *balloon_alloc_empty_page_ra
                set_page_count(page + i, 1);
 
        return page;
+
+ err:
+       free_pages(vstart, order);
+       balloon_unlock(flags);
+       return NULL;
 }
 
 void balloon_dealloc_empty_page_range(
diff -r bfc69471550e -r 54550e85f25a 
linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c
--- a/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c        Wed Aug 09 
08:01:52 2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/blkback/blkback.c        Wed Aug 09 
08:34:06 2006 -0600
@@ -513,6 +513,12 @@ static int __init blkif_init(void)
                return -ENODEV;
 
        mmap_pages            = blkif_reqs * BLKIF_MAX_SEGMENTS_PER_REQUEST;
+
+       page = balloon_alloc_empty_page_range(mmap_pages);
+       if (page == NULL)
+               return -ENOMEM;
+       mmap_vstart = (unsigned long)pfn_to_kaddr(page_to_pfn(page));
+
        pending_reqs          = kmalloc(sizeof(pending_reqs[0]) *
                                        blkif_reqs, GFP_KERNEL);
        pending_grant_handles = kmalloc(sizeof(pending_grant_handles[0]) *
@@ -529,9 +535,6 @@ static int __init blkif_init(void)
 
        blkif_interface_init();
        
-       page = balloon_alloc_empty_page_range(mmap_pages);
-       BUG_ON(page == NULL);
-       mmap_vstart = (unsigned long)pfn_to_kaddr(page_to_pfn(page));
        printk("%s: reqs=%d, pages=%d, mmap_vstart=0x%lx\n",
               __FUNCTION__, blkif_reqs, mmap_pages, mmap_vstart);
        BUG_ON(mmap_vstart == 0);
diff -r bfc69471550e -r 54550e85f25a 
linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c
--- a/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c  Wed Aug 09 08:01:52 
2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/blktap/blktap.c  Wed Aug 09 08:34:06 
2006 -0600
@@ -709,29 +709,18 @@ static void make_response(blkif_t *blkif
 /******************************************************************
  * misc small helpers
  */
-/* FIXME: Return ENOMEM properly on failure to allocate additional reqs. */
-static void req_increase(void)
+static int req_increase(void)
 {
        int i, j;
        struct page *page;
        unsigned long flags;
+       int ret;
 
        spin_lock_irqsave(&pending_free_lock, flags);
 
+       ret = -EINVAL;
        if (mmap_alloc >= MAX_PENDING_REQS || mmap_lock) 
                goto done;
-
-       pending_reqs[mmap_alloc]  = kzalloc(sizeof(pending_req_t) *
-                                       blkif_reqs, GFP_KERNEL);
-       pending_addrs[mmap_alloc] = kzalloc(sizeof(unsigned long) *
-                                       mmap_pages, GFP_KERNEL);
-
-       if (!pending_reqs[mmap_alloc] || !pending_addrs[mmap_alloc]) {
-               kfree(pending_reqs[mmap_alloc]);
-               kfree(pending_addrs[mmap_alloc]);
-               WPRINTK("%s: out of memory\n", __FUNCTION__); 
-               goto done;
-       }
 
 #ifdef __ia64__
        extern unsigned long alloc_empty_foreign_map_page_range(
@@ -740,7 +729,11 @@ static void req_increase(void)
                alloc_empty_foreign_map_page_range(mmap_pages);
 #else /* ! ia64 */
        page = balloon_alloc_empty_page_range(mmap_pages);
-       BUG_ON(page == NULL);
+       ret = -ENOMEM;
+       if (page == NULL) {
+               printk("%s balloon_alloc_empty_page_range gave NULL\n", 
__FUNCTION__);
+               goto done;
+       }
 
        /* Pin all of the pages. */
        for (i=0; i<mmap_pages; i++)
@@ -751,6 +744,23 @@ static void req_increase(void)
        mmap_start[mmap_alloc].mpage = page;
 
 #endif
+
+       pending_reqs[mmap_alloc]  = kzalloc(sizeof(pending_req_t) *
+                                       blkif_reqs, GFP_KERNEL);
+       pending_addrs[mmap_alloc] = kzalloc(sizeof(unsigned long) *
+                                       mmap_pages, GFP_KERNEL);
+
+       ret = -ENOMEM;
+       if (!pending_reqs[mmap_alloc] || !pending_addrs[mmap_alloc]) {
+               kfree(pending_reqs[mmap_alloc]);
+               kfree(pending_addrs[mmap_alloc]);
+               WPRINTK("%s: out of memory\n", __FUNCTION__); 
+               ret = -ENOMEM;
+               goto done;
+       }
+
+       ret = 0;
+
        DPRINTK("%s: reqs=%d, pages=%d, mmap_vstart=0x%lx\n",
                __FUNCTION__, blkif_reqs, mmap_pages, 
               mmap_start[mmap_alloc].start);
@@ -774,7 +784,7 @@ static void req_increase(void)
        DPRINTK("# MMAPs increased to %d\n",mmap_alloc);
  done:
        spin_unlock_irqrestore(&pending_free_lock, flags);
-
+       return ret;
 }
 
 static void mmap_req_del(int mmap)
@@ -1389,7 +1399,13 @@ static int __init blkif_init(void)
                return -ENODEV;
 
        INIT_LIST_HEAD(&pending_free);
-        for(i = 0; i < 2; i++) req_increase();
+        for(i = 0; i < 2; i++) {
+               ret = req_increase();
+               if (ret)
+                       break;
+       }
+       if (i == 0)
+               return ret;
 
        tap_blkif_interface_init();
 
diff -r bfc69471550e -r 54550e85f25a 
linux-2.6-xen-sparse/drivers/xen/netback/netback.c
--- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c        Wed Aug 09 
08:01:52 2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c        Wed Aug 09 
08:34:06 2006 -0600
@@ -1306,7 +1306,9 @@ static int __init netback_init(void)
        net_timer.function = net_alarm;
     
        page = balloon_alloc_empty_page_range(MAX_PENDING_REQS);
-       BUG_ON(page == NULL);
+       if (page == NULL)
+               return -ENOMEM;
+
        mmap_vstart = (unsigned long)pfn_to_kaddr(page_to_pfn(page));
 
        for (i = 0; i < MAX_PENDING_REQS; i++) {
diff -r bfc69471550e -r 54550e85f25a 
linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c
--- a/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c      Wed Aug 09 
08:01:52 2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/netfront/netfront.c      Wed Aug 09 
08:34:06 2006 -0600
@@ -497,6 +497,9 @@ static int network_open(struct net_devic
        network_alloc_rx_buffers(dev);
        np->rx.sring->rsp_event = np->rx.rsp_cons + 1;
 
+       if (RING_HAS_UNCONSUMED_RESPONSES(&np->rx))
+               netif_rx_schedule(dev);
+
        netif_start_queue(dev);
 
        return 0;
diff -r bfc69471550e -r 54550e85f25a 
linux-2.6-xen-sparse/drivers/xen/pciback/Makefile
--- a/linux-2.6-xen-sparse/drivers/xen/pciback/Makefile Wed Aug 09 08:01:52 
2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/pciback/Makefile Wed Aug 09 08:34:06 
2006 -0600
@@ -7,6 +7,7 @@ pciback-y += conf_space.o conf_space_hea
             conf_space_capability_pm.o \
              conf_space_quirks.o
 pciback-$(CONFIG_XEN_PCIDEV_BACKEND_VPCI) += vpci.o
+pciback-$(CONFIG_XEN_PCIDEV_BACKEND_SLOT) += slot.o
 pciback-$(CONFIG_XEN_PCIDEV_BACKEND_PASS) += passthrough.o
 
 ifeq ($(CONFIG_XEN_PCIDEV_BE_DEBUG),y)
diff -r bfc69471550e -r 54550e85f25a 
linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c
--- a/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c        Wed Aug 09 
08:01:52 2006 -0600
+++ b/linux-2.6-xen-sparse/drivers/xen/privcmd/privcmd.c        Wed Aug 09 
08:34:06 2006 -0600
@@ -270,6 +270,7 @@ static int __init privcmd_init(void)
        set_bit(__HYPERVISOR_sched_op_compat,  hypercall_permission_map);
        set_bit(__HYPERVISOR_event_channel_op_compat,
                hypercall_permission_map);
+       set_bit(__HYPERVISOR_hvm_op,           hypercall_permission_map);
 
        privcmd_intf = create_xen_proc_entry("privcmd", 0400);
        if (privcmd_intf != NULL)
diff -r bfc69471550e -r 54550e85f25a 
linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/mmu_context.h
--- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/mmu_context.h  Wed Aug 
09 08:01:52 2006 -0600
+++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/mmu_context.h  Wed Aug 
09 08:34:06 2006 -0600
@@ -51,7 +51,8 @@ static inline void switch_mm(struct mm_s
        struct mmuext_op _op[2], *op = _op;
 
        if (likely(prev != next)) {
-               BUG_ON(!test_bit(PG_pinned, &virt_to_page(next->pgd)->flags));
+               BUG_ON(!xen_feature(XENFEAT_writable_page_tables) &&
+                      !test_bit(PG_pinned, &virt_to_page(next->pgd)->flags));
 
                /* stop flush ipis for the previous mm */
                cpu_clear(cpu, prev->cpu_vm_mask);
diff -r bfc69471550e -r 54550e85f25a 
linux-2.6-xen-sparse/include/asm-i386/spinlock.h
--- a/linux-2.6-xen-sparse/include/asm-i386/spinlock.h  Wed Aug 09 08:01:52 
2006 -0600
+++ b/linux-2.6-xen-sparse/include/asm-i386/spinlock.h  Wed Aug 09 08:34:06 
2006 -0600
@@ -23,7 +23,7 @@
                (*(volatile signed char *)(&(x)->slock) <= 0)
 
 #define __raw_spin_lock_string \
-       "\n1:\n" \
+       "\n1:\t" \
        LOCK \
        "decb %0\n\t" \
        "jns 3f\n" \
@@ -35,7 +35,7 @@
        "3:\n\t"
 
 #define __raw_spin_lock_string_flags \
-       "\n1:\n" \
+       "\n1:\t" \
        LOCK \
        "decb %0\n\t" \
        "jns 4f\n\t" \
diff -r bfc69471550e -r 54550e85f25a tools/Makefile
--- a/tools/Makefile    Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/Makefile    Wed Aug 09 08:34:06 2006 -0600
@@ -8,7 +8,7 @@ SUBDIRS-y += examples
 SUBDIRS-y += examples
 SUBDIRS-y += xentrace
 SUBDIRS-$(CONFIG_XCUTILS) += xcutils
-SUBDIRS-y += firmware
+SUBDIRS-$(CONFIG_X86) += firmware
 SUBDIRS-y += security
 SUBDIRS-y += console
 SUBDIRS-y += xenmon
diff -r bfc69471550e -r 54550e85f25a tools/blktap/drivers/Makefile
--- a/tools/blktap/drivers/Makefile     Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/blktap/drivers/Makefile     Wed Aug 09 08:34:06 2006 -0600
@@ -33,9 +33,7 @@ LIBS      += -lz
 LIBS      += -lz
 LIBS      += -L$(XEN_XENSTORE) -lxenstore
 
-AIOLIBS   := -L $(LIBAIO_DIR)
-AIOLIBS   += -laio
-AIOLIBS   += -static
+AIOLIBS   := $(LIBAIO_DIR)/libaio.a
 
 BLK-OBJS  := block-aio.o 
 BLK-OBJS  += block-sync.o 
@@ -49,21 +47,18 @@ LINUX_ROOT := $(wildcard $(XEN_ROOT)/lin
 LINUX_ROOT := $(wildcard $(XEN_ROOT)/linux-2.6.*-xen-sparse)
 
 
-blktapctrl: 
+blktapctrl: blktapctrl.c
        $(CC) $(CFLAGS) -o blktapctrl $(LIBS) blktapctrl.c
 
-tapdisk: $(BLK-OBJS)
+tapdisk: $(BLK-OBJS) tapdisk.c
        $(CC) $(CFLAGS) -o tapdisk $(BLK-OBJS) tapdisk.c \
                $(AIOLIBS) $(LIBS)
 
+.PHONY: qcow-util
+qcow-util: img2qcow qcow2raw qcow-create
 
-qcow-util: $(BLK-OBJS)
-       $(CC) $(CFLAGS) -o img2qcow $(BLK-OBJS) img2qcow.c \
-               $(AIOLIBS)  $(LIBS)
-       $(CC) $(CFLAGS) -o qcow2raw $(BLK-OBJS) qcow2raw.c  \
-               $(AIOLIBS)  $(LIBS)
-       $(CC) $(CFLAGS) -o qcow-create $(BLK-OBJS) qcow-create.c  \
-               $(AIOLIBS)  $(LIBS)
+img2qcow qcow2raw qcow-create: %: $(BLK-OBJS)
+       $(CC) $(CFLAGS) -o $* $(BLK-OBJS) $*.c $(AIOLIBS)  $(LIBS)
 
 install: all
        $(INSTALL_PROG) $(IBIN) $(QCOW_UTIL) $(DESTDIR)$(INSTALL_DIR)
diff -r bfc69471550e -r 54550e85f25a tools/blktap/lib/Makefile
--- a/tools/blktap/lib/Makefile Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/blktap/lib/Makefile Wed Aug 09 08:34:06 2006 -0600
@@ -35,10 +35,14 @@ IBINS   :=
 
 LIB      = libblktap.a libblktap.so.$(MAJOR).$(MINOR)
 
+.PHONY: all
 all: build
 
-build:
-       $(MAKE) libblktap
+.PHONY: build
+build: libblktap.a
+
+.PHONY: libblktap
+libblktap: libblktap.a
 
 install: all
        $(INSTALL_DIR) -p $(DESTDIR)/usr/$(LIBDIR)
@@ -51,13 +55,13 @@ clean:
 clean:
        rm -rf *.a *.so* *.o *.rpm $(LIB) *~ $(DEPS) xen TAGS
 
-libblktap: $(OBJS) 
+libblktap.a: $(OBJS) 
        $(CC) $(CFLAGS) -Wl,-soname -Wl,$(SONAME) -shared         \
              -L$(XEN_XENSTORE) -l xenstore                       \
              -o libblktap.so.$(MAJOR).$(MINOR) $^ $(LIBS)
        ln -sf libblktap.so.$(MAJOR).$(MINOR) libblktap.so.$(MAJOR)
-       ln -sf libblktap.so.$(MAJOR) $@.so
-       ar rc libblktap.a $@.so
+       ln -sf libblktap.so.$(MAJOR) libblktap.so
+       ar rc $@ libblktap.so
 
 .PHONY: TAGS all build clean install libblktap
 
diff -r bfc69471550e -r 54550e85f25a tools/examples/block
--- a/tools/examples/block      Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/examples/block      Wed Aug 09 08:34:06 2006 -0600
@@ -239,8 +239,11 @@ case "$command" in
       exit 0
     fi
 
-    p=$(xenstore_read "$XENBUS_PATH/params")
-    mode=$(xenstore_read "$XENBUS_PATH/mode")
+    if [ -n "$t" ]
+    then
+      p=$(xenstore_read "$XENBUS_PATH/params")
+      mode=$(xenstore_read "$XENBUS_PATH/mode")
+    fi
 
     case $t in 
       phy)
@@ -370,6 +373,13 @@ mount it read-write in a guest domain."
         release_lock "block"
         exit 0
        ;;
+
+      "")
+        claim_lock "block"
+        success
+        echo happy gun \"$t\" >>/tmp/block.$$
+        release_lock "block"
+       ;;
     esac
     ;;
 
@@ -384,6 +394,10 @@ mount it read-write in a guest domain."
        losetup -d "$node"
        exit 0
        ;;
+
+      "")
+        exit 0
+       ;;
     esac
     ;;
 
diff -r bfc69471550e -r 54550e85f25a tools/examples/xend-config.sxp
--- a/tools/examples/xend-config.sxp    Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/examples/xend-config.sxp    Wed Aug 09 08:34:06 2006 -0600
@@ -54,7 +54,7 @@
 #  (xend-relocation-hosts-allow '^localhost$ ^.*\.example\.org$')
 #
 #(xend-relocation-hosts-allow '')
-(xend-relocation-hosts-allow '^localhost$')
+(xend-relocation-hosts-allow '^localhost$ ^localhost\.localdomain$')
 
 # The limit (in kilobytes) on the size of the console buffer
 #(console-limit 1024)
diff -r bfc69471550e -r 54550e85f25a tools/examples/xmexample.hvm
--- a/tools/examples/xmexample.hvm      Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/examples/xmexample.hvm      Wed Aug 09 08:34:06 2006 -0600
@@ -66,7 +66,7 @@ vif = [ 'type=ioemu, bridge=xenbr0' ]
 # and MODE is r for read-only, w for read-write.
 
 #disk = [ 'phy:hda1,hda1,r' ]
-disk = [ 'file:/var/images/min-el3-i386.img,ioemu:hda,w' ]
+disk = [ 'file:/var/images/min-el3-i386.img,hda,w', ',hdc:cdrom,r' ]
 
 #----------------------------------------------------------------------------
 # Configure the behaviour when a domain exits.  There are three 'reasons'
@@ -111,10 +111,6 @@ device_model = '/usr/' + arch_libdir + '
 device_model = '/usr/' + arch_libdir + '/xen/bin/qemu-dm'
 
 #-----------------------------------------------------------------------------
-# Disk image for 
-#cdrom=
-
-#-----------------------------------------------------------------------------
 # boot on floppy (a), hard disk (c) or CD-ROM (d) 
 #boot=[a|c|d]
 #-----------------------------------------------------------------------------
@@ -153,8 +149,8 @@ serial='pty'
 
 
 #-----------------------------------------------------------------------------
-#   enable audio support
-#audio=1
+#   enable sound card support, [sb16|es1370|all|..,..], default none
+#soundhw='sb16'
 
 
 #-----------------------------------------------------------------------------
diff -r bfc69471550e -r 54550e85f25a tools/firmware/acpi/acpi_dsdt.asl
--- a/tools/firmware/acpi/acpi_dsdt.asl Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/firmware/acpi/acpi_dsdt.asl Wed Aug 09 08:34:06 2006 -0600
@@ -16,7 +16,7 @@
 //* Place - Suite 330, Boston, MA 02111-1307 USA.
 
 //**
-//**           DSDT for Xen with Qemu device model
+//**  DSDT for Xen with Qemu device model
 //**
 //**
 
@@ -50,21 +50,36 @@ DefinitionBlock ("DSDT.aml", "DSDT", 1, 
     })
 
 
-       Name(PICD, 0)   
-
-       Method(_PIC, 1) { 
+    Name(PICD, 0)
+
+    Method(_PIC, 1) { 
  
-               Store(Arg0, PICD) 
-       }
+    Store(Arg0, PICD) 
+    }
     Scope (\_SB)
     {
-        Device (PCI0)
+       /* Fix HCT test for 0x400 pci memory - need to report low 640 MB mem as 
motherboard resource            */
+
+       Device(MEM0) {
+           Name(_HID, EISAID("PNP0C02"))
+           Name(_CRS, ResourceTemplate() {
+           QWordMemory (ResourceConsumer, PosDecode, MinFixed, MaxFixed, 
Cacheable, ReadWrite,
+                    0x00000000,
+                    0x00000000,
+                    0x0009ffff,
+                    0x00000000,
+                    0x000a0000)
+           }
+           )
+       }
+
+       Device (PCI0)
         {
-            Name (_HID, EisaId ("PNP0A03"))
-            Name (_UID, 0x00)
-            Name (_ADR, 0x00)
-            Name (_BBN, 0x00)
-            OperationRegion (PIRP, PCI_Config, 0x3c, 0x10)
+           Name (_HID, EisaId ("PNP0A03"))
+           Name (_UID, 0x00)
+           Name (_ADR, 0x00)
+           Name (_BBN, 0x00)
+           OperationRegion (PIRP, PCI_Config, 0x3c, 0x10)
            Field(PIRP, ByteAcc, NoLock, Preserve){        
           IRQ3,3,
           IRQ5,5,
@@ -79,7 +94,7 @@ DefinitionBlock ("DSDT.aml", "DSDT", 1, 
           
                Name (PRT0, ResourceTemplate ()
                 {
-                                       /* bus number is from 0 - 255*/
+         /* bus number is from 0 - 255*/
                     WordBusNumber (ResourceConsumer, MinFixed, MaxFixed, 
SubDecode,
                         0x0000,
                         0x0000,
@@ -122,7 +137,7 @@ DefinitionBlock ("DSDT.aml", "DSDT", 1, 
                         0x00000000,
                         0x00030000)
 
-                 /* reserve what device model consumed for PCI VGA device      
  */
+                /* reserve what device model consumed for PCI VGA device       
 */
 
                     DWordMemory (ResourceConsumer, PosDecode, MinFixed, 
MaxFixed, Cacheable, ReadWrite,
                         0x00000000,
@@ -146,9 +161,9 @@ DefinitionBlock ("DSDT.aml", "DSDT", 1, 
                 })
                 Return (PRT0)
             }
-       Name(BUFA, ResourceTemplate() {
+       Name(BUFA, ResourceTemplate() {
                 IRQ(Level, ActiveLow, Shared) {
-                        3,4,5,6,7,10,11,12,14,15}               
+                        3,4,5,6,7,10,11,12,14,15} 
                 }) 
 
                 Name(BUFB, Buffer(){
@@ -156,7 +171,7 @@ DefinitionBlock ("DSDT.aml", "DSDT", 1, 
                 0x79, 0})
 
                 CreateWordField(BUFB, 0x01, IRQV)
-               
+
                 Name(BUFC, Buffer(){
                 5, 7, 10, 11
                  })
@@ -165,17 +180,17 @@ DefinitionBlock ("DSDT.aml", "DSDT", 1, 
                 CreateByteField(BUFC, 0x01, PIQB)
                 CreateByteField(BUFC, 0x01, PIQC)
                 CreateByteField(BUFC, 0x01, PIQD)
-                               
-               Device(LNKA)    {
-                Name(_HID, EISAID("PNP0C0F"))  // PCI interrupt link
+                
+                Device(LNKA)    {
+                Name(_HID, EISAID("PNP0C0F")) // PCI interrupt link
                 Name(_UID, 1)
                 Method(_STA, 0) {
                                And(PIRA, 0x80, Local0)
                         If(LEqual(Local0, 0x80)) {
-                                Return(0x09)   
+                                Return(0x09)   
                                 }
                         Else {
-                                Return(0x0B)   
+                                Return(0x0B) 
                                 }
                         }
 
@@ -189,34 +204,34 @@ DefinitionBlock ("DSDT.aml", "DSDT", 1, 
                 }
 
                 Method(_CRS) {
-                        And(PIRB, 0x0f, Local0)                 
-                        ShiftLeft(0x1, Local0, IRQV)    
-                        Return(BUFB)                    
+                        And(PIRB, 0x0f, Local0) 
+                        ShiftLeft(0x1, Local0, IRQV) 
+                        Return(BUFB) 
                 } 
 
                 Method(_SRS, 1) {
-                                CreateWordField(ARG0, 0x01, IRQ1)       
-                        FindSetRightBit(IRQ1, Local0)           
-                        Decrement(Local0)                       
-                        Store(Local0, PIRA)                     
+                                CreateWordField(ARG0, 0x01, IRQ1) 
+                        FindSetRightBit(IRQ1, Local0) 
+                        Decrement(Local0) 
+                        Store(Local0, PIRA)
                  } // Method(_SRS)
         }
 
-        Device(LNKB)   {
-                Name(_HID, EISAID("PNP0C0F"))   
+        Device(LNKB){
+                Name(_HID, EISAID("PNP0C0F"))  
                 Name(_UID, 2)
                 Method(_STA, 0) {
                                And(PIRB, 0x80, Local0)
                         If(LEqual(Local0, 0x80)) {
-                                Return(0x09)    
+                                Return(0x09) 
                                 }
                         Else {
-                                Return(0x0B)    
+                                Return(0x0B) 
                                 }
                         }
 
                 Method(_PRS) {
-                                Return(BUFA)                    
+                                Return(BUFA) 
                 } // Method(_PRS)
 
                 Method(_DIS) {
@@ -225,35 +240,35 @@ DefinitionBlock ("DSDT.aml", "DSDT", 1, 
                 }
 
                 Method(_CRS) {
-                        And(PIRB, 0x0f, Local0)                 
-                        ShiftLeft(0x1, Local0, IRQV)    
-                        Return(BUFB)                    
+                        And(PIRB, 0x0f, Local0) 
+                        ShiftLeft(0x1, Local0, IRQV) 
+                        Return(BUFB) 
                 } // Method(_CRS)
 
                 Method(_SRS, 1) {
-                                CreateWordField(ARG0, 0x01, IRQ1)       
-                        FindSetRightBit(IRQ1, Local0)           
-                        Decrement(Local0)                       
-                        Store(Local0, PIRB)                     
+                        CreateWordField(ARG0, 0x01, IRQ1) 
+                        FindSetRightBit(IRQ1, Local0) 
+                        Decrement(Local0)
+                        Store(Local0, PIRB) 
                  } // Method(_SRS)
         }
 
-        Device(LNKC)   {
-                Name(_HID, EISAID("PNP0C0F"))  // PCI interrupt link
+        Device(LNKC){
+                Name(_HID, EISAID("PNP0C0F")) // PCI interrupt link
                 Name(_UID, 3)
                 Method(_STA, 0) {
-                               And(PIRC, 0x80, Local0)
+                        And(PIRC, 0x80, Local0)
                         If(LEqual(Local0, 0x80)) {
-                                Return(0x09)    
+                                Return(0x09) 
                         }
                         Else {
-                                Return(0x0B)    
-                        }
-                }
-
-                Method(_PRS) {                          
-                        Return(BUFA)                    
-                } // Method(_PRS)                       
+                                Return(0x0B)
+                        }
+                }
+
+                Method(_PRS) { 
+                        Return(BUFA)
+                } // Method(_PRS)
 
                 Method(_DIS) {
 
@@ -261,91 +276,89 @@ DefinitionBlock ("DSDT.aml", "DSDT", 1, 
                 }
 
                 Method(_CRS) {
-                        And(PIRC, 0x0f, Local0)                 
-                        ShiftLeft(0x1, Local0, IRQV)    
-                        Return(BUFB)                    
+                        And(PIRC, 0x0f, Local0) 
+                        ShiftLeft(0x1, Local0, IRQV) 
+                        Return(BUFB) 
                 } // Method(_CRS)
 
                 Method(_SRS, 1) {
-                                CreateWordField(ARG0, 0x01, IRQ1)       
-                        FindSetRightBit(IRQ1, Local0)           
-                        Decrement(Local0)                       
-                        Store(Local0, PIRC)                     
+                                CreateWordField(ARG0, 0x01, IRQ1) 
+                        FindSetRightBit(IRQ1, Local0) 
+                        Decrement(Local0) 
+                        Store(Local0, PIRC)
                  } // Method(_SRS)
         }
 
-        Device(LNKD)   {
-                Name(_HID, EISAID("PNP0C0F"))   
+        Device(LNKD) {
+                Name(_HID, EISAID("PNP0C0F"))  
                 Name(_UID, 4)
                 Method(_STA, 0) {
                                And(PIRD, 0x80, Local0)
                         If(LEqual(Local0, 0x80)) {
-                                Return(0x09)    
+                                Return(0x09) 
                         }
                         Else {
-                                Return(0x0B)    
-                        }
-                }
-
-                Method(_PRS) {                          
-                        Return(BUFA)                    
-                } // Method(_PRS)                       
+                                Return(0x0B) 
+                        }
+                }
+
+                Method(_PRS) { 
+                        Return(BUFA) 
+                } // Method(_PRS)
 
                 Method(_DIS) {
                                Or(PIRD, 0x80, PIRD)
                 }
 
                 Method(_CRS) {
-                        And(PIRD, 0x0f, Local0)                 
-                        ShiftLeft(0x1, Local0, IRQV)    
-                        Return(BUFB)                    
+                        And(PIRD, 0x0f, Local0) 
+                        ShiftLeft(0x1, Local0, IRQV) 
+                        Return(BUFB) 
                 } // Method(_CRS)
 
                 Method(_SRS, 1) {
-                                CreateWordField(ARG0, 0x01, IRQ1)       
-                        FindSetRightBit(IRQ1, Local0)           
-                        Decrement(Local0)                       
-                        Store(Local0, PIRD)                     
+                                CreateWordField(ARG0, 0x01, IRQ1) 
+                        FindSetRightBit(IRQ1, Local0) 
+                        Decrement(Local0) 
+                        Store(Local0, PIRD) 
                  } // Method(_SRS)
         }
         Method(_PRT,0) {
-                       If(PICD) {Return(PRTA)}  
-                       Return (PRTP)  
-               } // end _PRT
-               
-               
+               If(PICD) {Return(PRTA)}  
+               Return (PRTP)  
+               } // end _PRT
+
         Name(PRTP, Package(){
-                        Package(){0x0000ffff, 0, \_SB.PCI0.LNKA, 0},   // Slot 
1, INTA
-                        Package(){0x0000ffff, 1, \_SB.PCI0.LNKB, 0},   // Slot 
1, INTB
-                        Package(){0x0000ffff, 2, \_SB.PCI0.LNKC, 0},   // Slot 
1, INTC
-                        Package(){0x0000ffff, 3, \_SB.PCI0.LNKD, 0},   // Slot 
1, INTD
-
-                        Package(){0x0001ffff, 0, \_SB.PCI0.LNKB, 0},   // Slot 
2, INTB
-                        Package(){0x0001ffff, 1, \_SB.PCI0.LNKC, 0},   // Slot 
2, INTC
-                        Package(){0x0001ffff, 2, \_SB.PCI0.LNKD, 0},   // Slot 
2, INTD
-                        Package(){0x0001ffff, 3, \_SB.PCI0.LNKA, 0},   // Slot 
2, INTA
+                        Package(){0x0000ffff, 0, \_SB.PCI0.LNKA, 0}, // Slot 
1, INTA
+                        Package(){0x0000ffff, 1, \_SB.PCI0.LNKB, 0}, // Slot 
1, INTB
+                        Package(){0x0000ffff, 2, \_SB.PCI0.LNKC, 0}, // Slot 
1, INTC
+                        Package(){0x0000ffff, 3, \_SB.PCI0.LNKD, 0}, // Slot 
1, INTD
+
+                        Package(){0x0001ffff, 0, \_SB.PCI0.LNKB, 0}, // Slot 
2, INTB
+                        Package(){0x0001ffff, 1, \_SB.PCI0.LNKC, 0}, // Slot 
2, INTC
+                        Package(){0x0001ffff, 2, \_SB.PCI0.LNKD, 0}, // Slot 
2, INTD
+                        Package(){0x0001ffff, 3, \_SB.PCI0.LNKA, 0}, // Slot 
2, INTA
                         
-                        Package(){0x0002ffff, 0, \_SB.PCI0.LNKC, 0},   // Slot 
3, INTC
-                        Package(){0x0002ffff, 1, \_SB.PCI0.LNKD, 0},   // Slot 
3, INTD
-                        Package(){0x0002ffff, 2, \_SB.PCI0.LNKA, 0},   // Slot 
3, INTA
-                        Package(){0x0002ffff, 3, \_SB.PCI0.LNKB, 0},   // Slot 
3, INTB
+                        Package(){0x0002ffff, 0, \_SB.PCI0.LNKC, 0}, // Slot 
3, INTC
+                        Package(){0x0002ffff, 1, \_SB.PCI0.LNKD, 0}, // Slot 
3, INTD
+                        Package(){0x0002ffff, 2, \_SB.PCI0.LNKA, 0}, // Slot 
3, INTA
+                        Package(){0x0002ffff, 3, \_SB.PCI0.LNKB, 0}, // Slot 
3, INTB
                         
-                        Package(){0x0003ffff, 0, \_SB.PCI0.LNKD, 0},   // Slot 
2, INTD
-                        Package(){0x0003ffff, 1, \_SB.PCI0.LNKA, 0},   // Slot 
2, INTA
-                        Package(){0x0003ffff, 2, \_SB.PCI0.LNKB, 0},   // Slot 
2, INTB
-                        Package(){0x0003ffff, 3, \_SB.PCI0.LNKC, 0},   // Slot 
2, INTC
+                        Package(){0x0003ffff, 0, \_SB.PCI0.LNKD, 0}, // Slot 
2, INTD
+                        Package(){0x0003ffff, 1, \_SB.PCI0.LNKA, 0}, // Slot 
2, INTA
+                        Package(){0x0003ffff, 2, \_SB.PCI0.LNKB, 0}, // Slot 
2, INTB
+                        Package(){0x0003ffff, 3, \_SB.PCI0.LNKC, 0}, // Slot 
2, INTC
                         
                         }
             )
-       Name(PRTA, Package(){
-                        Package(){0x0001ffff, 0, 0, 5},        // Device 1, 
INTA
-
-                        Package(){0x0002ffff, 0, 0, 7},        // Device 2, 
INTA
+        Name(PRTA, Package(){
+                        Package(){0x0001ffff, 0, 0, 5}, // Device 1, INTA
+
+                        Package(){0x0002ffff, 0, 0, 7},  // Device 2, INTA
                        
-                        Package(){0x0003ffff, 0, 0, 10},       // Device 3, 
INTA
-
-                        Package(){0x0003ffff, 0, 0, 11},       // Device 4, 
INTA
-                                   
+                        Package(){0x0003ffff, 0, 0, 10}, // Device 3, INTA
+
+                        Package(){0x0004ffff, 0, 0, 11},  // Device 4, INTA    
                            
                         
                         }
             )
@@ -354,22 +367,22 @@ DefinitionBlock ("DSDT.aml", "DSDT", 1, 
             {
                 Name (_ADR, 0x00000000) /* device id, PCI bus num, ... */
  
-               OperationRegion(PIRQ, PCI_Config, 0x60, 0x4)
+            OperationRegion(PIRQ, PCI_Config, 0x60, 0x4)
                         Scope(\) {
-                                Field (\_SB.PCI0.ISA.PIRQ, ByteAcc, NoLock, 
Preserve) {
+                                 Field (\_SB.PCI0.ISA.PIRQ, ByteAcc, NoLock, 
Preserve) {
                                         PIRA, 8,
                                         PIRB, 8,
                                         PIRC, 8,
                                         PIRD, 8
                                         }
-                                }
+                                 }
                 Device (SYSR)
                 {
                     Name (_HID, EisaId ("PNP0C02"))
                     Name (_UID, 0x01)
                     Name (CRS, ResourceTemplate ()
                     {
-                                               /* TODO: list hidden resources 
*/
+               /* TODO: list hidden resources */
                         IO (Decode16, 0x0010, 0x0010, 0x00, 0x10)
                         IO (Decode16, 0x0022, 0x0022, 0x00, 0x0C)
                         IO (Decode16, 0x0030, 0x0030, 0x00, 0x10)
@@ -417,7 +430,7 @@ DefinitionBlock ("DSDT.aml", "DSDT", 1, 
                         IO (Decode16, 0x0089, 0x0089, 0x00, 0x03)
                         IO (Decode16, 0x008F, 0x008F, 0x00, 0x01)
                         IO (Decode16, 0x00C0, 0x00C0, 0x00, 0x20)
-                                               IO (Decode16, 0x0480, 0x0480, 
0x00, 0x10)
+                        IO (Decode16, 0x0480, 0x0480, 0x00, 0x10)
                     })
                 }
 
diff -r bfc69471550e -r 54550e85f25a tools/firmware/acpi/acpi_dsdt.c
--- a/tools/firmware/acpi/acpi_dsdt.c   Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/firmware/acpi/acpi_dsdt.c   Wed Aug 09 08:34:06 2006 -0600
@@ -5,15 +5,15 @@
  * Copyright (C) 2000 - 2005 Intel Corporation
  * Supports ACPI Specification Revision 3.0
  * 
- * Compilation of "acpi_dsdt.asl" - Mon Jun 12 22:33:41 2006
+ * Compilation of "acpi_dsdt.asl" - Thu Aug  3 11:05:15 2006
  * 
  * C source code output
  *
  */
 unsigned char AmlCode[] = 
 {
-    0x44,0x53,0x44,0x54,0xC3,0x08,0x00,0x00,  /* 00000000    "DSDT...." */
-    0x01,0x0C,0x49,0x4E,0x54,0x45,0x4C,0x00,  /* 00000008    "..INTEL." */
+    0x44,0x53,0x44,0x54,0x0E,0x09,0x00,0x00,  /* 00000000    "DSDT...." */
+    0x01,0x03,0x49,0x4E,0x54,0x45,0x4C,0x00,  /* 00000008    "..INTEL." */
     0x69,0x6E,0x74,0x2D,0x78,0x65,0x6E,0x00,  /* 00000010    "int-xen." */
     0xD6,0x07,0x00,0x00,0x49,0x4E,0x54,0x4C,  /* 00000018    "....INTL" */
     0x13,0x05,0x05,0x20,0x08,0x50,0x4D,0x42,  /* 00000020    "... .PMB" */
@@ -34,264 +34,273 @@ unsigned char AmlCode[] =
     0x12,0x08,0x04,0x0A,0x07,0x0A,0x07,0x00,  /* 00000098    "........" */
     0x00,0x08,0x50,0x49,0x43,0x44,0x00,0x14,  /* 000000A0    "..PICD.." */
     0x0C,0x5F,0x50,0x49,0x43,0x01,0x70,0x68,  /* 000000A8    "._PIC.ph" */
-    0x50,0x49,0x43,0x44,0x10,0x4E,0x80,0x5F,  /* 000000B0    "PICD.N._" */
-    0x53,0x42,0x5F,0x5B,0x82,0x46,0x80,0x50,  /* 000000B8    "SB_[.F.P" */
-    0x43,0x49,0x30,0x08,0x5F,0x48,0x49,0x44,  /* 000000C0    "CI0._HID" */
-    0x0C,0x41,0xD0,0x0A,0x03,0x08,0x5F,0x55,  /* 000000C8    ".A...._U" */
-    0x49,0x44,0x00,0x08,0x5F,0x41,0x44,0x52,  /* 000000D0    "ID.._ADR" */
-    0x00,0x08,0x5F,0x42,0x42,0x4E,0x00,0x5B,  /* 000000D8    ".._BBN.[" */
-    0x80,0x50,0x49,0x52,0x50,0x02,0x0A,0x3C,  /* 000000E0    ".PIRP..<" */
-    0x0A,0x10,0x5B,0x81,0x24,0x50,0x49,0x52,  /* 000000E8    "..[.$PIR" */
-    0x50,0x01,0x49,0x52,0x51,0x33,0x03,0x49,  /* 000000F0    "P.IRQ3.I" */
-    0x52,0x51,0x35,0x05,0x49,0x52,0x51,0x37,  /* 000000F8    "RQ5.IRQ7" */
-    0x07,0x49,0x52,0x51,0x39,0x09,0x49,0x52,  /* 00000100    ".IRQ9.IR" */
-    0x51,0x41,0x0A,0x49,0x52,0x51,0x42,0x0B,  /* 00000108    "QA.IRQB." */
-    0x14,0x48,0x0D,0x5F,0x43,0x52,0x53,0x00,  /* 00000110    ".H._CRS." */
-    0x08,0x50,0x52,0x54,0x30,0x11,0x46,0x0C,  /* 00000118    ".PRT0.F." */
-    0x0A,0xC2,0x88,0x0D,0x00,0x02,0x0F,0x00,  /* 00000120    "........" */
-    0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,  /* 00000128    "........" */
-    0x00,0x01,0x47,0x01,0xF8,0x0C,0xF8,0x0C,  /* 00000130    "..G....." */
-    0x01,0x08,0x88,0x0D,0x00,0x01,0x0C,0x03,  /* 00000138    "........" */
-    0x00,0x00,0x00,0x00,0xF7,0x0C,0x00,0x00,  /* 00000140    "........" */
-    0xF8,0x0C,0x88,0x0D,0x00,0x01,0x0C,0x03,  /* 00000148    "........" */
-    0x00,0x00,0x00,0x0D,0xFF,0x0F,0x00,0x00,  /* 00000150    "........" */
-    0x00,0x03,0x88,0x0D,0x00,0x01,0x0D,0x03,  /* 00000158    "........" */
-    0x00,0x00,0x00,0xC0,0x1F,0xC0,0x00,0x00,  /* 00000160    "........" */
-    0x20,0x00,0x88,0x0D,0x00,0x01,0x0D,0x03,  /* 00000168    " ......." */
-    0x00,0x00,0x20,0xC0,0x3F,0xC0,0x00,0x00,  /* 00000170    ".. .?..." */
-    0x10,0x00,0x87,0x17,0x00,0x00,0x0C,0x02,  /* 00000178    "........" */
-    0x00,0x00,0x00,0x00,0x00,0x00,0x0C,0x00,  /* 00000180    "........" */
-    0xFF,0xFF,0x0F,0x00,0x00,0x00,0x00,0x00,  /* 00000188    "........" */
-    0x00,0x00,0x03,0x00,0x87,0x17,0x00,0x00,  /* 00000190    "........" */
-    0x0D,0x03,0x00,0x00,0x00,0x00,0x00,0x00,  /* 00000198    "........" */
-    0x00,0xF0,0xFF,0xFF,0xFF,0xF1,0x00,0x00,  /* 000001A0    "........" */
-    0x00,0x00,0x00,0x00,0x00,0x02,0x87,0x17,  /* 000001A8    "........" */
-    0x00,0x00,0x0D,0x03,0x00,0x00,0x00,0x00,  /* 000001B0    "........" */
-    0x00,0x00,0x00,0xF2,0xFF,0x0F,0x00,0xF2,  /* 000001B8    "........" */
-    0x00,0x00,0x00,0x00,0x00,0x10,0x00,0x00,  /* 000001C0    "........" */
-    0x87,0x17,0x00,0x00,0x0D,0x03,0x00,0x00,  /* 000001C8    "........" */
-    0x00,0x00,0x00,0x10,0x00,0xF2,0x1F,0x10,  /* 000001D0    "........" */
-    0x00,0xF2,0x00,0x00,0x00,0x00,0x20,0x00,  /* 000001D8    "...... ." */
-    0x00,0x00,0x79,0x00,0xA4,0x50,0x52,0x54,  /* 000001E0    "..y..PRT" */
-    0x30,0x08,0x42,0x55,0x46,0x41,0x11,0x09,  /* 000001E8    "0.BUFA.." */
-    0x0A,0x06,0x23,0xF8,0xDC,0x18,0x79,0x00,  /* 000001F0    "..#...y." */
-    0x08,0x42,0x55,0x46,0x42,0x11,0x09,0x0A,  /* 000001F8    ".BUFB..." */
-    0x06,0x23,0x00,0x00,0x18,0x79,0x00,0x8B,  /* 00000200    ".#...y.." */
-    0x42,0x55,0x46,0x42,0x01,0x49,0x52,0x51,  /* 00000208    "BUFB.IRQ" */
-    0x56,0x08,0x42,0x55,0x46,0x43,0x11,0x07,  /* 00000210    "V.BUFC.." */
-    0x0A,0x04,0x05,0x07,0x0A,0x0B,0x8C,0x42,  /* 00000218    ".......B" */
-    0x55,0x46,0x43,0x01,0x50,0x49,0x51,0x41,  /* 00000220    "UFC.PIQA" */
-    0x8C,0x42,0x55,0x46,0x43,0x01,0x50,0x49,  /* 00000228    ".BUFC.PI" */
-    0x51,0x42,0x8C,0x42,0x55,0x46,0x43,0x01,  /* 00000230    "QB.BUFC." */
-    0x50,0x49,0x51,0x43,0x8C,0x42,0x55,0x46,  /* 00000238    "PIQC.BUF" */
-    0x43,0x01,0x50,0x49,0x51,0x44,0x5B,0x82,  /* 00000240    "C.PIQD[." */
-    0x48,0x08,0x4C,0x4E,0x4B,0x41,0x08,0x5F,  /* 00000248    "H.LNKA._" */
-    0x48,0x49,0x44,0x0C,0x41,0xD0,0x0C,0x0F,  /* 00000250    "HID.A..." */
-    0x08,0x5F,0x55,0x49,0x44,0x01,0x14,0x1C,  /* 00000258    "._UID..." */
-    0x5F,0x53,0x54,0x41,0x00,0x7B,0x50,0x49,  /* 00000260    "_STA.{PI" */
-    0x52,0x41,0x0A,0x80,0x60,0xA0,0x08,0x93,  /* 00000268    "RA..`..." */
-    0x60,0x0A,0x80,0xA4,0x0A,0x09,0xA1,0x04,  /* 00000270    "`......." */
-    0xA4,0x0A,0x0B,0x14,0x0B,0x5F,0x50,0x52,  /* 00000278    "....._PR" */
-    0x53,0x00,0xA4,0x42,0x55,0x46,0x41,0x14,  /* 00000280    "S..BUFA." */
-    0x11,0x5F,0x44,0x49,0x53,0x00,0x7D,0x50,  /* 00000288    "._DIS.}P" */
-    0x49,0x52,0x41,0x0A,0x80,0x50,0x49,0x52,  /* 00000290    "IRA..PIR" */
-    0x41,0x14,0x1A,0x5F,0x43,0x52,0x53,0x00,  /* 00000298    "A.._CRS." */
-    0x7B,0x50,0x49,0x52,0x42,0x0A,0x0F,0x60,  /* 000002A0    "{PIRB..`" */
-    0x79,0x01,0x60,0x49,0x52,0x51,0x56,0xA4,  /* 000002A8    "y.`IRQV." */
-    0x42,0x55,0x46,0x42,0x14,0x1B,0x5F,0x53,  /* 000002B0    "BUFB.._S" */
-    0x52,0x53,0x01,0x8B,0x68,0x01,0x49,0x52,  /* 000002B8    "RS..h.IR" */
-    0x51,0x31,0x82,0x49,0x52,0x51,0x31,0x60,  /* 000002C0    "Q1.IRQ1`" */
-    0x76,0x60,0x70,0x60,0x50,0x49,0x52,0x41,  /* 000002C8    "v`p`PIRA" */
-    0x5B,0x82,0x49,0x08,0x4C,0x4E,0x4B,0x42,  /* 000002D0    "[.I.LNKB" */
-    0x08,0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0,  /* 000002D8    "._HID.A." */
-    0x0C,0x0F,0x08,0x5F,0x55,0x49,0x44,0x0A,  /* 000002E0    "..._UID." */
-    0x02,0x14,0x1C,0x5F,0x53,0x54,0x41,0x00,  /* 000002E8    "..._STA." */
-    0x7B,0x50,0x49,0x52,0x42,0x0A,0x80,0x60,  /* 000002F0    "{PIRB..`" */
-    0xA0,0x08,0x93,0x60,0x0A,0x80,0xA4,0x0A,  /* 000002F8    "...`...." */
-    0x09,0xA1,0x04,0xA4,0x0A,0x0B,0x14,0x0B,  /* 00000300    "........" */
-    0x5F,0x50,0x52,0x53,0x00,0xA4,0x42,0x55,  /* 00000308    "_PRS..BU" */
-    0x46,0x41,0x14,0x11,0x5F,0x44,0x49,0x53,  /* 00000310    "FA.._DIS" */
-    0x00,0x7D,0x50,0x49,0x52,0x42,0x0A,0x80,  /* 00000318    ".}PIRB.." */
-    0x50,0x49,0x52,0x42,0x14,0x1A,0x5F,0x43,  /* 00000320    "PIRB.._C" */
-    0x52,0x53,0x00,0x7B,0x50,0x49,0x52,0x42,  /* 00000328    "RS.{PIRB" */
-    0x0A,0x0F,0x60,0x79,0x01,0x60,0x49,0x52,  /* 00000330    "..`y.`IR" */
-    0x51,0x56,0xA4,0x42,0x55,0x46,0x42,0x14,  /* 00000338    "QV.BUFB." */
-    0x1B,0x5F,0x53,0x52,0x53,0x01,0x8B,0x68,  /* 00000340    "._SRS..h" */
-    0x01,0x49,0x52,0x51,0x31,0x82,0x49,0x52,  /* 00000348    ".IRQ1.IR" */
-    0x51,0x31,0x60,0x76,0x60,0x70,0x60,0x50,  /* 00000350    "Q1`v`p`P" */
-    0x49,0x52,0x42,0x5B,0x82,0x49,0x08,0x4C,  /* 00000358    "IRB[.I.L" */
-    0x4E,0x4B,0x43,0x08,0x5F,0x48,0x49,0x44,  /* 00000360    "NKC._HID" */
-    0x0C,0x41,0xD0,0x0C,0x0F,0x08,0x5F,0x55,  /* 00000368    ".A...._U" */
-    0x49,0x44,0x0A,0x03,0x14,0x1C,0x5F,0x53,  /* 00000370    "ID...._S" */
-    0x54,0x41,0x00,0x7B,0x50,0x49,0x52,0x43,  /* 00000378    "TA.{PIRC" */
-    0x0A,0x80,0x60,0xA0,0x08,0x93,0x60,0x0A,  /* 00000380    "..`...`." */
-    0x80,0xA4,0x0A,0x09,0xA1,0x04,0xA4,0x0A,  /* 00000388    "........" */
-    0x0B,0x14,0x0B,0x5F,0x50,0x52,0x53,0x00,  /* 00000390    "..._PRS." */
-    0xA4,0x42,0x55,0x46,0x41,0x14,0x11,0x5F,  /* 00000398    ".BUFA.._" */
-    0x44,0x49,0x53,0x00,0x7D,0x50,0x49,0x52,  /* 000003A0    "DIS.}PIR" */
-    0x43,0x0A,0x80,0x50,0x49,0x52,0x43,0x14,  /* 000003A8    "C..PIRC." */
-    0x1A,0x5F,0x43,0x52,0x53,0x00,0x7B,0x50,  /* 000003B0    "._CRS.{P" */
-    0x49,0x52,0x43,0x0A,0x0F,0x60,0x79,0x01,  /* 000003B8    "IRC..`y." */
-    0x60,0x49,0x52,0x51,0x56,0xA4,0x42,0x55,  /* 000003C0    "`IRQV.BU" */
-    0x46,0x42,0x14,0x1B,0x5F,0x53,0x52,0x53,  /* 000003C8    "FB.._SRS" */
-    0x01,0x8B,0x68,0x01,0x49,0x52,0x51,0x31,  /* 000003D0    "..h.IRQ1" */
-    0x82,0x49,0x52,0x51,0x31,0x60,0x76,0x60,  /* 000003D8    ".IRQ1`v`" */
-    0x70,0x60,0x50,0x49,0x52,0x43,0x5B,0x82,  /* 000003E0    "p`PIRC[." */
-    0x49,0x08,0x4C,0x4E,0x4B,0x44,0x08,0x5F,  /* 000003E8    "I.LNKD._" */
-    0x48,0x49,0x44,0x0C,0x41,0xD0,0x0C,0x0F,  /* 000003F0    "HID.A..." */
-    0x08,0x5F,0x55,0x49,0x44,0x0A,0x04,0x14,  /* 000003F8    "._UID..." */
-    0x1C,0x5F,0x53,0x54,0x41,0x00,0x7B,0x50,  /* 00000400    "._STA.{P" */
-    0x49,0x52,0x44,0x0A,0x80,0x60,0xA0,0x08,  /* 00000408    "IRD..`.." */
-    0x93,0x60,0x0A,0x80,0xA4,0x0A,0x09,0xA1,  /* 00000410    ".`......" */
-    0x04,0xA4,0x0A,0x0B,0x14,0x0B,0x5F,0x50,  /* 00000418    "......_P" */
-    0x52,0x53,0x00,0xA4,0x42,0x55,0x46,0x41,  /* 00000420    "RS..BUFA" */
-    0x14,0x11,0x5F,0x44,0x49,0x53,0x00,0x7D,  /* 00000428    ".._DIS.}" */
-    0x50,0x49,0x52,0x44,0x0A,0x80,0x50,0x49,  /* 00000430    "PIRD..PI" */
-    0x52,0x44,0x14,0x1A,0x5F,0x43,0x52,0x53,  /* 00000438    "RD.._CRS" */
-    0x00,0x7B,0x50,0x49,0x52,0x44,0x0A,0x0F,  /* 00000440    ".{PIRD.." */
-    0x60,0x79,0x01,0x60,0x49,0x52,0x51,0x56,  /* 00000448    "`y.`IRQV" */
-    0xA4,0x42,0x55,0x46,0x42,0x14,0x1B,0x5F,  /* 00000450    ".BUFB.._" */
-    0x53,0x52,0x53,0x01,0x8B,0x68,0x01,0x49,  /* 00000458    "SRS..h.I" */
-    0x52,0x51,0x31,0x82,0x49,0x52,0x51,0x31,  /* 00000460    "RQ1.IRQ1" */
-    0x60,0x76,0x60,0x70,0x60,0x50,0x49,0x52,  /* 00000468    "`v`p`PIR" */
-    0x44,0x14,0x16,0x5F,0x50,0x52,0x54,0x00,  /* 00000470    "D.._PRT." */
-    0xA0,0x0A,0x50,0x49,0x43,0x44,0xA4,0x50,  /* 00000478    "..PICD.P" */
-    0x52,0x54,0x41,0xA4,0x50,0x52,0x54,0x50,  /* 00000480    "RTA.PRTP" */
-    0x08,0x50,0x52,0x54,0x50,0x12,0x43,0x0E,  /* 00000488    ".PRTP.C." */
-    0x10,0x12,0x0B,0x04,0x0B,0xFF,0xFF,0x00,  /* 00000490    "........" */
-    0x4C,0x4E,0x4B,0x41,0x00,0x12,0x0B,0x04,  /* 00000498    "LNKA...." */
-    0x0B,0xFF,0xFF,0x01,0x4C,0x4E,0x4B,0x42,  /* 000004A0    "....LNKB" */
-    0x00,0x12,0x0C,0x04,0x0B,0xFF,0xFF,0x0A,  /* 000004A8    "........" */
-    0x02,0x4C,0x4E,0x4B,0x43,0x00,0x12,0x0C,  /* 000004B0    ".LNKC..." */
-    0x04,0x0B,0xFF,0xFF,0x0A,0x03,0x4C,0x4E,  /* 000004B8    "......LN" */
-    0x4B,0x44,0x00,0x12,0x0D,0x04,0x0C,0xFF,  /* 000004C0    "KD......" */
-    0xFF,0x01,0x00,0x00,0x4C,0x4E,0x4B,0x42,  /* 000004C8    "....LNKB" */
-    0x00,0x12,0x0D,0x04,0x0C,0xFF,0xFF,0x01,  /* 000004D0    "........" */
-    0x00,0x01,0x4C,0x4E,0x4B,0x43,0x00,0x12,  /* 000004D8    "..LNKC.." */
-    0x0E,0x04,0x0C,0xFF,0xFF,0x01,0x00,0x0A,  /* 000004E0    "........" */
-    0x02,0x4C,0x4E,0x4B,0x44,0x00,0x12,0x0E,  /* 000004E8    ".LNKD..." */
-    0x04,0x0C,0xFF,0xFF,0x01,0x00,0x0A,0x03,  /* 000004F0    "........" */
-    0x4C,0x4E,0x4B,0x41,0x00,0x12,0x0D,0x04,  /* 000004F8    "LNKA...." */
-    0x0C,0xFF,0xFF,0x02,0x00,0x00,0x4C,0x4E,  /* 00000500    "......LN" */
-    0x4B,0x43,0x00,0x12,0x0D,0x04,0x0C,0xFF,  /* 00000508    "KC......" */
-    0xFF,0x02,0x00,0x01,0x4C,0x4E,0x4B,0x44,  /* 00000510    "....LNKD" */
-    0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x02,  /* 00000518    "........" */
-    0x00,0x0A,0x02,0x4C,0x4E,0x4B,0x41,0x00,  /* 00000520    "...LNKA." */
-    0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x02,0x00,  /* 00000528    "........" */
-    0x0A,0x03,0x4C,0x4E,0x4B,0x42,0x00,0x12,  /* 00000530    "..LNKB.." */
-    0x0D,0x04,0x0C,0xFF,0xFF,0x03,0x00,0x00,  /* 00000538    "........" */
-    0x4C,0x4E,0x4B,0x44,0x00,0x12,0x0D,0x04,  /* 00000540    "LNKD...." */
-    0x0C,0xFF,0xFF,0x03,0x00,0x01,0x4C,0x4E,  /* 00000548    "......LN" */
-    0x4B,0x41,0x00,0x12,0x0E,0x04,0x0C,0xFF,  /* 00000550    "KA......" */
-    0xFF,0x03,0x00,0x0A,0x02,0x4C,0x4E,0x4B,  /* 00000558    ".....LNK" */
-    0x42,0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF,  /* 00000560    "B......." */
-    0x03,0x00,0x0A,0x03,0x4C,0x4E,0x4B,0x43,  /* 00000568    "....LNKC" */
-    0x00,0x08,0x50,0x52,0x54,0x41,0x12,0x32,  /* 00000570    "..PRTA.2" */
-    0x04,0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x01,  /* 00000578    "........" */
-    0x00,0x00,0x00,0x0A,0x05,0x12,0x0B,0x04,  /* 00000580    "........" */
-    0x0C,0xFF,0xFF,0x02,0x00,0x00,0x00,0x0A,  /* 00000588    "........" */
-    0x07,0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x03,  /* 00000590    "........" */
-    0x00,0x00,0x00,0x0A,0x0A,0x12,0x0B,0x04,  /* 00000598    "........" */
-    0x0C,0xFF,0xFF,0x03,0x00,0x00,0x00,0x0A,  /* 000005A0    "........" */
-    0x0B,0x5B,0x82,0x48,0x31,0x49,0x53,0x41,  /* 000005A8    ".[.H1ISA" */
-    0x5F,0x08,0x5F,0x41,0x44,0x52,0x00,0x5B,  /* 000005B0    "_._ADR.[" */
-    0x80,0x50,0x49,0x52,0x51,0x02,0x0A,0x60,  /* 000005B8    ".PIRQ..`" */
-    0x0A,0x04,0x10,0x2E,0x5C,0x00,0x5B,0x81,  /* 000005C0    "....\.[." */
-    0x29,0x5C,0x2F,0x04,0x5F,0x53,0x42,0x5F,  /* 000005C8    ")\/._SB_" */
-    0x50,0x43,0x49,0x30,0x49,0x53,0x41,0x5F,  /* 000005D0    "PCI0ISA_" */
-    0x50,0x49,0x52,0x51,0x01,0x50,0x49,0x52,  /* 000005D8    "PIRQ.PIR" */
-    0x41,0x08,0x50,0x49,0x52,0x42,0x08,0x50,  /* 000005E0    "A.PIRB.P" */
-    0x49,0x52,0x43,0x08,0x50,0x49,0x52,0x44,  /* 000005E8    "IRC.PIRD" */
-    0x08,0x5B,0x82,0x46,0x0B,0x53,0x59,0x53,  /* 000005F0    ".[.F.SYS" */
-    0x52,0x08,0x5F,0x48,0x49,0x44,0x0C,0x41,  /* 000005F8    "R._HID.A" */
-    0xD0,0x0C,0x02,0x08,0x5F,0x55,0x49,0x44,  /* 00000600    "...._UID" */
-    0x01,0x08,0x43,0x52,0x53,0x5F,0x11,0x4E,  /* 00000608    "..CRS_.N" */
-    0x08,0x0A,0x8A,0x47,0x01,0x10,0x00,0x10,  /* 00000610    "...G...." */
-    0x00,0x00,0x10,0x47,0x01,0x22,0x00,0x22,  /* 00000618    "...G."."" */
-    0x00,0x00,0x0C,0x47,0x01,0x30,0x00,0x30,  /* 00000620    "...G.0.0" */
-    0x00,0x00,0x10,0x47,0x01,0x44,0x00,0x44,  /* 00000628    "...G.D.D" */
-    0x00,0x00,0x1C,0x47,0x01,0x62,0x00,0x62,  /* 00000630    "...G.b.b" */
-    0x00,0x00,0x02,0x47,0x01,0x65,0x00,0x65,  /* 00000638    "...G.e.e" */
-    0x00,0x00,0x0B,0x47,0x01,0x72,0x00,0x72,  /* 00000640    "...G.r.r" */
-    0x00,0x00,0x0E,0x47,0x01,0x80,0x00,0x80,  /* 00000648    "...G...." */
-    0x00,0x00,0x01,0x47,0x01,0x84,0x00,0x84,  /* 00000650    "...G...." */
-    0x00,0x00,0x03,0x47,0x01,0x88,0x00,0x88,  /* 00000658    "...G...." */
-    0x00,0x00,0x01,0x47,0x01,0x8C,0x00,0x8C,  /* 00000660    "...G...." */
-    0x00,0x00,0x03,0x47,0x01,0x90,0x00,0x90,  /* 00000668    "...G...." */
-    0x00,0x00,0x10,0x47,0x01,0xA2,0x00,0xA2,  /* 00000670    "...G...." */
-    0x00,0x00,0x1C,0x47,0x01,0xE0,0x00,0xE0,  /* 00000678    "...G...." */
-    0x00,0x00,0x10,0x47,0x01,0xA0,0x08,0xA0,  /* 00000680    "...G...." */
-    0x08,0x00,0x04,0x47,0x01,0xC0,0x0C,0xC0,  /* 00000688    "...G...." */
-    0x0C,0x00,0x10,0x47,0x01,0xD0,0x04,0xD0,  /* 00000690    "...G...." */
-    0x04,0x00,0x02,0x79,0x00,0x14,0x0B,0x5F,  /* 00000698    "...y..._" */
-    0x43,0x52,0x53,0x00,0xA4,0x43,0x52,0x53,  /* 000006A0    "CRS..CRS" */
-    0x5F,0x5B,0x82,0x2B,0x50,0x49,0x43,0x5F,  /* 000006A8    "_[.+PIC_" */
-    0x08,0x5F,0x48,0x49,0x44,0x0B,0x41,0xD0,  /* 000006B0    "._HID.A." */
-    0x08,0x5F,0x43,0x52,0x53,0x11,0x18,0x0A,  /* 000006B8    "._CRS..." */
-    0x15,0x47,0x01,0x20,0x00,0x20,0x00,0x01,  /* 000006C0    ".G. . .." */
-    0x02,0x47,0x01,0xA0,0x00,0xA0,0x00,0x01,  /* 000006C8    ".G......" */
-    0x02,0x22,0x04,0x00,0x79,0x00,0x5B,0x82,  /* 000006D0    "."..y.[." */
-    0x47,0x05,0x44,0x4D,0x41,0x30,0x08,0x5F,  /* 000006D8    "G.DMA0._" */
-    0x48,0x49,0x44,0x0C,0x41,0xD0,0x02,0x00,  /* 000006E0    "HID.A..." */
-    0x08,0x5F,0x43,0x52,0x53,0x11,0x41,0x04,  /* 000006E8    "._CRS.A." */
-    0x0A,0x3D,0x2A,0x10,0x04,0x47,0x01,0x00,  /* 000006F0    ".=*..G.." */
-    0x00,0x00,0x00,0x00,0x10,0x47,0x01,0x81,  /* 000006F8    ".....G.." */
-    0x00,0x81,0x00,0x00,0x03,0x47,0x01,0x87,  /* 00000700    ".....G.." */
-    0x00,0x87,0x00,0x00,0x01,0x47,0x01,0x89,  /* 00000708    ".....G.." */
-    0x00,0x89,0x00,0x00,0x03,0x47,0x01,0x8F,  /* 00000710    ".....G.." */
-    0x00,0x8F,0x00,0x00,0x01,0x47,0x01,0xC0,  /* 00000718    ".....G.." */
-    0x00,0xC0,0x00,0x00,0x20,0x47,0x01,0x80,  /* 00000720    ".... G.." */
-    0x04,0x80,0x04,0x00,0x10,0x79,0x00,0x5B,  /* 00000728    ".....y.[" */
-    0x82,0x25,0x54,0x4D,0x52,0x5F,0x08,0x5F,  /* 00000730    ".%TMR_._" */
-    0x48,0x49,0x44,0x0C,0x41,0xD0,0x01,0x00,  /* 00000738    "HID.A..." */
-    0x08,0x5F,0x43,0x52,0x53,0x11,0x10,0x0A,  /* 00000740    "._CRS..." */
-    0x0D,0x47,0x01,0x40,0x00,0x40,0x00,0x00,  /* 00000748    ".G.@.@.." */
-    0x04,0x22,0x01,0x00,0x79,0x00,0x5B,0x82,  /* 00000750    "."..y.[." */
-    0x25,0x52,0x54,0x43,0x5F,0x08,0x5F,0x48,  /* 00000758    "%RTC_._H" */
-    0x49,0x44,0x0C,0x41,0xD0,0x0B,0x00,0x08,  /* 00000760    "ID.A...." */
-    0x5F,0x43,0x52,0x53,0x11,0x10,0x0A,0x0D,  /* 00000768    "_CRS...." */
-    0x47,0x01,0x70,0x00,0x70,0x00,0x00,0x02,  /* 00000770    "G.p.p..." */
-    0x22,0x00,0x01,0x79,0x00,0x5B,0x82,0x22,  /* 00000778    ""..y.[."" */
-    0x53,0x50,0x4B,0x52,0x08,0x5F,0x48,0x49,  /* 00000780    "SPKR._HI" */
-    0x44,0x0C,0x41,0xD0,0x08,0x00,0x08,0x5F,  /* 00000788    "D.A...._" */
-    0x43,0x52,0x53,0x11,0x0D,0x0A,0x0A,0x47,  /* 00000790    "CRS....G" */
-    0x01,0x61,0x00,0x61,0x00,0x00,0x01,0x79,  /* 00000798    ".a.a...y" */
-    0x00,0x5B,0x82,0x31,0x50,0x53,0x32,0x4D,  /* 000007A0    ".[.1PS2M" */
+    0x50,0x49,0x43,0x44,0x10,0x49,0x85,0x5F,  /* 000000B0    "PICD.I._" */
+    0x53,0x42,0x5F,0x5B,0x82,0x49,0x04,0x4D,  /* 000000B8    "SB_[.I.M" */
+    0x45,0x4D,0x30,0x08,0x5F,0x48,0x49,0x44,  /* 000000C0    "EM0._HID" */
+    0x0C,0x41,0xD0,0x0C,0x02,0x08,0x5F,0x43,  /* 000000C8    ".A...._C" */
+    0x52,0x53,0x11,0x33,0x0A,0x30,0x8A,0x2B,  /* 000000D0    "RS.3.0.+" */
+    0x00,0x00,0x0D,0x03,0x00,0x00,0x00,0x00,  /* 000000D8    "........" */
+    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  /* 000000E0    "........" */
+    0x00,0x00,0x00,0x00,0xFF,0xFF,0x09,0x00,  /* 000000E8    "........" */
+    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  /* 000000F0    "........" */
+    0x00,0x00,0x00,0x00,0x00,0x00,0x0A,0x00,  /* 000000F8    "........" */
+    0x00,0x00,0x00,0x00,0x79,0x00,0x5B,0x82,  /* 00000100    "....y.[." */
+    0x46,0x80,0x50,0x43,0x49,0x30,0x08,0x5F,  /* 00000108    "F.PCI0._" */
+    0x48,0x49,0x44,0x0C,0x41,0xD0,0x0A,0x03,  /* 00000110    "HID.A..." */
+    0x08,0x5F,0x55,0x49,0x44,0x00,0x08,0x5F,  /* 00000118    "._UID.._" */
+    0x41,0x44,0x52,0x00,0x08,0x5F,0x42,0x42,  /* 00000120    "ADR.._BB" */
+    0x4E,0x00,0x5B,0x80,0x50,0x49,0x52,0x50,  /* 00000128    "N.[.PIRP" */
+    0x02,0x0A,0x3C,0x0A,0x10,0x5B,0x81,0x24,  /* 00000130    "..<..[.$" */
+    0x50,0x49,0x52,0x50,0x01,0x49,0x52,0x51,  /* 00000138    "PIRP.IRQ" */
+    0x33,0x03,0x49,0x52,0x51,0x35,0x05,0x49,  /* 00000140    "3.IRQ5.I" */
+    0x52,0x51,0x37,0x07,0x49,0x52,0x51,0x39,  /* 00000148    "RQ7.IRQ9" */
+    0x09,0x49,0x52,0x51,0x41,0x0A,0x49,0x52,  /* 00000150    ".IRQA.IR" */
+    0x51,0x42,0x0B,0x14,0x48,0x0D,0x5F,0x43,  /* 00000158    "QB..H._C" */
+    0x52,0x53,0x00,0x08,0x50,0x52,0x54,0x30,  /* 00000160    "RS..PRT0" */
+    0x11,0x46,0x0C,0x0A,0xC2,0x88,0x0D,0x00,  /* 00000168    ".F......" */
+    0x02,0x0F,0x00,0x00,0x00,0x00,0x00,0xFF,  /* 00000170    "........" */
+    0x00,0x00,0x00,0x00,0x01,0x47,0x01,0xF8,  /* 00000178    ".....G.." */
+    0x0C,0xF8,0x0C,0x01,0x08,0x88,0x0D,0x00,  /* 00000180    "........" */
+    0x01,0x0C,0x03,0x00,0x00,0x00,0x00,0xF7,  /* 00000188    "........" */
+    0x0C,0x00,0x00,0xF8,0x0C,0x88,0x0D,0x00,  /* 00000190    "........" */
+    0x01,0x0C,0x03,0x00,0x00,0x00,0x0D,0xFF,  /* 00000198    "........" */
+    0x0F,0x00,0x00,0x00,0x03,0x88,0x0D,0x00,  /* 000001A0    "........" */
+    0x01,0x0D,0x03,0x00,0x00,0x00,0xC0,0x1F,  /* 000001A8    "........" */
+    0xC0,0x00,0x00,0x20,0x00,0x88,0x0D,0x00,  /* 000001B0    "... ...." */
+    0x01,0x0D,0x03,0x00,0x00,0x20,0xC0,0x3F,  /* 000001B8    "..... .?" */
+    0xC0,0x00,0x00,0x10,0x00,0x87,0x17,0x00,  /* 000001C0    "........" */
+    0x00,0x0C,0x02,0x00,0x00,0x00,0x00,0x00,  /* 000001C8    "........" */
+    0x00,0x0C,0x00,0xFF,0xFF,0x0F,0x00,0x00,  /* 000001D0    "........" */
+    0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x87,  /* 000001D8    "........" */
+    0x17,0x00,0x00,0x0D,0x03,0x00,0x00,0x00,  /* 000001E0    "........" */
+    0x00,0x00,0x00,0x00,0xF0,0xFF,0xFF,0xFF,  /* 000001E8    "........" */
+    0xF1,0x00,0x00,0x00,0x00,0x00,0x00,0x00,  /* 000001F0    "........" */
+    0x02,0x87,0x17,0x00,0x00,0x0D,0x03,0x00,  /* 000001F8    "........" */
+    0x00,0x00,0x00,0x00,0x00,0x00,0xF2,0xFF,  /* 00000200    "........" */
+    0x0F,0x00,0xF2,0x00,0x00,0x00,0x00,0x00,  /* 00000208    "........" */
+    0x10,0x00,0x00,0x87,0x17,0x00,0x00,0x0D,  /* 00000210    "........" */
+    0x03,0x00,0x00,0x00,0x00,0x00,0x10,0x00,  /* 00000218    "........" */
+    0xF2,0x1F,0x10,0x00,0xF2,0x00,0x00,0x00,  /* 00000220    "........" */
+    0x00,0x20,0x00,0x00,0x00,0x79,0x00,0xA4,  /* 00000228    ". ...y.." */
+    0x50,0x52,0x54,0x30,0x08,0x42,0x55,0x46,  /* 00000230    "PRT0.BUF" */
+    0x41,0x11,0x09,0x0A,0x06,0x23,0xF8,0xDC,  /* 00000238    "A....#.." */
+    0x18,0x79,0x00,0x08,0x42,0x55,0x46,0x42,  /* 00000240    ".y..BUFB" */
+    0x11,0x09,0x0A,0x06,0x23,0x00,0x00,0x18,  /* 00000248    "....#..." */
+    0x79,0x00,0x8B,0x42,0x55,0x46,0x42,0x01,  /* 00000250    "y..BUFB." */
+    0x49,0x52,0x51,0x56,0x08,0x42,0x55,0x46,  /* 00000258    "IRQV.BUF" */
+    0x43,0x11,0x07,0x0A,0x04,0x05,0x07,0x0A,  /* 00000260    "C......." */
+    0x0B,0x8C,0x42,0x55,0x46,0x43,0x01,0x50,  /* 00000268    "..BUFC.P" */
+    0x49,0x51,0x41,0x8C,0x42,0x55,0x46,0x43,  /* 00000270    "IQA.BUFC" */
+    0x01,0x50,0x49,0x51,0x42,0x8C,0x42,0x55,  /* 00000278    ".PIQB.BU" */
+    0x46,0x43,0x01,0x50,0x49,0x51,0x43,0x8C,  /* 00000280    "FC.PIQC." */
+    0x42,0x55,0x46,0x43,0x01,0x50,0x49,0x51,  /* 00000288    "BUFC.PIQ" */
+    0x44,0x5B,0x82,0x48,0x08,0x4C,0x4E,0x4B,  /* 00000290    "D[.H.LNK" */
+    0x41,0x08,0x5F,0x48,0x49,0x44,0x0C,0x41,  /* 00000298    "A._HID.A" */
+    0xD0,0x0C,0x0F,0x08,0x5F,0x55,0x49,0x44,  /* 000002A0    "...._UID" */
+    0x01,0x14,0x1C,0x5F,0x53,0x54,0x41,0x00,  /* 000002A8    "..._STA." */
+    0x7B,0x50,0x49,0x52,0x41,0x0A,0x80,0x60,  /* 000002B0    "{PIRA..`" */
+    0xA0,0x08,0x93,0x60,0x0A,0x80,0xA4,0x0A,  /* 000002B8    "...`...." */
+    0x09,0xA1,0x04,0xA4,0x0A,0x0B,0x14,0x0B,  /* 000002C0    "........" */
+    0x5F,0x50,0x52,0x53,0x00,0xA4,0x42,0x55,  /* 000002C8    "_PRS..BU" */
+    0x46,0x41,0x14,0x11,0x5F,0x44,0x49,0x53,  /* 000002D0    "FA.._DIS" */
+    0x00,0x7D,0x50,0x49,0x52,0x41,0x0A,0x80,  /* 000002D8    ".}PIRA.." */
+    0x50,0x49,0x52,0x41,0x14,0x1A,0x5F,0x43,  /* 000002E0    "PIRA.._C" */
+    0x52,0x53,0x00,0x7B,0x50,0x49,0x52,0x42,  /* 000002E8    "RS.{PIRB" */
+    0x0A,0x0F,0x60,0x79,0x01,0x60,0x49,0x52,  /* 000002F0    "..`y.`IR" */
+    0x51,0x56,0xA4,0x42,0x55,0x46,0x42,0x14,  /* 000002F8    "QV.BUFB." */
+    0x1B,0x5F,0x53,0x52,0x53,0x01,0x8B,0x68,  /* 00000300    "._SRS..h" */
+    0x01,0x49,0x52,0x51,0x31,0x82,0x49,0x52,  /* 00000308    ".IRQ1.IR" */
+    0x51,0x31,0x60,0x76,0x60,0x70,0x60,0x50,  /* 00000310    "Q1`v`p`P" */
+    0x49,0x52,0x41,0x5B,0x82,0x49,0x08,0x4C,  /* 00000318    "IRA[.I.L" */
+    0x4E,0x4B,0x42,0x08,0x5F,0x48,0x49,0x44,  /* 00000320    "NKB._HID" */
+    0x0C,0x41,0xD0,0x0C,0x0F,0x08,0x5F,0x55,  /* 00000328    ".A...._U" */
+    0x49,0x44,0x0A,0x02,0x14,0x1C,0x5F,0x53,  /* 00000330    "ID...._S" */
+    0x54,0x41,0x00,0x7B,0x50,0x49,0x52,0x42,  /* 00000338    "TA.{PIRB" */
+    0x0A,0x80,0x60,0xA0,0x08,0x93,0x60,0x0A,  /* 00000340    "..`...`." */
+    0x80,0xA4,0x0A,0x09,0xA1,0x04,0xA4,0x0A,  /* 00000348    "........" */
+    0x0B,0x14,0x0B,0x5F,0x50,0x52,0x53,0x00,  /* 00000350    "..._PRS." */
+    0xA4,0x42,0x55,0x46,0x41,0x14,0x11,0x5F,  /* 00000358    ".BUFA.._" */
+    0x44,0x49,0x53,0x00,0x7D,0x50,0x49,0x52,  /* 00000360    "DIS.}PIR" */
+    0x42,0x0A,0x80,0x50,0x49,0x52,0x42,0x14,  /* 00000368    "B..PIRB." */
+    0x1A,0x5F,0x43,0x52,0x53,0x00,0x7B,0x50,  /* 00000370    "._CRS.{P" */
+    0x49,0x52,0x42,0x0A,0x0F,0x60,0x79,0x01,  /* 00000378    "IRB..`y." */
+    0x60,0x49,0x52,0x51,0x56,0xA4,0x42,0x55,  /* 00000380    "`IRQV.BU" */
+    0x46,0x42,0x14,0x1B,0x5F,0x53,0x52,0x53,  /* 00000388    "FB.._SRS" */
+    0x01,0x8B,0x68,0x01,0x49,0x52,0x51,0x31,  /* 00000390    "..h.IRQ1" */
+    0x82,0x49,0x52,0x51,0x31,0x60,0x76,0x60,  /* 00000398    ".IRQ1`v`" */
+    0x70,0x60,0x50,0x49,0x52,0x42,0x5B,0x82,  /* 000003A0    "p`PIRB[." */
+    0x49,0x08,0x4C,0x4E,0x4B,0x43,0x08,0x5F,  /* 000003A8    "I.LNKC._" */
+    0x48,0x49,0x44,0x0C,0x41,0xD0,0x0C,0x0F,  /* 000003B0    "HID.A..." */
+    0x08,0x5F,0x55,0x49,0x44,0x0A,0x03,0x14,  /* 000003B8    "._UID..." */
+    0x1C,0x5F,0x53,0x54,0x41,0x00,0x7B,0x50,  /* 000003C0    "._STA.{P" */
+    0x49,0x52,0x43,0x0A,0x80,0x60,0xA0,0x08,  /* 000003C8    "IRC..`.." */
+    0x93,0x60,0x0A,0x80,0xA4,0x0A,0x09,0xA1,  /* 000003D0    ".`......" */
+    0x04,0xA4,0x0A,0x0B,0x14,0x0B,0x5F,0x50,  /* 000003D8    "......_P" */
+    0x52,0x53,0x00,0xA4,0x42,0x55,0x46,0x41,  /* 000003E0    "RS..BUFA" */
+    0x14,0x11,0x5F,0x44,0x49,0x53,0x00,0x7D,  /* 000003E8    ".._DIS.}" */
+    0x50,0x49,0x52,0x43,0x0A,0x80,0x50,0x49,  /* 000003F0    "PIRC..PI" */
+    0x52,0x43,0x14,0x1A,0x5F,0x43,0x52,0x53,  /* 000003F8    "RC.._CRS" */
+    0x00,0x7B,0x50,0x49,0x52,0x43,0x0A,0x0F,  /* 00000400    ".{PIRC.." */
+    0x60,0x79,0x01,0x60,0x49,0x52,0x51,0x56,  /* 00000408    "`y.`IRQV" */
+    0xA4,0x42,0x55,0x46,0x42,0x14,0x1B,0x5F,  /* 00000410    ".BUFB.._" */
+    0x53,0x52,0x53,0x01,0x8B,0x68,0x01,0x49,  /* 00000418    "SRS..h.I" */
+    0x52,0x51,0x31,0x82,0x49,0x52,0x51,0x31,  /* 00000420    "RQ1.IRQ1" */
+    0x60,0x76,0x60,0x70,0x60,0x50,0x49,0x52,  /* 00000428    "`v`p`PIR" */
+    0x43,0x5B,0x82,0x49,0x08,0x4C,0x4E,0x4B,  /* 00000430    "C[.I.LNK" */
+    0x44,0x08,0x5F,0x48,0x49,0x44,0x0C,0x41,  /* 00000438    "D._HID.A" */
+    0xD0,0x0C,0x0F,0x08,0x5F,0x55,0x49,0x44,  /* 00000440    "...._UID" */
+    0x0A,0x04,0x14,0x1C,0x5F,0x53,0x54,0x41,  /* 00000448    "...._STA" */
+    0x00,0x7B,0x50,0x49,0x52,0x44,0x0A,0x80,  /* 00000450    ".{PIRD.." */
+    0x60,0xA0,0x08,0x93,0x60,0x0A,0x80,0xA4,  /* 00000458    "`...`..." */
+    0x0A,0x09,0xA1,0x04,0xA4,0x0A,0x0B,0x14,  /* 00000460    "........" */
+    0x0B,0x5F,0x50,0x52,0x53,0x00,0xA4,0x42,  /* 00000468    "._PRS..B" */
+    0x55,0x46,0x41,0x14,0x11,0x5F,0x44,0x49,  /* 00000470    "UFA.._DI" */
+    0x53,0x00,0x7D,0x50,0x49,0x52,0x44,0x0A,  /* 00000478    "S.}PIRD." */
+    0x80,0x50,0x49,0x52,0x44,0x14,0x1A,0x5F,  /* 00000480    ".PIRD.._" */
+    0x43,0x52,0x53,0x00,0x7B,0x50,0x49,0x52,  /* 00000488    "CRS.{PIR" */
+    0x44,0x0A,0x0F,0x60,0x79,0x01,0x60,0x49,  /* 00000490    "D..`y.`I" */
+    0x52,0x51,0x56,0xA4,0x42,0x55,0x46,0x42,  /* 00000498    "RQV.BUFB" */
+    0x14,0x1B,0x5F,0x53,0x52,0x53,0x01,0x8B,  /* 000004A0    ".._SRS.." */
+    0x68,0x01,0x49,0x52,0x51,0x31,0x82,0x49,  /* 000004A8    "h.IRQ1.I" */
+    0x52,0x51,0x31,0x60,0x76,0x60,0x70,0x60,  /* 000004B0    "RQ1`v`p`" */
+    0x50,0x49,0x52,0x44,0x14,0x16,0x5F,0x50,  /* 000004B8    "PIRD.._P" */
+    0x52,0x54,0x00,0xA0,0x0A,0x50,0x49,0x43,  /* 000004C0    "RT...PIC" */
+    0x44,0xA4,0x50,0x52,0x54,0x41,0xA4,0x50,  /* 000004C8    "D.PRTA.P" */
+    0x52,0x54,0x50,0x08,0x50,0x52,0x54,0x50,  /* 000004D0    "RTP.PRTP" */
+    0x12,0x43,0x0E,0x10,0x12,0x0B,0x04,0x0B,  /* 000004D8    ".C......" */
+    0xFF,0xFF,0x00,0x4C,0x4E,0x4B,0x41,0x00,  /* 000004E0    "...LNKA." */
+    0x12,0x0B,0x04,0x0B,0xFF,0xFF,0x01,0x4C,  /* 000004E8    ".......L" */
+    0x4E,0x4B,0x42,0x00,0x12,0x0C,0x04,0x0B,  /* 000004F0    "NKB....." */
+    0xFF,0xFF,0x0A,0x02,0x4C,0x4E,0x4B,0x43,  /* 000004F8    "....LNKC" */
+    0x00,0x12,0x0C,0x04,0x0B,0xFF,0xFF,0x0A,  /* 00000500    "........" */
+    0x03,0x4C,0x4E,0x4B,0x44,0x00,0x12,0x0D,  /* 00000508    ".LNKD..." */
+    0x04,0x0C,0xFF,0xFF,0x01,0x00,0x00,0x4C,  /* 00000510    ".......L" */
+    0x4E,0x4B,0x42,0x00,0x12,0x0D,0x04,0x0C,  /* 00000518    "NKB....." */
+    0xFF,0xFF,0x01,0x00,0x01,0x4C,0x4E,0x4B,  /* 00000520    ".....LNK" */
+    0x43,0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF,  /* 00000528    "C......." */
+    0x01,0x00,0x0A,0x02,0x4C,0x4E,0x4B,0x44,  /* 00000530    "....LNKD" */
+    0x00,0x12,0x0E,0x04,0x0C,0xFF,0xFF,0x01,  /* 00000538    "........" */
+    0x00,0x0A,0x03,0x4C,0x4E,0x4B,0x41,0x00,  /* 00000540    "...LNKA." */
+    0x12,0x0D,0x04,0x0C,0xFF,0xFF,0x02,0x00,  /* 00000548    "........" */
+    0x00,0x4C,0x4E,0x4B,0x43,0x00,0x12,0x0D,  /* 00000550    ".LNKC..." */
+    0x04,0x0C,0xFF,0xFF,0x02,0x00,0x01,0x4C,  /* 00000558    ".......L" */
+    0x4E,0x4B,0x44,0x00,0x12,0x0E,0x04,0x0C,  /* 00000560    "NKD....." */
+    0xFF,0xFF,0x02,0x00,0x0A,0x02,0x4C,0x4E,  /* 00000568    "......LN" */
+    0x4B,0x41,0x00,0x12,0x0E,0x04,0x0C,0xFF,  /* 00000570    "KA......" */
+    0xFF,0x02,0x00,0x0A,0x03,0x4C,0x4E,0x4B,  /* 00000578    ".....LNK" */
+    0x42,0x00,0x12,0x0D,0x04,0x0C,0xFF,0xFF,  /* 00000580    "B......." */
+    0x03,0x00,0x00,0x4C,0x4E,0x4B,0x44,0x00,  /* 00000588    "...LNKD." */
+    0x12,0x0D,0x04,0x0C,0xFF,0xFF,0x03,0x00,  /* 00000590    "........" */
+    0x01,0x4C,0x4E,0x4B,0x41,0x00,0x12,0x0E,  /* 00000598    ".LNKA..." */
+    0x04,0x0C,0xFF,0xFF,0x03,0x00,0x0A,0x02,  /* 000005A0    "........" */
+    0x4C,0x4E,0x4B,0x42,0x00,0x12,0x0E,0x04,  /* 000005A8    "LNKB...." */
+    0x0C,0xFF,0xFF,0x03,0x00,0x0A,0x03,0x4C,  /* 000005B0    ".......L" */
+    0x4E,0x4B,0x43,0x00,0x08,0x50,0x52,0x54,  /* 000005B8    "NKC..PRT" */
+    0x41,0x12,0x32,0x04,0x12,0x0B,0x04,0x0C,  /* 000005C0    "A.2....." */
+    0xFF,0xFF,0x01,0x00,0x00,0x00,0x0A,0x05,  /* 000005C8    "........" */
+    0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x02,0x00,  /* 000005D0    "........" */
+    0x00,0x00,0x0A,0x07,0x12,0x0B,0x04,0x0C,  /* 000005D8    "........" */
+    0xFF,0xFF,0x03,0x00,0x00,0x00,0x0A,0x0A,  /* 000005E0    "........" */
+    0x12,0x0B,0x04,0x0C,0xFF,0xFF,0x04,0x00,  /* 000005E8    "........" */
+    0x00,0x00,0x0A,0x0B,0x5B,0x82,0x48,0x31,  /* 000005F0    "....[.H1" */
+    0x49,0x53,0x41,0x5F,0x08,0x5F,0x41,0x44,  /* 000005F8    "ISA_._AD" */
+    0x52,0x00,0x5B,0x80,0x50,0x49,0x52,0x51,  /* 00000600    "R.[.PIRQ" */
+    0x02,0x0A,0x60,0x0A,0x04,0x10,0x2E,0x5C,  /* 00000608    "..`....\" */
+    0x00,0x5B,0x81,0x29,0x5C,0x2F,0x04,0x5F,  /* 00000610    ".[.)\/._" */
+    0x53,0x42,0x5F,0x50,0x43,0x49,0x30,0x49,  /* 00000618    "SB_PCI0I" */
+    0x53,0x41,0x5F,0x50,0x49,0x52,0x51,0x01,  /* 00000620    "SA_PIRQ." */
+    0x50,0x49,0x52,0x41,0x08,0x50,0x49,0x52,  /* 00000628    "PIRA.PIR" */
+    0x42,0x08,0x50,0x49,0x52,0x43,0x08,0x50,  /* 00000630    "B.PIRC.P" */
+    0x49,0x52,0x44,0x08,0x5B,0x82,0x46,0x0B,  /* 00000638    "IRD.[.F." */
+    0x53,0x59,0x53,0x52,0x08,0x5F,0x48,0x49,  /* 00000640    "SYSR._HI" */
+    0x44,0x0C,0x41,0xD0,0x0C,0x02,0x08,0x5F,  /* 00000648    "D.A...._" */
+    0x55,0x49,0x44,0x01,0x08,0x43,0x52,0x53,  /* 00000650    "UID..CRS" */
+    0x5F,0x11,0x4E,0x08,0x0A,0x8A,0x47,0x01,  /* 00000658    "_.N...G." */
+    0x10,0x00,0x10,0x00,0x00,0x10,0x47,0x01,  /* 00000660    "......G." */
+    0x22,0x00,0x22,0x00,0x00,0x0C,0x47,0x01,  /* 00000668    ""."...G." */
+    0x30,0x00,0x30,0x00,0x00,0x10,0x47,0x01,  /* 00000670    "0.0...G." */
+    0x44,0x00,0x44,0x00,0x00,0x1C,0x47,0x01,  /* 00000678    "D.D...G." */
+    0x62,0x00,0x62,0x00,0x00,0x02,0x47,0x01,  /* 00000680    "b.b...G." */
+    0x65,0x00,0x65,0x00,0x00,0x0B,0x47,0x01,  /* 00000688    "e.e...G." */
+    0x72,0x00,0x72,0x00,0x00,0x0E,0x47,0x01,  /* 00000690    "r.r...G." */
+    0x80,0x00,0x80,0x00,0x00,0x01,0x47,0x01,  /* 00000698    "......G." */
+    0x84,0x00,0x84,0x00,0x00,0x03,0x47,0x01,  /* 000006A0    "......G." */
+    0x88,0x00,0x88,0x00,0x00,0x01,0x47,0x01,  /* 000006A8    "......G." */
+    0x8C,0x00,0x8C,0x00,0x00,0x03,0x47,0x01,  /* 000006B0    "......G." */
+    0x90,0x00,0x90,0x00,0x00,0x10,0x47,0x01,  /* 000006B8    "......G." */
+    0xA2,0x00,0xA2,0x00,0x00,0x1C,0x47,0x01,  /* 000006C0    "......G." */
+    0xE0,0x00,0xE0,0x00,0x00,0x10,0x47,0x01,  /* 000006C8    "......G." */
+    0xA0,0x08,0xA0,0x08,0x00,0x04,0x47,0x01,  /* 000006D0    "......G." */
+    0xC0,0x0C,0xC0,0x0C,0x00,0x10,0x47,0x01,  /* 000006D8    "......G." */
+    0xD0,0x04,0xD0,0x04,0x00,0x02,0x79,0x00,  /* 000006E0    "......y." */
+    0x14,0x0B,0x5F,0x43,0x52,0x53,0x00,0xA4,  /* 000006E8    ".._CRS.." */
+    0x43,0x52,0x53,0x5F,0x5B,0x82,0x2B,0x50,  /* 000006F0    "CRS_[.+P" */
+    0x49,0x43,0x5F,0x08,0x5F,0x48,0x49,0x44,  /* 000006F8    "IC_._HID" */
+    0x0B,0x41,0xD0,0x08,0x5F,0x43,0x52,0x53,  /* 00000700    ".A.._CRS" */
+    0x11,0x18,0x0A,0x15,0x47,0x01,0x20,0x00,  /* 00000708    "....G. ." */
+    0x20,0x00,0x01,0x02,0x47,0x01,0xA0,0x00,  /* 00000710    " ...G..." */
+    0xA0,0x00,0x01,0x02,0x22,0x04,0x00,0x79,  /* 00000718    "...."..y" */
+    0x00,0x5B,0x82,0x47,0x05,0x44,0x4D,0x41,  /* 00000720    ".[.G.DMA" */
+    0x30,0x08,0x5F,0x48,0x49,0x44,0x0C,0x41,  /* 00000728    "0._HID.A" */
+    0xD0,0x02,0x00,0x08,0x5F,0x43,0x52,0x53,  /* 00000730    "...._CRS" */
+    0x11,0x41,0x04,0x0A,0x3D,0x2A,0x10,0x04,  /* 00000738    ".A..=*.." */
+    0x47,0x01,0x00,0x00,0x00,0x00,0x00,0x10,  /* 00000740    "G......." */
+    0x47,0x01,0x81,0x00,0x81,0x00,0x00,0x03,  /* 00000748    "G......." */
+    0x47,0x01,0x87,0x00,0x87,0x00,0x00,0x01,  /* 00000750    "G......." */
+    0x47,0x01,0x89,0x00,0x89,0x00,0x00,0x03,  /* 00000758    "G......." */
+    0x47,0x01,0x8F,0x00,0x8F,0x00,0x00,0x01,  /* 00000760    "G......." */
+    0x47,0x01,0xC0,0x00,0xC0,0x00,0x00,0x20,  /* 00000768    "G...... " */
+    0x47,0x01,0x80,0x04,0x80,0x04,0x00,0x10,  /* 00000770    "G......." */
+    0x79,0x00,0x5B,0x82,0x25,0x54,0x4D,0x52,  /* 00000778    "y.[.%TMR" */
+    0x5F,0x08,0x5F,0x48,0x49,0x44,0x0C,0x41,  /* 00000780    "_._HID.A" */
+    0xD0,0x01,0x00,0x08,0x5F,0x43,0x52,0x53,  /* 00000788    "...._CRS" */
+    0x11,0x10,0x0A,0x0D,0x47,0x01,0x40,0x00,  /* 00000790    "....G.@." */
+    0x40,0x00,0x00,0x04,0x22,0x01,0x00,0x79,  /* 00000798    "@..."..y" */
+    0x00,0x5B,0x82,0x25,0x52,0x54,0x43,0x5F,  /* 000007A0    ".[.%RTC_" */
     0x08,0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0,  /* 000007A8    "._HID.A." */
-    0x0F,0x13,0x08,0x5F,0x43,0x49,0x44,0x0C,  /* 000007B0    "..._CID." */
-    0x41,0xD0,0x0F,0x13,0x14,0x09,0x5F,0x53,  /* 000007B8    "A....._S" */
-    0x54,0x41,0x00,0xA4,0x0A,0x0F,0x08,0x5F,  /* 000007C0    "TA....._" */
-    0x43,0x52,0x53,0x11,0x08,0x0A,0x05,0x22,  /* 000007C8    "CRS...."" */
-    0x00,0x10,0x79,0x00,0x5B,0x82,0x42,0x04,  /* 000007D0    "..y.[.B." */
-    0x50,0x53,0x32,0x4B,0x08,0x5F,0x48,0x49,  /* 000007D8    "PS2K._HI" */
-    0x44,0x0C,0x41,0xD0,0x03,0x03,0x08,0x5F,  /* 000007E0    "D.A...._" */
-    0x43,0x49,0x44,0x0C,0x41,0xD0,0x03,0x0B,  /* 000007E8    "CID.A..." */
-    0x14,0x09,0x5F,0x53,0x54,0x41,0x00,0xA4,  /* 000007F0    ".._STA.." */
-    0x0A,0x0F,0x08,0x5F,0x43,0x52,0x53,0x11,  /* 000007F8    "..._CRS." */
-    0x18,0x0A,0x15,0x47,0x01,0x60,0x00,0x60,  /* 00000800    "...G.`.`" */
-    0x00,0x00,0x01,0x47,0x01,0x64,0x00,0x64,  /* 00000808    "...G.d.d" */
-    0x00,0x00,0x01,0x22,0x02,0x00,0x79,0x00,  /* 00000810    "..."..y." */
-    0x5B,0x82,0x3A,0x46,0x44,0x43,0x30,0x08,  /* 00000818    "[.:FDC0." */
-    0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0,0x07,  /* 00000820    "_HID.A.." */
-    0x00,0x14,0x09,0x5F,0x53,0x54,0x41,0x00,  /* 00000828    "..._STA." */
-    0xA4,0x0A,0x0F,0x08,0x5F,0x43,0x52,0x53,  /* 00000830    "...._CRS" */
-    0x11,0x1B,0x0A,0x18,0x47,0x01,0xF0,0x03,  /* 00000838    "....G..." */
-    0xF0,0x03,0x01,0x06,0x47,0x01,0xF7,0x03,  /* 00000840    "....G..." */
-    0xF7,0x03,0x01,0x01,0x22,0x40,0x00,0x2A,  /* 00000848    "...."@.*" */
-    0x04,0x00,0x79,0x00,0x5B,0x82,0x35,0x55,  /* 00000850    "..y.[.5U" */
-    0x41,0x52,0x31,0x08,0x5F,0x48,0x49,0x44,  /* 00000858    "AR1._HID" */
-    0x0C,0x41,0xD0,0x05,0x01,0x08,0x5F,0x55,  /* 00000860    ".A...._U" */
-    0x49,0x44,0x01,0x14,0x09,0x5F,0x53,0x54,  /* 00000868    "ID..._ST" */
-    0x41,0x00,0xA4,0x0A,0x0F,0x08,0x5F,0x43,  /* 00000870    "A....._C" */
-    0x52,0x53,0x11,0x10,0x0A,0x0D,0x47,0x01,  /* 00000878    "RS....G." */
-    0xF8,0x03,0xF8,0x03,0x01,0x08,0x22,0x10,  /* 00000880    "......"." */
-    0x00,0x79,0x00,0x5B,0x82,0x36,0x55,0x41,  /* 00000888    ".y.[.6UA" */
-    0x52,0x32,0x08,0x5F,0x48,0x49,0x44,0x0C,  /* 00000890    "R2._HID." */
-    0x41,0xD0,0x05,0x01,0x08,0x5F,0x55,0x49,  /* 00000898    "A...._UI" */
-    0x44,0x0A,0x02,0x14,0x09,0x5F,0x53,0x54,  /* 000008A0    "D...._ST" */
-    0x41,0x00,0xA4,0x0A,0x0F,0x08,0x5F,0x43,  /* 000008A8    "A....._C" */
-    0x52,0x53,0x11,0x10,0x0A,0x0D,0x47,0x01,  /* 000008B0    "RS....G." */
-    0xF8,0x02,0xF8,0x02,0x01,0x08,0x22,0x08,  /* 000008B8    "......"." */
-    0x00,0x79,0x00,
+    0x0B,0x00,0x08,0x5F,0x43,0x52,0x53,0x11,  /* 000007B0    "..._CRS." */
+    0x10,0x0A,0x0D,0x47,0x01,0x70,0x00,0x70,  /* 000007B8    "...G.p.p" */
+    0x00,0x00,0x02,0x22,0x00,0x01,0x79,0x00,  /* 000007C0    "..."..y." */
+    0x5B,0x82,0x22,0x53,0x50,0x4B,0x52,0x08,  /* 000007C8    "[."SPKR." */
+    0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0,0x08,  /* 000007D0    "_HID.A.." */
+    0x00,0x08,0x5F,0x43,0x52,0x53,0x11,0x0D,  /* 000007D8    ".._CRS.." */
+    0x0A,0x0A,0x47,0x01,0x61,0x00,0x61,0x00,  /* 000007E0    "..G.a.a." */
+    0x00,0x01,0x79,0x00,0x5B,0x82,0x31,0x50,  /* 000007E8    "..y.[.1P" */
+    0x53,0x32,0x4D,0x08,0x5F,0x48,0x49,0x44,  /* 000007F0    "S2M._HID" */
+    0x0C,0x41,0xD0,0x0F,0x13,0x08,0x5F,0x43,  /* 000007F8    ".A...._C" */
+    0x49,0x44,0x0C,0x41,0xD0,0x0F,0x13,0x14,  /* 00000800    "ID.A...." */
+    0x09,0x5F,0x53,0x54,0x41,0x00,0xA4,0x0A,  /* 00000808    "._STA..." */
+    0x0F,0x08,0x5F,0x43,0x52,0x53,0x11,0x08,  /* 00000810    ".._CRS.." */
+    0x0A,0x05,0x22,0x00,0x10,0x79,0x00,0x5B,  /* 00000818    ".."..y.[" */
+    0x82,0x42,0x04,0x50,0x53,0x32,0x4B,0x08,  /* 00000820    ".B.PS2K." */
+    0x5F,0x48,0x49,0x44,0x0C,0x41,0xD0,0x03,  /* 00000828    "_HID.A.." */
+    0x03,0x08,0x5F,0x43,0x49,0x44,0x0C,0x41,  /* 00000830    ".._CID.A" */
+    0xD0,0x03,0x0B,0x14,0x09,0x5F,0x53,0x54,  /* 00000838    "....._ST" */
+    0x41,0x00,0xA4,0x0A,0x0F,0x08,0x5F,0x43,  /* 00000840    "A....._C" */
+    0x52,0x53,0x11,0x18,0x0A,0x15,0x47,0x01,  /* 00000848    "RS....G." */
+    0x60,0x00,0x60,0x00,0x00,0x01,0x47,0x01,  /* 00000850    "`.`...G." */
+    0x64,0x00,0x64,0x00,0x00,0x01,0x22,0x02,  /* 00000858    "d.d..."." */
+    0x00,0x79,0x00,0x5B,0x82,0x3A,0x46,0x44,  /* 00000860    ".y.[.:FD" */
+    0x43,0x30,0x08,0x5F,0x48,0x49,0x44,0x0C,  /* 00000868    "C0._HID." */
+    0x41,0xD0,0x07,0x00,0x14,0x09,0x5F,0x53,  /* 00000870    "A....._S" */
+    0x54,0x41,0x00,0xA4,0x0A,0x0F,0x08,0x5F,  /* 00000878    "TA....._" */
+    0x43,0x52,0x53,0x11,0x1B,0x0A,0x18,0x47,  /* 00000880    "CRS....G" */
+    0x01,0xF0,0x03,0xF0,0x03,0x01,0x06,0x47,  /* 00000888    ".......G" */
+    0x01,0xF7,0x03,0xF7,0x03,0x01,0x01,0x22,  /* 00000890    "......."" */
+    0x40,0x00,0x2A,0x04,0x00,0x79,0x00,0x5B,  /* 00000898    "@.*..y.[" */
+    0x82,0x35,0x55,0x41,0x52,0x31,0x08,0x5F,  /* 000008A0    ".5UAR1._" */
+    0x48,0x49,0x44,0x0C,0x41,0xD0,0x05,0x01,  /* 000008A8    "HID.A..." */
+    0x08,0x5F,0x55,0x49,0x44,0x01,0x14,0x09,  /* 000008B0    "._UID..." */
+    0x5F,0x53,0x54,0x41,0x00,0xA4,0x0A,0x0F,  /* 000008B8    "_STA...." */
+    0x08,0x5F,0x43,0x52,0x53,0x11,0x10,0x0A,  /* 000008C0    "._CRS..." */
+    0x0D,0x47,0x01,0xF8,0x03,0xF8,0x03,0x01,  /* 000008C8    ".G......" */
+    0x08,0x22,0x10,0x00,0x79,0x00,0x5B,0x82,  /* 000008D0    "."..y.[." */
+    0x36,0x55,0x41,0x52,0x32,0x08,0x5F,0x48,  /* 000008D8    "6UAR2._H" */
+    0x49,0x44,0x0C,0x41,0xD0,0x05,0x01,0x08,  /* 000008E0    "ID.A...." */
+    0x5F,0x55,0x49,0x44,0x0A,0x02,0x14,0x09,  /* 000008E8    "_UID...." */
+    0x5F,0x53,0x54,0x41,0x00,0xA4,0x0A,0x0F,  /* 000008F0    "_STA...." */
+    0x08,0x5F,0x43,0x52,0x53,0x11,0x10,0x0A,  /* 000008F8    "._CRS..." */
+    0x0D,0x47,0x01,0xF8,0x02,0xF8,0x02,0x01,  /* 00000900    ".G......" */
+    0x08,0x22,0x08,0x00,0x79,0x00,
 };
 int DsdtLen=sizeof(AmlCode);
diff -r bfc69471550e -r 54550e85f25a tools/firmware/hvmloader/Makefile
--- a/tools/firmware/hvmloader/Makefile Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/firmware/hvmloader/Makefile Wed Aug 09 08:34:06 2006 -0600
@@ -42,12 +42,15 @@ CFLAGS  += $(DEFINES) -I. $(XENINC) -fno
 CFLAGS  += $(DEFINES) -I. $(XENINC) -fno-builtin -O2 -msoft-float
 LDFLAGS  = -m32 -nostdlib -Wl,-N -Wl,-Ttext -Wl,$(LOADADDR)
 
+SRCS = hvmloader.c acpi_madt.c mp_tables.c util.c
+OBJS = $(patsubst %.c,%.o,$(SRCS))
+
 .PHONY: all
 all: hvmloader
 
-hvmloader: roms.h hvmloader.c acpi_madt.c mp_tables.c
-       $(CC) $(CFLAGS) -c hvmloader.c acpi_madt.c mp_tables.c
-       $(CC) $(LDFLAGS) -o hvmloader.tmp hvmloader.o acpi_madt.o mp_tables.o
+hvmloader: roms.h $(SRCS)
+       $(CC) $(CFLAGS) -c $(SRCS)
+       $(CC) $(LDFLAGS) -o hvmloader.tmp $(OBJS)
        $(OBJCOPY) hvmloader.tmp hvmloader
        rm -f hvmloader.tmp
 
diff -r bfc69471550e -r 54550e85f25a tools/firmware/hvmloader/acpi_madt.c
--- a/tools/firmware/hvmloader/acpi_madt.c      Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/firmware/hvmloader/acpi_madt.c      Wed Aug 09 08:34:06 2006 -0600
@@ -20,12 +20,10 @@
 
 #include "../acpi/acpi2_0.h"
 #include "../acpi/acpi_madt.h"
-
+#include "util.h"
 #include <xen/hvm/hvm_info_table.h>
 
 #define NULL ((void*)0)
-
-extern int puts(const char *s);
 
 static struct hvm_info_table *table = NULL;
 
diff -r bfc69471550e -r 54550e85f25a tools/firmware/hvmloader/hvmloader.c
--- a/tools/firmware/hvmloader/hvmloader.c      Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/firmware/hvmloader/hvmloader.c      Wed Aug 09 08:34:06 2006 -0600
@@ -23,9 +23,13 @@
  */
 #include "roms.h"
 #include "../acpi/acpi2_0.h"  /* for ACPI_PHYSICAL_ADDRESS */
+#include "hypercall.h"
+#include "util.h"
+#include <xen/version.h>
 #include <xen/hvm/hvm_info_table.h>
 
 /* memory map */
+#define HYPERCALL_PHYSICAL_ADDRESS     0x00080000
 #define VGABIOS_PHYSICAL_ADDRESS       0x000C0000
 #define        VMXASSIST_PHYSICAL_ADDRESS      0x000D0000
 #define        ROMBIOS_PHYSICAL_ADDRESS        0x000F0000
@@ -75,65 +79,14 @@ extern void create_mp_tables(void);
 extern void create_mp_tables(void);
 struct hvm_info_table *get_hvm_info_table(void);
 
-static inline void
-outw(unsigned short addr, unsigned short val)
-{
-        __asm__ __volatile__ ("outw %%ax, %%dx" :: "d"(addr), "a"(val));
-}
-
-static inline void
-outb(unsigned short addr, unsigned char val)
-{
-        __asm__ __volatile__ ("outb %%al, %%dx" :: "d"(addr), "a"(val));
-}
-
-static inline unsigned char
-inb(unsigned short addr)
-{
-        unsigned char val;
-
-        __asm__ __volatile__ ("inb %w1,%0" : "=a" (val) : "Nd" (addr));
-        return val;
-}
-
-void *
-memcpy(void *dest, const void *src, unsigned n)
-{
-       int t0, t1, t2;
-
-       __asm__ __volatile__(
-               "cld\n"
-               "rep; movsl\n"
-               "testb $2,%b4\n"
-               "je 1f\n"
-               "movsw\n"
-               "1: testb $1,%b4\n"
-               "je 2f\n"
-               "movsb\n"
-               "2:"
-               : "=&c" (t0), "=&D" (t1), "=&S" (t2)
-               : "0" (n/4), "q" (n), "1" ((long) dest), "2" ((long) src)
-               : "memory"
-       );
-       return dest;
-}
-
-int
-puts(const char *s)
-{
-       while (*s)
-               outb(0xE9, *s++);
-       return 0;
-}
-
-int
+static int
 cirrus_check(void)
 {
        outw(0x3C4, 0x9206);
        return inb(0x3C5) == 0x12;
 }
 
-int
+static int
 vmmcall(int function, int edi, int esi, int edx, int ecx, int ebx)
 {
         int eax;
@@ -147,7 +100,7 @@ vmmcall(int function, int edi, int esi, 
         return eax;
 }
 
-int
+static int
 check_amd(void)
 {
        char id[12];
@@ -162,12 +115,68 @@ check_amd(void)
        return __builtin_memcmp(id, "AuthenticAMD", 12) == 0;
 }
 
+static void
+cpuid(uint32_t idx, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
+{
+       __asm__ __volatile__(
+               "cpuid"
+               : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx)
+               : "0" (idx) );
+}
+
+static void
+wrmsr(uint32_t idx, uint64_t v)
+{
+       __asm__ __volatile__(
+               "wrmsr"
+               : : "c" (idx), "a" ((uint32_t)v), "d" ((uint32_t)(v>>32)) );
+}
+
+static void
+init_hypercalls(void)
+{
+       uint32_t eax, ebx, ecx, edx;
+       unsigned long i;
+       char signature[13], number[13];
+       xen_extraversion_t extraversion;
+
+       cpuid(0x40000000, &eax, &ebx, &ecx, &edx);
+
+       *(uint32_t *)(signature + 0) = ebx;
+       *(uint32_t *)(signature + 4) = ecx;
+       *(uint32_t *)(signature + 8) = edx;
+       signature[12] = '\0';
+
+       if (strcmp("XenVMMXenVMM", signature) || (eax < 0x40000002)) {
+               puts("FATAL: Xen hypervisor not detected\n");
+               __asm__ __volatile__( "ud2" );
+       }
+
+       cpuid(0x40000001, &eax, &ebx, &ecx, &edx);
+
+       puts("Detected Xen v");
+       puts(itoa(number, eax >> 16));
+       puts(".");
+       puts(itoa(number, eax & 0xffff));
+
+       cpuid(0x40000002, &eax, &ebx, &ecx, &edx);
+
+       for (i = 0; i < eax; i++)
+               wrmsr(ebx, HYPERCALL_PHYSICAL_ADDRESS + (i << 12) + i);
+
+       hypercall_xen_version(XENVER_extraversion, extraversion);
+       puts(extraversion);
+       puts("\n");
+}
+
 int
 main(void)
 {
        struct hvm_info_table *t = get_hvm_info_table();
 
        puts("HVM Loader\n");
+
+       init_hypercalls();
 
        puts("Loading ROMBIOS ...\n");
        memcpy((void *)ROMBIOS_PHYSICAL_ADDRESS, rombios, sizeof(rombios));
diff -r bfc69471550e -r 54550e85f25a tools/firmware/hvmloader/mp_tables.c
--- a/tools/firmware/hvmloader/mp_tables.c      Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/firmware/hvmloader/mp_tables.c      Wed Aug 09 08:34:06 2006 -0600
@@ -93,7 +93,8 @@ typedef   signed long int64_t;
 
 #define INTR_MAX_NR            16
 
-extern int puts(const char *); /* for printing */
+#include "util.h"
+
 extern int get_vcpu_nr(void);  /* for the guest's VCPU count */
 
 /*
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/.CVS/Entries
--- a/tools/ioemu/.CVS/Entries  Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/.CVS/Entries  Wed Aug 09 08:34:06 2006 -0600
@@ -11,99 +11,99 @@ D/fpu////
 D/fpu////
 D/keymaps////
 D/target-mips////
-/.cvsignore/1.13/Thu May 25 18:22:25 2006//Trelease_0_8_1
-/COPYING/1.1/Wed May 17 14:47:01 2006//Trelease_0_8_1
-/COPYING.LIB/1.2/Wed May 17 14:47:01 2006//Trelease_0_8_1
-/Changelog/1.116/Thu May 25 18:22:25 2006//Trelease_0_8_1
-/LICENSE/1.2/Sat Feb 12 14:45:23 2005//Trelease_0_8_1
-/Makefile/1.99/Thu May 25 18:22:25 2006//Trelease_0_8_1
-/Makefile.target/1.107/Thu May 25 18:22:25 2006//Trelease_0_8_1
-/README/1.12/Wed May 24 10:40:08 2006//Trelease_0_8_1
-/README.distrib/1.2/Wed May 17 14:47:01 2006//Trelease_0_8_1
-/TODO/1.38/Thu May 25 18:22:25 2006//Trelease_0_8_1
-/VERSION/1.28/Thu May 25 18:22:25 2006//Trelease_0_8_1
-/a.out.h/1.2/Wed May 24 10:40:08 2006//Trelease_0_8_1
-/aes.c/1.1/Wed May 17 14:47:01 2006//Trelease_0_8_1
-/aes.h/1.1/Wed May 17 14:47:01 2006//Trelease_0_8_1
-/alpha-dis.c/1.3/Thu May 25 18:22:25 2006//Trelease_0_8_1
-/alpha.ld/1.1/Wed May 17 14:47:01 2006//Trelease_0_8_1
-/arm-dis.c/1.3/Wed May 24 10:40:08 2006//Trelease_0_8_1
-/arm.ld/1.1/Wed May 17 14:47:01 2006//Trelease_0_8_1
-/block-bochs.c/1.1/Tue Apr 26 21:34:00 2005//Trelease_0_8_1
-/block-cloop.c/1.3/Thu May 25 18:22:25 2006//Trelease_0_8_1
-/block-cow.c/1.5/Thu May 25 12:38:49 2006//Trelease_0_8_1
-/block-dmg.c/1.4/Thu May 25 18:22:25 2006//Trelease_0_8_1
-/block-qcow.c/1.6/Thu May 25 18:22:25 2006//Trelease_0_8_1
-/block-vmdk.c/1.7/Thu May 25 18:22:25 2006//Trelease_0_8_1
-/block-vpc.c/1.2/Thu May 25 12:38:49 2006//Trelease_0_8_1
-/block-vvfat.c/1.5/Thu May 25 18:22:25 2006//Trelease_0_8_1
-/block.c/1.26/Thu May 25 18:22:26 2006//Trelease_0_8_1
-/block_int.h/1.4/Thu May 25 18:22:26 2006//Trelease_0_8_1
-/bswap.h/1.5/Wed May 17 14:47:01 2006//Trelease_0_8_1
-/cocoa.m/1.8/Thu May 25 18:22:26 2006//Trelease_0_8_1
-/configure/1.100/Thu May 25 18:22:26 2006//Trelease_0_8_1
-/console.c/1.5/Thu May 25 18:22:26 2006//Trelease_0_8_1
-/cpu-all.h/1.54/Thu May 25 18:22:26 2006//Trelease_0_8_1
-/cpu-defs.h/1.15/Thu May 25 18:22:26 2006//Trelease_0_8_1
-/cpu-exec.c/1.78/Thu May 25 18:22:26 2006//Trelease_0_8_1
-/dis-asm.h/1.11/Thu May 25 18:22:26 2006//Trelease_0_8_1
-/disas.c/1.30/Thu May 25 18:22:26 2006//Trelease_0_8_1
-/disas.h/1.7/Thu May 25 18:22:26 2006//Trelease_0_8_1
-/dyngen-exec.h/1.27/Thu May 25 18:22:26 2006//Trelease_0_8_1
-/dyngen-op.h/1.1/Mon Jan  3 23:40:55 2005//Trelease_0_8_1
-/dyngen.c/1.42/Thu May 25 18:22:26 2006//Trelease_0_8_1
-/dyngen.h/1.10/Thu May 25 18:22:26 2006//Trelease_0_8_1
-/elf.h/1.6/Thu May 25 12:38:50 2006//Trelease_0_8_1
-/elf_ops.h/1.3/Tue May  2 20:54:12 2006//Trelease_0_8_1
-/exec-all.h/1.47/Thu May 25 18:22:26 2006//Trelease_0_8_1
-/exec.c/1.79/Thu May 25 18:22:26 2006//Trelease_0_8_1
-/gdbstub.c/1.36/Thu May 25 18:22:26 2006//Trelease_0_8_1
-/gdbstub.h/1.2/Tue Apr 26 20:42:36 2005//Trelease_0_8_1
-/i386-dis.c/1.5/Wed May 17 14:47:01 2006//Trelease_0_8_1
-/i386-vl.ld/1.3/Wed May 17 14:47:01 2006//Trelease_0_8_1
-/i386.ld/1.2/Wed May 17 14:47:01 2006//Trelease_0_8_1
-/ia64.ld/1.1/Thu Apr  7 22:20:28 2005//Trelease_0_8_1
-/keymaps.c/1.2/Thu May 25 18:22:26 2006//Trelease_0_8_1
-/kqemu.c/1.10/Thu May 25 18:22:26 2006//Trelease_0_8_1
-/kqemu.h/1.1/Wed Feb  8 22:39:17 2006//Trelease_0_8_1
-/linux-2.6.9-qemu-fast.patch/1.1/Wed Dec  8 23:48:11 2004//Trelease_0_8_1
-/loader.c/1.2/Wed Apr 26 22:05:26 2006//Trelease_0_8_1
-/m68k-dis.c/1.1/Sun Nov  6 16:52:11 2005//Trelease_0_8_1
-/m68k.ld/1.1/Wed May 17 14:47:01 2006//Trelease_0_8_1
-/mips-dis.c/1.3/Thu May 25 18:22:28 2006//Trelease_0_8_1
-/monitor.c/1.48/Thu May 25 18:22:28 2006//Trelease_0_8_1
-/osdep.c/1.10/Wed May 24 10:40:10 2006//Trelease_0_8_1
-/osdep.h/1.5/Wed May 24 10:40:10 2006//Trelease_0_8_1
-/ppc-dis.c/1.7/Thu May 25 12:38:51 2006//Trelease_0_8_1
-/ppc.ld/1.2/Thu May 25 12:38:51 2006//Trelease_0_8_1
-/qemu-binfmt-conf.sh/1.4/Thu May 25 18:22:28 2006//Trelease_0_8_1
-/qemu-doc.texi/1.87/Thu May 25 18:22:29 2006//Trelease_0_8_1
-/qemu-img.c/1.8/Thu May 25 12:38:51 2006//Trelease_0_8_1
-/qemu-img.texi/1.2/Thu May 25 12:38:51 2006//Trelease_0_8_1
-/qemu-tech.texi/1.9/Thu May 25 18:22:29 2006//Trelease_0_8_1
-/qemu_socket.h/1.1/Sun Apr 30 22:53:25 2006//Trelease_0_8_1
-/readline.c/1.1/Tue May 23 19:16:56 2006//Trelease_0_8_1
-/s390.ld/1.1/Wed May 17 14:47:01 2006//Trelease_0_8_1
-/sdl.c/1.26/Thu May 25 18:22:29 2006//Trelease_0_8_1
-/sdl_keysym.h/1.3/Tue Mar  1 21:43:41 2005//Trelease_0_8_1
-/sh4-dis.c/1.1/Thu Apr 27 21:05:14 2006//Trelease_0_8_1
-/softmmu_exec.h/1.1/Sun Oct 30 18:16:26 2005//Trelease_0_8_1
-/softmmu_header.h/1.13/Thu May 25 18:22:29 2006//Trelease_0_8_1
-/softmmu_template.h/1.16/Thu May 25 18:22:29 2006//Trelease_0_8_1
-/sparc-dis.c/1.2/Thu May 25 18:22:29 2006//Trelease_0_8_1
-/sparc.ld/1.1/Wed May 17 14:47:01 2006//Trelease_0_8_1
-/tap-win32.c/1.2/Sun Feb 19 12:40:00 2006//Trelease_0_8_1
-/texi2pod.pl/1.1/Wed May 17 14:47:02 2006//Trelease_0_8_1
-/thunk.c/1.6/Wed May 24 10:40:10 2006//Trelease_0_8_1
-/thunk.h/1.13/Wed May 17 14:47:02 2006//Trelease_0_8_1
-/translate-all.c/1.14/Thu May 25 18:22:29 2006//Trelease_0_8_1
-/translate-op.c/1.1/Sun Mar 13 16:53:06 2005//Trelease_0_8_1
-/usb-linux.c/1.4/Sat Mar 11 18:03:38 2006//Trelease_0_8_1
-/vgafont.h/1.1/Wed May 17 14:47:02 2006//Trelease_0_8_1
-/vl.c/1.184/Thu May 25 18:22:30 2006//Trelease_0_8_1
-/vl.h/1.116/Thu May 25 18:22:30 2006//Trelease_0_8_1
-/vnc.c/1.4/Mon May  1 21:44:22 2006//Trelease_0_8_1
-/vnc_keysym.h/1.1/Sun Apr 30 21:28:36 2006//Trelease_0_8_1
-/vnchextile.h/1.1/Sun Apr 30 21:28:36 2006//Trelease_0_8_1
-/x86_64.ld/1.1/Thu Jan  6 20:50:00 2005//Trelease_0_8_1
 D/target-sh4////
+/.cvsignore/1.14/Sun Aug  6 01:03:44 2006//Trelease_0_8_2
+/COPYING/1.1/Thu Jul 13 09:23:22 2006//Trelease_0_8_2
+/COPYING.LIB/1.2/Thu Jul 13 09:23:22 2006//Trelease_0_8_2
+/Changelog/1.121/Sun Aug  6 01:03:44 2006//Trelease_0_8_2
+/LICENSE/1.2/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/Makefile/1.104/Sun Aug  6 01:03:44 2006//Trelease_0_8_2
+/Makefile.target/1.121/Sun Aug  6 01:03:44 2006//Trelease_0_8_2
+/README/1.12/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/README.distrib/1.2/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/TODO/1.39/Sun Aug  6 01:03:44 2006//Trelease_0_8_2
+/VERSION/1.29/Sun Aug  6 01:03:44 2006//Trelease_0_8_2
+/a.out.h/1.2/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/aes.c/1.1/Thu Jul 13 09:23:22 2006//Trelease_0_8_2
+/aes.h/1.1/Thu Jul 13 09:23:22 2006//Trelease_0_8_2
+/alpha-dis.c/1.3/Sun Aug  6 01:03:45 2006//Trelease_0_8_2
+/alpha.ld/1.1/Sun Aug  6 01:03:45 2006//Trelease_0_8_2
+/arm-dis.c/1.3/Sun Aug  6 01:03:45 2006//Trelease_0_8_2
+/arm.ld/1.1/Sun Aug  6 01:03:45 2006//Trelease_0_8_2
+/block-bochs.c/1.1/Sun Aug  6 00:55:02 2006//Trelease_0_8_2
+/block-cloop.c/1.3/Sun Aug  6 00:55:02 2006//Trelease_0_8_2
+/block-cow.c/1.6/Sun Aug  6 01:03:45 2006//Trelease_0_8_2
+/block-dmg.c/1.4/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/block-qcow.c/1.7/Sun Aug  6 01:03:45 2006//Trelease_0_8_2
+/block-vmdk.c/1.8/Sun Aug  6 01:03:45 2006//Trelease_0_8_2
+/block-vpc.c/1.3/Sun Aug  6 01:03:45 2006//Trelease_0_8_2
+/block-vvfat.c/1.6/Sun Aug  6 01:03:45 2006//Trelease_0_8_2
+/block.c/1.28/Sun Aug  6 01:03:45 2006//Trelease_0_8_2
+/block_int.h/1.5/Sun Aug  6 01:03:45 2006//Trelease_0_8_2
+/bswap.h/1.5/Thu Jul 13 09:23:22 2006//Trelease_0_8_2
+/cocoa.m/1.10/Sun Aug  6 01:03:45 2006//Trelease_0_8_2
+/configure/1.110/Sun Aug  6 01:03:45 2006//Trelease_0_8_2
+/console.c/1.8/Sun Aug  6 01:03:45 2006//Trelease_0_8_2
+/cpu-all.h/1.57/Sun Aug  6 01:03:45 2006//Trelease_0_8_2
+/cpu-defs.h/1.16/Sun Aug  6 01:03:45 2006//Trelease_0_8_2
+/cpu-exec.c/1.83/Sun Aug  6 01:03:45 2006//Trelease_0_8_2
+/dis-asm.h/1.11/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/disas.c/1.31/Sun Aug  6 01:03:45 2006//Trelease_0_8_2
+/disas.h/1.7/Sun Aug  6 00:55:03 2006//Trelease_0_8_2
+/dyngen-exec.h/1.29/Sun Aug  6 01:03:45 2006//Trelease_0_8_2
+/dyngen-op.h/1.1/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/dyngen.c/1.45/Sun Aug  6 01:03:45 2006//Trelease_0_8_2
+/dyngen.h/1.11/Sun Aug  6 01:03:45 2006//Trelease_0_8_2
+/elf.h/1.7/Sun Aug  6 01:03:45 2006//Trelease_0_8_2
+/elf_ops.h/1.3/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/exec-all.h/1.48/Sun Aug  6 01:03:45 2006//Trelease_0_8_2
+/exec.c/1.82/Sun Aug  6 01:03:45 2006//Trelease_0_8_2
+/gdbstub.c/1.40/Sun Aug  6 01:03:45 2006//Trelease_0_8_2
+/gdbstub.h/1.2/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/i386-dis.c/1.5/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/i386-vl.ld/1.3/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/i386.ld/1.2/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/ia64.ld/1.1/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/keymaps.c/1.2/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/kqemu.c/1.12/Sun Aug  6 01:03:45 2006//Trelease_0_8_2
+/kqemu.h/1.1/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/linux-2.6.9-qemu-fast.patch/1.1/Sun Aug  6 01:03:45 2006//Trelease_0_8_2
+/loader.c/1.3/Sun Aug  6 01:03:45 2006//Trelease_0_8_2
+/m68k-dis.c/1.1/Sun Aug  6 01:03:46 2006//Trelease_0_8_2
+/m68k.ld/1.1/Sun Aug  6 01:03:46 2006//Trelease_0_8_2
+/mips-dis.c/1.4/Sun Aug  6 01:03:47 2006//Trelease_0_8_2
+/monitor.c/1.54/Sun Aug  6 01:03:47 2006//Trelease_0_8_2
+/osdep.c/1.11/Sun Aug  6 01:03:47 2006//Trelease_0_8_2
+/osdep.h/1.6/Sun Aug  6 01:03:47 2006//Trelease_0_8_2
+/ppc-dis.c/1.7/Sun Aug  6 01:03:48 2006//Trelease_0_8_2
+/ppc.ld/1.2/Sun Aug  6 01:03:48 2006//Trelease_0_8_2
+/qemu-binfmt-conf.sh/1.4/Fri Jul 14 12:43:46 2006//Trelease_0_8_2
+/qemu-doc.texi/1.100/Sun Aug  6 01:03:48 2006//Trelease_0_8_2
+/qemu-img.c/1.10/Sun Aug  6 01:03:48 2006//Trelease_0_8_2
+/qemu-img.texi/1.2/Fri Jul 14 12:43:46 2006//Trelease_0_8_2
+/qemu-tech.texi/1.9/Fri Jul 14 12:43:46 2006//Trelease_0_8_2
+/qemu_socket.h/1.1/Fri Jul 14 12:43:46 2006//Trelease_0_8_2
+/readline.c/1.1/Fri Jul 14 12:43:46 2006//Trelease_0_8_2
+/s390.ld/1.1/Sun Aug  6 01:03:48 2006//Trelease_0_8_2
+/sdl.c/1.29/Sun Aug  6 01:03:48 2006//Trelease_0_8_2
+/sdl_keysym.h/1.3/Fri Jul 14 12:43:46 2006//Trelease_0_8_2
+/sh4-dis.c/1.1/Sun Aug  6 01:03:48 2006//Trelease_0_8_2
+/softmmu_exec.h/1.1/Fri Jul 14 12:43:46 2006//Trelease_0_8_2
+/softmmu_header.h/1.13/Fri Jul 14 12:43:46 2006//Trelease_0_8_2
+/softmmu_template.h/1.16/Fri Jul 14 12:43:46 2006//Trelease_0_8_2
+/sparc-dis.c/1.3/Sun Aug  6 01:03:49 2006//Trelease_0_8_2
+/sparc.ld/1.1/Sun Aug  6 01:03:49 2006//Trelease_0_8_2
+/tap-win32.c/1.3/Sun Aug  6 01:03:49 2006//Trelease_0_8_2
+/texi2pod.pl/1.1/Fri Jul 14 12:43:46 2006//Trelease_0_8_2
+/thunk.c/1.6/Fri Jul 14 12:43:46 2006//Trelease_0_8_2
+/thunk.h/1.13/Thu Jul 13 09:23:22 2006//Trelease_0_8_2
+/translate-all.c/1.14/Fri Jul 14 12:43:46 2006//Trelease_0_8_2
+/translate-op.c/1.1/Fri Jul 14 12:43:46 2006//Trelease_0_8_2
+/usb-linux.c/1.8/Sun Aug  6 01:03:49 2006//Trelease_0_8_2
+/vgafont.h/1.1/Thu Jul 13 09:23:22 2006//Trelease_0_8_2
+/vl.c/1.202/Sun Aug  6 01:03:49 2006//Trelease_0_8_2
+/vl.h/1.136/Sun Aug  6 01:03:49 2006//Trelease_0_8_2
+/vnc.c/1.7/Sun Aug  6 01:03:49 2006//Trelease_0_8_2
+/vnc_keysym.h/1.1/Fri Jul 14 12:43:46 2006//Trelease_0_8_2
+/vnchextile.h/1.2/Sun Aug  6 01:03:49 2006//Trelease_0_8_2
+/x86_64.ld/1.1/Thu Jul 13 09:23:22 2006//Trelease_0_8_2
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/.CVS/Tag
--- a/tools/ioemu/.CVS/Tag      Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/.CVS/Tag      Wed Aug 09 08:34:06 2006 -0600
@@ -1,1 +1,1 @@ Nrelease_0_8_1
-Nrelease_0_8_1
+Nrelease_0_8_2
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/.cvsignore
--- a/tools/ioemu/.cvsignore    Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/.cvsignore    Wed Aug 09 08:34:06 2006 -0600
@@ -11,6 +11,8 @@ ppc-user
 ppc-user
 qemu-doc.html
 qemu-tech.html
+qemu-doc.info
+qemu-tech.info
 qemu.1
 qemu.pod
 qemu-img.1
@@ -25,5 +27,16 @@ mipsel-softmmu
 mipsel-softmmu
 mips-user
 mipsel-user
+.gdbinit
 sh4-user
 sh4-softmmu
+*.aux
+*.cp
+*.dvi
+*.fn
+*.ky
+*.log
+*.pg
+*.toc
+*.tp
+*.vr
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/Changelog
--- a/tools/ioemu/Changelog     Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/Changelog     Wed Aug 09 08:34:06 2006 -0600
@@ -1,3 +1,22 @@ version 0.8.1:
+version 0.8.2:
+
+  - ACPI support
+  - PC VGA BIOS fixes
+  - switch to OpenBios for SPARC targets (Blue Swirl)
+  - VNC server fixes
+  - MIPS FPU support (Marius Groeger)
+  - Solaris/SPARC host support (Ben Taylor)
+  - PPC breakpoints and single stepping (Jason Wessel)
+  - USB updates (Paul Brook)
+  - UDP/TCP/telnet character devices (Jason Wessel)
+  - Windows sparse file support (Frediano Ziglio)
+  - RTL8139 NIC TCP segmentation offloading (Igor Kovalenko)
+  - PCNET NIC support (Antony T Curtis)
+  - Support for variable frequency host CPUs
+  - Workaround for win32 SMP hosts
+  - Support for AMD Flash memories (Jocelyn Mayer)
+  - Audio capture to WAV files support (malc)
+
 version 0.8.1:
 
   - USB tablet support (Brad Campbell, Anthony Liguori)
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/Makefile
--- a/tools/ioemu/Makefile      Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/Makefile      Wed Aug 09 08:34:06 2006 -0600
@@ -1,11 +1,19 @@ XEN_ROOT=../..
+# Makefile for QEMU.
+
 XEN_ROOT=../..
 include $(XEN_ROOT)/tools/Rules.mk
 
 -include config-host.mak
 
+.PHONY: all clean distclean dvi info install install-doc tar tarbin \
+       speed test test2 html dvi info
+
 CFLAGS+=-Wall -O2 -g -fno-strict-aliasing -I.
 ifdef CONFIG_DARWIN
 CFLAGS+= -mdynamic-no-pic
+endif
+ifeq ($(ARCH),sparc)
+CFLAGS+=-mcpu=ultrasparc
 endif
 LDFLAGS=-g
 LIBS=
@@ -20,11 +28,15 @@ DOCS=
 DOCS=
 endif
 
-all: $(DOCS)
-       for d in $(TARGET_DIRS); do \
-       $(MAKE) -C $$d $@ || exit 1 ; \
-        done
+TOOLS=
 
+all: $(TOOLS) $(DOCS) recurse-all
+
+subdir-%:
+       $(MAKE) -C $(subst subdir-,,$@) all
+
+recurse-all: $(patsubst %,subdir-%, $(TARGET_DIRS))
+        
 qemu-img$(EXESUF): qemu-img.c block.c block-cow.c block-qcow.c aes.c 
block-vmdk.c block-cloop.c block-dmg.c block-bochs.c block-vpc.c block-vvfat.c
        $(CC) -DQEMU_TOOL $(CFLAGS) $(LDFLAGS) $(DEFINES) -o $@ $^ -lz $(LIBS)
 
@@ -42,6 +54,7 @@ clean:
 
 distclean: clean
        rm -f config-host.mak config-host.h $(DOCS)
+       rm -f qemu-{doc,tech}.{info,aux,cp,dvi,fn,info,ky,log,pg,toc,tp,vr}
        for d in $(TARGET_DIRS); do \
        rm -rf $$d || exit 1 ; \
         done
@@ -63,7 +76,7 @@ install: all $(if $(BUILD_DOCS),install-
 #      $(INSTALL) -m 755 -s $(TOOLS) "$(DESTDIR)$(bindir)"
 #      mkdir -p "$(DESTDIR)$(datadir)"
 #      for x in bios.bin vgabios.bin vgabios-cirrus.bin ppc_rom.bin \
-#                      video.x proll.elf linux_boot.bin; do \
+#                      video.x openbios-sparc32 linux_boot.bin; do \
 #              $(INSTALL) -m 644 $(SRC_PATH)/pc-bios/$$x 
"$(DESTDIR)$(datadir)"; \
 #      done
 ifndef CONFIG_WIN32
@@ -106,6 +119,12 @@ qemu-img.1: qemu-img.texi
        perl -w $(SRC_PATH)/texi2pod.pl $< qemu-img.pod
        pod2man --section=1 --center=" " --release=" " qemu-img.pod > $@
 
+info: qemu-doc.info qemu-tech.info
+
+dvi: qemu-doc.dvi qemu-tech.dvi
+
+html: qemu-doc.html qemu-tech.html
+
 FILE=qemu-$(shell cat VERSION)
 
 # tar release (use 'make -k tar' on a checkouted tree)
@@ -138,7 +157,7 @@ tarbin:
        $(datadir)/vgabios-cirrus.bin \
        $(datadir)/ppc_rom.bin \
        $(datadir)/video.x \
-       $(datadir)/proll.elf \
+       $(datadir)/openbios-sparc32 \
        $(datadir)/linux_boot.bin \
        $(docdir)/qemu-doc.html \
        $(docdir)/qemu-tech.html \
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/Makefile.target
--- a/tools/ioemu/Makefile.target       Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/Makefile.target       Wed Aug 09 08:34:06 2006 -0600
@@ -40,6 +40,11 @@ ifeq ($(TARGET_ARCH),arm)
     TARGET_ARCH2=armeb
   endif
 endif
+ifeq ($(TARGET_ARCH),sh4)
+  ifeq ($(TARGET_WORDS_BIGENDIAN),yes)
+    TARGET_ARCH2=sh4eb
+  endif
+endif
 ifeq ($(TARGET_ARCH),mips)
   ifneq ($(TARGET_WORDS_BIGENDIAN),yes)
     TARGET_ARCH2=mipsel
@@ -114,17 +119,24 @@ endif
 endif
 
 ifeq ($(ARCH),sparc)
-CFLAGS+=-m32 -ffixed-g1 -ffixed-g2 -ffixed-g3 -ffixed-g6
+ifeq ($(CONFIG_SOLARIS),yes)
+CFLAGS+=-mcpu=ultrasparc -m32 -ffixed-g2 -ffixed-g3
+LDFLAGS+=-m32
+OP_CFLAGS=$(CFLAGS) -fno-delayed-branch -fno-omit-frame-pointer -ffixed-i0
+else
+CFLAGS+=-mcpu=ultrasparc -m32 -ffixed-g1 -ffixed-g2 -ffixed-g3 -ffixed-g6
 LDFLAGS+=-m32
 OP_CFLAGS=$(CFLAGS) -fno-delayed-branch -ffixed-i0
 HELPER_CFLAGS=$(CFLAGS) -ffixed-i0 -mflat
 # -static is used to avoid g1/g3 usage by the dynamic linker
 LDFLAGS+=-Wl,-T,$(SRC_PATH)/sparc.ld -static
 endif
+endif
 
 ifeq ($(ARCH),sparc64)
-CFLAGS+=-m64 -ffixed-g1 -ffixed-g2 -ffixed-g3 -ffixed-g6
+CFLAGS+=-mcpu=ultrasparc -m64 -ffixed-g1 -ffixed-g4 -ffixed-g5 -ffixed-g7
 LDFLAGS+=-m64
+LDFLAGS+=-Wl,-T,$(SRC_PATH)/sparc64.ld
 OP_CFLAGS=$(CFLAGS) -fno-delayed-branch -ffixed-i0
 endif
 
@@ -186,7 +198,12 @@ main.o: CFLAGS+=-p
 main.o: CFLAGS+=-p
 endif
 
-OBJS= elfload.o main.o syscall.o mmap.o signal.o path.o osdep.o thunk.o 
+OBJS= main.o syscall.o mmap.o signal.o path.o osdep.o thunk.o \
+      elfload.o linuxload.o
+ifdef TARGET_HAS_BFLT
+OBJS+= flatload.o
+endif
+
 ifeq ($(TARGET_ARCH), i386)
 OBJS+= vm86.o
 endif
@@ -323,25 +340,32 @@ ifdef CONFIG_ADLIB
 ifdef CONFIG_ADLIB
 SOUND_HW += fmopl.o adlib.o
 endif
+AUDIODRV+= wavcapture.o
+
+# SCSI layer
+VL_OBJS+= scsi-disk.o cdrom.o lsi53c895a.o
 
 # USB layer
-VL_OBJS+= usb.o usb-hub.o usb-uhci.o usb-linux.o usb-hid.o
+VL_OBJS+= usb.o usb-hub.o usb-linux.o usb-hid.o usb-ohci.o usb-msd.o
 
 # PCI network cards
-VL_OBJS+= ne2000.o rtl8139.o
+VL_OBJS+= ne2000.o rtl8139.o pcnet.o
 
 ifeq ($(TARGET_BASE_ARCH), i386)
 # Hardware support
 VL_OBJS+= ide.o pckbd.o ps2.o vga.o $(SOUND_HW) dma.o $(AUDIODRV)
 VL_OBJS+= fdc.o mc146818rtc.o serial.o pc.o
-VL_OBJS+= cirrus_vga.o mixeng.o parallel.o
+VL_OBJS+= cirrus_vga.o mixeng.o parallel.o acpi.o piix_pci.o
+VL_OBJS+= usb-uhci.o
 VL_OBJS+= piix4acpi.o
+VL_OBJS+= xenstore.o
 DEFINES += -DHAS_AUDIO
 endif
 ifeq ($(TARGET_BASE_ARCH), ppc)
 VL_OBJS+= ppc.o ide.o pckbd.o ps2.o vga.o $(SOUND_HW) dma.o $(AUDIODRV)
 VL_OBJS+= mc146818rtc.o serial.o i8259.o i8254.o fdc.o m48t59.o
 VL_OBJS+= ppc_prep.o ppc_chrp.o cuda.o adb.o openpic.o heathrow_pic.o mixeng.o
+VL_OBJS+= grackle_pci.o prep_pci.o unin_pci.o
 DEFINES += -DHAS_AUDIO
 endif
 ifeq ($(TARGET_ARCH), mips)
@@ -350,7 +374,7 @@ endif
 endif
 ifeq ($(TARGET_BASE_ARCH), sparc)
 ifeq ($(TARGET_ARCH), sparc64)
-VL_OBJS+= sun4u.o ide.o pckbd.o ps2.o vga.o
+VL_OBJS+= sun4u.o ide.o pckbd.o ps2.o vga.o apb_pci.o
 VL_OBJS+= fdc.o mc146818rtc.o serial.o m48t59.o
 VL_OBJS+= cirrus_vga.o parallel.o
 else
@@ -361,6 +385,7 @@ ifeq ($(TARGET_BASE_ARCH), arm)
 ifeq ($(TARGET_BASE_ARCH), arm)
 VL_OBJS+= integratorcp.o versatilepb.o ps2.o smc91c111.o arm_pic.o arm_timer.o
 VL_OBJS+= arm_boot.o pl011.o pl050.o pl080.o pl110.o pl190.o
+VL_OBJS+= versatile_pci.o
 endif
 ifeq ($(TARGET_BASE_ARCH), sh4)
 VL_OBJS+= shix.o sh7750.o sh7750_regnames.o tc58128.o
@@ -398,7 +423,7 @@ ifndef CONFIG_DARWIN
 ifndef CONFIG_DARWIN
 ifndef CONFIG_WIN32
 ifndef CONFIG_SOLARIS
-VL_LIBS=-lutil
+VL_LIBS=-lutil -lrt
 endif
 endif
 endif
@@ -409,6 +434,11 @@ endif
 
 ifeq ($(ARCH),ia64)
 VL_LDFLAGS+=-Wl,-G0 -Wl,-T,$(SRC_PATH)/ia64.ld
+endif
+
+ifeq ($(ARCH),sparc64)
+VL_LDFLAGS+=-m64
+VL_LDFLAGS+=-Wl,-T,$(SRC_PATH)/sparc64.ld
 endif
 
 ifdef CONFIG_WIN32
@@ -489,6 +519,13 @@ endif
 endif
 
 loader.o: loader.c elf_ops.h
+
+acpi.o: acpi.c acpi-dsdt.hex
+
+ifdef BUILD_ACPI_TABLES
+$(SRC_PATH)/hw/acpi-dsdt.hex: acpi-dsdt.dsl
+       iasl -tc -p $@ $<
+endif
 
 ifeq ($(TARGET_ARCH), sh4)
 op.o: op.c op_mem.c cpu.h
@@ -500,6 +537,8 @@ tc58128.o: tc58128.c
 tc58128.o: tc58128.c
 endif
 
+$(OBJS) $(LIBOBJS) $(VL_OBJS): config.h ../config-host.h
+
 %.o: %.c
        $(CC) $(CFLAGS) $(DEFINES) -c -o $@ $<
 
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/TODO
--- a/tools/ioemu/TODO  Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/TODO  Wed Aug 09 08:34:06 2006 -0600
@@ -1,24 +1,20 @@ short term:
 short term:
 ----------
+- cycle counter for all archs
+- cpu_interrupt() win32/SMP fix
 - support variable tsc freq
-- cpu_interrupt() win32/SMP fix
 - USB host async
 - IDE async
 - debug option in 'configure' script + disable -fomit-frame-pointer
 - Precise VGA timings for old games/demos (malc patch)
 - merge PIC spurious interrupt patch
-- merge Solaris patch
 - warning for OS/2: must not use 128 MB memory (merge bochs cmos patch ?)
 - config file (at least for windows/Mac OS X)
-- commit message if execution of code in IO memory
 - update doc: PCI infos.
-- VNC patch + Synaptic patch.
 - basic VGA optimizations
-- physical memory cache (reduce qemu-fast address space size to about 32 MB)
 - better code fetch (different exception handling + CS.limit support)
 - do not resize vga if invalid size.
 - avoid looping if only exceptions
-- cycle counter for all archs
 - TLB code protection support for PPC
 - see openMosix Doc 
 - disable SMC handling for ARM/SPARC/PPC (not finished)
@@ -31,12 +27,10 @@ short term:
 - fix CCOP optimisation
 - fix all remaining thread lock issues (must put TBs in a specific invalid
   state, find a solution for tb_flush()).
-- fix arm fpu rounding (at least for float->integer conversions)
 
 ppc specific:
 ------------
 - TLB invalidate not needed if msr_pr changes
-- SPR_ENCODE() not useful
 - enable shift optimizations ?
 
 linux-user specific:
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/VERSION
--- a/tools/ioemu/VERSION       Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/VERSION       Wed Aug 09 08:34:06 2006 -0600
@@ -1,1 +1,1 @@ 0.8.1
-0.8.1
\ No newline at end of file
+0.8.2
\ No newline at end of file
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/audio/.CVS/Entries
--- a/tools/ioemu/audio/.CVS/Entries    Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/audio/.CVS/Entries    Wed Aug 09 08:34:06 2006 -0600
@@ -1,19 +1,20 @@
-/alsaaudio.c/1.5/Sun Nov 20 18:53:05 2005//Trelease_0_8_1
-/audio.c/1.9/Thu May 25 18:22:31 2006//Trelease_0_8_1
-/audio.h/1.5/Thu May 25 18:22:31 2006//Trelease_0_8_1
-/audio_int.h/1.7/Thu May 25 18:22:31 2006//Trelease_0_8_1
-/audio_template.h/1.4/Sun Nov 20 16:24:34 2005//Trelease_0_8_1
-/coreaudio.c/1.5/Sun Nov 20 18:53:42 2005//Trelease_0_8_1
-/dsound_template.h/1.2/Sat Nov  5 18:55:27 2005//Trelease_0_8_1
-/dsoundaudio.c/1.2/Sat Nov  5 18:55:27 2005//Trelease_0_8_1
-/fmodaudio.c/1.5/Thu May 25 18:22:32 2006//Trelease_0_8_1
-/mixeng.c/1.4/Thu May 25 18:22:32 2006//Trelease_0_8_1
-/mixeng.h/1.2/Thu May 25 18:22:32 2006//Trelease_0_8_1
-/mixeng_template.h/1.2/Thu May 25 18:22:32 2006//Trelease_0_8_1
-/noaudio.c/1.4/Thu May 25 18:22:32 2006//Trelease_0_8_1
-/ossaudio.c/1.9/Thu May 25 18:22:32 2006//Trelease_0_8_1
-/rate_template.h/1.2/Sat Nov  5 18:55:27 2005//Trelease_0_8_1
-/sdlaudio.c/1.6/Thu May 25 18:22:32 2006//Trelease_0_8_1
-/sys-queue.h/1.1/Sun Oct 30 18:58:22 2005//Trelease_0_8_1
-/wavaudio.c/1.6/Thu May 25 18:22:32 2006//Trelease_0_8_1
+/alsaaudio.c/1.7/Sun Aug  6 01:03:49 2006//Trelease_0_8_2
+/audio.c/1.14/Sun Aug  6 01:03:50 2006//Trelease_0_8_2
+/audio.h/1.8/Sun Aug  6 01:03:50 2006//Trelease_0_8_2
+/audio_int.h/1.10/Sun Aug  6 01:03:50 2006//Trelease_0_8_2
+/audio_template.h/1.8/Sun Aug  6 01:03:50 2006//Trelease_0_8_2
+/coreaudio.c/1.7/Sun Aug  6 01:03:50 2006//Trelease_0_8_2
+/dsound_template.h/1.4/Sun Aug  6 01:03:50 2006//Trelease_0_8_2
+/dsoundaudio.c/1.3/Sun Aug  6 01:03:50 2006//Trelease_0_8_2
+/fmodaudio.c/1.7/Sun Aug  6 01:03:50 2006//Trelease_0_8_2
+/mixeng.c/1.4/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/mixeng.h/1.2/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/mixeng_template.h/1.2/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/noaudio.c/1.7/Sun Aug  6 01:03:50 2006//Trelease_0_8_2
+/ossaudio.c/1.11/Sun Aug  6 01:03:50 2006//Trelease_0_8_2
+/rate_template.h/1.3/Sun Aug  6 01:03:50 2006//Trelease_0_8_2
+/sdlaudio.c/1.8/Sun Aug  6 01:03:50 2006//Trelease_0_8_2
+/sys-queue.h/1.1/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/wavaudio.c/1.8/Sun Aug  6 01:03:50 2006//Trelease_0_8_2
+/wavcapture.c/1.5/Sat Jul 22 17:06:44 2006//Trelease_0_8_2
 D
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/audio/.CVS/Tag
--- a/tools/ioemu/audio/.CVS/Tag        Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/audio/.CVS/Tag        Wed Aug 09 08:34:06 2006 -0600
@@ -1,1 +1,1 @@ Nrelease_0_8_1
-Nrelease_0_8_1
+Nrelease_0_8_2
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/audio/alsaaudio.c
--- a/tools/ioemu/audio/alsaaudio.c     Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/audio/alsaaudio.c     Wed Aug 09 08:34:06 2006 -0600
@@ -61,8 +61,8 @@ static struct {
     .size_in_usec_in = 1,
     .size_in_usec_out = 1,
 #endif
-    .pcm_name_out = "hw:0,0",
-    .pcm_name_in = "hw:0,0",
+    .pcm_name_out = "default",
+    .pcm_name_in = "default",
 #ifdef HIGH_LATENCY
     .buffer_size_in = 400000,
     .period_size_in = 400000 / 4,
@@ -606,7 +606,6 @@ static int alsa_run_out (HWVoiceOut *hw)
                 }
             }
 
-            mixeng_clear (src, written);
             rpos = (rpos + written) % hw->samples;
             samples -= written;
             len -= written;
@@ -663,12 +662,9 @@ static int alsa_init_out (HWVoiceOut *hw
     obt_as.freq = obt.freq;
     obt_as.nchannels = obt.nchannels;
     obt_as.fmt = effective_fmt;
-
-    audio_pcm_init_info (
-        &hw->info,
-        &obt_as,
-        audio_need_to_swap_endian (endianness)
-        );
+    obt_as.endianness = endianness;
+
+    audio_pcm_init_info (&hw->info, &obt_as);
     hw->samples = obt.samples;
 
     alsa->pcm_buf = audio_calloc (AUDIO_FUNC, obt.samples, 1 << 
hw->info.shift);
@@ -752,12 +748,9 @@ static int alsa_init_in (HWVoiceIn *hw, 
     obt_as.freq = obt.freq;
     obt_as.nchannels = obt.nchannels;
     obt_as.fmt = effective_fmt;
-
-    audio_pcm_init_info (
-        &hw->info,
-        &obt_as,
-        audio_need_to_swap_endian (endianness)
-        );
+    obt_as.endianness = endianness;
+
+    audio_pcm_init_info (&hw->info, &obt_as);
     hw->samples = obt.samples;
 
     alsa->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << 
hw->info.shift);
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/audio/audio.c
--- a/tools/ioemu/audio/audio.c Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/audio/audio.c Wed Aug 09 08:34:06 2006 -0600
@@ -29,6 +29,7 @@
 /* #define DEBUG_PLIVE */
 /* #define DEBUG_LIVE */
 /* #define DEBUG_OUT */
+/* #define DEBUG_CAPTURE */
 
 #define SW_NAME(sw) (sw)->name ? (sw)->name : "unknown"
 
@@ -137,7 +138,7 @@ int audio_bug (const char *funcname, int
     if (cond) {
         static int shown;
 
-        AUD_log (NULL, "Error a bug that was just triggered in %s\n", 
funcname);
+        AUD_log (NULL, "A bug was just triggered in %s\n", funcname);
         if (!shown) {
             shown = 1;
             AUD_log (NULL, "Save all your work and restart without audio\n");
@@ -509,14 +510,28 @@ static void audio_print_settings (audset
         AUD_log (NULL, "invalid(%d)", as->fmt);
         break;
     }
+
+    AUD_log (NULL, " endianness=");
+    switch (as->endianness) {
+    case 0:
+        AUD_log (NULL, "little");
+        break;
+    case 1:
+        AUD_log (NULL, "big");
+        break;
+    default:
+        AUD_log (NULL, "invalid");
+        break;
+    }
     AUD_log (NULL, "\n");
 }
 
-static int audio_validate_settigs (audsettings_t *as)
+static int audio_validate_settings (audsettings_t *as)
 {
     int invalid;
 
     invalid = as->nchannels != 1 && as->nchannels != 2;
+    invalid |= as->endianness != 0 && as->endianness != 1;
 
     switch (as->fmt) {
     case AUD_FMT_S8:
@@ -530,11 +545,7 @@ static int audio_validate_settigs (audse
     }
 
     invalid |= as->freq <= 0;
-
-    if (invalid) {
-        return -1;
-    }
-    return 0;
+    return invalid ? -1 : 0;
 }
 
 static int audio_pcm_info_eq (struct audio_pcm_info *info, audsettings_t *as)
@@ -556,14 +567,11 @@ static int audio_pcm_info_eq (struct aud
     return info->freq == as->freq
         && info->nchannels == as->nchannels
         && info->sign == sign
-        && info->bits == bits;
-}
-
-void audio_pcm_init_info (
-    struct audio_pcm_info *info,
-    audsettings_t *as,
-    int swap_endian
-    )
+        && info->bits == bits
+        && info->swap_endianness == (as->endianness != AUDIO_HOST_ENDIANNESS);
+}
+
+void audio_pcm_init_info (struct audio_pcm_info *info, audsettings_t *as)
 {
     int bits = 8, sign = 0;
 
@@ -587,7 +595,7 @@ void audio_pcm_init_info (
     info->shift = (as->nchannels == 2) + (bits == 16);
     info->align = (1 << info->shift) - 1;
     info->bytes_per_second = info->freq << info->shift;
-    info->swap_endian = swap_endian;
+    info->swap_endianness = (as->endianness != AUDIO_HOST_ENDIANNESS);
 }
 
 void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len)
@@ -597,11 +605,11 @@ void audio_pcm_info_clear_buf (struct au
     }
 
     if (info->sign) {
-        memset (buf, len << info->shift, 0x00);
+        memset (buf, 0x00, len << info->shift);
     }
     else {
         if (info->bits == 8) {
-            memset (buf, len << info->shift, 0x80);
+            memset (buf, 0x80, len << info->shift);
         }
         else {
             int i;
@@ -609,7 +617,7 @@ void audio_pcm_info_clear_buf (struct au
             int shift = info->nchannels - 1;
             short s = INT16_MAX;
 
-            if (info->swap_endian) {
+            if (info->swap_endianness) {
                 s = bswap16 (s);
             }
 
@@ -618,6 +626,143 @@ void audio_pcm_info_clear_buf (struct au
             }
         }
     }
+}
+
+/*
+ * Capture
+ */
+static void noop_conv (st_sample_t *dst, const void *src,
+                       int samples, volume_t *vol)
+{
+    (void) src;
+    (void) dst;
+    (void) samples;
+    (void) vol;
+}
+
+static CaptureVoiceOut *audio_pcm_capture_find_specific (
+    AudioState *s,
+    audsettings_t *as
+    )
+{
+    CaptureVoiceOut *cap;
+
+    for (cap = s->cap_head.lh_first; cap; cap = cap->entries.le_next) {
+        if (audio_pcm_info_eq (&cap->hw.info, as)) {
+            return cap;
+        }
+    }
+    return NULL;
+}
+
+static void audio_notify_capture (CaptureVoiceOut *cap, audcnotification_e cmd)
+{
+    struct capture_callback *cb;
+
+#ifdef DEBUG_CAPTURE
+    dolog ("notification %d sent\n", cmd);
+#endif
+    for (cb = cap->cb_head.lh_first; cb; cb = cb->entries.le_next) {
+        cb->ops.notify (cb->opaque, cmd);
+    }
+}
+
+static void audio_capture_maybe_changed (CaptureVoiceOut *cap, int enabled)
+{
+    if (cap->hw.enabled != enabled) {
+        audcnotification_e cmd;
+        cap->hw.enabled = enabled;
+        cmd = enabled ? AUD_CNOTIFY_ENABLE : AUD_CNOTIFY_DISABLE;
+        audio_notify_capture (cap, cmd);
+    }
+}
+
+static void audio_recalc_and_notify_capture (CaptureVoiceOut *cap)
+{
+    HWVoiceOut *hw = &cap->hw;
+    SWVoiceOut *sw;
+    int enabled = 0;
+
+    for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
+        if (sw->active) {
+            enabled = 1;
+            break;
+        }
+    }
+    audio_capture_maybe_changed (cap, enabled);
+}
+
+static void audio_detach_capture (HWVoiceOut *hw)
+{
+    SWVoiceCap *sc = hw->cap_head.lh_first;
+
+    while (sc) {
+        SWVoiceCap *sc1 = sc->entries.le_next;
+        SWVoiceOut *sw = &sc->sw;
+        CaptureVoiceOut *cap = sc->cap;
+        int was_active = sw->active;
+
+        if (sw->rate) {
+            st_rate_stop (sw->rate);
+            sw->rate = NULL;
+        }
+
+        LIST_REMOVE (sw, entries);
+        LIST_REMOVE (sc, entries);
+        qemu_free (sc);
+        if (was_active) {
+            /* We have removed soft voice from the capture:
+               this might have changed the overall status of the capture
+               since this might have been the only active voice */
+            audio_recalc_and_notify_capture (cap);
+        }
+        sc = sc1;
+    }
+}
+
+static int audio_attach_capture (AudioState *s, HWVoiceOut *hw)
+{
+    CaptureVoiceOut *cap;
+
+    audio_detach_capture (hw);
+    for (cap = s->cap_head.lh_first; cap; cap = cap->entries.le_next) {
+        SWVoiceCap *sc;
+        SWVoiceOut *sw;
+        HWVoiceOut *hw_cap = &cap->hw;
+
+        sc = audio_calloc (AUDIO_FUNC, 1, sizeof (*sc));
+        if (!sc) {
+            dolog ("Could not allocate soft capture voice (%zu bytes)\n",
+                   sizeof (*sc));
+            return -1;
+        }
+
+        sc->cap = cap;
+        sw = &sc->sw;
+        sw->hw = hw_cap;
+        sw->info = hw->info;
+        sw->empty = 1;
+        sw->active = hw->enabled;
+        sw->conv = noop_conv;
+        sw->ratio = ((int64_t) hw_cap->info.freq << 32) / sw->info.freq;
+        sw->rate = st_rate_start (sw->info.freq, hw_cap->info.freq);
+        if (!sw->rate) {
+            dolog ("Could not start rate conversion for `%s'\n", SW_NAME (sw));
+            qemu_free (sw);
+            return -1;
+        }
+        LIST_INSERT_HEAD (&hw_cap->sw_head, sw, entries);
+        LIST_INSERT_HEAD (&hw->cap_head, sc, entries);
+#ifdef DEBUG_CAPTURE
+        asprintf (&sw->name, "for %p %d,%d,%d",
+                  hw, sw->info.freq, sw->info.bits, sw->info.nchannels);
+        dolog ("Added %s active = %d\n", sw->name, sw->active);
+#endif
+        if (sw->active) {
+            audio_capture_maybe_changed (cap, 1);
+        }
+    }
+    return 0;
 }
 
 /*
@@ -796,6 +941,9 @@ int audio_pcm_sw_write (SWVoiceOut *sw, 
     }
 
     if (live == hwsamples) {
+#ifdef DEBUG_OUT
+        dolog ("%s is full %d\n", sw->name, live);
+#endif
         return 0;
     }
 
@@ -914,19 +1062,14 @@ void AUD_set_active_out (SWVoiceOut *sw,
     hw = sw->hw;
     if (sw->active != on) {
         SWVoiceOut *temp_sw;
+        SWVoiceCap *sc;
 
         if (on) {
-            int total;
-
             hw->pending_disable = 0;
             if (!hw->enabled) {
                 hw->enabled = 1;
                 hw->pcm_ops->ctl_out (hw, VOICE_ENABLE);
             }
-
-            if (sw->empty) {
-                total = 0;
-            }
         }
         else {
             if (hw->enabled) {
@@ -940,6 +1083,13 @@ void AUD_set_active_out (SWVoiceOut *sw,
                 hw->pending_disable = nb_active == 1;
             }
         }
+
+        for (sc = hw->cap_head.lh_first; sc; sc = sc->entries.le_next) {
+            sc->sw.active = hw->enabled;
+            if (hw->enabled) {
+                audio_capture_maybe_changed (sc->cap, 1);
+            }
+        }
         sw->active = on;
     }
 }
@@ -997,7 +1147,7 @@ static int audio_get_avail (SWVoiceIn *s
     }
 
     ldebug (
-        "%s: get_avail live %d ret %lld\n",
+        "%s: get_avail live %d ret %" PRId64 "\n",
         SW_NAME (sw),
         live, (((int64_t) live << 32) / sw->ratio) << sw->info.shift
         );
@@ -1023,7 +1173,7 @@ static int audio_get_free (SWVoiceOut *s
     dead = sw->hw->samples - live;
 
 #ifdef DEBUG_OUT
-    dolog ("%s: get_free live %d dead %d ret %lld\n",
+    dolog ("%s: get_free live %d dead %d ret %" PRId64 "\n",
            SW_NAME (sw),
            live, dead, (((int64_t) dead << 32) / sw->ratio) << sw->info.shift);
 #endif
@@ -1031,6 +1181,43 @@ static int audio_get_free (SWVoiceOut *s
     return (((int64_t) dead << 32) / sw->ratio) << sw->info.shift;
 }
 
+static void audio_capture_mix_and_clear (HWVoiceOut *hw, int rpos, int samples)
+{
+    int n;
+
+    if (hw->enabled) {
+        SWVoiceCap *sc;
+
+        for (sc = hw->cap_head.lh_first; sc; sc = sc->entries.le_next) {
+            SWVoiceOut *sw = &sc->sw;
+            int rpos2 = rpos;
+
+            n = samples;
+            while (n) {
+                int till_end_of_hw = hw->samples - rpos2;
+                int to_write = audio_MIN (till_end_of_hw, n);
+                int bytes = to_write << hw->info.shift;
+                int written;
+
+                sw->buf = hw->mix_buf + rpos2;
+                written = audio_pcm_sw_write (sw, NULL, bytes);
+                if (written - bytes) {
+                    dolog ("Could not mix %d bytes into a capture "
+                           "buffer, mixed %d\n",
+                           bytes, written);
+                    break;
+                }
+                n -= to_write;
+                rpos2 = (rpos2 + to_write) % hw->samples;
+            }
+        }
+    }
+
+    n = audio_MIN (samples, hw->samples - rpos);
+    mixeng_clear (hw->mix_buf + rpos, n);
+    mixeng_clear (hw->mix_buf, samples - n);
+}
+
 static void audio_run_out (AudioState *s)
 {
     HWVoiceOut *hw = NULL;
@@ -1038,7 +1225,7 @@ static void audio_run_out (AudioState *s
 
     while ((hw = audio_pcm_hw_find_any_enabled_out (s, hw))) {
         int played;
-        int live, free, nb_live, cleanup_required;
+        int live, free, nb_live, cleanup_required, prev_rpos;
 
         live = audio_pcm_hw_get_live_out2 (hw, &nb_live);
         if (!nb_live) {
@@ -1051,12 +1238,17 @@ static void audio_run_out (AudioState *s
         }
 
         if (hw->pending_disable && !nb_live) {
+            SWVoiceCap *sc;
 #ifdef DEBUG_OUT
             dolog ("Disabling voice\n");
 #endif
             hw->enabled = 0;
             hw->pending_disable = 0;
             hw->pcm_ops->ctl_out (hw, VOICE_DISABLE);
+            for (sc = hw->cap_head.lh_first; sc; sc = sc->entries.le_next) {
+                sc->sw.active = 0;
+                audio_recalc_and_notify_capture (sc->cap);
+            }
             continue;
         }
 
@@ -1072,6 +1264,7 @@ static void audio_run_out (AudioState *s
             continue;
         }
 
+        prev_rpos = hw->rpos;
         played = hw->pcm_ops->run_out (hw);
         if (audio_bug (AUDIO_FUNC, hw->rpos >= hw->samples)) {
             dolog ("hw->rpos=%d hw->samples=%d played=%d\n",
@@ -1085,6 +1278,7 @@ static void audio_run_out (AudioState *s
 
         if (played) {
             hw->ts_helper += played;
+            audio_capture_mix_and_clear (hw, prev_rpos, played);
         }
 
         cleanup_required = 0;
@@ -1115,15 +1309,18 @@ static void audio_run_out (AudioState *s
         }
 
         if (cleanup_required) {
-        restart:
-            for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
+            SWVoiceOut *sw1;
+
+            sw = hw->sw_head.lh_first;
+            while (sw) {
+                sw1 = sw->entries.le_next;
                 if (!sw->active && !sw->callback.fn) {
 #ifdef DEBUG_PLIVE
                     dolog ("Finishing with old voice\n");
 #endif
                     audio_close_out (s, sw);
-                    goto restart; /* play it safe */
                 }
+                sw = sw1;
             }
         }
     }
@@ -1158,12 +1355,60 @@ static void audio_run_in (AudioState *s)
     }
 }
 
+static void audio_run_capture (AudioState *s)
+{
+    CaptureVoiceOut *cap;
+
+    for (cap = s->cap_head.lh_first; cap; cap = cap->entries.le_next) {
+        int live, rpos, captured;
+        HWVoiceOut *hw = &cap->hw;
+        SWVoiceOut *sw;
+
+        captured = live = audio_pcm_hw_get_live_out (hw);
+        rpos = hw->rpos;
+        while (live) {
+            int left = hw->samples - rpos;
+            int to_capture = audio_MIN (live, left);
+            st_sample_t *src;
+            struct capture_callback *cb;
+
+            src = hw->mix_buf + rpos;
+            hw->clip (cap->buf, src, to_capture);
+            mixeng_clear (src, to_capture);
+
+            for (cb = cap->cb_head.lh_first; cb; cb = cb->entries.le_next) {
+                cb->ops.capture (cb->opaque, cap->buf,
+                                 to_capture << hw->info.shift);
+            }
+            rpos = (rpos + to_capture) % hw->samples;
+            live -= to_capture;
+        }
+        hw->rpos = rpos;
+
+        for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
+            if (!sw->active && sw->empty) {
+                continue;
+            }
+
+            if (audio_bug (AUDIO_FUNC, captured > sw->total_hw_samples_mixed)) 
{
+                dolog ("captured=%d sw->total_hw_samples_mixed=%d\n",
+                       captured, sw->total_hw_samples_mixed);
+                captured = sw->total_hw_samples_mixed;
+            }
+
+            sw->total_hw_samples_mixed -= captured;
+            sw->empty = sw->total_hw_samples_mixed == 0;
+        }
+    }
+}
+
 static void audio_timer (void *opaque)
 {
     AudioState *s = opaque;
 
     audio_run_out (s);
     audio_run_in (s);
+    audio_run_capture (s);
 
     qemu_mod_timer (s->ts, qemu_get_clock (vm_clock) + conf.period.ticks);
 }
@@ -1327,8 +1572,19 @@ static void audio_atexit (void)
     HWVoiceIn *hwi = NULL;
 
     while ((hwo = audio_pcm_hw_find_any_enabled_out (s, hwo))) {
+        SWVoiceCap *sc;
+
         hwo->pcm_ops->ctl_out (hwo, VOICE_DISABLE);
         hwo->pcm_ops->fini_out (hwo);
+
+        for (sc = hwo->cap_head.lh_first; sc; sc = sc->entries.le_next) {
+            CaptureVoiceOut *cap = sc->cap;
+            struct capture_callback *cb;
+
+            for (cb = cap->cb_head.lh_first; cb; cb = cb->entries.le_next) {
+                cb->ops.destroy (cb->opaque);
+            }
+        }
     }
 
     while ((hwi = audio_pcm_hw_find_any_enabled_in (s, hwi))) {
@@ -1383,6 +1639,7 @@ AudioState *AUD_init (void)
 
     LIST_INIT (&s->hw_head_out);
     LIST_INIT (&s->hw_head_in);
+    LIST_INIT (&s->cap_head);
     atexit (audio_atexit);
 
     s->ts = qemu_new_timer (vm_clock, audio_timer, s);
@@ -1479,3 +1736,136 @@ AudioState *AUD_init (void)
     qemu_mod_timer (s->ts, qemu_get_clock (vm_clock) + conf.period.ticks);
     return s;
 }
+
+CaptureVoiceOut *AUD_add_capture (
+    AudioState *s,
+    audsettings_t *as,
+    struct audio_capture_ops *ops,
+    void *cb_opaque
+    )
+{
+    CaptureVoiceOut *cap;
+    struct capture_callback *cb;
+
+    if (!s) {
+        /* XXX suppress */
+        s = &glob_audio_state;
+    }
+
+    if (audio_validate_settings (as)) {
+        dolog ("Invalid settings were passed when trying to add capture\n");
+        audio_print_settings (as);
+        goto err0;
+    }
+
+    cb = audio_calloc (AUDIO_FUNC, 1, sizeof (*cb));
+    if (!cb) {
+        dolog ("Could not allocate capture callback information, size %zu\n",
+               sizeof (*cb));
+        goto err0;
+    }
+    cb->ops = *ops;
+    cb->opaque = cb_opaque;
+
+    cap = audio_pcm_capture_find_specific (s, as);
+    if (cap) {
+        LIST_INSERT_HEAD (&cap->cb_head, cb, entries);
+        return cap;
+    }
+    else {
+        HWVoiceOut *hw;
+        CaptureVoiceOut *cap;
+
+        cap = audio_calloc (AUDIO_FUNC, 1, sizeof (*cap));
+        if (!cap) {
+            dolog ("Could not allocate capture voice, size %zu\n",
+                   sizeof (*cap));
+            goto err1;
+        }
+
+        hw = &cap->hw;
+        LIST_INIT (&hw->sw_head);
+        LIST_INIT (&cap->cb_head);
+
+        /* XXX find a more elegant way */
+        hw->samples = 4096 * 4;
+        hw->mix_buf = audio_calloc (AUDIO_FUNC, hw->samples,
+                                    sizeof (st_sample_t));
+        if (!hw->mix_buf) {
+            dolog ("Could not allocate capture mix buffer (%d samples)\n",
+                   hw->samples);
+            goto err2;
+        }
+
+        audio_pcm_init_info (&hw->info, as);
+
+        cap->buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift);
+        if (!cap->buf) {
+            dolog ("Could not allocate capture buffer "
+                   "(%d samples, each %d bytes)\n",
+                   hw->samples, 1 << hw->info.shift);
+            goto err3;
+        }
+
+        hw->clip = mixeng_clip
+            [hw->info.nchannels == 2]
+            [hw->info.sign]
+            [hw->info.swap_endianness]
+            [hw->info.bits == 16];
+
+        LIST_INSERT_HEAD (&s->cap_head, cap, entries);
+        LIST_INSERT_HEAD (&cap->cb_head, cb, entries);
+
+        hw = NULL;
+        while ((hw = audio_pcm_hw_find_any_out (s, hw))) {
+            audio_attach_capture (s, hw);
+        }
+        return cap;
+
+    err3:
+        qemu_free (cap->hw.mix_buf);
+    err2:
+        qemu_free (cap);
+    err1:
+        qemu_free (cb);
+    err0:
+        return NULL;
+    }
+}
+
+void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque)
+{
+    struct capture_callback *cb;
+
+    for (cb = cap->cb_head.lh_first; cb; cb = cb->entries.le_next) {
+        if (cb->opaque == cb_opaque) {
+            cb->ops.destroy (cb_opaque);
+            LIST_REMOVE (cb, entries);
+            qemu_free (cb);
+
+            if (!cap->cb_head.lh_first) {
+                SWVoiceOut *sw = cap->hw.sw_head.lh_first, *sw1;
+
+                while (sw) {
+                    SWVoiceCap *sc = (SWVoiceCap *) sw;
+#ifdef DEBUG_CAPTURE
+                    dolog ("freeing %s\n", sw->name);
+#endif
+
+                    sw1 = sw->entries.le_next;
+                    if (sw->rate) {
+                        st_rate_stop (sw->rate);
+                        sw->rate = NULL;
+                    }
+                    LIST_REMOVE (sw, entries);
+                    LIST_REMOVE (sc, entries);
+                    qemu_free (sc);
+                    sw = sw1;
+                }
+                LIST_REMOVE (cap, entries);
+                qemu_free (cap);
+            }
+            return;
+        }
+    }
+}
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/audio/audio.h
--- a/tools/ioemu/audio/audio.h Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/audio/audio.h Wed Aug 09 08:34:06 2006 -0600
@@ -24,6 +24,7 @@
 #ifndef QEMU_AUDIO_H
 #define QEMU_AUDIO_H
 
+#include "config.h"
 #include "sys-queue.h"
 
 typedef void (*audio_callback_fn_t) (void *opaque, int avail);
@@ -35,14 +36,44 @@ typedef enum {
     AUD_FMT_S16
 } audfmt_e;
 
+#ifdef WORDS_BIGENDIAN
+#define AUDIO_HOST_ENDIANNESS 1
+#else
+#define AUDIO_HOST_ENDIANNESS 0
+#endif
+
 typedef struct {
     int freq;
     int nchannels;
     audfmt_e fmt;
+    int endianness;
 } audsettings_t;
+
+typedef enum {
+    AUD_CNOTIFY_ENABLE,
+    AUD_CNOTIFY_DISABLE
+} audcnotification_e;
+
+struct audio_capture_ops {
+    void (*notify) (void *opaque, audcnotification_e cmd);
+    void (*capture) (void *opaque, void *buf, int size);
+    void (*destroy) (void *opaque);
+};
+
+struct capture_ops {
+    void (*info) (void *opaque);
+    void (*destroy) (void *opaque);
+};
+
+typedef struct CaptureState {
+    void *opaque;
+    struct capture_ops ops;
+    LIST_ENTRY (CaptureState) entries;
+} CaptureState;
 
 typedef struct AudioState AudioState;
 typedef struct SWVoiceOut SWVoiceOut;
+typedef struct CaptureVoiceOut CaptureVoiceOut;
 typedef struct SWVoiceIn SWVoiceIn;
 
 typedef struct QEMUSoundCard {
@@ -66,6 +97,13 @@ void AUD_help (void);
 void AUD_help (void);
 void AUD_register_card (AudioState *s, const char *name, QEMUSoundCard *card);
 void AUD_remove_card (QEMUSoundCard *card);
+CaptureVoiceOut *AUD_add_capture (
+    AudioState *s,
+    audsettings_t *as,
+    struct audio_capture_ops *ops,
+    void *opaque
+    );
+void AUD_del_capture (CaptureVoiceOut *cap, void *cb_opaque);
 
 SWVoiceOut *AUD_open_out (
     QEMUSoundCard *card,
@@ -73,8 +111,7 @@ SWVoiceOut *AUD_open_out (
     const char *name,
     void *callback_opaque,
     audio_callback_fn_t callback_fn,
-    audsettings_t *settings,
-    int sw_endian
+    audsettings_t *settings
     );
 
 void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
@@ -92,8 +129,7 @@ SWVoiceIn *AUD_open_in (
     const char *name,
     void *callback_opaque,
     audio_callback_fn_t callback_fn,
-    audsettings_t *settings,
-    int sw_endian
+    audsettings_t *settings
     );
 
 void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw);
@@ -111,7 +147,7 @@ static inline void *advance (void *p, in
 }
 
 uint32_t popcount (uint32_t u);
-inline uint32_t lsbindex (uint32_t u);
+uint32_t lsbindex (uint32_t u);
 
 #ifdef __GNUC__
 #define audio_MIN(a, b) ( __extension__ ({      \
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/audio/audio_int.h
--- a/tools/ioemu/audio/audio_int.h     Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/audio/audio_int.h     Wed Aug 09 08:34:06 2006 -0600
@@ -61,13 +61,14 @@ struct audio_pcm_info {
     int align;
     int shift;
     int bytes_per_second;
-    int swap_endian;
-};
+    int swap_endianness;
+};
+
+typedef struct SWVoiceCap SWVoiceCap;
 
 typedef struct HWVoiceOut {
     int enabled;
     int pending_disable;
-    int valid;
     struct audio_pcm_info info;
 
     f_sample *clip;
@@ -79,6 +80,7 @@ typedef struct HWVoiceOut {
 
     int samples;
     LIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head;
+    LIST_HEAD (sw_cap_listhead, SWVoiceCap) cap_head;
     struct audio_pcm_ops *pcm_ops;
     LIST_ENTRY (HWVoiceOut) entries;
 } HWVoiceOut;
@@ -160,14 +162,34 @@ struct audio_pcm_ops {
     int  (*ctl_in)  (HWVoiceIn *hw, int cmd, ...);
 };
 
+struct capture_callback {
+    struct audio_capture_ops ops;
+    void *opaque;
+    LIST_ENTRY (capture_callback) entries;
+};
+
+struct CaptureVoiceOut {
+    HWVoiceOut hw;
+    void *buf;
+    LIST_HEAD (cb_listhead, capture_callback) cb_head;
+    LIST_ENTRY (CaptureVoiceOut) entries;
+};
+
+struct SWVoiceCap {
+    SWVoiceOut sw;
+    CaptureVoiceOut *cap;
+    LIST_ENTRY (SWVoiceCap) entries;
+};
+
 struct AudioState {
     struct audio_driver *drv;
     void *drv_opaque;
 
     QEMUTimer *ts;
-    LIST_HEAD (card_head, QEMUSoundCard) card_head;
+    LIST_HEAD (card_listhead, QEMUSoundCard) card_head;
     LIST_HEAD (hw_in_listhead, HWVoiceIn) hw_head_in;
     LIST_HEAD (hw_out_listhead, HWVoiceOut) hw_head_out;
+    LIST_HEAD (cap_listhead, CaptureVoiceOut) cap_head;
     int nb_hw_voices_out;
     int nb_hw_voices_in;
 };
@@ -182,8 +204,7 @@ extern struct audio_driver dsound_audio_
 extern struct audio_driver dsound_audio_driver;
 extern volume_t nominal_volume;
 
-void audio_pcm_init_info (struct audio_pcm_info *info, audsettings_t *as,
-                          int swap_endian);
+void audio_pcm_init_info (struct audio_pcm_info *info, audsettings_t *as);
 void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int 
len);
 
 int  audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int len);
@@ -202,15 +223,6 @@ static inline int audio_ring_dist (int d
 static inline int audio_ring_dist (int dst, int src, int len)
 {
     return (dst >= src) ? (dst - src) : (len - src + dst);
-}
-
-static inline int audio_need_to_swap_endian (int endianness)
-{
-#ifdef WORDS_BIGENDIAN
-    return endianness != 1;
-#else
-    return endianness != 0;
-#endif
 }
 
 #if defined __GNUC__
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/audio/audio_template.h
--- a/tools/ioemu/audio/audio_template.h        Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/audio/audio_template.h        Wed Aug 09 08:34:06 2006 -0600
@@ -140,13 +140,12 @@ static int glue (audio_pcm_sw_init_, TYP
     SW *sw,
     HW *hw,
     const char *name,
-    audsettings_t *as,
-    int endian
+    audsettings_t *as
     )
 {
     int err;
 
-    audio_pcm_init_info (&sw->info, as, audio_need_to_swap_endian (endian));
+    audio_pcm_init_info (&sw->info, as);
     sw->hw = hw;
     sw->active = 0;
 #ifdef DAC
@@ -164,7 +163,7 @@ static int glue (audio_pcm_sw_init_, TYP
 #endif
         [sw->info.nchannels == 2]
         [sw->info.sign]
-        [sw->info.swap_endian]
+        [sw->info.swap_endianness]
         [sw->info.bits == 16];
 
     sw->name = qemu_strdup (name);
@@ -200,6 +199,9 @@ static void glue (audio_pcm_hw_gc_, TYPE
     HW *hw = *hwp;
 
     if (!hw->sw_head.lh_first) {
+#ifdef DAC
+        audio_detach_capture (hw);
+#endif
         LIST_REMOVE (hw, entries);
         glue (s->nb_hw_voices_, TYPE) += 1;
         glue (audio_pcm_hw_free_resources_ ,TYPE) (hw);
@@ -266,7 +268,9 @@ static HW *glue (audio_pcm_hw_add_new_, 
 
     hw->pcm_ops = drv->pcm_ops;
     LIST_INIT (&hw->sw_head);
-
+#ifdef DAC
+    LIST_INIT (&hw->cap_head);
+#endif
     if (glue (hw->pcm_ops->init_, TYPE) (hw, as)) {
         goto err0;
     }
@@ -283,7 +287,7 @@ static HW *glue (audio_pcm_hw_add_new_, 
 #endif
         [hw->info.nchannels == 2]
         [hw->info.sign]
-        [hw->info.swap_endian]
+        [hw->info.swap_endianness]
         [hw->info.bits == 16];
 
     if (glue (audio_pcm_hw_alloc_resources_, TYPE) (hw)) {
@@ -292,6 +296,9 @@ static HW *glue (audio_pcm_hw_add_new_, 
 
     LIST_INSERT_HEAD (&s->glue (hw_head_, TYPE), hw, entries);
     glue (s->nb_hw_voices_, TYPE) -= 1;
+#ifdef DAC
+    audio_attach_capture (s, hw);
+#endif
     return hw;
 
  err1:
@@ -328,8 +335,7 @@ static SW *glue (audio_pcm_create_voice_
 static SW *glue (audio_pcm_create_voice_pair_, TYPE) (
     AudioState *s,
     const char *sw_name,
-    audsettings_t *as,
-    int sw_endian
+    audsettings_t *as
     )
 {
     SW *sw;
@@ -357,7 +363,7 @@ static SW *glue (audio_pcm_create_voice_
 
     glue (audio_pcm_hw_add_sw_, TYPE) (hw, sw);
 
-    if (glue (audio_pcm_sw_init_, TYPE) (sw, hw, sw_name, as, sw_endian)) {
+    if (glue (audio_pcm_sw_init_, TYPE) (sw, hw, sw_name, as)) {
         goto err3;
     }
 
@@ -399,8 +405,7 @@ SW *glue (AUD_open_, TYPE) (
     const char *name,
     void *callback_opaque ,
     audio_callback_fn_t callback_fn,
-    audsettings_t *as,
-    int sw_endian
+    audsettings_t *as
     )
 {
     AudioState *s;
@@ -421,7 +426,7 @@ SW *glue (AUD_open_, TYPE) (
 
     s = card->audio;
 
-    if (audio_bug (AUDIO_FUNC, audio_validate_settigs (as))) {
+    if (audio_bug (AUDIO_FUNC, audio_validate_settings (as))) {
         audio_print_settings (as);
         goto fail;
     }
@@ -473,12 +478,12 @@ SW *glue (AUD_open_, TYPE) (
         }
 
         glue (audio_pcm_sw_fini_, TYPE) (sw);
-        if (glue (audio_pcm_sw_init_, TYPE) (sw, hw, name, as, sw_endian)) {
+        if (glue (audio_pcm_sw_init_, TYPE) (sw, hw, name, as)) {
             goto fail;
         }
     }
     else {
-        sw = glue (audio_pcm_create_voice_pair_, TYPE) (s, name, as, 
sw_endian);
+        sw = glue (audio_pcm_create_voice_pair_, TYPE) (s, name, as);
         if (!sw) {
             dolog ("Failed to create voice `%s'\n", name);
             return NULL;
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/audio/coreaudio.c
--- a/tools/ioemu/audio/coreaudio.c     Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/audio/coreaudio.c     Wed Aug 09 08:34:06 2006 -0600
@@ -275,8 +275,6 @@ static OSStatus audioDeviceIOProc(
 #endif
     }
 
-    /* cleanup */
-    mixeng_clear (src, frameCount);
     rpos = (rpos + frameCount) % hw->samples;
     core->decr += frameCount;
     core->rpos = rpos;
@@ -297,7 +295,6 @@ static int coreaudio_init_out (HWVoiceOu
     UInt32 propertySize;
     int err;
     int bits = 8;
-    int endianess = 0;
     const char *typ = "playback";
     AudioValueRange frameRange;
 
@@ -310,16 +307,9 @@ static int coreaudio_init_out (HWVoiceOu
 
     if (as->fmt == AUD_FMT_S16 || as->fmt == AUD_FMT_U16) {
         bits = 16;
-        endianess = 1;
-    }
-
-    audio_pcm_init_info (
-        &hw->info,
-        as,
-        /* Following is irrelevant actually since we do not use
-           mixengs clipping routines */
-        audio_need_to_swap_endian (endianess)
-        );
+    }
+
+    audio_pcm_init_info (&hw->info, as);
 
     /* open default output device */
     propertySize = sizeof(core->outputDeviceID);
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/audio/dsound_template.h
--- a/tools/ioemu/audio/dsound_template.h       Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/audio/dsound_template.h       Wed Aug 09 08:34:06 2006 -0600
@@ -70,7 +70,13 @@ static int glue (dsound_lock_, TYPE) (
     int i;
     LPVOID p1 = NULL, p2 = NULL;
     DWORD blen1 = 0, blen2 = 0;
-
+    DWORD flag;
+
+#ifdef DSBTYPE_IN
+    flag = entire ? DSCBLOCK_ENTIREBUFFER : 0;
+#else
+    flag = entire ? DSBLOCK_ENTIREBUFFER : 0;
+#endif
     for (i = 0; i < conf.lock_retries; ++i) {
         hr = glue (IFACE, _Lock) (
             buf,
@@ -80,13 +86,7 @@ static int glue (dsound_lock_, TYPE) (
             &blen1,
             &p2,
             &blen2,
-            (entire
-#ifdef DSBTYPE_IN
-             ? DSCBLOCK_ENTIREBUFFER
-#else
-             ? DSBLOCK_ENTIREBUFFER
-#endif
-             : 0)
+            flag
             );
 
         if (FAILED (hr)) {
@@ -250,8 +250,8 @@ static int dsound_init_out (HWVoiceOut *
     }
 
     ds->first_time = 1;
-
-    audio_pcm_init_info (&hw->info, &obt_as, audio_need_to_swap_endian (0));
+    obt_as.endianness = 0;
+    audio_pcm_init_info (&hw->info, &obt_as);
 
     if (bc.dwBufferBytes & hw->info.align) {
         dolog (
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/audio/dsoundaudio.c
--- a/tools/ioemu/audio/dsoundaudio.c   Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/audio/dsoundaudio.c   Wed Aug 09 08:34:06 2006 -0600
@@ -453,13 +453,11 @@ static void dsound_write_sample (HWVoice
 
     if (src_len1) {
         hw->clip (dst, src1, src_len1);
-        mixeng_clear (src1, src_len1);
     }
 
     if (src_len2) {
         dst = advance (dst, src_len1 << hw->info.shift);
         hw->clip (dst, src2, src_len2);
-        mixeng_clear (src2, src_len2);
     }
 
     hw->rpos = pos % hw->samples;
@@ -987,6 +985,12 @@ static void *dsound_audio_init (void)
     hr = IDirectSound_Initialize (s->dsound, NULL);
     if (FAILED (hr)) {
         dsound_logerr (hr, "Could not initialize DirectSound\n");
+
+        hr = IDirectSound_Release (s->dsound);
+        if (FAILED (hr)) {
+            dsound_logerr (hr, "Could not release DirectSound\n");
+        }
+        s->dsound = NULL;
         return NULL;
     }
 
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/audio/fmodaudio.c
--- a/tools/ioemu/audio/fmodaudio.c     Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/audio/fmodaudio.c     Wed Aug 09 08:34:06 2006 -0600
@@ -153,13 +153,11 @@ static void fmod_write_sample (HWVoiceOu
 
     if (src_len1) {
         hw->clip (dst, src1, src_len1);
-        mixeng_clear (src1, src_len1);
     }
 
     if (src_len2) {
         dst = advance (dst, src_len1 << hw->info.shift);
         hw->clip (dst, src2, src_len2);
-        mixeng_clear (src2, src_len2);
     }
 
     hw->rpos = pos % hw->samples;
@@ -360,6 +358,7 @@ static int fmod_init_out (HWVoiceOut *hw
 {
     int bits16, mode, channel;
     FMODVoiceOut *fmd = (FMODVoiceOut *) hw;
+    audsettings_t obt_as = *as;
 
     mode = aud_to_fmodfmt (as->fmt, as->nchannels == 2 ? 1 : 0);
     fmd->fmod_sample = FSOUND_Sample_Alloc (
@@ -386,7 +385,8 @@ static int fmod_init_out (HWVoiceOut *hw
     fmd->channel = channel;
 
     /* FMOD always operates on little endian frames? */
-    audio_pcm_init_info (&hw->info, as, audio_need_to_swap_endian (0));
+    obt_as.endianness = 0;
+    audio_pcm_init_info (&hw->info, &obt_as);
     bits16 = (mode & FSOUND_16BITS) != 0;
     hw->samples = conf.nb_samples;
     return 0;
@@ -420,6 +420,7 @@ static int fmod_init_in (HWVoiceIn *hw, 
 {
     int bits16, mode;
     FMODVoiceIn *fmd = (FMODVoiceIn *) hw;
+    audsettings_t obt_as = *as;
 
     if (conf.broken_adc) {
         return -1;
@@ -442,7 +443,8 @@ static int fmod_init_in (HWVoiceIn *hw, 
     }
 
     /* FMOD always operates on little endian frames? */
-    audio_pcm_init_info (&hw->info, as, audio_need_to_swap_endian (0));
+    obt_as.endianness = 0;
+    audio_pcm_init_info (&hw->info, &obt_as);
     bits16 = (mode & FSOUND_16BITS) != 0;
     hw->samples = conf.nb_samples;
     return 0;
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/audio/noaudio.c
--- a/tools/ioemu/audio/noaudio.c       Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/audio/noaudio.c       Wed Aug 09 08:34:06 2006 -0600
@@ -40,21 +40,20 @@ static int no_run_out (HWVoiceOut *hw)
 {
     NoVoiceOut *no = (NoVoiceOut *) hw;
     int live, decr, samples;
-    int64_t now = qemu_get_clock (vm_clock);
-    int64_t ticks = now - no->old_ticks;
-    int64_t bytes = (ticks * hw->info.bytes_per_second) / ticks_per_sec;
-
-    if (bytes > INT_MAX) {
-        samples = INT_MAX >> hw->info.shift;
-    }
-    else {
-        samples = bytes >> hw->info.shift;
-    }
+    int64_t now;
+    int64_t ticks;
+    int64_t bytes;
 
     live = audio_pcm_hw_get_live_out (&no->hw);
     if (!live) {
         return 0;
     }
+
+    now = qemu_get_clock (vm_clock);
+    ticks = now - no->old_ticks;
+    bytes = (ticks * hw->info.bytes_per_second) / ticks_per_sec;
+    bytes = audio_MIN (bytes, INT_MAX);
+    samples = bytes >> hw->info.shift;
 
     no->old_ticks = now;
     decr = audio_MIN (live, samples);
@@ -69,7 +68,7 @@ static int no_write (SWVoiceOut *sw, voi
 
 static int no_init_out (HWVoiceOut *hw, audsettings_t *as)
 {
-    audio_pcm_init_info (&hw->info, as, 0);
+    audio_pcm_init_info (&hw->info, as);
     hw->samples = 1024;
     return 0;
 }
@@ -88,7 +87,7 @@ static int no_ctl_out (HWVoiceOut *hw, i
 
 static int no_init_in (HWVoiceIn *hw, audsettings_t *as)
 {
-    audio_pcm_init_info (&hw->info, as, 0);
+    audio_pcm_init_info (&hw->info, as);
     hw->samples = 1024;
     return 0;
 }
@@ -101,17 +100,20 @@ static int no_run_in (HWVoiceIn *hw)
 static int no_run_in (HWVoiceIn *hw)
 {
     NoVoiceIn *no = (NoVoiceIn *) hw;
-    int64_t now = qemu_get_clock (vm_clock);
-    int64_t ticks = now - no->old_ticks;
-    int64_t bytes = (ticks * hw->info.bytes_per_second) / ticks_per_sec;
     int live = audio_pcm_hw_get_live_in (hw);
     int dead = hw->samples - live;
-    int samples;
+    int samples = 0;
 
-    bytes = audio_MIN (bytes, INT_MAX);
-    samples = bytes >> hw->info.shift;
-    samples = audio_MIN (samples, dead);
+    if (dead) {
+        int64_t now = qemu_get_clock (vm_clock);
+        int64_t ticks = now - no->old_ticks;
+        int64_t bytes = (ticks * hw->info.bytes_per_second) / ticks_per_sec;
 
+        no->old_ticks = now;
+        bytes = audio_MIN (bytes, INT_MAX);
+        samples = bytes >> hw->info.shift;
+        samples = audio_MIN (samples, dead);
+    }
     return samples;
 }
 
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/audio/ossaudio.c
--- a/tools/ioemu/audio/ossaudio.c      Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/audio/ossaudio.c      Wed Aug 09 08:34:06 2006 -0600
@@ -55,12 +55,14 @@ static struct {
     int fragsize;
     const char *devpath_out;
     const char *devpath_in;
+    int debug;
 } conf = {
     .try_mmap = 0,
     .nfrags = 4,
     .fragsize = 4096,
     .devpath_out = "/dev/dsp",
-    .devpath_in = "/dev/dsp"
+    .devpath_in = "/dev/dsp",
+    .debug = 0
 };
 
 struct oss_params {
@@ -324,9 +326,20 @@ static int oss_run_out (HWVoiceOut *hw)
             return 0;
         }
 
-        if (abinfo.bytes < 0 || abinfo.bytes > bufsize) {
-            ldebug ("warning: Invalid available size, size=%d bufsize=%d\n",
-                    abinfo.bytes, bufsize);
+        if (abinfo.bytes > bufsize) {
+            if (conf.debug) {
+                dolog ("warning: Invalid available size, size=%d bufsize=%d\n"
+                       "please report your OS/audio hw to 
malc@xxxxxxxxxxxxx\n",
+                       abinfo.bytes, bufsize);
+            }
+            abinfo.bytes = bufsize;
+        }
+
+        if (abinfo.bytes < 0) {
+            if (conf.debug) {
+                dolog ("warning: Invalid available size, size=%d bufsize=%d\n",
+                       abinfo.bytes, bufsize);
+            }
             return 0;
         }
 
@@ -369,14 +382,11 @@ static int oss_run_out (HWVoiceOut *hw)
                            "alignment %d\n",
                            wbytes, written, hw->info.align + 1);
                 }
-                mixeng_clear (src, wsamples);
                 decr -= wsamples;
                 rpos = (rpos + wsamples) % hw->samples;
                 break;
             }
         }
-
-        mixeng_clear (src, convert_samples);
 
         rpos = (rpos + convert_samples) % hw->samples;
         samples -= convert_samples;
@@ -443,12 +453,9 @@ static int oss_init_out (HWVoiceOut *hw,
     obt_as.freq = obt.freq;
     obt_as.nchannels = obt.nchannels;
     obt_as.fmt = effective_fmt;
-
-    audio_pcm_init_info (
-        &hw->info,
-        &obt_as,
-        audio_need_to_swap_endian (endianness)
-        );
+    obt_as.endianness = endianness;
+
+    audio_pcm_init_info (&hw->info, &obt_as);
     oss->nfrags = obt.nfrags;
     oss->fragsize = obt.fragsize;
 
@@ -587,12 +594,9 @@ static int oss_init_in (HWVoiceIn *hw, a
     obt_as.freq = obt.freq;
     obt_as.nchannels = obt.nchannels;
     obt_as.fmt = effective_fmt;
-
-    audio_pcm_init_info (
-        &hw->info,
-        &obt_as,
-        audio_need_to_swap_endian (endianness)
-        );
+    obt_as.endianness = endianness;
+
+    audio_pcm_init_info (&hw->info, &obt_as);
     oss->nfrags = obt.nfrags;
     oss->fragsize = obt.fragsize;
 
@@ -730,6 +734,8 @@ static struct audio_option oss_options[]
      "Path to DAC device", NULL, 0},
     {"ADC_DEV", AUD_OPT_STR, &conf.devpath_in,
      "Path to ADC device", NULL, 0},
+    {"DEBUG", AUD_OPT_BOOL, &conf.debug,
+     "Turn on some debugging messages", NULL, 0},
     {NULL, 0, NULL, NULL, NULL, 0}
 };
 
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/audio/rate_template.h
--- a/tools/ioemu/audio/rate_template.h Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/audio/rate_template.h Wed Aug 09 08:34:06 2006 -0600
@@ -51,7 +51,7 @@ void NAME (void *opaque, st_sample_t *ib
     if (rate->opos_inc == (1ULL + UINT_MAX)) {
         int i, n = *isamp > *osamp ? *osamp : *isamp;
         for (i = 0; i < n; i++) {
-            OP (obuf[i].l, ibuf[i].r);
+            OP (obuf[i].l, ibuf[i].l);
             OP (obuf[i].r, ibuf[i].r);
         }
         *isamp = n;
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/audio/sdlaudio.c
--- a/tools/ioemu/audio/sdlaudio.c      Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/audio/sdlaudio.c      Wed Aug 09 08:34:06 2006 -0600
@@ -240,7 +240,6 @@ static void sdl_callback (void *opaque, 
 
             /* dolog ("in callback to_mix %d, chunk %d\n", to_mix, chunk); */
             hw->clip (buf, src, chunk);
-            mixeng_clear (src, chunk);
             sdl->rpos = (sdl->rpos + chunk) % hw->samples;
             to_mix -= chunk;
             buf += chunk << hw->info.shift;
@@ -336,12 +335,9 @@ static int sdl_init_out (HWVoiceOut *hw,
     obt_as.freq = obt.freq;
     obt_as.nchannels = obt.channels;
     obt_as.fmt = effective_fmt;
-
-    audio_pcm_init_info (
-        &hw->info,
-        &obt_as,
-        audio_need_to_swap_endian (endianess)
-        );
+    obt_as.endianness = endianess;
+
+    audio_pcm_init_info (&hw->info, &obt_as);
     hw->samples = obt.samples;
 
     s->initialized = 1;
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/audio/wavaudio.c
--- a/tools/ioemu/audio/wavaudio.c      Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/audio/wavaudio.c      Wed Aug 09 08:34:06 2006 -0600
@@ -81,7 +81,6 @@ static int wav_run_out (HWVoiceOut *hw)
 
         hw->clip (dst, src, convert_samples);
         qemu_put_buffer (wav->f, dst, convert_samples << hw->info.shift);
-        mixeng_clear (src, convert_samples);
 
         rpos = (rpos + convert_samples) % hw->samples;
         samples -= convert_samples;
@@ -136,7 +135,8 @@ static int wav_init_out (HWVoiceOut *hw,
 
     hdr[34] = bits16 ? 0x10 : 0x08;
 
-    audio_pcm_init_info (&hw->info, &wav_as, audio_need_to_swap_endian (0));
+    wav_as.endianness = 0;
+    audio_pcm_init_info (&hw->info, &wav_as);
 
     hw->samples = 1024;
     wav->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift);
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/block-bochs.c
--- a/tools/ioemu/block-bochs.c Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/block-bochs.c Wed Aug 09 08:34:06 2006 -0600
@@ -91,7 +91,7 @@ static int bochs_open(BlockDriverState *
     int fd, i;
     struct bochs_header bochs;
 
-    fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE);
+    fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE | O_SYNC);
     if (fd < 0) {
         fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
         if (fd < 0)
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/block-cloop.c
--- a/tools/ioemu/block-cloop.c Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/block-cloop.c Wed Aug 09 08:34:06 2006 -0600
@@ -55,7 +55,7 @@ static int cloop_open(BlockDriverState *
     BDRVCloopState *s = bs->opaque;
     uint32_t offsets_size,max_compressed_block_size=1,i;
 
-    s->fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
+    s->fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE | O_SYNC);
     if (s->fd < 0)
         return -1;
     bs->read_only = 1;
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/block-cow.c
--- a/tools/ioemu/block-cow.c   Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/block-cow.c   Wed Aug 09 08:34:06 2006 -0600
@@ -69,7 +69,7 @@ static int cow_open(BlockDriverState *bs
     struct cow_header_v2 cow_header;
     int64_t size;
 
-    fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE);
+    fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE | O_SYNC);
     if (fd < 0) {
         fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
         if (fd < 0)
@@ -250,6 +250,12 @@ static int cow_create(const char *filena
     return 0;
 }
 
+static void cow_flush(BlockDriverState *bs)
+{
+    BDRVCowState *s = bs->opaque;
+    fsync(s->fd);
+}
+
 BlockDriver bdrv_cow = {
     "cow",
     sizeof(BDRVCowState),
@@ -259,6 +265,7 @@ BlockDriver bdrv_cow = {
     cow_write,
     cow_close,
     cow_create,
+    cow_flush,
     cow_is_allocated,
 };
 #endif
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/block-qcow.c
--- a/tools/ioemu/block-qcow.c  Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/block-qcow.c  Wed Aug 09 08:34:06 2006 -0600
@@ -95,7 +95,7 @@ static int qcow_open(BlockDriverState *b
     int fd, len, i, shift;
     QCowHeader header;
     
-    fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE);
+    fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE | O_SYNC);
     if (fd < 0) {
         fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
         if (fd < 0)
@@ -693,6 +693,12 @@ int qcow_compress_cluster(BlockDriverSta
     return 0;
 }
 
+static void qcow_flush(BlockDriverState *bs)
+{
+    BDRVQcowState *s = bs->opaque;
+    fsync(s->fd);
+}
+
 BlockDriver bdrv_qcow = {
     "qcow",
     sizeof(BDRVQcowState),
@@ -702,6 +708,7 @@ BlockDriver bdrv_qcow = {
     qcow_write,
     qcow_close,
     qcow_create,
+    qcow_flush,
     qcow_is_allocated,
     qcow_set_key,
     qcow_make_empty
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/block-vmdk.c
--- a/tools/ioemu/block-vmdk.c  Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/block-vmdk.c  Wed Aug 09 08:34:06 2006 -0600
@@ -96,7 +96,7 @@ static int vmdk_open(BlockDriverState *b
     uint32_t magic;
     int l1_size;
 
-    fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE);
+    fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE | O_SYNC);
     if (fd < 0) {
         fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
         if (fd < 0)
@@ -426,6 +426,12 @@ static void vmdk_close(BlockDriverState 
     close(s->fd);
 }
 
+static void vmdk_flush(BlockDriverState *bs)
+{
+    BDRVVmdkState *s = bs->opaque;
+    fsync(s->fd);
+}
+
 BlockDriver bdrv_vmdk = {
     "vmdk",
     sizeof(BDRVVmdkState),
@@ -435,5 +441,6 @@ BlockDriver bdrv_vmdk = {
     vmdk_write,
     vmdk_close,
     vmdk_create,
+    vmdk_flush,
     vmdk_is_allocated,
 };
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/block-vpc.c
--- a/tools/ioemu/block-vpc.c   Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/block-vpc.c   Wed Aug 09 08:34:06 2006 -0600
@@ -163,7 +163,7 @@ static inline int seek_to_sector(BlockDr
     bitmap_offset = 512 * s->pagetable[pagetable_index];
     block_offset = bitmap_offset + 512 + (512 * pageentry_index);
     
-//    printf("sector: %llx, index: %x, offset: %x, bioff: %llx, bloff: %llx\n",
+//    printf("sector: %" PRIx64 ", index: %x, offset: %x, bioff: %" PRIx64 ", 
bloff: %" PRIx64 "\n",
 //     sector_num, pagetable_index, pageentry_index,
 //     bitmap_offset, block_offset);
 
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/block-vvfat.c
--- a/tools/ioemu/block-vvfat.c Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/block-vvfat.c Wed Aug 09 08:34:06 2006 -0600
@@ -2772,6 +2772,7 @@ BlockDriver bdrv_vvfat = {
     vvfat_read,
     vvfat_write,
     vvfat_close,
+    NULL, /* ??? Not sure if we can do any meaningful flushing.  */
     NULL,
     vvfat_is_allocated
 };
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/block.c
--- a/tools/ioemu/block.c       Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/block.c       Wed Aug 09 08:34:06 2006 -0600
@@ -615,6 +615,14 @@ const char *bdrv_get_device_name(BlockDr
     return bs->device_name;
 }
 
+void bdrv_flush(BlockDriverState *bs)
+{
+    if (bs->drv->bdrv_flush)
+        bs->drv->bdrv_flush(bs);
+    if (bs->backing_hd)
+        bdrv_flush(bs->backing_hd);
+}
+
 void bdrv_info(void)
 {
     BlockDriverState *bs;
@@ -677,7 +685,7 @@ static int raw_open(BlockDriverState *bs
     int rv;
 #endif
 
-    fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE);
+    fd = open(filename, O_RDWR | O_BINARY | O_LARGEFILE | O_SYNC);
     if (fd < 0) {
         fd = open(filename, O_RDONLY | O_BINARY | O_LARGEFILE);
         if (fd < 0)
@@ -750,8 +758,54 @@ static void raw_close(BlockDriverState *
 static void raw_close(BlockDriverState *bs)
 {
     BDRVRawState *s = bs->opaque;
+    bs->total_sectors = 0;
     close(s->fd);
 }
+
+#ifdef _WIN32
+#include <windows.h>
+#include <winioctl.h>
+
+int qemu_ftruncate64(int fd, int64_t length)
+{
+    LARGE_INTEGER li;
+    LONG high;
+    HANDLE h;
+    BOOL res;
+
+    if ((GetVersion() & 0x80000000UL) && (length >> 32) != 0)
+       return -1;
+
+    h = (HANDLE)_get_osfhandle(fd);
+
+    /* get current position, ftruncate do not change position */
+    li.HighPart = 0;
+    li.LowPart = SetFilePointer (h, 0, &li.HighPart, FILE_CURRENT);
+    if (li.LowPart == 0xffffffffUL && GetLastError() != NO_ERROR)
+       return -1;
+
+    high = length >> 32;
+    if (!SetFilePointer(h, (DWORD) length, &high, FILE_BEGIN))
+       return -1;
+    res = SetEndOfFile(h);
+
+    /* back to old position */
+    SetFilePointer(h, li.LowPart, &li.HighPart, FILE_BEGIN);
+    return res ? 0 : -1;
+}
+
+static int set_sparse(int fd)
+{
+    DWORD returned;
+    return (int) DeviceIoControl((HANDLE)_get_osfhandle(fd), FSCTL_SET_SPARSE,
+                                NULL, 0, NULL, 0, &returned, NULL);
+}
+#else
+static inline int set_sparse(int fd)
+{
+    return 1;
+}
+#endif
 
 static int raw_create(const char *filename, int64_t total_size,
                       const char *backing_file, int flags)
@@ -765,9 +819,16 @@ static int raw_create(const char *filena
               0644);
     if (fd < 0)
         return -EIO;
+    set_sparse(fd);
     ftruncate(fd, total_size * 512);
     close(fd);
     return 0;
+}
+
+static void raw_flush(BlockDriverState *bs)
+{
+    BDRVRawState *s = bs->opaque;
+    fsync(s->fd);
 }
 
 BlockDriver bdrv_raw = {
@@ -779,6 +840,7 @@ BlockDriver bdrv_raw = {
     raw_write,
     raw_close,
     raw_create,
+    raw_flush,
 };
 
 void bdrv_init(void)
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/block_int.h
--- a/tools/ioemu/block_int.h   Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/block_int.h   Wed Aug 09 08:34:06 2006 -0600
@@ -36,6 +36,7 @@ struct BlockDriver {
     void (*bdrv_close)(BlockDriverState *bs);
     int (*bdrv_create)(const char *filename, int64_t total_sectors, 
                        const char *backing_file, int flags);
+    void (*bdrv_flush)(BlockDriverState *bs);
     int (*bdrv_is_allocated)(BlockDriverState *bs, int64_t sector_num,
                              int nb_sectors, int *pnum);
     int (*bdrv_set_key)(BlockDriverState *bs, const char *key);
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/cocoa.m
--- a/tools/ioemu/cocoa.m       Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/cocoa.m       Wed Aug 09 08:34:06 2006 -0600
@@ -439,23 +439,40 @@ static void cocoa_refresh(DisplayState *
                                 kbd_put_keycode(keycode & 0x7f); //remove e0 
bit in front
                             /* handle monitor key events */
                             } else {
+                                int keysym = 0;
+
                                 switch([event keyCode]) {
-                                    case 123:
-                                        kbd_put_keysym(QEMU_KEY_LEFT);
-                                        break;
-                                    case 124:
-                                        kbd_put_keysym(QEMU_KEY_RIGHT);
-                                        break;
-                                    case 125:
-                                        kbd_put_keysym(QEMU_KEY_DOWN);
-                                        break;
-                                    case 126:
-                                        kbd_put_keysym(QEMU_KEY_UP);
-                                        break;
-                                    default:
-                                        kbd_put_keysym([[event characters] 
characterAtIndex:0]);
-                                        break;
+                                case 115:
+                                    keysym = QEMU_KEY_HOME;
+                                    break;
+                                case 117:
+                                    keysym = QEMU_KEY_DELETE;
+                                    break;
+                                case 119:
+                                    keysym = QEMU_KEY_END;
+                                    break;
+                                case 123:
+                                    keysym = QEMU_KEY_LEFT;
+                                    break;
+                                case 124:
+                                    keysym = QEMU_KEY_RIGHT;
+                                    break;
+                                case 125:
+                                    keysym = QEMU_KEY_DOWN;
+                                    break;
+                                case 126:
+                                    keysym = QEMU_KEY_UP;
+                                    break;
+                                default:
+                                    {
+                                        NSString *ks = [event characters];
+
+                                        if ([ks length] > 0)
+                                            keysym = [ks characterAtIndex:0];
+                                    }
                                 }
+                                if (keysym)
+                                    kbd_put_keysym(keysym);
                             }
                         }
                     }
@@ -867,10 +884,9 @@ static void setupWindowMenu(void)
     /* Finally give up our references to the objects */
     [windowMenu release];
     [windowMenuItem release];
- 
-}
-
-static void CustomApplicationMain (argc, argv)
+}
+
+static void CustomApplicationMain(void)
 {
     NSAutoreleasePool   *pool = [[NSAutoreleasePool alloc] init];
     QemuCocoaGUIController *gui_controller;
@@ -904,8 +920,8 @@ int main(int argc, char **argv)
 {
     gArgc = argc;
     gArgv = argv;
-    
-    CustomApplicationMain (argc, argv);
-    
+
+    CustomApplicationMain();
+
     return 0;
 }
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/configure
--- a/tools/ioemu/configure     Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/configure     Wed Aug 09 08:34:06 2006 -0600
@@ -96,6 +96,8 @@ softmmu="yes"
 softmmu="yes"
 user="no"
 build_docs="no"
+build_acpi_tables="no"
+uname_release=""
 
 # OS specific
 targetos=`uname -s`
@@ -212,7 +214,7 @@ for opt do
   ;;
   --fmod-inc=*) fmod_inc="$optarg"
   ;;
-  --enable-mingw32) mingw32="yes" ; cross_prefix="i386-mingw32-"
+  --enable-mingw32) mingw32="yes" ; cross_prefix="i386-mingw32-" ; user="no"
   ;;
   --disable-slirp) slirp="no"
   ;;
@@ -226,8 +228,6 @@ for opt do
   ;;
   --enable-cocoa) cocoa="yes" ; coreaudio="yes" ; sdl="no"
   ;;
-  --disable-gfx-check) check_gfx="no"
-  ;;
   --disable-gcc-check) check_gcc="no"
   ;;
   --disable-system) softmmu="no"
@@ -237,6 +237,10 @@ for opt do
   --disable-user) user="no"
   ;;
   --enable-user) user="yes"
+  ;;
+  --enable-uname-release=*) uname_release="$optarg"
+  ;;
+  --enable-iasl) build_acpi_tables="yes"
   ;;
   esac
 done
@@ -285,6 +289,8 @@ echo "  --disable-user           disable
 echo "  --disable-user           disable all linux usermode emulation targets"
 echo "  --fmod-lib               path to FMOD library"
 echo "  --fmod-inc               path to FMOD includes"
+echo "  --enable-uname-release=R Return R for uname -r in usermode emulation"
+echo "  --enable-iasl            compilation of ACPI tables with the IASL 
compiler"
 echo ""
 echo "NOTE: The object files are build at the place where configure is 
launched"
 exit 1
@@ -294,15 +300,21 @@ ar="${cross_prefix}${ar}"
 ar="${cross_prefix}${ar}"
 strip="${cross_prefix}${strip}"
 
-if [ ! -x "`which $cc`" ] ; then
-    echo "Compiler $cc could not be found"
-    exit
+# check that the C compiler works.
+cat > $TMPC <<EOF
+int main(void) {}
+EOF
+
+if $cc -c -o $TMPO $TMPC 2>/dev/null ; then
+  : C compiler works ok
+else
+    echo "ERROR: \"$cc\" either does not exist or does not work"
+    exit 1
 fi
 
 if test "$mingw32" = "yes" ; then
     linux="no"
     EXESUF=".exe"
-    gdbstub="no"
     oss="no"
     if [ "$cpu" = "i386" ] ; then
         kqemu="yes"
@@ -553,6 +565,8 @@ echo "FMOD support      $fmod $fmod_supp
 echo "FMOD support      $fmod $fmod_support"
 echo "kqemu support     $kqemu"
 echo "Documentation     $build_docs"
+[ ! -z "$uname_release" ] && \
+echo "uname -r          $uname_release"
 
 if test $sdl_too_old = "yes"; then
 echo "-> Your SDL version is too old - please upgrade to have SDL support"
@@ -705,6 +719,9 @@ if [ "$build_docs" = "yes" ] ; then
 if [ "$build_docs" = "yes" ] ; then
   echo "BUILD_DOCS=yes" >> $config_mak
 fi
+if [ "$build_acpi_tables" = "yes" ] ; then
+  echo "BUILD_ACPI_TABLES=yes" >> $config_mak
+fi
 
 # XXX: suppress that
 if [ "$bsd" = "yes" ] ; then
@@ -712,6 +729,8 @@ if [ "$bsd" = "yes" ] ; then
   echo "#define MAP_ANONYMOUS MAP_ANON" >> $config_h
   echo "#define _BSD 1" >> $config_h
 fi
+
+echo "#define CONFIG_UNAME_RELEASE \"$uname_release\"" >> $config_h
 
 for target in $target_list; do
 target_dir="$target"
@@ -725,6 +744,7 @@ target_bigendian="no"
 [ "$target_cpu" = "ppc" ] && target_bigendian=yes
 [ "$target_cpu" = "ppc64" ] && target_bigendian=yes
 [ "$target_cpu" = "mips" ] && target_bigendian=yes
+[ "$target_cpu" = "sh4eb" ] && target_bigendian=yes
 target_softmmu="no"
 if expr $target : '.*-softmmu' > /dev/null ; then
   target_softmmu="yes"
@@ -736,14 +756,6 @@ if expr $target : '.*-user' > /dev/null 
   target_user_only="yes"
 fi
 
-if test "$target_user_only" = "no" -a "$check_gfx" = "yes" \
-        -a "$sdl" = "no" -a "$cocoa" = "no" ; then
-    echo "ERROR: QEMU requires SDL or Cocoa for graphical output"
-    echo "To build QEMU without graphical output configure with 
--disable-gfx-check"
-    echo "Note that this will disable all output from the virtual graphics 
card."
-    exit 1;
-fi
-
 #echo "Creating $config_mak, $config_h and $target_dir/Makefile"
 
 mkdir -p $target_dir
@@ -769,6 +781,7 @@ echo "include ../config-host.mak" >> $co
 echo "include ../config-host.mak" >> $config_mak
 echo "#include \"../config-host.h\"" >> $config_h
 
+bflt="no"
 interp_prefix1=`echo "$interp_prefix" | sed "s/%M/$target_cpu/g"`
 echo "#define CONFIG_QEMU_PREFIX \"$interp_prefix1\"" >> $config_h
 
@@ -789,6 +802,7 @@ elif test "$target_cpu" = "arm" -o "$tar
   echo "TARGET_ARCH=arm" >> $config_mak
   echo "#define TARGET_ARCH \"arm\"" >> $config_h
   echo "#define TARGET_ARM 1" >> $config_h
+  bflt="yes"
 elif test "$target_cpu" = "sparc" ; then
   echo "TARGET_ARCH=sparc" >> $config_mak
   echo "#define TARGET_ARCH \"sparc\"" >> $config_h
@@ -819,10 +833,13 @@ elif test "$target_cpu" = "mips" -o "$ta
   echo "TARGET_ARCH=mips" >> $config_mak
   echo "#define TARGET_ARCH \"mips\"" >> $config_h
   echo "#define TARGET_MIPS 1" >> $config_h
-elif test "$target_cpu" = "sh4" ; then
+  echo "CONFIG_SOFTFLOAT=yes" >> $config_mak
+  echo "#define CONFIG_SOFTFLOAT 1" >> $config_h
+elif test "$target_cpu" = "sh4" -o "$target_cpu" = "sh4eb" ; then
   echo "TARGET_ARCH=sh4" >> $config_mak
   echo "#define TARGET_ARCH \"sh4\"" >> $config_h
   echo "#define TARGET_SH4 1" >> $config_h
+  bflt="yes"
 else
   echo "Unsupported target CPU"
   exit 1
@@ -844,9 +861,13 @@ if expr $target : '.*-dm' > /dev/null ; 
   echo "#define CONFIG_DM 1" >> $config_h
 fi
 
-if test "$target_cpu" = "arm" -o "$target_cpu" = "armeb" ; then
+if test "$target_cpu" = "arm" -o "$target_cpu" = "armeb" -o "$target_cpu" = 
"sparc" -o "$target_cpu" = "sparc64"; then
   echo "CONFIG_SOFTFLOAT=yes" >> $config_mak
   echo "#define CONFIG_SOFTFLOAT 1" >> $config_h
+fi
+if test "$target_user_only" = "yes" -a "$bflt" = "yes"; then
+  echo "TARGET_HAS_BFLT=yes" >> $config_mak
+  echo "#define TARGET_HAS_BFLT 1" >> $config_h
 fi
 # sdl defines
 
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/console.c
--- a/tools/ioemu/console.c     Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/console.c     Wed Aug 09 08:34:06 2006 -0600
@@ -27,8 +27,8 @@
 #define DEFAULT_BACKSCROLL 512
 #define MAX_CONSOLES 12
 
-#define RGBA(r, g, b, a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
-#define RGB(r, g, b) RGBA(r, g, b, 0xff)
+#define QEMU_RGBA(r, g, b, a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b))
+#define QEMU_RGB(r, g, b) QEMU_RGBA(r, g, b, 0xff)
 
 typedef struct TextAttributes {
     uint8_t fgcol:4;
@@ -52,6 +52,57 @@ enum TTYState {
     TTY_STATE_ESC,
     TTY_STATE_CSI,
 };
+
+typedef struct QEMUFIFO {
+    uint8_t *buf;
+    int buf_size;
+    int count, wptr, rptr;
+} QEMUFIFO;
+
+int qemu_fifo_write(QEMUFIFO *f, const uint8_t *buf, int len1)
+{
+    int l, len;
+
+    l = f->buf_size - f->count;
+    if (len1 > l)
+        len1 = l;
+    len = len1;
+    while (len > 0) {
+        l = f->buf_size - f->wptr;
+        if (l > len)
+            l = len;
+        memcpy(f->buf + f->wptr, buf, l);
+        f->wptr += l;
+        if (f->wptr >= f->buf_size)
+            f->wptr = 0;
+        buf += l;
+        len -= l;
+    }
+    f->count += len1;
+    return len1;
+}
+
+int qemu_fifo_read(QEMUFIFO *f, uint8_t *buf, int len1)
+{
+    int l, len;
+
+    if (len1 > f->count)
+        len1 = f->count;
+    len = len1;
+    while (len > 0) {
+        l = f->buf_size - f->rptr;
+        if (l > len)
+            l = len;
+        memcpy(buf, f->buf + f->rptr, l);
+        f->rptr += l;
+        if (f->rptr >= f->buf_size)
+            f->rptr = 0;
+        buf += l;
+        len -= l;
+    }
+    f->count -= len1;
+    return len1;
+}
 
 /* ??? This is mis-named.
    It is used for both text and graphical consoles.  */
@@ -81,8 +132,13 @@ struct TextConsole {
     int nb_esc_params;
 
     /* kbd read handler */
+    IOCanRWHandler *fd_can_read; 
     IOReadHandler *fd_read;
     void *fd_opaque;
+    /* fifo for key pressed */
+    QEMUFIFO out_fifo;
+    uint8_t out_fifo_buf[16];
+    QEMUTimer *kbd_timer;
 };
 
 static TextConsole *active_console;
@@ -274,24 +330,24 @@ enum color_names {
 
 static const uint32_t color_table_rgb[2][8] = {
     {   /* dark */
-        RGB(0x00, 0x00, 0x00),  /* black */
-        RGB(0xaa, 0x00, 0x00),  /* red */
-        RGB(0x00, 0xaa, 0x00),  /* green */
-        RGB(0xaa, 0xaa, 0x00),  /* yellow */
-        RGB(0x00, 0x00, 0xaa),  /* blue */
-        RGB(0xaa, 0x00, 0xaa),  /* magenta */
-        RGB(0x00, 0xaa, 0xaa),  /* cyan */
-        RGB(0xaa, 0xaa, 0xaa),  /* white */
+        QEMU_RGB(0x00, 0x00, 0x00),  /* black */
+        QEMU_RGB(0xaa, 0x00, 0x00),  /* red */
+        QEMU_RGB(0x00, 0xaa, 0x00),  /* green */
+        QEMU_RGB(0xaa, 0xaa, 0x00),  /* yellow */
+        QEMU_RGB(0x00, 0x00, 0xaa),  /* blue */
+        QEMU_RGB(0xaa, 0x00, 0xaa),  /* magenta */
+        QEMU_RGB(0x00, 0xaa, 0xaa),  /* cyan */
+        QEMU_RGB(0xaa, 0xaa, 0xaa),  /* white */
     },
     {   /* bright */
-        RGB(0x00, 0x00, 0x00),  /* black */
-        RGB(0xff, 0x00, 0x00),  /* red */
-        RGB(0x00, 0xff, 0x00),  /* green */
-        RGB(0xff, 0xff, 0x00),  /* yellow */
-        RGB(0x00, 0x00, 0xff),  /* blue */
-        RGB(0xff, 0x00, 0xff),  /* magenta */
-        RGB(0x00, 0xff, 0xff),  /* cyan */
-        RGB(0xff, 0xff, 0xff),  /* white */
+        QEMU_RGB(0x00, 0x00, 0x00),  /* black */
+        QEMU_RGB(0xff, 0x00, 0x00),  /* red */
+        QEMU_RGB(0x00, 0xff, 0x00),  /* green */
+        QEMU_RGB(0xff, 0xff, 0x00),  /* yellow */
+        QEMU_RGB(0x00, 0x00, 0xff),  /* blue */
+        QEMU_RGB(0xff, 0x00, 0xff),  /* magenta */
+        QEMU_RGB(0x00, 0xff, 0xff),  /* cyan */
+        QEMU_RGB(0xff, 0xff, 0xff),  /* white */
     }
 };
 
@@ -563,7 +619,6 @@ static void console_put_lf(TextConsole *
     TextCell *c;
     int x, y1;
 
-    s->x = 0;
     s->y++;
     if (s->y >= s->height) {
         s->y = s->height - 1;
@@ -712,15 +767,12 @@ static void console_putchar(TextConsole 
             console_put_lf(s);
             break;
         case '\b':  /* backspace */
-            if(s->x > 0) s->x--;
-            y1 = (s->y_base + s->y) % s->total_height;
-            c = &s->cells[y1 * s->width + s->x];
-            c->ch = ' ';
-            c->t_attrib = s->t_attrib;
-            update_xy(s, s->x, s->y);
+            if (s->x > 0) 
+                s->x--;
             break;
         case '\t':  /* tabspace */
             if (s->x + (8 - (s->x % 8)) > s->width) {
+                s->x = 0;
                 console_put_lf(s);
             } else {
                 s->x = s->x + (8 - (s->x % 8));
@@ -739,8 +791,10 @@ static void console_putchar(TextConsole 
             c->t_attrib = s->t_attrib;
             update_xy(s, s->x, s->y);
             s->x++;
-            if (s->x >= s->width)
+            if (s->x >= s->width) {
+                s->x = 0;
                 console_put_lf(s);
+            }
             break;
         }
         break;
@@ -835,6 +889,7 @@ static void console_chr_add_read_handler
                                          IOReadHandler *fd_read, void *opaque)
 {
     TextConsole *s = chr->opaque;
+    s->fd_can_read = fd_can_read;
     s->fd_read = fd_read;
     s->fd_opaque = opaque;
 }
@@ -854,6 +909,28 @@ static void console_send_event(CharDrive
     }
 }
 
+static void kbd_send_chars(void *opaque)
+{
+    TextConsole *s = opaque;
+    int len;
+    uint8_t buf[16];
+    
+    len = s->fd_can_read(s->fd_opaque);
+    if (len > s->out_fifo.count)
+        len = s->out_fifo.count;
+    if (len > 0) {
+        if (len > sizeof(buf))
+            len = sizeof(buf);
+        qemu_fifo_read(&s->out_fifo, buf, len);
+        s->fd_read(s->fd_opaque, buf, len);
+    }
+    /* characters are pending: we send them a bit later (XXX:
+       horrible, should change char device API) */
+    if (s->out_fifo.count > 0) {
+        qemu_mod_timer(s->kbd_timer, qemu_get_clock(rt_clock) + 1);
+    }
+}
+
 /* called when an ascii key is pressed */
 void kbd_put_keysym(int keysym)
 {
@@ -879,25 +956,26 @@ void kbd_put_keysym(int keysym)
         console_scroll(10);
         break;
     default:
+        /* convert the QEMU keysym to VT100 key string */
+        q = buf;
+        if (keysym >= 0xe100 && keysym <= 0xe11f) {
+            *q++ = '\033';
+            *q++ = '[';
+            c = keysym - 0xe100;
+            if (c >= 10)
+                *q++ = '0' + (c / 10);
+            *q++ = '0' + (c % 10);
+            *q++ = '~';
+        } else if (keysym >= 0xe120 && keysym <= 0xe17f) {
+            *q++ = '\033';
+            *q++ = '[';
+            *q++ = keysym & 0xff;
+        } else {
+                *q++ = keysym;
+        }
         if (s->fd_read) {
-            /* convert the QEMU keysym to VT100 key string */
-            q = buf;
-            if (keysym >= 0xe100 && keysym <= 0xe11f) {
-                *q++ = '\033';
-                *q++ = '[';
-                c = keysym - 0xe100;
-                if (c >= 10)
-                    *q++ = '0' + (c / 10);
-                *q++ = '0' + (c % 10);
-                *q++ = '~';
-            } else if (keysym >= 0xe120 && keysym <= 0xe17f) {
-                *q++ = '\033';
-                *q++ = '[';
-                *q++ = keysym & 0xff;
-            } else {
-                *q++ = keysym;
-            }
-            s->fd_read(s->fd_opaque, buf, q - buf);
+            qemu_fifo_write(&s->out_fifo, buf, q - buf);
+            kbd_send_chars(s);
         }
         break;
     }
@@ -984,6 +1062,10 @@ CharDriverState *text_console_init(Displ
     chr->chr_add_read_handler = console_chr_add_read_handler;
     chr->chr_send_event = console_send_event;
 
+    s->out_fifo.buf = s->out_fifo_buf;
+    s->out_fifo.buf_size = sizeof(s->out_fifo_buf);
+    s->kbd_timer = qemu_new_timer(rt_clock, kbd_send_chars, s);
+    
     if (!color_inited) {
         color_inited = 1;
         set_color_table(ds);
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/cpu-all.h
--- a/tools/ioemu/cpu-all.h     Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/cpu-all.h     Wed Aug 09 08:34:06 2006 -0600
@@ -878,6 +878,10 @@ extern uint8_t *phys_ram_dirty;
 #define IO_MEM_ROM         (1 << IO_MEM_SHIFT) /* hardcoded offset */
 #define IO_MEM_UNASSIGNED  (2 << IO_MEM_SHIFT)
 #define IO_MEM_NOTDIRTY    (4 << IO_MEM_SHIFT) /* used internally, never use 
directly */
+/* acts like a ROM when read and like a device when written. As an
+   exception, the write memory callback gets the ram offset instead of
+   the physical address */
+#define IO_MEM_ROMD        (1)
 
 typedef void CPUWriteMemoryFunc(void *opaque, target_phys_addr_t addr, 
uint32_t value);
 typedef uint32_t CPUReadMemoryFunc(void *opaque, target_phys_addr_t addr);
@@ -946,13 +950,105 @@ void dump_exec_info(FILE *f,
 void dump_exec_info(FILE *f,
                     int (*cpu_fprintf)(FILE *f, const char *fmt, ...));
 
+/*******************************************/
+/* host CPU ticks (if available) */
+
+#if defined(__powerpc__)
+
+static inline uint32_t get_tbl(void) 
+{
+    uint32_t tbl;
+    asm volatile("mftb %0" : "=r" (tbl));
+    return tbl;
+}
+
+static inline uint32_t get_tbu(void) 
+{
+       uint32_t tbl;
+       asm volatile("mftbu %0" : "=r" (tbl));
+       return tbl;
+}
+
+static inline int64_t cpu_get_real_ticks(void)
+{
+    uint32_t l, h, h1;
+    /* NOTE: we test if wrapping has occurred */
+    do {
+        h = get_tbu();
+        l = get_tbl();
+        h1 = get_tbu();
+    } while (h != h1);
+    return ((int64_t)h << 32) | l;
+}
+
+#elif defined(__i386__)
+
+static inline int64_t cpu_get_real_ticks(void)
+{
+    int64_t val;
+    asm volatile ("rdtsc" : "=A" (val));
+    return val;
+}
+
+#elif defined(__x86_64__)
+
+static inline int64_t cpu_get_real_ticks(void)
+{
+    uint32_t low,high;
+    int64_t val;
+    asm volatile("rdtsc" : "=a" (low), "=d" (high));
+    val = high;
+    val <<= 32;
+    val |= low;
+    return val;
+}
+
+#elif defined(__ia64)
+
+static inline int64_t cpu_get_real_ticks(void)
+{
+       int64_t val;
+       asm volatile ("mov %0 = ar.itc" : "=r"(val) :: "memory");
+       return val;
+}
+
+#elif defined(__s390__)
+
+static inline int64_t cpu_get_real_ticks(void)
+{
+    int64_t val;
+    asm volatile("stck 0(%1)" : "=m" (val) : "a" (&val) : "cc");
+    return val;
+}
+
+#elif defined(__sparc_v9__)
+
+static inline int64_t cpu_get_real_ticks (void)
+{
+#if     defined(_LP64)
+        uint64_t        rval;
+        asm volatile("rd %%tick,%0" : "=r"(rval));
+        return rval;
+#else
+        union {
+                uint64_t i64;
+                struct {
+                        uint32_t high;
+                        uint32_t low;
+                }       i32;
+        } rval;
+        asm volatile("rd %%tick,%1; srlx %1,32,%0"
+                : "=r"(rval.i32.high), "=r"(rval.i32.low));
+        return rval.i64;
+#endif
+}
+#endif
+
 /* profiling */
 #ifdef CONFIG_PROFILER
 static inline int64_t profile_getclock(void)
 {
-    int64_t val;
-    asm volatile ("rdtsc" : "=A" (val));
-    return val;
+    return cpu_get_real_ticks();
 }
 
 extern int64_t kqemu_time, kqemu_time_start;
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/cpu-defs.h
--- a/tools/ioemu/cpu-defs.h    Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/cpu-defs.h    Wed Aug 09 08:34:06 2006 -0600
@@ -47,7 +47,7 @@ typedef uint32_t target_ulong;
 #elif TARGET_LONG_SIZE == 8
 typedef int64_t target_long;
 typedef uint64_t target_ulong;
-#define TARGET_FMT_lx "%016llx"
+#define TARGET_FMT_lx "%016" PRIx64
 #else
 #error TARGET_LONG_SIZE undefined
 #endif
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/cpu-exec.c
--- a/tools/ioemu/cpu-exec.c    Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/cpu-exec.c    Wed Aug 09 08:34:06 2006 -0600
@@ -47,7 +47,7 @@ void cpu_loop_exit(void)
     longjmp(env->jmp_env, 1);
 }
 #endif
-#ifndef TARGET_SPARC
+#if !(defined(TARGET_SPARC) || defined(TARGET_SH4))
 #define reg_T2
 #endif
 
@@ -175,9 +175,13 @@ static inline TranslationBlock *tb_find_
     pc = env->regs[15];
 #elif defined(TARGET_SPARC)
 #ifdef TARGET_SPARC64
-    flags = (env->pstate << 2) | ((env->lsu & (DMMU_E | IMMU_E)) >> 2);
-#else
-    flags = env->psrs | ((env->mmuregs[0] & (MMU_E | MMU_NF)) << 1);
+    // Combined FPU enable bits . PRIV . DMMU enabled . IMMU enabled
+    flags = (((env->pstate & PS_PEF) >> 1) | ((env->fprs & FPRS_FEF) << 2))
+        | (env->pstate & PS_PRIV) | ((env->lsu & (DMMU_E | IMMU_E)) >> 2);
+#else
+    // FPU enable . MMU enabled . MMU no-fault . Supervisor
+    flags = (env->psref << 3) | ((env->mmuregs[0] & (MMU_E | MMU_NF)) << 1)
+        | env->psrs;
 #endif
     cs_base = env->npc;
     pc = env->pc;
@@ -253,7 +257,7 @@ int cpu_exec(CPUState *env1)
     uint32_t *saved_regwptr;
 #endif
 #endif
-#ifdef __sparc__
+#if defined(__sparc__) && !defined(HOST_SOLARIS)
     int saved_i7, tmp_T0;
 #endif
     int ret, interrupt_request;
@@ -323,7 +327,7 @@ int cpu_exec(CPUState *env1)
 #if defined(reg_T2)
     saved_T2 = T2;
 #endif
-#ifdef __sparc__
+#if defined(__sparc__) && !defined(HOST_SOLARIS)
     /* we also save i7 because longjmp may not restore it */
     asm volatile ("mov %%i7, %0" : "=r" (saved_i7));
 #endif
@@ -447,7 +451,7 @@ int cpu_exec(CPUState *env1)
 
             T0 = 0; /* force lookup of first TB */
             for(;;) {
-#ifdef __sparc__
+#if defined(__sparc__) && !defined(HOST_SOLARIS)
                 /* g1 can be modified by some libc? functions */ 
                 tmp_T0 = T0;
 #endif     
@@ -467,7 +471,7 @@ int cpu_exec(CPUState *env1)
                         do_interrupt(intno, 0, 0, 0, 1);
                         /* ensure that no TB jump will be modified as
                            the program flow was changed */
-#ifdef __sparc__
+#if defined(__sparc__) && !defined(HOST_SOLARIS)
                         tmp_T0 = 0;
 #else
                         T0 = 0;
@@ -486,7 +490,7 @@ int cpu_exec(CPUState *env1)
                            env->error_code = 0;
                             do_interrupt(env);
                             env->interrupt_request &= ~CPU_INTERRUPT_HARD;
-#ifdef __sparc__
+#if defined(__sparc__) && !defined(HOST_SOLARIS)
                             tmp_T0 = 0;
 #else
                             T0 = 0;
@@ -497,7 +501,7 @@ int cpu_exec(CPUState *env1)
                             env->error_code = 0;
                             do_interrupt(env);
                             env->interrupt_request &= ~CPU_INTERRUPT_TIMER;
-#ifdef __sparc__
+#if defined(__sparc__) && !defined(HOST_SOLARIS)
                             tmp_T0 = 0;
 #else
                             T0 = 0;
@@ -516,7 +520,7 @@ int cpu_exec(CPUState *env1)
                         env->error_code = 0;
                         do_interrupt(env);
                         env->interrupt_request &= ~CPU_INTERRUPT_HARD;
-#ifdef __sparc__
+#if defined(__sparc__) && !defined(HOST_SOLARIS)
                         tmp_T0 = 0;
 #else
                         T0 = 0;
@@ -534,7 +538,7 @@ int cpu_exec(CPUState *env1)
                            env->interrupt_request &= ~CPU_INTERRUPT_HARD;
                            do_interrupt(env->interrupt_index);
                            env->interrupt_index = 0;
-#ifdef __sparc__
+#if defined(__sparc__) && !defined(HOST_SOLARIS)
                             tmp_T0 = 0;
 #else
                             T0 = 0;
@@ -561,11 +565,13 @@ int cpu_exec(CPUState *env1)
 #elif defined(TARGET_SH4)
                    /* XXXXX */
 #endif
+                   /* Don't use the cached interupt_request value,
+                      do_interrupt may have updated the EXITTB flag. */
                     if (env->interrupt_request & CPU_INTERRUPT_EXITTB) {
                         env->interrupt_request &= ~CPU_INTERRUPT_EXITTB;
                         /* ensure that no TB jump will be modified as
                            the program flow was changed */
-#ifdef __sparc__
+#if defined(__sparc__) && !defined(HOST_SOLARIS)
                         tmp_T0 = 0;
 #else
                         T0 = 0;
@@ -633,7 +639,7 @@ int cpu_exec(CPUState *env1)
                             lookup_symbol(tb->pc));
                 }
 #endif
-#ifdef __sparc__
+#if defined(__sparc__) && !defined(HOST_SOLARIS)
                 T0 = tmp_T0;
 #endif     
                 /* see if we can patch the calling TB. When the TB
@@ -669,7 +675,9 @@ int cpu_exec(CPUState *env1)
                                      "mov      %%o7,%%i0"
                                      : /* no outputs */
                                      : "r" (gen_func) 
-                                     : "i0", "i1", "i2", "i3", "i4", "i5");
+                                     : "i0", "i1", "i2", "i3", "i4", "i5",
+                                       "l0", "l1", "l2", "l3", "l4", "l5",
+                                       "l6", "l7");
 #elif defined(__arm__)
                 asm volatile ("mov pc, %0\n\t"
                               ".global exec_loop\n\t"
@@ -834,7 +842,7 @@ int cpu_exec(CPUState *env1)
 #else
 #error unsupported target CPU
 #endif
-#ifdef __sparc__
+#if defined(__sparc__) && !defined(HOST_SOLARIS)
     asm volatile ("mov %0, %%i7" : : "r" (saved_i7));
 #endif
     T0 = saved_T0;
@@ -1168,19 +1176,14 @@ static inline int handle_cpu_signal(unsi
            a virtual CPU fault */
         cpu_restore_state(tb, env, pc, puc);
     }
-    if (ret == 1) {
 #if 0
         printf("PF exception: NIP=0x%08x error=0x%x %p\n", 
                env->nip, env->error_code, tb);
 #endif
     /* we restore the process signal mask as the sigreturn should
        do it (XXX: use sigsetjmp) */
-        sigprocmask(SIG_SETMASK, old_set, NULL);
-        //        do_raise_exception_err(env->exception_index, 
env->error_code);
-    } else {
-        /* activate soft MMU for this block */
-        cpu_resume_from_signal(env, puc);
-    }
+    sigprocmask(SIG_SETMASK, old_set, NULL);
+    cpu_loop_exit();
     /* never comes here */
     return 1;
 }
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/disas.c
--- a/tools/ioemu/disas.c       Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/disas.c       Wed Aug 09 08:34:06 2006 -0600
@@ -58,7 +58,7 @@ perror_memory (status, memaddr, info)
     /* Actually, address between memaddr and memaddr + len was
        out of bounds.  */
     (*info->fprintf_func) (info->stream,
-                          "Address 0x%llx is out of bounds.\n", memaddr);
+                          "Address 0x%" PRIx64 " is out of bounds.\n", 
memaddr);
 }
 
 /* This could be in a separate file, to save miniscule amounts of space
@@ -73,7 +73,7 @@ generic_print_address (addr, info)
      bfd_vma addr;
      struct disassemble_info *info;
 {
-    (*info->fprintf_func) (info->stream, "0x%llx", addr);
+    (*info->fprintf_func) (info->stream, "0x%" PRIx64, addr);
 }
 
 /* Just return the given address.  */
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/dyngen-exec.h
--- a/tools/ioemu/dyngen-exec.h Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/dyngen-exec.h Wed Aug 09 08:34:06 2006 -0600
@@ -35,11 +35,14 @@ typedef unsigned char uint8_t;
 typedef unsigned char uint8_t;
 typedef unsigned short uint16_t;
 typedef unsigned int uint32_t;
+// Linux/Sparc64 defines uint64_t
+#if !(defined (__sparc_v9__) && defined(__linux__))
 /* XXX may be done for all 64 bits targets ? */
 #if defined (__x86_64__) || defined(__ia64)
 typedef unsigned long uint64_t;
 #else
 typedef unsigned long long uint64_t;
+#endif
 #endif
 
 /* if Solaris/__sun__, don't typedef int8_t, as it will be typedef'd
@@ -50,10 +53,13 @@ typedef signed char int8_t;
 #endif
 typedef signed short int16_t;
 typedef signed int int32_t;
+// Linux/Sparc64 defines int64_t
+#if !(defined (__sparc_v9__) && defined(__linux__))
 #if defined (__x86_64__) || defined(__ia64)
 typedef signed long int64_t;
 #else
 typedef signed long long int64_t;
+#endif
 #endif
 
 #define INT8_MIN               (-128)
@@ -121,6 +127,19 @@ extern int printf(const char *, ...);
 #define AREG3 "s2"
 #endif
 #ifdef __sparc__
+#ifdef HOST_SOLARIS
+#define AREG0 "g2"
+#define AREG1 "g3"
+#define AREG2 "g4"
+#define AREG3 "g5"
+#define AREG4 "g6"
+#else
+#ifdef __sparc_v9__
+#define AREG0 "g1"
+#define AREG1 "g4"
+#define AREG2 "g5"
+#define AREG3 "g7"
+#else
 #define AREG0 "g6"
 #define AREG1 "g1"
 #define AREG2 "g2"
@@ -133,6 +152,8 @@ extern int printf(const char *, ...);
 #define AREG9 "l5"
 #define AREG10 "l6"
 #define AREG11 "l7"
+#endif
+#endif
 #define USE_FP_CONVERT
 #endif
 #ifdef __s390__
@@ -241,10 +262,8 @@ extern int __op_jmp0, __op_jmp1, __op_jm
                                          ASM_NAME(__op_gen_label) #n)
 #endif
 #ifdef __sparc__
-#define EXIT_TB() asm volatile ("jmpl %i0 + 8, %g0\n" \
-                                "nop")
-#define        GOTO_LABEL_PARAM(n) asm volatile ( \
-               "set " ASM_NAME(__op_gen_label) #n ", %g1; jmp %g1; nop")
+#define EXIT_TB() asm volatile ("jmpl %i0 + 8, %g0; nop")
+#define GOTO_LABEL_PARAM(n) asm volatile ("ba " ASM_NAME(__op_gen_label) #n 
";nop")
 #endif
 #ifdef __arm__
 #define EXIT_TB() asm volatile ("b exec_loop")
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/dyngen.c
--- a/tools/ioemu/dyngen.c      Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/dyngen.c      Wed Aug 09 08:34:06 2006 -0600
@@ -1196,7 +1196,7 @@ void get_reloc_expr(char *name, int name
     } else {
 #ifdef HOST_SPARC
         if (sym_name[0] == '.')
-            snprintf(name, sizeof(name),
+            snprintf(name, name_size,
                      "(long)(&__dot_%s)",
                      sym_name + 1);
         else
@@ -1440,6 +1440,15 @@ void gen_code(const char *name, host_ulo
     }
 #elif defined(HOST_SPARC)
     {
+#define INSN_SAVE       0x9de3a000
+#define INSN_RET        0x81c7e008
+#define INSN_RETL       0x81c3e008
+#define INSN_RESTORE    0x81e80000
+#define INSN_RETURN     0x81cfe008
+#define INSN_NOP        0x01000000
+#define INSN_ADD_SP     0x9c03a000 // add %sp, nn, %sp
+#define INSN_SUB_SP     0x9c23a000 // sub %sp, nn, %sp
+
         uint32_t start_insn, end_insn1, end_insn2;
         uint8_t *p;
         p = (void *)(p_end - 8);
@@ -1448,13 +1457,21 @@ void gen_code(const char *name, host_ulo
         start_insn = get32((uint32_t *)(p_start + 0x0));
         end_insn1 = get32((uint32_t *)(p + 0x0));
         end_insn2 = get32((uint32_t *)(p + 0x4));
-        if ((start_insn & ~0x1fff) == 0x9de3a000) {
+        if (((start_insn & ~0x1fff) == INSN_SAVE) ||
+            (start_insn & ~0x1fff) == INSN_ADD_SP) {
             p_start += 0x4;
             start_offset += 0x4;
-            if ((int)(start_insn | ~0x1fff) < -128)
-                error("Found bogus save at the start of %s", name);
-            if (end_insn1 != 0x81c7e008 || end_insn2 != 0x81e80000)
+            if (end_insn1 == INSN_RET && end_insn2 == INSN_RESTORE)
+                /* SPARC v7: ret; restore; */ ;
+            else if (end_insn1 == INSN_RETURN && end_insn2 == INSN_NOP)
+                /* SPARC v9: return; nop; */ ;
+            else if (end_insn1 == INSN_RETL && (end_insn2 & ~0x1fff) == 
INSN_SUB_SP)
+                /* SPARC v7: retl; sub %sp, nn, %sp; */ ;
+            else
+
                 error("ret; restore; not found at end of %s", name);
+        } else if (end_insn1 == INSN_RETL && end_insn2 == INSN_NOP) {
+            ;
         } else {
             error("No save at the beginning of %s", name);
         }
@@ -1462,7 +1479,7 @@ void gen_code(const char *name, host_ulo
         /* Skip a preceeding nop, if present.  */
         if (p > p_start) {
             skip_insn = get32((uint32_t *)(p - 0x4));
-            if (skip_insn == 0x01000000)
+            if (skip_insn == INSN_NOP)
                 p -= 4;
         }
 #endif
@@ -1470,21 +1487,41 @@ void gen_code(const char *name, host_ulo
     }
 #elif defined(HOST_SPARC64)
     {
+#define INSN_SAVE       0x9de3a000
+#define INSN_RET        0x81c7e008
+#define INSN_RETL       0x81c3e008
+#define INSN_RESTORE    0x81e80000
+#define INSN_RETURN     0x81cfe008
+#define INSN_NOP        0x01000000
+#define INSN_ADD_SP     0x9c03a000 // add %sp, nn, %sp
+#define INSN_SUB_SP     0x9c23a000 // sub %sp, nn, %sp
+
         uint32_t start_insn, end_insn1, end_insn2, skip_insn;
         uint8_t *p;
         p = (void *)(p_end - 8);
+#if 0
+        /* XXX: check why it occurs */
         if (p <= p_start)
             error("empty code for %s", name);
+#endif
         start_insn = get32((uint32_t *)(p_start + 0x0));
         end_insn1 = get32((uint32_t *)(p + 0x0));
         end_insn2 = get32((uint32_t *)(p + 0x4));
-        if ((start_insn & ~0x1fff) == 0x9de3a000) {
+        if (((start_insn & ~0x1fff) == INSN_SAVE) ||
+            (start_insn & ~0x1fff) == INSN_ADD_SP) {
             p_start += 0x4;
             start_offset += 0x4;
-            if ((int)(start_insn | ~0x1fff) < -256)
-                error("Found bogus save at the start of %s", name);
-            if (end_insn1 != 0x81c7e008 || end_insn2 != 0x81e80000)
+            if (end_insn1 == INSN_RET && end_insn2 == INSN_RESTORE)
+                /* SPARC v7: ret; restore; */ ;
+            else if (end_insn1 == INSN_RETURN && end_insn2 == INSN_NOP)
+                /* SPARC v9: return; nop; */ ;
+            else if (end_insn1 == INSN_RETL && (end_insn2 & ~0x1fff) == 
INSN_SUB_SP)
+                /* SPARC v7: retl; sub %sp, nn, %sp; */ ;
+            else
+
                 error("ret; restore; not found at end of %s", name);
+        } else if (end_insn1 == INSN_RETL && end_insn2 == INSN_NOP) {
+            ;
         } else {
             error("No save at the beginning of %s", name);
         }
@@ -2151,6 +2188,18 @@ void gen_code(const char *name, host_ulo
                                    reloc_offset, reloc_offset, name, addend,
                                    reloc_offset);
                            break;
+                        case R_SPARC_WDISP22:
+                            fprintf(outfile,
+                                    "    *(uint32_t *)(gen_code_ptr + %d) = "
+                                    "((*(uint32_t *)(gen_code_ptr + %d)) "
+                                    " & ~0x3fffff) "
+                                    " | ((((%s + %d) - (long)(gen_code_ptr + 
%d))>>2) "
+                                    "    & 0x3fffff);\n",
+                                    rel->r_offset - start_offset,
+                                    rel->r_offset - start_offset,
+                                    name, addend,
+                                    rel->r_offset - start_offset);
+                            break;
                         default:
                             error("unsupported sparc relocation (%d)", type);
                         }
@@ -2168,7 +2217,7 @@ void gen_code(const char *name, host_ulo
                        rel->r_offset < start_offset + copy_size) {
                         sym_name = strtab + 
symtab[ELF64_R_SYM(rel->r_info)].st_name;
                         get_reloc_expr(name, sizeof(name), sym_name);
-                        type = ELF64_R_TYPE(rel->r_info);
+                        type = ELF32_R_TYPE(rel->r_info);
                         addend = rel->r_addend;
                         reloc_offset = rel->r_offset - start_offset;
                         switch(type) {
@@ -2192,6 +2241,15 @@ void gen_code(const char *name, host_ulo
                                    " | ((%s + %d) & 0x3ff);\n",
                                     reloc_offset, reloc_offset, name, addend);
                            break;
+                        case R_SPARC_OLO10:
+                            addend += ELF64_R_TYPE_DATA (rel->r_info);
+                            fprintf(outfile,
+                                   "    *(uint32_t *)(gen_code_ptr + %d) = "
+                                   "((*(uint32_t *)(gen_code_ptr + %d)) "
+                                   " & ~0x3ff) "
+                                   " | ((%s + %d) & 0x3ff);\n",
+                                    reloc_offset, reloc_offset, name, addend);
+                           break;
                        case R_SPARC_WDISP30:
                            fprintf(outfile,
                                    "    *(uint32_t *)(gen_code_ptr + %d) = "
@@ -2202,8 +2260,18 @@ void gen_code(const char *name, host_ulo
                                    reloc_offset, reloc_offset, name, addend,
                                    reloc_offset);
                            break;
+                        case R_SPARC_WDISP22:
+                            fprintf(outfile,
+                                    "    *(uint32_t *)(gen_code_ptr + %d) = "
+                                    "((*(uint32_t *)(gen_code_ptr + %d)) "
+                                    " & ~0x3fffff) "
+                                    " | ((((%s + %d) - (long)(gen_code_ptr + 
%d))>>2) "
+                                    "    & 0x3fffff);\n",
+                                    reloc_offset, reloc_offset, name, addend,
+                                   reloc_offset);
+                            break;
                         default:
-                           error("unsupported sparc64 relocation (%d)", type);
+                           error("unsupported sparc64 relocation (%d) for 
symbol %s", type, name);
                         }
                     }
                 }
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/dyngen.h
--- a/tools/ioemu/dyngen.h      Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/dyngen.h      Wed Aug 09 08:34:06 2006 -0600
@@ -19,7 +19,13 @@
  */
 
 int __op_param1, __op_param2, __op_param3;
-int __op_gen_label1, __op_gen_label2, __op_gen_label3;
+#ifdef __sparc__
+  void __op_gen_label1(){}
+  void __op_gen_label2(){}
+  void __op_gen_label3(){}
+#else
+  int __op_gen_label1, __op_gen_label2, __op_gen_label3;
+#endif
 int __op_jmp0, __op_jmp1, __op_jmp2, __op_jmp3;
 
 #ifdef __i386__
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/elf.h
--- a/tools/ioemu/elf.h Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/elf.h Wed Aug 09 08:34:06 2006 -0600
@@ -227,6 +227,7 @@ typedef struct {
 
 #define ELF64_R_SYM(i)                 ((i) >> 32)
 #define ELF64_R_TYPE(i)                        ((i) & 0xffffffff)
+#define ELF64_R_TYPE_DATA(i)            (((ELF64_R_TYPE(i) >> 8) ^ 0x00800000) 
- 0x00800000)
 
 #define R_386_NONE     0
 #define R_386_32       1
@@ -326,6 +327,7 @@ typedef struct {
 #define R_SPARC_10             30
 #define R_SPARC_11             31
 #define R_SPARC_64             32
+#define R_SPARC_OLO10           33
 #define R_SPARC_WDISP16                40
 #define R_SPARC_WDISP19                41
 #define R_SPARC_7              43
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/exec-all.h
--- a/tools/ioemu/exec-all.h    Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/exec-all.h    Wed Aug 09 08:34:06 2006 -0600
@@ -571,7 +571,7 @@ static inline target_ulong get_phys_addr
         ldub_code(addr);
     }
     pd = env->tlb_table[is_user][index].addr_code & ~TARGET_PAGE_MASK;
-    if (pd > IO_MEM_ROM) {
+    if (pd > IO_MEM_ROM && !(pd & IO_MEM_ROMD)) {
         cpu_abort(env, "Trying to execute code outside RAM or ROM at 
0x%08lx\n", addr);
     }
     return addr + env->tlb_table[is_user][index].addend - (unsigned 
long)phys_ram_base;
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/exec.c
--- a/tools/ioemu/exec.c        Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/exec.c        Wed Aug 09 08:34:06 2006 -0600
@@ -1488,7 +1488,7 @@ int tlb_set_page_exec(CPUState *env, tar
     if (is_softmmu) 
 #endif
     {
-        if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM) {
+        if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM && !(pd & IO_MEM_ROMD)) {
             /* IO memory case */
             address = vaddr | pd;
             addend = paddr;
@@ -1513,9 +1513,11 @@ int tlb_set_page_exec(CPUState *env, tar
             te->addr_code = -1;
         }
         if (prot & PAGE_WRITE) {
-            if ((pd & ~TARGET_PAGE_MASK) == IO_MEM_ROM) {
-                /* ROM: access is ignored (same as unassigned) */
-                te->addr_write = vaddr | IO_MEM_ROM;
+            if ((pd & ~TARGET_PAGE_MASK) == IO_MEM_ROM || 
+                (pd & IO_MEM_ROMD)) {
+                /* write access calls the I/O callback */
+                te->addr_write = vaddr | 
+                    (pd & ~(TARGET_PAGE_MASK | IO_MEM_ROMD));
             } else if ((pd & ~TARGET_PAGE_MASK) == IO_MEM_RAM && 
                        !cpu_physical_memory_is_dirty(pd)) {
                 te->addr_write = vaddr | IO_MEM_NOTDIRTY;
@@ -1779,14 +1781,23 @@ void cpu_register_physical_memory(target
 {
     target_phys_addr_t addr, end_addr;
     PhysPageDesc *p;
+    CPUState *env;
 
     size = (size + TARGET_PAGE_SIZE - 1) & TARGET_PAGE_MASK;
     end_addr = start_addr + size;
     for(addr = start_addr; addr != end_addr; addr += TARGET_PAGE_SIZE) {
         p = phys_page_find_alloc(addr >> TARGET_PAGE_BITS, 1);
         p->phys_offset = phys_offset;
-        if ((phys_offset & ~TARGET_PAGE_MASK) <= IO_MEM_ROM)
+        if ((phys_offset & ~TARGET_PAGE_MASK) <= IO_MEM_ROM ||
+            (phys_offset & IO_MEM_ROMD))
             phys_offset += TARGET_PAGE_SIZE;
+    }
+    
+    /* since each CPU stores ram addresses in its TLB cache, we must
+       reset the modified entries */
+    /* XXX: slow ! */
+    for(env = first_cpu; env != NULL; env = env->next_cpu) {
+        tlb_flush(env, 1);
     }
 }
 
@@ -2048,7 +2059,8 @@ void cpu_physical_memory_rw(target_phys_
                 }
             }
         } else {
-            if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM) {
+            if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM && 
+                !(pd & IO_MEM_ROMD)) {
                 /* I/O case */
                 io_index = (pd >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1);
                 if (l >= 4 && ((addr & 3) == 0)) {
@@ -2103,7 +2115,8 @@ void cpu_physical_memory_write_rom(targe
         }
         
         if ((pd & ~TARGET_PAGE_MASK) != IO_MEM_RAM &&
-            (pd & ~TARGET_PAGE_MASK) != IO_MEM_ROM) {
+            (pd & ~TARGET_PAGE_MASK) != IO_MEM_ROM &&
+            !(pd & IO_MEM_ROMD)) {
             /* do nothing */
         } else {
             unsigned long addr1;
@@ -2135,7 +2148,8 @@ uint32_t ldl_phys(target_phys_addr_t add
         pd = p->phys_offset;
     }
         
-    if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM) {
+    if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM && 
+        !(pd & IO_MEM_ROMD)) {
         /* I/O case */
         io_index = (pd >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1);
         val = io_mem_read[io_index][2](io_mem_opaque[io_index], addr);
@@ -2164,7 +2178,8 @@ uint64_t ldq_phys(target_phys_addr_t add
         pd = p->phys_offset;
     }
         
-    if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM) {
+    if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM &&
+        !(pd & IO_MEM_ROMD)) {
         /* I/O case */
         io_index = (pd >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1);
 #ifdef TARGET_WORDS_BIGENDIAN
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/fpu/.CVS/Entries
--- a/tools/ioemu/fpu/.CVS/Entries      Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/fpu/.CVS/Entries      Wed Aug 09 08:34:06 2006 -0600
@@ -1,7 +1,7 @@
-/softfloat-macros.h/1.1/Sun Mar 13 16:54:06 2005//Trelease_0_8_1
-/softfloat-native.c/1.3/Thu May 25 18:22:32 2006//Trelease_0_8_1
-/softfloat-native.h/1.6/Thu May 25 18:22:32 2006//Trelease_0_8_1
-/softfloat-specialize.h/1.1/Sun Mar 13 16:54:06 2005//Trelease_0_8_1
-/softfloat.c/1.2/Sun Mar 13 18:52:28 2005//Trelease_0_8_1
-/softfloat.h/1.3/Thu May 25 18:22:32 2006//Trelease_0_8_1
+/softfloat-macros.h/1.1/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/softfloat-native.c/1.4/Sun Aug  6 01:03:50 2006//Trelease_0_8_2
+/softfloat-native.h/1.6/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/softfloat-specialize.h/1.1/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/softfloat.c/1.2/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/softfloat.h/1.3/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
 D
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/fpu/.CVS/Tag
--- a/tools/ioemu/fpu/.CVS/Tag  Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/fpu/.CVS/Tag  Wed Aug 09 08:34:06 2006 -0600
@@ -1,1 +1,1 @@ Nrelease_0_8_1
-Nrelease_0_8_1
+Nrelease_0_8_2
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/fpu/softfloat-native.c
--- a/tools/ioemu/fpu/softfloat-native.c        Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/fpu/softfloat-native.c        Wed Aug 09 08:34:06 2006 -0600
@@ -6,7 +6,7 @@ void set_float_rounding_mode(int val STA
 void set_float_rounding_mode(int val STATUS_PARAM)
 {
     STATUS(float_rounding_mode) = val;
-#if defined(_BSD) && !defined(__APPLE__)
+#if defined(_BSD) && !defined(__APPLE__) || (defined(HOST_SOLARIS) && 
HOST_SOLARIS < 10)
     fpsetround(val);
 #elif defined(__arm__)
     /* nothing to do */
@@ -22,9 +22,14 @@ void set_floatx80_rounding_precision(int
 }
 #endif
 
-#if defined(_BSD)
-#define lrint(d)               ((long)rint(d))
-#define llrint(d)              ((long long)rint(d))
+#if defined(_BSD) || (defined(HOST_SOLARIS) && HOST_SOLARIS < 10)
+#define lrint(d)               ((int32_t)rint(d))
+#define llrint(d)              ((int64_t)rint(d))
+#define lrintf(f)              ((int32_t)rint(f))
+#define llrintf(f)             ((int64_t)rint(f))
+#define sqrtf(f)               ((float)sqrt(f))
+#define remainderf(fa, fb)     ((float)remainder(fa, fb))
+#define rintf(f)               ((float)rint(f))
 #endif
 
 #if defined(__powerpc__)
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/gdbstub.c
--- a/tools/ioemu/gdbstub.c     Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/gdbstub.c     Wed Aug 09 08:34:06 2006 -0600
@@ -17,6 +17,7 @@
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+#include "config.h"
 #ifdef CONFIG_USER_ONLY
 #include <stdlib.h>
 #include <stdio.h>
@@ -24,16 +25,25 @@
 #include <string.h>
 #include <errno.h>
 #include <unistd.h>
+#include <fcntl.h>
 
 #include "qemu.h"
 #else
 #include "vl.h"
 #endif
 
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <netinet/tcp.h>
+#include "qemu_socket.h"
+#ifdef _WIN32
+/* XXX: these constants may be independent of the host ones even for Unix */
+#ifndef SIGTRAP
+#define SIGTRAP 5
+#endif
+#ifndef SIGINT
+#define SIGINT 2
+#endif
+#else
 #include <signal.h>
+#endif
 
 //#define DEBUG_GDB
 
@@ -69,7 +79,7 @@ static int get_char(GDBState *s)
     int ret;
 
     for(;;) {
-        ret = read(s->fd, &ch, 1);
+        ret = recv(s->fd, &ch, 1, 0);
         if (ret < 0) {
             if (errno != EINTR && errno != EAGAIN)
                 return -1;
@@ -87,7 +97,7 @@ static void put_buffer(GDBState *s, cons
     int ret;
 
     while (len > 0) {
-        ret = write(s->fd, buf, len);
+        ret = send(s->fd, buf, len, 0);
         if (ret < 0) {
             if (errno != EINTR && errno != EAGAIN)
                 return;
@@ -305,11 +315,11 @@ static int cpu_gdb_read_registers(CPUSta
     for(i = 0; i < 24; i++) {
         registers[i + 8] = tswapl(env->regwptr[i]);
     }
+#ifndef TARGET_SPARC64
     /* fill in fprs */
     for (i = 0; i < 32; i++) {
         registers[i + 32] = tswapl(*((uint32_t *)&env->fpr[i]));
     }
-#ifndef TARGET_SPARC64
     /* Y, PSR, WIM, TBR, PC, NPC, FPSR, CPSR */
     registers[64] = tswapl(env->y);
     {
@@ -327,16 +337,21 @@ static int cpu_gdb_read_registers(CPUSta
     registers[72] = 0;
     return 73 * sizeof(target_ulong);
 #else
-    for (i = 0; i < 32; i += 2) {
-        registers[i/2 + 64] = tswapl(*((uint64_t *)&env->fpr[i]));
-    }
-    registers[81] = tswapl(env->pc);
-    registers[82] = tswapl(env->npc);
-    registers[83] = tswapl(env->tstate[env->tl]);
-    registers[84] = tswapl(env->fsr);
-    registers[85] = tswapl(env->fprs);
-    registers[86] = tswapl(env->y);
-    return 87 * sizeof(target_ulong);
+    /* fill in fprs */
+    for (i = 0; i < 64; i += 2) {
+       uint64_t tmp;
+
+        tmp = (uint64_t)tswap32(*((uint32_t *)&env->fpr[i])) << 32;
+        tmp |= tswap32(*((uint32_t *)&env->fpr[i + 1]));
+        registers[i/2 + 32] = tmp;
+    }
+    registers[64] = tswapl(env->pc);
+    registers[65] = tswapl(env->npc);
+    registers[66] = tswapl(env->tstate[env->tl]);
+    registers[67] = tswapl(env->fsr);
+    registers[68] = tswapl(env->fprs);
+    registers[69] = tswapl(env->y);
+    return 70 * sizeof(target_ulong);
 #endif
 }
 
@@ -353,11 +368,11 @@ static void cpu_gdb_write_registers(CPUS
     for(i = 0; i < 24; i++) {
         env->regwptr[i] = tswapl(registers[i + 8]);
     }
+#ifndef TARGET_SPARC64
     /* fill in fprs */
     for (i = 0; i < 32; i++) {
         *((uint32_t *)&env->fpr[i]) = tswapl(registers[i + 32]);
     }
-#ifndef TARGET_SPARC64
     /* Y, PSR, WIM, TBR, PC, NPC, FPSR, CPSR */
     env->y = tswapl(registers[64]);
     PUT_PSR(env, tswapl(registers[65]));
@@ -367,18 +382,16 @@ static void cpu_gdb_write_registers(CPUS
     env->npc = tswapl(registers[69]);
     env->fsr = tswapl(registers[70]);
 #else
-    for (i = 0; i < 32; i += 2) {
-       uint64_t tmp;
-       tmp = tswapl(registers[i/2 + 64]) << 32;
-       tmp |= tswapl(registers[i/2 + 64 + 1]);
-        *((uint64_t *)&env->fpr[i]) = tmp;
-    }
-    env->pc = tswapl(registers[81]);
-    env->npc = tswapl(registers[82]);
-    env->tstate[env->tl] = tswapl(registers[83]);
-    env->fsr = tswapl(registers[84]);
-    env->fprs = tswapl(registers[85]);
-    env->y = tswapl(registers[86]);
+    for (i = 0; i < 64; i += 2) {
+       *((uint32_t *)&env->fpr[i]) = tswap32(registers[i/2 + 32] >> 32);
+       *((uint32_t *)&env->fpr[i + 1]) = tswap32(registers[i/2 + 32] & 
0xffffffff);
+    }
+    env->pc = tswapl(registers[64]);
+    env->npc = tswapl(registers[65]);
+    env->tstate[env->tl] = tswapl(registers[66]);
+    env->fsr = tswapl(registers[67]);
+    env->fprs = tswapl(registers[68]);
+    env->y = tswapl(registers[69]);
 #endif
 }
 #elif defined (TARGET_ARM)
@@ -494,7 +507,12 @@ static int cpu_gdb_read_registers(CPUSta
   int i;
 
 #define SAVE(x) *ptr++=tswapl(x)
-  for (i = 0; i < 16; i++) SAVE(env->gregs[i]);
+  if ((env->sr & (SR_MD | SR_RB)) == (SR_MD | SR_RB)) {
+      for (i = 0; i < 8; i++) SAVE(env->gregs[i + 16]);
+  } else {
+      for (i = 0; i < 8; i++) SAVE(env->gregs[i]);
+  }
+  for (i = 8; i < 16; i++) SAVE(env->gregs[i]);
   SAVE (env->pc);
   SAVE (env->pr);
   SAVE (env->gbr);
@@ -517,7 +535,12 @@ static void cpu_gdb_write_registers(CPUS
   int i;
 
 #define LOAD(x) (x)=*ptr++;
-  for (i = 0; i < 16; i++) LOAD(env->gregs[i]);
+  if ((env->sr & (SR_MD | SR_RB)) == (SR_MD | SR_RB)) {
+      for (i = 0; i < 8; i++) LOAD(env->gregs[i + 16]);
+  } else {
+      for (i = 0; i < 8; i++) LOAD(env->gregs[i]);
+  }
+  for (i = 8; i < 16; i++) LOAD(env->gregs[i]);
   LOAD (env->pc);
   LOAD (env->pr);
   LOAD (env->gbr);
@@ -545,7 +568,7 @@ static int gdb_handle_packet(GDBState *s
     char buf[4096];
     uint8_t mem_buf[2000];
     uint32_t *registers;
-    uint32_t addr, len;
+    target_ulong addr, len;
     
 #ifdef DEBUG_GDB
     printf("command='%s'\n", line_buf);
@@ -560,7 +583,7 @@ static int gdb_handle_packet(GDBState *s
         break;
     case 'c':
         if (*p != '\0') {
-            addr = strtoul(p, (char **)&p, 16);
+            addr = strtoull(p, (char **)&p, 16);
 #if defined(TARGET_I386)
             env->eip = addr;
 #elif defined (TARGET_PPC)
@@ -616,10 +639,10 @@ static int gdb_handle_packet(GDBState *s
         put_packet(s, "OK");
         break;
     case 'm':
-        addr = strtoul(p, (char **)&p, 16);
+        addr = strtoull(p, (char **)&p, 16);
         if (*p == ',')
             p++;
-        len = strtoul(p, NULL, 16);
+        len = strtoull(p, NULL, 16);
         if (cpu_memory_rw_debug(env, addr, mem_buf, len, 0) != 0) {
             put_packet (s, "E14");
         } else {
@@ -628,10 +651,10 @@ static int gdb_handle_packet(GDBState *s
         }
         break;
     case 'M':
-        addr = strtoul(p, (char **)&p, 16);
+        addr = strtoull(p, (char **)&p, 16);
         if (*p == ',')
             p++;
-        len = strtoul(p, (char **)&p, 16);
+        len = strtoull(p, (char **)&p, 16);
         if (*p == ':')
             p++;
         hextomem(mem_buf, p, len);
@@ -644,10 +667,10 @@ static int gdb_handle_packet(GDBState *s
         type = strtoul(p, (char **)&p, 16);
         if (*p == ',')
             p++;
-        addr = strtoul(p, (char **)&p, 16);
+        addr = strtoull(p, (char **)&p, 16);
         if (*p == ',')
             p++;
-        len = strtoul(p, (char **)&p, 16);
+        len = strtoull(p, (char **)&p, 16);
         if (type == 0 || type == 1) {
             if (cpu_breakpoint_insert(env, addr) < 0)
                 goto breakpoint_error;
@@ -661,10 +684,10 @@ static int gdb_handle_packet(GDBState *s
         type = strtoul(p, (char **)&p, 16);
         if (*p == ',')
             p++;
-        addr = strtoul(p, (char **)&p, 16);
+        addr = strtoull(p, (char **)&p, 16);
         if (*p == ',')
             p++;
-        len = strtoul(p, (char **)&p, 16);
+        len = strtoull(p, (char **)&p, 16);
         if (type == 0 || type == 1) {
             cpu_breakpoint_remove(env, addr);
             put_packet(s, "OK");
@@ -672,6 +695,18 @@ static int gdb_handle_packet(GDBState *s
             goto breakpoint_error;
         }
         break;
+#ifdef CONFIG_USER_ONLY
+    case 'q':
+        if (strncmp(p, "Offsets", 7) == 0) {
+            TaskState *ts = env->opaque;
+
+            sprintf(buf, "Text=%x;Data=%x;Bss=%x", ts->info->code_offset,
+                ts->info->data_offset, ts->info->data_offset);
+            put_packet(s, buf);
+            break;
+        }
+        /* Fall through.  */
+#endif
     default:
         //        unknown_command:
         /* put empty packet */
@@ -829,7 +864,7 @@ static void gdb_read(void *opaque)
     int i, size;
     uint8_t buf[4096];
 
-    size = read(s->fd, buf, sizeof(buf));
+    size = recv(s->fd, buf, sizeof(buf), 0);
     if (size < 0)
         return;
     if (size == 0) {
@@ -866,7 +901,7 @@ static void gdb_accept(void *opaque)
 
     /* set short latency */
     val = 1;
-    setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof(val));
+    setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *)&val, sizeof(val));
     
 #ifdef CONFIG_USER_ONLY
     s = &gdbserver_state;
@@ -881,9 +916,11 @@ static void gdb_accept(void *opaque)
     s->env = first_cpu; /* XXX: allow to change CPU */
     s->fd = fd;
 
+#ifdef CONFIG_USER_ONLY
     fcntl(fd, F_SETFL, O_NONBLOCK);
-
-#ifndef CONFIG_USER_ONLY
+#else
+    socket_set_nonblock(fd);
+
     /* stop the VM */
     vm_stop(EXCP_INTERRUPT);
 
@@ -907,7 +944,7 @@ static int gdbserver_open(int port)
 
     /* allow fast reuse */
     val = 1;
-    setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
+    setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val));
 
     sockaddr.sin_family = AF_INET;
     sockaddr.sin_port = htons(port);
@@ -923,7 +960,7 @@ static int gdbserver_open(int port)
         return -1;
     }
 #ifndef CONFIG_USER_ONLY
-    fcntl(fd, F_SETFL, O_NONBLOCK);
+    socket_set_nonblock(fd);
 #endif
     return fd;
 }
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/hw/.CVS/Entries
--- a/tools/ioemu/hw/.CVS/Entries       Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/hw/.CVS/Entries       Wed Aug 09 08:34:06 2006 -0600
@@ -1,72 +1,89 @@
-/adb.c/1.6/Thu May 25 18:22:32 2006//Trelease_0_8_1
-/adlib.c/1.5/Thu May 25 18:22:32 2006//Trelease_0_8_1
-/apic.c/1.8/Thu May 25 18:22:32 2006//Trelease_0_8_1
-/arm_boot.c/1.1/Thu Apr 27 23:15:07 2006//Trelease_0_8_1
-/arm_pic.c/1.1/Sun Apr  9 01:32:52 2006//Trelease_0_8_1
-/arm_pic.h/1.1/Sun Apr  9 01:32:52 2006//Trelease_0_8_1
-/arm_timer.c/1.1/Sun Apr  9 01:32:52 2006//Trelease_0_8_1
-/cirrus_vga.c/1.21/Thu May 25 18:22:32 2006//Trelease_0_8_1
-/cirrus_vga_rop.h/1.1/Wed May 17 14:47:01 2006//Trelease_0_8_1
-/cirrus_vga_rop2.h/1.7/Thu May 25 12:52:49 2006//Trelease_0_8_1
-/cuda.c/1.10/Thu May 25 12:38:51 2006//Trelease_0_8_1
-/dma.c/1.14/Thu May 25 18:22:32 2006//Trelease_0_8_1
-/es1370.c/1.4/Sun Nov 20 16:20:39 2005//Trelease_0_8_1
-/esp.c/1.6/Thu May 25 18:22:33 2006//Trelease_0_8_1
-/fdc.c/1.18/Wed May 24 10:40:13 2006//Trelease_0_8_1
-/fmopl.c/1.1/Wed May 17 14:47:01 2006//Trelease_0_8_1
-/fmopl.h/1.1/Wed May 17 14:47:01 2006//Trelease_0_8_1
-/heathrow_pic.c/1.2/Thu May 25 18:22:33 2006//Trelease_0_8_1
-/i8254.c/1.8/Thu May 25 18:22:33 2006//Trelease_0_8_1
-/i8259.c/1.18/Thu May 25 18:22:33 2006//Trelease_0_8_1
-/ide.c/1.42/Thu May 25 18:22:33 2006//Trelease_0_8_1
-/integratorcp.c/1.9/Thu Apr 27 23:15:07 2006//Trelease_0_8_1
-/iommu.c/1.6/Thu May 25 18:22:33 2006//Trelease_0_8_1
-/lance.c/1.7/Thu May 25 18:22:33 2006//Trelease_0_8_1
-/m48t59.c/1.7/Thu May 25 18:22:33 2006//Trelease_0_8_1
-/m48t59.h/1.5/Thu May 25 18:22:33 2006//Trelease_0_8_1
-/mc146818rtc.c/1.6/Wed May 17 14:47:01 2006//Trelease_0_8_1
-/mips_r4k.c/1.16/Thu May 25 18:22:33 2006//Trelease_0_8_1
-/ne2000.c/1.19/Thu May 25 18:22:33 2006//Trelease_0_8_1
-/openpic.c/1.9/Thu May 25 18:22:33 2006//Trelease_0_8_1
-/parallel.c/1.4/Thu May 25 18:22:33 2006//Trelease_0_8_1
-/pc.c/1.53/Thu May 25 18:22:33 2006//Trelease_0_8_1
-/pci.c/1.24/Thu May 25 18:22:33 2006//Trelease_0_8_1
-/pckbd.c/1.15/Thu May 25 18:22:33 2006//Trelease_0_8_1
-/pcspk.c/1.1/Mon Apr 24 21:58:30 2006//Trelease_0_8_1
-/pl011.c/1.1/Sun Apr  9 01:32:52 2006//Trelease_0_8_1
-/pl050.c/1.1/Sun Apr  9 01:32:52 2006//Trelease_0_8_1
-/pl080.c/1.1/Sun Apr  9 01:32:52 2006//Trelease_0_8_1
-/pl110.c/1.6/Tue Apr 18 19:02:59 2006//Trelease_0_8_1
-/pl110_template.h/1.2/Sun Feb 19 12:31:32 2006//Trelease_0_8_1
-/pl190.c/1.1/Sun Apr  9 01:32:52 2006//Trelease_0_8_1
-/ppc.c/1.9/Thu May 25 18:22:33 2006//Trelease_0_8_1
-/ppc_chrp.c/1.21/Thu May 25 18:22:33 2006//Trelease_0_8_1
-/ppc_prep.c/1.26/Thu May 25 18:22:33 2006//Trelease_0_8_1
-/ps2.c/1.4/Wed Apr 12 21:09:07 2006//Trelease_0_8_1
-/rtl8139.c/1.1/Sun Feb  5 04:14:41 2006//Trelease_0_8_1
-/sb16.c/1.19/Thu May 25 18:22:34 2006//Trelease_0_8_1
-/serial.c/1.12/Thu May 25 18:22:34 2006//Trelease_0_8_1
-/sh7750.c/1.1/Thu Apr 27 21:32:09 2006//Trelease_0_8_1
-/sh7750_regnames.c/1.1/Thu Apr 27 21:32:09 2006//Trelease_0_8_1
-/sh7750_regnames.h/1.1/Thu Apr 27 21:32:09 2006//Trelease_0_8_1
-/sh7750_regs.h/1.1/Thu Apr 27 21:32:09 2006//Trelease_0_8_1
-/shix.c/1.1/Thu Apr 27 21:32:09 2006//Trelease_0_8_1
-/slavio_intctl.c/1.6/Thu May 25 18:22:35 2006//Trelease_0_8_1
-/slavio_misc.c/1.3/Thu May 25 18:22:35 2006//Trelease_0_8_1
-/slavio_serial.c/1.6/Thu May 25 18:22:35 2006//Trelease_0_8_1
-/slavio_timer.c/1.3/Thu May 25 18:22:35 2006//Trelease_0_8_1
-/smc91c111.c/1.3/Sat Feb  4 22:15:28 2006//Trelease_0_8_1
-/sun4m.c/1.16/Thu May 25 18:22:35 2006//Trelease_0_8_1
-/sun4u.c/1.8/Thu May 25 18:22:35 2006//Trelease_0_8_1
-/tc58128.c/1.1/Thu Apr 27 21:32:09 2006//Trelease_0_8_1
-/tcx.c/1.7/Thu May 25 18:22:35 2006//Trelease_0_8_1
-/usb-hid.c/1.2/Wed Apr 12 21:09:07 2006//Trelease_0_8_1
-/usb-hub.c/1.3/Sun Apr 30 21:53:59 2006//Trelease_0_8_1
-/usb-uhci.c/1.8/Tue Apr 25 21:01:19 2006//Trelease_0_8_1
-/usb.c/1.6/Mon Apr 24 21:18:20 2006//Trelease_0_8_1
-/usb.h/1.4/Wed Apr 12 21:09:07 2006//Trelease_0_8_1
-/versatilepb.c/1.2/Thu Apr 27 23:15:07 2006//Trelease_0_8_1
-/vga.c/1.42/Thu May 25 18:22:36 2006//Trelease_0_8_1
-/vga_int.h/1.6/Thu May 25 18:20:53 2006//Trelease_0_8_1
-/vga_template.h/1.11/Wed May 17 14:47:01 2006//Trelease_0_8_1
+/acpi-dsdt.dsl/1.3/Wed Jun 14 18:17:04 2006//Trelease_0_8_2
+/acpi-dsdt.hex/1.3/Wed Jun 14 18:17:04 2006//Trelease_0_8_2
+/acpi.c/1.5/Wed Jun 14 18:17:04 2006//Trelease_0_8_2
+/adb.c/1.6/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/adlib.c/1.6/Sun Aug  6 01:03:50 2006//Trelease_0_8_2
+/apb_pci.c/1.1/Sat May 13 16:11:23 2006//Trelease_0_8_2
+/apic.c/1.9/Sun Aug  6 01:03:50 2006//Trelease_0_8_2
+/arm_boot.c/1.1/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/arm_pic.c/1.1/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/arm_pic.h/1.1/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/arm_timer.c/1.1/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/cdrom.c/1.1/Thu May 25 23:58:51 2006//Trelease_0_8_2
+/cirrus_vga.c/1.21/Sun Aug  6 00:55:02 2006//Trelease_0_8_2
+/cirrus_vga_rop.h/1.1/Thu Jul 13 09:23:22 2006//Trelease_0_8_2
+/cirrus_vga_rop2.h/1.7/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/cuda.c/1.11/Sun Aug  6 01:03:50 2006//Trelease_0_8_2
+/dma.c/1.14/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/es1370.c/1.6/Sun Aug  6 01:03:50 2006//Trelease_0_8_2
+/esp.c/1.12/Sun Aug  6 01:03:50 2006//Trelease_0_8_2
+/fdc.c/1.18/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/fmopl.c/1.1/Thu Jul 13 09:23:22 2006//Trelease_0_8_2
+/fmopl.h/1.1/Thu Jul 13 09:23:22 2006//Trelease_0_8_2
+/grackle_pci.c/1.1/Sat May 13 16:11:23 2006//Trelease_0_8_2
+/heathrow_pic.c/1.2/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/i8254.c/1.8/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/i8259.c/1.19/Sun Aug  6 01:03:50 2006//Trelease_0_8_2
+/ide.c/1.45/Sun Aug  6 01:03:50 2006//Trelease_0_8_2
+/integratorcp.c/1.9/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/iommu.c/1.6/Sun Aug  6 00:55:03 2006//Trelease_0_8_2
+/lance.c/1.7/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/lsi53c895a.c/1.1/Tue May 30 01:48:12 2006//Trelease_0_8_2
+/m48t59.c/1.8/Sun Aug  6 01:03:50 2006//Trelease_0_8_2
+/m48t59.h/1.5/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/mc146818rtc.c/1.6/Sun Aug  6 00:55:02 2006//Trelease_0_8_2
+/mips_r4k.c/1.18/Sun Aug  6 01:03:50 2006//Trelease_0_8_2
+/ne2000.c/1.20/Sun Aug  6 01:03:50 2006//Trelease_0_8_2
+/openpic.c/1.9/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/parallel.c/1.4/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/pc.c/1.60/Sun Aug  6 01:03:50 2006//Trelease_0_8_2
+/pci.c/1.27/Sun Aug  6 01:03:50 2006//Trelease_0_8_2
+/pci_host.h/1.1/Sat May 13 16:11:23 2006//Trelease_0_8_2
+/pckbd.c/1.15/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/pcnet.c/1.4/Fri Jul 14 09:40:02 2006//Trelease_0_8_2
+/pcspk.c/1.2/Sun Aug  6 01:03:51 2006//Trelease_0_8_2
+/pflash_cfi02.c/1.2/Tue Jul  4 09:46:31 2006//Trelease_0_8_2
+/piix_pci.c/1.1/Sat May 13 16:11:23 2006//Trelease_0_8_2
+/pl011.c/1.1/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/pl050.c/1.2/Sun Aug  6 01:03:51 2006//Trelease_0_8_2
+/pl080.c/1.1/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/pl110.c/1.6/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/pl110_template.h/1.2/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/pl190.c/1.1/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/ppc.c/1.9/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/ppc_chrp.c/1.23/Sun Aug  6 01:03:51 2006//Trelease_0_8_2
+/ppc_prep.c/1.27/Sun Aug  6 01:03:51 2006//Trelease_0_8_2
+/prep_pci.c/1.1/Sat May 13 16:11:23 2006//Trelease_0_8_2
+/ps2.c/1.4/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/rtl8139.c/1.4/Sun Aug  6 01:03:51 2006//Trelease_0_8_2
+/sb16.c/1.22/Sun Aug  6 01:03:51 2006//Trelease_0_8_2
+/scsi-disk.c/1.7/Sun Jun  4 11:39:07 2006//Trelease_0_8_2
+/serial.c/1.12/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/sh7750.c/1.2/Sun Aug  6 01:03:51 2006//Trelease_0_8_2
+/sh7750_regnames.c/1.1/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/sh7750_regnames.h/1.1/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/sh7750_regs.h/1.1/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/shix.c/1.1/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/slavio_intctl.c/1.7/Sun Aug  6 01:03:51 2006//Trelease_0_8_2
+/slavio_misc.c/1.3/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/slavio_serial.c/1.6/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/slavio_timer.c/1.4/Sun Aug  6 01:03:51 2006//Trelease_0_8_2
+/smc91c111.c/1.3/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/sun4m.c/1.18/Sun Aug  6 01:03:51 2006//Trelease_0_8_2
+/sun4u.c/1.11/Sun Aug  6 01:03:51 2006//Trelease_0_8_2
+/tc58128.c/1.1/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/tcx.c/1.7/Fri Jul 14 12:43:45 2006//Trelease_0_8_2
+/unin_pci.c/1.1/Sat May 13 16:11:23 2006//Trelease_0_8_2
+/usb-hid.c/1.5/Sun Aug  6 01:03:51 2006//Trelease_0_8_2
+/usb-hub.c/1.8/Sun Aug  6 01:03:51 2006//Trelease_0_8_2
+/usb-msd.c/1.4/Wed Jul 19 18:06:15 2006//Trelease_0_8_2
+/usb-ohci.c/1.3/Thu May 25 23:37:07 2006//Trelease_0_8_2
+/usb-uhci.c/1.11/Sun Aug  6 01:03:51 2006//Trelease_0_8_2
+/usb.c/1.8/Sun Aug  6 01:03:51 2006//Trelease_0_8_2
+/usb.h/1.9/Sun Aug  6 01:03:51 2006//Trelease_0_8_2
+/versatile_pci.c/1.1/Sat May 13 16:11:23 2006//Trelease_0_8_2
+/versatilepb.c/1.5/Sun Aug  6 01:03:51 2006//Trelease_0_8_2
+/vga.c/1.44/Sun Aug  6 01:03:51 2006//Trelease_0_8_2
+/vga_int.h/1.7/Sun Aug  6 01:03:51 2006//Trelease_0_8_2
+/vga_template.h/1.13/Sun Aug  6 01:03:51 2006//Trelease_0_8_2
 D
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/hw/.CVS/Tag
--- a/tools/ioemu/hw/.CVS/Tag   Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/hw/.CVS/Tag   Wed Aug 09 08:34:06 2006 -0600
@@ -1,1 +1,1 @@ Nrelease_0_8_1
-Nrelease_0_8_1
+Nrelease_0_8_2
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/hw/adlib.c
--- a/tools/ioemu/hw/adlib.c    Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/hw/adlib.c    Wed Aug 09 08:34:06 2006 -0600
@@ -301,6 +301,7 @@ int Adlib_init (AudioState *audio)
     as.freq = conf.freq;
     as.nchannels = SHIFT;
     as.fmt = AUD_FMT_S16;
+    as.endianness = AUDIO_HOST_ENDIANNESS;
 
     AUD_register_card (audio, "adlib", &s->card);
 
@@ -310,8 +311,7 @@ int Adlib_init (AudioState *audio)
         "adlib",
         s,
         adlib_callback,
-        &as,
-        0                       /* XXX: little endian? */
+        &as
         );
     if (!s->voice) {
         Adlib_fini (s);
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/hw/apic.c
--- a/tools/ioemu/hw/apic.c     Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/hw/apic.c     Wed Aug 09 08:34:06 2006 -0600
@@ -239,7 +239,7 @@ void cpu_set_apic_base(CPUState *env, ui
 {
     APICState *s = env->apic_state;
 #ifdef DEBUG_APIC
-    printf("cpu_set_apic_base: %016llx\n", val);
+    printf("cpu_set_apic_base: %016" PRIx64 "\n", val);
 #endif
     s->apicbase = (val & 0xfffff000) | 
         (s->apicbase & (MSR_IA32_APICBASE_BSP | MSR_IA32_APICBASE_ENABLE));
@@ -255,7 +255,7 @@ uint64_t cpu_get_apic_base(CPUState *env
 {
     APICState *s = env->apic_state;
 #ifdef DEBUG_APIC
-    printf("cpu_get_apic_base: %016llx\n", (uint64_t)s->apicbase);
+    printf("cpu_get_apic_base: %016" PRIx64 "\n", (uint64_t)s->apicbase);
 #endif
     return s->apicbase;
 }
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/hw/cuda.c
--- a/tools/ioemu/hw/cuda.c     Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/hw/cuda.c     Wed Aug 09 08:34:06 2006 -0600
@@ -209,7 +209,7 @@ static int64_t get_next_irq_time(CUDATim
     }
 #if 0
 #ifdef DEBUG_CUDA
-    printf("latch=%d counter=%lld delta_next=%lld\n", 
+    printf("latch=%d counter=%" PRId64 " delta_next=%" PRId64 "\n", 
            s->latch, d, next_time - d);
 #endif
 #endif
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/hw/es1370.c
--- a/tools/ioemu/hw/es1370.c   Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/hw/es1370.c   Wed Aug 09 08:34:06 2006 -0600
@@ -423,6 +423,7 @@ static void es1370_update_voices (ES1370
                 as.freq = new_freq;
                 as.nchannels = 1 << (new_fmt & 1);
                 as.fmt = (new_fmt & 2) ? AUD_FMT_S16 : AUD_FMT_U8;
+                as.endianness = 0;
 
                 if (i == ADC_CHANNEL) {
                     s->adc_voice =
@@ -432,8 +433,7 @@ static void es1370_update_voices (ES1370
                             "es1370.adc",
                             s,
                             es1370_adc_callback,
-                            &as,
-                            0   /* little endian */
+                            &as
                             );
                 }
                 else {
@@ -444,8 +444,7 @@ static void es1370_update_voices (ES1370
                             i ? "es1370.dac2" : "es1370.dac1",
                             s,
                             i ? es1370_dac2_callback : es1370_dac1_callback,
-                            &as,
-                            0   /* litle endian */
+                            &as
                             );
                 }
             }
@@ -479,8 +478,9 @@ IO_WRITE_PROTO (es1370_writeb)
 IO_WRITE_PROTO (es1370_writeb)
 {
     ES1370State *s = opaque;
+    uint32_t shift, mask;
+
     addr = es1370_fixup (s, addr);
-    uint32_t shift, mask;
 
     switch (addr) {
     case ES1370_REG_CONTROL:
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/hw/esp.c
--- a/tools/ioemu/hw/esp.c      Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/hw/esp.c      Wed Aug 09 08:34:06 2006 -0600
@@ -38,16 +38,13 @@ do { printf("ESP: set_irq(%d): %d\n", (i
 #define ESPDMA_REGS 4
 #define ESPDMA_MAXADDR (ESPDMA_REGS * 4 - 1)
 #define ESP_MAXREG 0x3f
-#define TI_BUFSZ 1024*1024 // XXX
+#define TI_BUFSZ 32
 #define DMA_VER 0xa0000000
 #define DMA_INTR 1
 #define DMA_INTREN 0x10
+#define DMA_WRITE_MEM 0x100
 #define DMA_LOADED 0x04000000
 typedef struct ESPState ESPState;
-
-typedef int ESPDMAFunc(ESPState *s, 
-                       target_phys_addr_t phys_addr, 
-                       int transfer_size1);
 
 struct ESPState {
     BlockDriverState **bd;
@@ -57,12 +54,14 @@ struct ESPState {
     uint32_t espdmaregs[ESPDMA_REGS];
     uint32_t ti_size;
     uint32_t ti_rptr, ti_wptr;
-    int ti_dir;
     uint8_t ti_buf[TI_BUFSZ];
+    int sense;
     int dma;
-    ESPDMAFunc *dma_cb;
-    int64_t offset, len;
-    int target;
+    SCSIDevice *scsi_dev[MAX_DISKS];
+    SCSIDevice *current_dev;
+    uint8_t cmdbuf[TI_BUFSZ];
+    int cmdlen;
+    int do_cmd;
 };
 
 #define STAT_DO 0x00
@@ -83,394 +82,200 @@ struct ESPState {
 #define SEQ_0 0x0
 #define SEQ_CD 0x4
 
-/* XXX: stolen from ide.c, move to common ATAPI/SCSI library */
-static void lba_to_msf(uint8_t *buf, int lba)
-{
-    lba += 150;
-    buf[0] = (lba / 75) / 60;
-    buf[1] = (lba / 75) % 60;
-    buf[2] = lba % 75;
-}
-
-static inline void cpu_to_ube16(uint8_t *buf, int val)
-{
-    buf[0] = val >> 8;
-    buf[1] = val;
-}
-
-static inline void cpu_to_ube32(uint8_t *buf, unsigned int val)
-{
-    buf[0] = val >> 24;
-    buf[1] = val >> 16;
-    buf[2] = val >> 8;
-    buf[3] = val;
-}
-
-/* same toc as bochs. Return -1 if error or the toc length */
-/* XXX: check this */
-static int cdrom_read_toc(int nb_sectors, uint8_t *buf, int msf, int 
start_track)
-{
-    uint8_t *q;
-    int len;
-    
-    if (start_track > 1 && start_track != 0xaa)
-        return -1;
-    q = buf + 2;
-    *q++ = 1; /* first session */
-    *q++ = 1; /* last session */
-    if (start_track <= 1) {
-        *q++ = 0; /* reserved */
-        *q++ = 0x14; /* ADR, control */
-        *q++ = 1;    /* track number */
-        *q++ = 0; /* reserved */
-        if (msf) {
-            *q++ = 0; /* reserved */
-            lba_to_msf(q, 0);
-            q += 3;
-        } else {
-            /* sector 0 */
-            cpu_to_ube32(q, 0);
-            q += 4;
-        }
-    }
-    /* lead out track */
-    *q++ = 0; /* reserved */
-    *q++ = 0x16; /* ADR, control */
-    *q++ = 0xaa; /* track number */
-    *q++ = 0; /* reserved */
-    if (msf) {
-        *q++ = 0; /* reserved */
-        lba_to_msf(q, nb_sectors);
-        q += 3;
-    } else {
-        cpu_to_ube32(q, nb_sectors);
-        q += 4;
-    }
-    len = q - buf;
-    cpu_to_ube16(buf, len - 2);
-    return len;
-}
-
-/* mostly same info as PearPc */
-static int cdrom_read_toc_raw(int nb_sectors, uint8_t *buf, int msf, 
-                              int session_num)
-{
-    uint8_t *q;
-    int len;
-    
-    q = buf + 2;
-    *q++ = 1; /* first session */
-    *q++ = 1; /* last session */
-
-    *q++ = 1; /* session number */
-    *q++ = 0x14; /* data track */
-    *q++ = 0; /* track number */
-    *q++ = 0xa0; /* lead-in */
-    *q++ = 0; /* min */
-    *q++ = 0; /* sec */
-    *q++ = 0; /* frame */
-    *q++ = 0;
-    *q++ = 1; /* first track */
-    *q++ = 0x00; /* disk type */
-    *q++ = 0x00;
-    
-    *q++ = 1; /* session number */
-    *q++ = 0x14; /* data track */
-    *q++ = 0; /* track number */
-    *q++ = 0xa1;
-    *q++ = 0; /* min */
-    *q++ = 0; /* sec */
-    *q++ = 0; /* frame */
-    *q++ = 0;
-    *q++ = 1; /* last track */
-    *q++ = 0x00;
-    *q++ = 0x00;
-    
-    *q++ = 1; /* session number */
-    *q++ = 0x14; /* data track */
-    *q++ = 0; /* track number */
-    *q++ = 0xa2; /* lead-out */
-    *q++ = 0; /* min */
-    *q++ = 0; /* sec */
-    *q++ = 0; /* frame */
-    if (msf) {
-        *q++ = 0; /* reserved */
-        lba_to_msf(q, nb_sectors);
-        q += 3;
-    } else {
-        cpu_to_ube32(q, nb_sectors);
-        q += 4;
-    }
-
-    *q++ = 1; /* session number */
-    *q++ = 0x14; /* ADR, control */
-    *q++ = 0;    /* track number */
-    *q++ = 1;    /* point */
-    *q++ = 0; /* min */
-    *q++ = 0; /* sec */
-    *q++ = 0; /* frame */
-    if (msf) {
-        *q++ = 0; 
-        lba_to_msf(q, 0);
-        q += 3;
-    } else {
-        *q++ = 0; 
-        *q++ = 0; 
-        *q++ = 0; 
-        *q++ = 0; 
-    }
-
-    len = q - buf;
-    cpu_to_ube16(buf, len - 2);
-    return len;
-}
-
-static int esp_write_dma_cb(ESPState *s, 
-                            target_phys_addr_t phys_addr, 
-                            int transfer_size1)
-{
-    DPRINTF("Write callback (offset %lld len %lld size %d trans_size %d)\n",
-            s->offset, s->len, s->ti_size, transfer_size1);
-    bdrv_write(s->bd[s->target], s->offset, s->ti_buf, s->len);
-    s->offset = 0;
-    s->len = 0;
-    s->target = 0;
-    return 0;
-}
-
-static void handle_satn(ESPState *s)
-{
-    uint8_t buf[32];
+static int get_cmd(ESPState *s, uint8_t *buf)
+{
     uint32_t dmaptr, dmalen;
-    unsigned int i;
-    int64_t nb_sectors;
     int target;
 
     dmalen = s->wregs[0] | (s->wregs[1] << 8);
     target = s->wregs[4] & 7;
-    DPRINTF("Select with ATN len %d target %d\n", dmalen, target);
+    DPRINTF("get_cmd: len %d target %d\n", dmalen, target);
     if (s->dma) {
        dmaptr = iommu_translate(s->espdmaregs[1]);
-       DPRINTF("DMA Direction: %c, addr 0x%8.8x\n", s->espdmaregs[0] & 0x100? 
'w': 'r', dmaptr);
+       DPRINTF("DMA Direction: %c, addr 0x%8.8x\n",
+                s->espdmaregs[0] & DMA_WRITE_MEM ? 'w': 'r', dmaptr);
        cpu_physical_memory_read(dmaptr, buf, dmalen);
     } else {
        buf[0] = 0;
        memcpy(&buf[1], s->ti_buf, dmalen);
        dmalen++;
     }
-    for (i = 0; i < dmalen; i++) {
-       DPRINTF("Command %2.2x\n", buf[i]);
-    }
-    s->ti_dir = 0;
+
     s->ti_size = 0;
     s->ti_rptr = 0;
     s->ti_wptr = 0;
 
-    if (target >= 4 || !s->bd[target]) { // No such drive
+    if (target >= 4 || !s->scsi_dev[target]) {
+        // No such drive
        s->rregs[4] = STAT_IN;
        s->rregs[5] = INTR_DC;
        s->rregs[6] = SEQ_0;
        s->espdmaregs[0] |= DMA_INTR;
        pic_set_irq(s->irq, 1);
-       return;
-    }
-    switch (buf[1]) {
-    case 0x0:
-       DPRINTF("Test Unit Ready (len %d)\n", buf[5]);
-       break;
-    case 0x12:
-       DPRINTF("Inquiry (len %d)\n", buf[5]);
-       memset(s->ti_buf, 0, 36);
-       if (bdrv_get_type_hint(s->bd[target]) == BDRV_TYPE_CDROM) {
-           s->ti_buf[0] = 5;
-           memcpy(&s->ti_buf[16], "QEMU CDROM     ", 16);
-       } else {
-           s->ti_buf[0] = 0;
-           memcpy(&s->ti_buf[16], "QEMU HARDDISK  ", 16);
-       }
-       memcpy(&s->ti_buf[8], "QEMU   ", 8);
-       s->ti_buf[2] = 1;
-       s->ti_buf[3] = 2;
-       s->ti_buf[4] = 32;
-       s->ti_dir = 1;
-       s->ti_size = 36;
-       break;
-    case 0x1a:
-       DPRINTF("Mode Sense(6) (page %d, len %d)\n", buf[3], buf[5]);
-       break;
-    case 0x25:
-       DPRINTF("Read Capacity (len %d)\n", buf[5]);
-       memset(s->ti_buf, 0, 8);
-       bdrv_get_geometry(s->bd[target], &nb_sectors);
-       s->ti_buf[0] = (nb_sectors >> 24) & 0xff;
-       s->ti_buf[1] = (nb_sectors >> 16) & 0xff;
-       s->ti_buf[2] = (nb_sectors >> 8) & 0xff;
-       s->ti_buf[3] = nb_sectors & 0xff;
-       s->ti_buf[4] = 0;
-       s->ti_buf[5] = 0;
-       if (bdrv_get_type_hint(s->bd[target]) == BDRV_TYPE_CDROM)
-           s->ti_buf[6] = 8; // sector size 2048
-       else
-           s->ti_buf[6] = 2; // sector size 512
-       s->ti_buf[7] = 0;
-       s->ti_dir = 1;
-       s->ti_size = 8;
-       break;
-    case 0x28:
-       {
-           int64_t offset, len;
-
-           if (bdrv_get_type_hint(s->bd[target]) == BDRV_TYPE_CDROM) {
-               offset = ((buf[3] << 24) | (buf[4] << 16) | (buf[5] << 8) | 
buf[6]) * 4;
-               len = ((buf[8] << 8) | buf[9]) * 4;
-               s->ti_size = len * 2048;
-           } else {
-               offset = (buf[3] << 24) | (buf[4] << 16) | (buf[5] << 8) | 
buf[6];
-               len = (buf[8] << 8) | buf[9];
-               s->ti_size = len * 512;
-           }
-           DPRINTF("Read (10) (offset %lld len %lld)\n", offset, len);
-            if (s->ti_size > TI_BUFSZ) {
-                DPRINTF("size too large %d\n", s->ti_size);
-            }
-           bdrv_read(s->bd[target], offset, s->ti_buf, len);
-           // XXX error handling
-           s->ti_dir = 1;
-           break;
-       }
-    case 0x2a:
-       {
-           int64_t offset, len;
-
-           if (bdrv_get_type_hint(s->bd[target]) == BDRV_TYPE_CDROM) {
-               offset = ((buf[3] << 24) | (buf[4] << 16) | (buf[5] << 8) | 
buf[6]) * 4;
-               len = ((buf[8] << 8) | buf[9]) * 4;
-               s->ti_size = len * 2048;
-           } else {
-               offset = (buf[3] << 24) | (buf[4] << 16) | (buf[5] << 8) | 
buf[6];
-               len = (buf[8] << 8) | buf[9];
-               s->ti_size = len * 512;
-           }
-           DPRINTF("Write (10) (offset %lld len %lld)\n", offset, len);
-            if (s->ti_size > TI_BUFSZ) {
-                DPRINTF("size too large %d\n", s->ti_size);
-            }
-            s->dma_cb = esp_write_dma_cb;
-            s->offset = offset;
-            s->len = len;
-            s->target = target;
-           // XXX error handling
-           s->ti_dir = 0;
-           break;
-       }
-    case 0x43:
-        {
-            int start_track, format, msf, len;
-
-            msf = buf[2] & 2;
-            format = buf[3] & 0xf;
-            start_track = buf[7];
-            bdrv_get_geometry(s->bd[target], &nb_sectors);
-            DPRINTF("Read TOC (track %d format %d msf %d)\n", start_track, 
format, msf >> 1);
-            switch(format) {
-            case 0:
-                len = cdrom_read_toc(nb_sectors, buf, msf, start_track);
-                if (len < 0)
-                    goto error_cmd;
-                s->ti_size = len;
-                break;
-            case 1:
-                /* multi session : only a single session defined */
-                memset(buf, 0, 12);
-                buf[1] = 0x0a;
-                buf[2] = 0x01;
-                buf[3] = 0x01;
-                s->ti_size = 12;
-                break;
-            case 2:
-                len = cdrom_read_toc_raw(nb_sectors, buf, msf, start_track);
-                if (len < 0)
-                    goto error_cmd;
-                s->ti_size = len;
-                break;
-            default:
-            error_cmd:
-                DPRINTF("Read TOC error\n");
-                // XXX error handling
-                break;
-            }
-           s->ti_dir = 1;
-            break;
-        }
-    default:
-       DPRINTF("Unknown SCSI command (%2.2x)\n", buf[1]);
-       break;
-    }
-    s->rregs[4] = STAT_IN | STAT_TC | STAT_DI;
+       return 0;
+    }
+    s->current_dev = s->scsi_dev[target];
+    return dmalen;
+}
+
+static void do_cmd(ESPState *s, uint8_t *buf)
+{
+    int32_t datalen;
+    int lun;
+
+    DPRINTF("do_cmd: busid 0x%x\n", buf[0]);
+    lun = buf[0] & 7;
+    datalen = scsi_send_command(s->current_dev, 0, &buf[1], lun);
+    if (datalen == 0) {
+        s->ti_size = 0;
+    } else {
+        s->rregs[4] = STAT_IN | STAT_TC;
+        if (datalen > 0) {
+            s->rregs[4] |= STAT_DI;
+            s->ti_size = datalen;
+        } else {
+            s->rregs[4] |= STAT_DO;
+            s->ti_size = -datalen;
+        }
+    }
     s->rregs[5] = INTR_BS | INTR_FC;
     s->rregs[6] = SEQ_CD;
     s->espdmaregs[0] |= DMA_INTR;
     pic_set_irq(s->irq, 1);
 }
 
-static void dma_write(ESPState *s, const uint8_t *buf, uint32_t len)
-{
-    uint32_t dmaptr, dmalen;
-
-    dmalen = s->wregs[0] | (s->wregs[1] << 8);
-    DPRINTF("Transfer status len %d\n", dmalen);
+static void handle_satn(ESPState *s)
+{
+    uint8_t buf[32];
+    int len;
+
+    len = get_cmd(s, buf);
+    if (len)
+        do_cmd(s, buf);
+}
+
+static void handle_satn_stop(ESPState *s)
+{
+    s->cmdlen = get_cmd(s, s->cmdbuf);
+    if (s->cmdlen) {
+        DPRINTF("Set ATN & Stop: cmdlen %d\n", s->cmdlen);
+        s->do_cmd = 1;
+        s->espdmaregs[1] += s->cmdlen;
+        s->rregs[4] = STAT_IN | STAT_TC | STAT_CD;
+        s->rregs[5] = INTR_BS | INTR_FC;
+        s->rregs[6] = SEQ_CD;
+        s->espdmaregs[0] |= DMA_INTR;
+        pic_set_irq(s->irq, 1);
+    }
+}
+
+static void write_response(ESPState *s)
+{
+    uint32_t dmaptr;
+
+    DPRINTF("Transfer status (sense=%d)\n", s->sense);
+    s->ti_buf[0] = s->sense;
+    s->ti_buf[1] = 0;
     if (s->dma) {
        dmaptr = iommu_translate(s->espdmaregs[1]);
-       DPRINTF("DMA Direction: %c\n", s->espdmaregs[0] & 0x100? 'w': 'r');
-       cpu_physical_memory_write(dmaptr, buf, len);
+       DPRINTF("DMA Direction: %c\n",
+                s->espdmaregs[0] & DMA_WRITE_MEM ? 'w': 'r');
+       cpu_physical_memory_write(dmaptr, s->ti_buf, 2);
        s->rregs[4] = STAT_IN | STAT_TC | STAT_ST;
        s->rregs[5] = INTR_BS | INTR_FC;
        s->rregs[6] = SEQ_CD;
     } else {
-       memcpy(s->ti_buf, buf, len);
-       s->ti_size = dmalen;
+       s->ti_size = 2;
        s->ti_rptr = 0;
        s->ti_wptr = 0;
-       s->rregs[7] = dmalen;
+       s->rregs[7] = 2;
     }
     s->espdmaregs[0] |= DMA_INTR;
     pic_set_irq(s->irq, 1);
 
 }
 
-static const uint8_t okbuf[] = {0, 0};
+static void esp_command_complete(void *opaque, uint32_t tag, int sense)
+{
+    ESPState *s = (ESPState *)opaque;
+
+    DPRINTF("SCSI Command complete\n");
+    if (s->ti_size != 0)
+        DPRINTF("SCSI command completed unexpectedly\n");
+    s->ti_size = 0;
+    if (sense)
+        DPRINTF("Command failed\n");
+    s->sense = sense;
+    s->rregs[4] = STAT_IN | STAT_TC | STAT_ST;
+}
 
 static void handle_ti(ESPState *s)
 {
-    uint32_t dmaptr, dmalen;
+    uint32_t dmaptr, dmalen, minlen, len, from, to;
     unsigned int i;
+    int to_device;
+    uint8_t buf[TARGET_PAGE_SIZE];
 
     dmalen = s->wregs[0] | (s->wregs[1] << 8);
-    DPRINTF("Transfer Information len %d\n", dmalen);
+    if (dmalen==0) {
+      dmalen=0x10000;
+    }
+
+    if (s->do_cmd)
+        minlen = (dmalen < 32) ? dmalen : 32;
+    else
+        minlen = (dmalen < s->ti_size) ? dmalen : s->ti_size;
+    DPRINTF("Transfer Information len %d\n", minlen);
     if (s->dma) {
        dmaptr = iommu_translate(s->espdmaregs[1]);
-       DPRINTF("DMA Direction: %c, addr 0x%8.8x\n", s->espdmaregs[0] & 0x100? 
'w': 'r', dmaptr);
-       for (i = 0; i < s->ti_size; i++) {
+        /* Check if the transfer writes to to reads from the device.  */
+        to_device = (s->espdmaregs[0] & DMA_WRITE_MEM) == 0;
+       DPRINTF("DMA Direction: %c, addr 0x%8.8x %08x\n",
+                to_device ? 'r': 'w', dmaptr, s->ti_size);
+       from = s->espdmaregs[1];
+       to = from + minlen;
+       for (i = 0; i < minlen; i += len, from += len) {
            dmaptr = iommu_translate(s->espdmaregs[1] + i);
-           if (s->ti_dir)
-               cpu_physical_memory_write(dmaptr, &s->ti_buf[i], 1);
-           else
-               cpu_physical_memory_read(dmaptr, &s->ti_buf[i], 1);
-       }
-        if (s->dma_cb) {
-            s->dma_cb(s, s->espdmaregs[1], dmalen);
-            s->dma_cb = NULL;
-        }
-       s->rregs[4] = STAT_IN | STAT_TC | STAT_ST;
-       s->rregs[5] = INTR_BS;
+           if ((from & TARGET_PAGE_MASK) != (to & TARGET_PAGE_MASK)) {
+               len = TARGET_PAGE_SIZE - (from & ~TARGET_PAGE_MASK);
+            } else {
+              len = to - from;
+            }
+            DPRINTF("DMA address p %08x v %08x len %08x, from %08x, to 
%08x\n", dmaptr, s->espdmaregs[1] + i, len, from, to);
+            s->ti_size -= len;
+            if (s->do_cmd) {
+                DPRINTF("command len %d + %d\n", s->cmdlen, len);
+                cpu_physical_memory_read(dmaptr, &s->cmdbuf[s->cmdlen], len);
+                s->ti_size = 0;
+                s->cmdlen = 0;
+                s->do_cmd = 0;
+                do_cmd(s, s->cmdbuf);
+                return;
+            } else {
+                if (to_device) {
+                    cpu_physical_memory_read(dmaptr, buf, len);
+                    scsi_write_data(s->current_dev, buf, len);
+                } else {
+                    scsi_read_data(s->current_dev, buf, len);
+                    cpu_physical_memory_write(dmaptr, buf, len);
+                }
+            }
+        }
+        if (s->ti_size) {
+           s->rregs[4] = STAT_IN | STAT_TC | (to_device ? STAT_DO : STAT_DI);
+        }
+        s->rregs[5] = INTR_BS;
        s->rregs[6] = 0;
+       s->rregs[7] = 0;
        s->espdmaregs[0] |= DMA_INTR;
-    } else {
-       s->ti_size = dmalen;
-       s->ti_rptr = 0;
-       s->ti_wptr = 0;
-       s->rregs[7] = dmalen;
-    }  
+    } else if (s->do_cmd) {
+        DPRINTF("command len %d\n", s->cmdlen);
+        s->ti_size = 0;
+        s->cmdlen = 0;
+        s->do_cmd = 0;
+        do_cmd(s, s->cmdbuf);
+        return;
+    }
     pic_set_irq(s->irq, 1);
 }
 
@@ -484,9 +289,8 @@ static void esp_reset(void *opaque)
     s->ti_size = 0;
     s->ti_rptr = 0;
     s->ti_wptr = 0;
-    s->ti_dir = 0;
     s->dma = 0;
-    s->dma_cb = NULL;
+    s->do_cmd = 0;
 }
 
 static uint32_t esp_mem_readb(void *opaque, target_phys_addr_t addr)
@@ -501,7 +305,12 @@ static uint32_t esp_mem_readb(void *opaq
        // FIFO
        if (s->ti_size > 0) {
            s->ti_size--;
-           s->rregs[saddr] = s->ti_buf[s->ti_rptr++];
+            if ((s->rregs[4] & 6) == 0) {
+                /* Data in/out.  */
+                scsi_read_data(s->current_dev, &s->rregs[2], 0);
+            } else {
+                s->rregs[2] = s->ti_buf[s->ti_rptr++];
+            }
            pic_set_irq(s->irq, 1);
        }
        if (s->ti_size == 0) {
@@ -536,8 +345,17 @@ static void esp_mem_writeb(void *opaque,
         break;
     case 2:
        // FIFO
-       s->ti_size++;
-       s->ti_buf[s->ti_wptr++] = val & 0xff;
+        if (s->do_cmd) {
+            s->cmdbuf[s->cmdlen++] = val & 0xff;
+        } else if ((s->rregs[4] & 6) == 0) {
+            uint8_t buf;
+            buf = val & 0xff;
+            s->ti_size--;
+            scsi_write_data(s->current_dev, &buf, 0);
+        } else {
+            s->ti_size++;
+            s->ti_buf[s->ti_wptr++] = val & 0xff;
+        }
        break;
     case 3:
         s->rregs[saddr] = val;
@@ -574,11 +392,11 @@ static void esp_mem_writeb(void *opaque,
            break;
        case 0x11:
            DPRINTF("Initiator Command Complete Sequence (%2.2x)\n", val);
-           dma_write(s, okbuf, 2);
+           write_response(s);
            break;
        case 0x12:
            DPRINTF("Message Accepted (%2.2x)\n", val);
-           dma_write(s, okbuf, 2);
+           write_response(s);
            s->rregs[5] = INTR_DC;
            s->rregs[6] = 0;
            break;
@@ -586,11 +404,12 @@ static void esp_mem_writeb(void *opaque,
            DPRINTF("Set ATN (%2.2x)\n", val);
            break;
        case 0x42:
+           DPRINTF("Set ATN (%2.2x)\n", val);
            handle_satn(s);
            break;
        case 0x43:
            DPRINTF("Set ATN & stop (%2.2x)\n", val);
-           handle_satn(s);
+           handle_satn_stop(s);
            break;
        default:
            DPRINTF("Unhandled ESP command (%2.2x)\n", val);
@@ -660,7 +479,7 @@ static void espdma_mem_writel(void *opaq
         val |= DMA_VER;
        break;
     case 1:
-        s->espdmaregs[0] = DMA_LOADED;
+        s->espdmaregs[0] |= DMA_LOADED;
         break;
     default:
        break;
@@ -693,7 +512,6 @@ static void esp_save(QEMUFile *f, void *
     qemu_put_be32s(f, &s->ti_size);
     qemu_put_be32s(f, &s->ti_rptr);
     qemu_put_be32s(f, &s->ti_wptr);
-    qemu_put_be32s(f, &s->ti_dir);
     qemu_put_buffer(f, s->ti_buf, TI_BUFSZ);
     qemu_put_be32s(f, &s->dma);
 }
@@ -714,7 +532,6 @@ static int esp_load(QEMUFile *f, void *o
     qemu_get_be32s(f, &s->ti_size);
     qemu_get_be32s(f, &s->ti_rptr);
     qemu_get_be32s(f, &s->ti_wptr);
-    qemu_get_be32s(f, &s->ti_dir);
     qemu_get_buffer(f, s->ti_buf, TI_BUFSZ);
     qemu_get_be32s(f, &s->dma);
 
@@ -725,6 +542,7 @@ void esp_init(BlockDriverState **bd, int
 {
     ESPState *s;
     int esp_io_memory, espdma_io_memory;
+    int i;
 
     s = qemu_mallocz(sizeof(ESPState));
     if (!s)
@@ -743,5 +561,11 @@ void esp_init(BlockDriverState **bd, int
 
     register_savevm("esp", espaddr, 1, esp_save, esp_load, s);
     qemu_register_reset(esp_reset, s);
-}
-
+    for (i = 0; i < MAX_DISKS; i++) {
+        if (bs_table[i]) {
+            s->scsi_dev[i] =
+                scsi_disk_init(bs_table[i], esp_command_complete, s);
+        }
+    }
+}
+
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/hw/i8259.c
--- a/tools/ioemu/hw/i8259.c    Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/hw/i8259.c    Wed Aug 09 08:34:06 2006 -0600
@@ -531,7 +531,7 @@ void irq_info(void)
     for (i = 0; i < 16; i++) {
         count = irq_count[i];
         if (count > 0)
-            term_printf("%2d: %lld\n", i, count);
+            term_printf("%2d: %" PRId64 "\n", i, count);
     }
 #endif
 }
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/hw/ide.c
--- a/tools/ioemu/hw/ide.c      Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/hw/ide.c      Wed Aug 09 08:34:06 2006 -0600
@@ -1133,127 +1133,6 @@ static void ide_atapi_cmd_read(IDEState 
     }
 }
 
-/* same toc as bochs. Return -1 if error or the toc length */
-/* XXX: check this */
-static int cdrom_read_toc(IDEState *s, uint8_t *buf, int msf, int start_track)
-{
-    uint8_t *q;
-    int nb_sectors, len;
-    
-    if (start_track > 1 && start_track != 0xaa)
-        return -1;
-    q = buf + 2;
-    *q++ = 1; /* first session */
-    *q++ = 1; /* last session */
-    if (start_track <= 1) {
-        *q++ = 0; /* reserved */
-        *q++ = 0x14; /* ADR, control */
-        *q++ = 1;    /* track number */
-        *q++ = 0; /* reserved */
-        if (msf) {
-            *q++ = 0; /* reserved */
-            lba_to_msf(q, 0);
-            q += 3;
-        } else {
-            /* sector 0 */
-            cpu_to_ube32(q, 0);
-            q += 4;
-        }
-    }
-    /* lead out track */
-    *q++ = 0; /* reserved */
-    *q++ = 0x16; /* ADR, control */
-    *q++ = 0xaa; /* track number */
-    *q++ = 0; /* reserved */
-    nb_sectors = s->nb_sectors >> 2;
-    if (msf) {
-        *q++ = 0; /* reserved */
-        lba_to_msf(q, nb_sectors);
-        q += 3;
-    } else {
-        cpu_to_ube32(q, nb_sectors);
-        q += 4;
-    }
-    len = q - buf;
-    cpu_to_ube16(buf, len - 2);
-    return len;
-}
-
-/* mostly same info as PearPc */
-static int cdrom_read_toc_raw(IDEState *s, uint8_t *buf, int msf, 
-                              int session_num)
-{
-    uint8_t *q;
-    int nb_sectors, len;
-    
-    q = buf + 2;
-    *q++ = 1; /* first session */
-    *q++ = 1; /* last session */
-
-    *q++ = 1; /* session number */
-    *q++ = 0x14; /* data track */
-    *q++ = 0; /* track number */
-    *q++ = 0xa0; /* lead-in */
-    *q++ = 0; /* min */
-    *q++ = 0; /* sec */
-    *q++ = 0; /* frame */
-    *q++ = 0;
-    *q++ = 1; /* first track */
-    *q++ = 0x00; /* disk type */
-    *q++ = 0x00;
-    
-    *q++ = 1; /* session number */
-    *q++ = 0x14; /* data track */
-    *q++ = 0; /* track number */
-    *q++ = 0xa1;
-    *q++ = 0; /* min */
-    *q++ = 0; /* sec */
-    *q++ = 0; /* frame */
-    *q++ = 0;
-    *q++ = 1; /* last track */
-    *q++ = 0x00;
-    *q++ = 0x00;
-    
-    *q++ = 1; /* session number */
-    *q++ = 0x14; /* data track */
-    *q++ = 0; /* track number */
-    *q++ = 0xa2; /* lead-out */
-    *q++ = 0; /* min */
-    *q++ = 0; /* sec */
-    *q++ = 0; /* frame */
-    nb_sectors = s->nb_sectors >> 2;
-    if (msf) {
-        *q++ = 0; /* reserved */
-        lba_to_msf(q, nb_sectors);
-        q += 3;
-    } else {
-        cpu_to_ube32(q, nb_sectors);
-        q += 4;
-    }
-
-    *q++ = 1; /* session number */
-    *q++ = 0x14; /* ADR, control */
-    *q++ = 0;    /* track number */
-    *q++ = 1;    /* point */
-    *q++ = 0; /* min */
-    *q++ = 0; /* sec */
-    *q++ = 0; /* frame */
-    if (msf) {
-        *q++ = 0; 
-        lba_to_msf(q, 0);
-        q += 3;
-    } else {
-        *q++ = 0; 
-        *q++ = 0; 
-        *q++ = 0; 
-        *q++ = 0; 
-    }
-
-    len = q - buf;
-    cpu_to_ube16(buf, len - 2);
-    return len;
-}
-
 static void ide_atapi_cmd(IDEState *s)
 {
     const uint8_t *packet;
@@ -1279,6 +1158,7 @@ static void ide_atapi_cmd(IDEState *s)
         } else {
             ide_atapi_cmd_error(s, SENSE_NOT_READY, 
                                 ASC_MEDIUM_NOT_PRESENT);
+            xenstore_check_new_media_present(1000);
         }
         break;
     case GPCMD_MODE_SENSE_10:
@@ -1500,7 +1380,7 @@ static void ide_atapi_cmd(IDEState *s)
             start_track = packet[6];
             switch(format) {
             case 0:
-                len = cdrom_read_toc(s, buf, msf, start_track);
+                len = cdrom_read_toc(s->nb_sectors >> 2, buf, msf, 
start_track);
                 if (len < 0)
                     goto error_cmd;
                 ide_atapi_cmd_reply(s, len, max_len);
@@ -1514,7 +1394,7 @@ static void ide_atapi_cmd(IDEState *s)
                 ide_atapi_cmd_reply(s, 12, max_len);
                 break;
             case 2:
-                len = cdrom_read_toc_raw(s, buf, msf, start_track);
+                len = cdrom_read_toc_raw(s->nb_sectors >> 2, buf, msf, 
start_track);
                 if (len < 0)
                     goto error_cmd;
                 ide_atapi_cmd_reply(s, len, max_len);
@@ -1828,6 +1708,11 @@ static void ide_ioport_write(void *opaqu
             break;
         case WIN_FLUSH_CACHE:
         case WIN_FLUSH_CACHE_EXT:
+            if (s->bs)
+                bdrv_flush(s->bs);
+           s->status = READY_STAT;
+            ide_set_irq(s);
+            break;
        case WIN_STANDBYNOW1:
         case WIN_IDLEIMMEDIATE:
            s->status = READY_STAT;
@@ -2562,7 +2447,7 @@ void pci_cmd646_ide_init(PCIBus *bus, Bl
 
 /* hd_table must contain 4 block drivers */
 /* NOTE: for the PIIX3, the IRQs and IOports are hardcoded */
-void pci_piix3_ide_init(PCIBus *bus, BlockDriverState **hd_table)
+void pci_piix3_ide_init(PCIBus *bus, BlockDriverState **hd_table, int devfn)
 {
     PCIIDEState *d;
     uint8_t *pci_conf;
@@ -2570,7 +2455,7 @@ void pci_piix3_ide_init(PCIBus *bus, Blo
     /* register a function 1 of PIIX3 */
     d = (PCIIDEState *)pci_register_device(bus, "PIIX3 IDE", 
                                            sizeof(PCIIDEState),
-                                           ((PCIDevice *)piix3_state)->devfn + 
1, 
+                                           devfn,
                                            NULL, NULL);
     d->type = IDE_TYPE_PIIX3;
 
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/hw/m48t59.c
--- a/tools/ioemu/hw/m48t59.c   Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/hw/m48t59.c   Wed Aug 09 08:34:06 2006 -0600
@@ -332,7 +332,10 @@ void m48t59_write (m48t59_t *NVRAM, uint
        tmp = fromBCD(val);
        if (tmp >= 0 && tmp <= 99) {
            get_time(NVRAM, &tm);
-           tm.tm_year = fromBCD(val);
+            if (NVRAM->type == 8)
+                tm.tm_year = fromBCD(val) + 68; // Base year is 1968
+            else
+                tm.tm_year = fromBCD(val);
            set_time(NVRAM, &tm);
        }
         break;
@@ -421,7 +424,10 @@ uint32_t m48t59_read (m48t59_t *NVRAM, u
     case 0x1FFF:
         /* year */
         get_time(NVRAM, &tm);
-        retval = toBCD(tm.tm_year);
+        if (NVRAM->type == 8) 
+            retval = toBCD(tm.tm_year - 68); // Base year is 1968
+        else
+            retval = toBCD(tm.tm_year);
         break;
     default:
         /* Check lock registers state */
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/hw/mips_r4k.c
--- a/tools/ioemu/hw/mips_r4k.c Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/hw/mips_r4k.c Wed Aug 09 08:34:06 2006 -0600
@@ -60,7 +60,7 @@ static void cpu_mips_update_count (CPUSt
        next++;
 #if 0
     if (logfile) {
-        fprintf(logfile, "%s: 0x%08llx %08x %08x => 0x%08llx\n",
+        fprintf(logfile, "%s: 0x%08" PRIx64 " %08x %08x => 0x%08" PRIx64 "\n",
                 __func__, now, count, compare, next - now);
     }
 #endif
@@ -214,14 +214,10 @@ void mips_r4k_init (int ram_size, int vg
        run. */
     bios_offset = ram_size + vga_ram_size;
     snprintf(buf, sizeof(buf), "%s/%s", bios_dir, BIOS_FILENAME);
-    printf("%s: load BIOS '%s' size %d\n", __func__, buf, BIOS_SIZE);
     ret = load_image(buf, phys_ram_base + bios_offset);
     if (ret == BIOS_SIZE) {
        cpu_register_physical_memory((uint32_t)(0x1fc00000),
                                     BIOS_SIZE, bios_offset | IO_MEM_ROM);
-       env->PC = 0xBFC00000;
-       if (!kernel_filename)
-           return;
     } else {
        /* not fatal */
         fprintf(stderr, "qemu: Warning, could not load MIPS bios '%s'\n",
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/hw/ne2000.c
--- a/tools/ioemu/hw/ne2000.c   Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/hw/ne2000.c   Wed Aug 09 08:34:06 2006 -0600
@@ -206,7 +206,7 @@ static int ne2000_buffer_full(NE2000Stat
 
     index = s->curpag << 8;
     boundary = s->boundary << 8;
-    if (index < boundary)
+    if (index <= boundary)
         avail = boundary - index;
     else
         avail = (s->stop - s->start) - (index - boundary);
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/hw/pc.c
--- a/tools/ioemu/hw/pc.c       Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/hw/pc.c       Wed Aug 09 08:34:06 2006 -0600
@@ -44,7 +44,6 @@ static PITState *pit;
 #ifndef CONFIG_DM
 static IOAPICState *ioapic;
 #endif /* !CONFIG_DM */
-static USBPort *usb_root_ports[2];
 
 static void ioport80_write(void *opaque, uint32_t addr, uint32_t data)
 {
@@ -63,10 +62,19 @@ static void ioportF0_write(void *opaque,
 }
 
 /* TSC handling */
-
 uint64_t cpu_get_tsc(CPUX86State *env)
 {
-    return qemu_get_clock(vm_clock);
+    /* Note: when using kqemu, it is more logical to return the host TSC
+       because kqemu does not trap the RDTSC instruction for
+       performance reasons */
+#if USE_KQEMU
+    if (env->kqemu_enabled) {
+        return cpu_get_real_ticks();
+    } else 
+#endif
+    {
+        return cpu_get_ticks();
+    }
 }
 
 #ifndef CONFIG_DM
@@ -201,6 +209,8 @@ static void cmos_init(uint64_t ram_size,
     case 'a':
     case 'b':
         rtc_set_memory(s, 0x3d, 0x01); /* floppy boot */
+        if (!fd_bootchk)
+            rtc_set_memory(s, 0x38, 0x01); /* disable signature check */
         break;
     default:
     case 'c':
@@ -272,10 +282,6 @@ static void cmos_init(uint64_t ram_size,
         }
     }
     rtc_set_memory(s, 0x39, val);
-
-    /* Disable check of 0x55AA signature on the last two bytes of
-       first sector of disk. XXX: make it the default ? */
-    //    rtc_set_memory(s, 0x38, 1);
 }
 
 void ioport_set_a20(int enable)
@@ -567,7 +573,7 @@ static int parallel_irq[MAX_PARALLEL_POR
 static int parallel_irq[MAX_PARALLEL_PORTS] = { 7, 7, 7 };
 
 /* PIIX4 acpi pci configuration space, func 3 */
-extern void pci_piix4_acpi_init(PCIBus *bus);
+extern void pci_piix4_acpi_init(PCIBus *bus, int devfn);
 
 #ifdef HAS_AUDIO
 static void audio_init (PCIBus *pci_bus)
@@ -630,6 +636,7 @@ static void pc_init1(uint64_t ram_size, 
     int bios_size, isa_bios_size;
 #endif /* !NOBIOS */
     PCIBus *pci_bus;
+    int piix3_devfn = -1;
     CPUState *env;
     NICInfo *nd;
 
@@ -774,7 +781,7 @@ static void pc_init1(uint64_t ram_size, 
 
     if (pci_enabled) {
         pci_bus = i440fx_init();
-        piix3_init(pci_bus);
+        piix3_devfn = piix3_init(pci_bus);
     } else {
         pci_bus = NULL;
     }
@@ -852,7 +859,7 @@ static void pc_init1(uint64_t ram_size, 
     }
 
     if (pci_enabled) {
-        pci_piix3_ide_init(pci_bus, bs_table);
+        pci_piix3_ide_init(pci_bus, bs_table, piix3_devfn + 1);
     } else {
         for(i = 0; i < 2; i++) {
             isa_ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i],
@@ -871,18 +878,40 @@ static void pc_init1(uint64_t ram_size, 
     cmos_init(ram_size, boot_device, bs_table, timeoffset);
 
     /* using PIIX4 acpi model */
-    if (pci_enabled)
-        pci_piix4_acpi_init(pci_bus);
+    if (pci_enabled && acpi_enabled)
+        pci_piix4_acpi_init(pci_bus, piix3_devfn + 3);
 
     if (pci_enabled && usb_enabled) {
-        usb_uhci_init(pci_bus, usb_root_ports);
-        usb_attach(usb_root_ports[0], vm_usb_hub);
-    }
-
+        usb_uhci_init(pci_bus, piix3_devfn + 2);
+    }
+
+    if (pci_enabled && acpi_enabled && 0) {
+        piix4_pm_init(pci_bus, piix3_devfn + 3);
+    }
+
+#if 0
+    /* ??? Need to figure out some way for the user to
+       specify SCSI devices.  */
+    if (pci_enabled) {
+        void *scsi;
+        BlockDriverState *bdrv;
+
+        scsi = lsi_scsi_init(pci_bus, -1);
+        bdrv = bdrv_new("scsidisk");
+        bdrv_open(bdrv, "scsi_disk.img", 0);
+        lsi_scsi_attach(scsi, bdrv, -1);
+        bdrv = bdrv_new("scsicd");
+        bdrv_open(bdrv, "scsi_cd.iso", 0);
+        bdrv_set_type_hint(bdrv, BDRV_TYPE_CDROM);
+        lsi_scsi_attach(scsi, bdrv, -1);
+    }
+#endif
     /* must be done after all PCI devices are instanciated */
     /* XXX: should be done in the Bochs BIOS */
     if (pci_enabled) {
         pci_bios_init();
+        if (acpi_enabled)
+            acpi_bios_init();
     }
 }
 
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/hw/pci.c
--- a/tools/ioemu/hw/pci.c      Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/hw/pci.c      Wed Aug 09 08:34:06 2006 -0600
@@ -25,25 +25,10 @@
 
 //#define DEBUG_PCI
 
-#define PCI_VENDOR_ID          0x00    /* 16 bits */
-#define PCI_DEVICE_ID          0x02    /* 16 bits */
-#define PCI_COMMAND            0x04    /* 16 bits */
-#define  PCI_COMMAND_IO                0x1     /* Enable response in I/O space 
*/
-#define  PCI_COMMAND_MEMORY    0x2     /* Enable response in Memory space */
-#define PCI_CLASS_DEVICE        0x0a    /* Device class */
-#define PCI_INTERRUPT_LINE     0x3c    /* 8 bits */
-#define PCI_INTERRUPT_PIN      0x3d    /* 8 bits */
-#define PCI_MIN_GNT            0x3e    /* 8 bits */
-#define PCI_MAX_LAT            0x3f    /* 8 bits */
-
-/* just used for simpler irq handling. */
-#define PCI_DEVICES_MAX 64
-#define PCI_IRQ_WORDS   ((PCI_DEVICES_MAX + 31) / 32)
-
 struct PCIBus {
     int bus_num;
     int devfn_min;
-    void (*set_irq)(PCIDevice *pci_dev, int irq_num, int level);
+    pci_set_irq_fn set_irq;
     uint32_t config_reg; /* XXX: suppress */
     /* low level pic */
     SetIRQFunc *low_set_irq;
@@ -53,15 +38,22 @@ struct PCIBus {
 
 target_phys_addr_t pci_mem_base;
 static int pci_irq_index;
-static uint32_t pci_irq_levels[4][PCI_IRQ_WORDS];
 static PCIBus *first_bus;
 
-static PCIBus *pci_register_bus(void)
+PCIBus *pci_register_bus(pci_set_irq_fn set_irq, void *pic, int devfn_min)
 {
     PCIBus *bus;
     bus = qemu_mallocz(sizeof(PCIBus));
+    bus->set_irq = set_irq;
+    bus->irq_opaque = pic;
+    bus->devfn_min = devfn_min;
     first_bus = bus;
     return bus;
+}
+
+int pci_bus_num(PCIBus *s)
+{
+    return s->bus_num;
 }
 
 void generic_pci_save(QEMUFile* f, void *opaque)
@@ -141,16 +133,9 @@ void pci_register_io_region(PCIDevice *p
     *(uint32_t *)(pci_dev->config + addr) = cpu_to_le32(type);
 }
 
-static void pci_addr_writel(void* opaque, uint32_t addr, uint32_t val)
-{
-    PCIBus *s = opaque;
-    s->config_reg = val;
-}
-
-static uint32_t pci_addr_readl(void* opaque, uint32_t addr)
-{
-    PCIBus *s = opaque;
-    return s->config_reg;
+target_phys_addr_t pci_to_cpu_addr(target_phys_addr_t addr)
+{
+    return addr + pci_mem_base;
 }
 
 static void pci_update_mappings(PCIDevice *d)
@@ -218,7 +203,7 @@ static void pci_update_mappings(PCIDevic
                             isa_unassign_ioport(r->addr, r->size);
                         }
                     } else {
-                        cpu_register_physical_memory(r->addr + pci_mem_base, 
+                        cpu_register_physical_memory(pci_to_cpu_addr(r->addr),
                                                      r->size, 
                                                      IO_MEM_UNASSIGNED);
                     }
@@ -346,8 +331,7 @@ void pci_default_write_config(PCIDevice 
     }
 }
 
-static void pci_data_write(void *opaque, uint32_t addr, 
-                           uint32_t val, int len)
+void pci_data_write(void *opaque, uint32_t addr, uint32_t val, int len)
 {
     PCIBus *s = opaque;
     PCIDevice *pci_dev;
@@ -355,18 +339,15 @@ static void pci_data_write(void *opaque,
     
 #if defined(DEBUG_PCI) && 0
     printf("pci_data_write: addr=%08x val=%08x len=%d\n",
-           s->config_reg, val, len);
+           addr, val, len);
 #endif
-    if (!(s->config_reg & (1 << 31))) {
-        return;
-    }
-    bus_num = (s->config_reg >> 16) & 0xff;
+    bus_num = (addr >> 16) & 0xff;
     if (bus_num != 0)
         return;
-    pci_dev = s->devices[(s->config_reg >> 8) & 0xff];
+    pci_dev = s->devices[(addr >> 8) & 0xff];
     if (!pci_dev)
         return;
-    config_addr = (s->config_reg & 0xfc) | (addr & 3);
+    config_addr = addr & 0xff;
 #if defined(DEBUG_PCI)
     printf("pci_config_write: %s: addr=%02x val=%08x len=%d\n",
            pci_dev->name, config_addr, val, len);
@@ -374,20 +355,17 @@ static void pci_data_write(void *opaque,
     pci_dev->config_write(pci_dev, config_addr, val, len);
 }
 
-static uint32_t pci_data_read(void *opaque, uint32_t addr, 
-                              int len)
+uint32_t pci_data_read(void *opaque, uint32_t addr, int len)
 {
     PCIBus *s = opaque;
     PCIDevice *pci_dev;
     int config_addr, bus_num;
     uint32_t val;
 
-    if (!(s->config_reg & (1 << 31)))
-        goto fail;
-    bus_num = (s->config_reg >> 16) & 0xff;
+    bus_num = (addr >> 16) & 0xff;
     if (bus_num != 0)
         goto fail;
-    pci_dev = s->devices[(s->config_reg >> 8) & 0xff];
+    pci_dev = s->devices[(addr >> 8) & 0xff];
     if (!pci_dev) {
     fail:
         switch(len) {
@@ -404,7 +382,7 @@ static uint32_t pci_data_read(void *opaq
         }
         goto the_end;
     }
-    config_addr = (s->config_reg & 0xfc) | (addr & 3);
+    config_addr = addr & 0xff;
     val = pci_dev->config_read(pci_dev, config_addr, len);
 #if defined(DEBUG_PCI)
     printf("pci_config_read: %s: addr=%02x val=%08x len=%d\n",
@@ -413,1133 +391,11 @@ static uint32_t pci_data_read(void *opaq
  the_end:
 #if defined(DEBUG_PCI) && 0
     printf("pci_data_read: addr=%08x val=%08x len=%d\n",
-           s->config_reg, val, len);
+           addr, val, len);
 #endif
     return val;
 }
 
-static void pci_data_writeb(void* opaque, uint32_t addr, uint32_t val)
-{
-    pci_data_write(opaque, addr, val, 1);
-}
-
-static void pci_data_writew(void* opaque, uint32_t addr, uint32_t val)
-{
-    pci_data_write(opaque, addr, val, 2);
-}
-
-static void pci_data_writel(void* opaque, uint32_t addr, uint32_t val)
-{
-    pci_data_write(opaque, addr, val, 4);
-}
-
-static uint32_t pci_data_readb(void* opaque, uint32_t addr)
-{
-    return pci_data_read(opaque, addr, 1);
-}
-
-static uint32_t pci_data_readw(void* opaque, uint32_t addr)
-{
-    return pci_data_read(opaque, addr, 2);
-}
-
-static uint32_t pci_data_readl(void* opaque, uint32_t addr)
-{
-    return pci_data_read(opaque, addr, 4);
-}
-
-/* i440FX PCI bridge */
-
-static void piix3_set_irq(PCIDevice *pci_dev, int irq_num, int level);
-
-PCIBus *i440fx_init(void)
-{
-    PCIBus *s;
-    PCIDevice *d;
-
-    s = pci_register_bus();
-    s->set_irq = piix3_set_irq;
-
-    register_ioport_write(0xcf8, 4, 4, pci_addr_writel, s);
-    register_ioport_read(0xcf8, 4, 4, pci_addr_readl, s);
-
-    register_ioport_write(0xcfc, 4, 1, pci_data_writeb, s);
-    register_ioport_write(0xcfc, 4, 2, pci_data_writew, s);
-    register_ioport_write(0xcfc, 4, 4, pci_data_writel, s);
-    register_ioport_read(0xcfc, 4, 1, pci_data_readb, s);
-    register_ioport_read(0xcfc, 4, 2, pci_data_readw, s);
-    register_ioport_read(0xcfc, 4, 4, pci_data_readl, s);
-
-    d = pci_register_device(s, "i440FX", sizeof(PCIDevice), 0, 
-                            NULL, NULL);
-
-    d->config[0x00] = 0x86; // vendor_id
-    d->config[0x01] = 0x80;
-    d->config[0x02] = 0x37; // device_id
-    d->config[0x03] = 0x12;
-    d->config[0x08] = 0x02; // revision
-    d->config[0x0a] = 0x00; // class_sub = host2pci
-    d->config[0x0b] = 0x06; // class_base = PCI_bridge
-    d->config[0x0e] = 0x00; // header_type
-    return s;
-}
-
-/* PIIX3 PCI to ISA bridge */
-
-typedef struct PIIX3State {
-    PCIDevice dev;
-} PIIX3State;
-
-PIIX3State *piix3_state;
-
-/* return the global irq number corresponding to a given device irq
-   pin. We could also use the bus number to have a more precise
-   mapping. */
-static inline int pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num)
-{
-    int slot_addend;
-    slot_addend = (pci_dev->devfn >> 3) - 1;
-    return (irq_num + slot_addend) & 3;
-}
-
-static inline int get_pci_irq_level(int irq_num)
-{
-    int pic_level;
-#if (PCI_IRQ_WORDS == 2)
-    pic_level = ((pci_irq_levels[irq_num][0] | 
-                  pci_irq_levels[irq_num][1]) != 0);
-#else
-    {
-        int i;
-        pic_level = 0;
-        for(i = 0; i < PCI_IRQ_WORDS; i++) {
-            if (pci_irq_levels[irq_num][i]) {
-                pic_level = 1;
-                break;
-            }
-        }
-    }
-#endif
-    return pic_level;
-}
-
-static void piix3_set_irq(PCIDevice *pci_dev, int irq_num, int level)
-{
-    int irq_index, shift, pic_irq, pic_level;
-    uint32_t *p;
-
-    irq_num = pci_slot_get_pirq(pci_dev, irq_num);
-    irq_index = pci_dev->irq_index;
-    p = &pci_irq_levels[irq_num][irq_index >> 5];
-    shift = (irq_index & 0x1f);
-    *p = (*p & ~(1 << shift)) | (level << shift);
-
-    /* now we change the pic irq level according to the piix irq mappings */
-    /* XXX: optimize */
-    pic_irq = piix3_state->dev.config[0x60 + irq_num];
-    if (pic_irq < 16) {
-        /* the pic level is the logical OR of all the PCI irqs mapped
-           to it */
-        pic_level = 0;
-        if (pic_irq == piix3_state->dev.config[0x60])
-            pic_level |= get_pci_irq_level(0);
-        if (pic_irq == piix3_state->dev.config[0x61])
-            pic_level |= get_pci_irq_level(1);
-        if (pic_irq == piix3_state->dev.config[0x62])
-            pic_level |= get_pci_irq_level(2);
-        if (pic_irq == piix3_state->dev.config[0x63])
-            pic_level |= get_pci_irq_level(3);
-        pic_set_irq(pic_irq, pic_level);
-    }
-}
-
-static void piix3_reset(PIIX3State *d)
-{
-    uint8_t *pci_conf = d->dev.config;
-
-    pci_conf[0x04] = 0x07; // master, memory and I/O
-    pci_conf[0x05] = 0x00;
-    pci_conf[0x06] = 0x00;
-    pci_conf[0x07] = 0x02; // PCI_status_devsel_medium
-    pci_conf[0x4c] = 0x4d;
-    pci_conf[0x4e] = 0x03;
-    pci_conf[0x4f] = 0x00;
-    pci_conf[0x60] = 0x80;
-    pci_conf[0x69] = 0x02;
-    pci_conf[0x70] = 0x80;
-    pci_conf[0x76] = 0x0c;
-    pci_conf[0x77] = 0x0c;
-    pci_conf[0x78] = 0x02;
-    pci_conf[0x79] = 0x00;
-    pci_conf[0x80] = 0x00;
-    pci_conf[0x82] = 0x00;
-    pci_conf[0xa0] = 0x08;
-    pci_conf[0xa0] = 0x08;
-    pci_conf[0xa2] = 0x00;
-    pci_conf[0xa3] = 0x00;
-    pci_conf[0xa4] = 0x00;
-    pci_conf[0xa5] = 0x00;
-    pci_conf[0xa6] = 0x00;
-    pci_conf[0xa7] = 0x00;
-    pci_conf[0xa8] = 0x0f;
-    pci_conf[0xaa] = 0x00;
-    pci_conf[0xab] = 0x00;
-    pci_conf[0xac] = 0x00;
-    pci_conf[0xae] = 0x00;
-}
-
-void piix3_init(PCIBus *bus)
-{
-    PIIX3State *d;
-    uint8_t *pci_conf;
-
-    d = (PIIX3State *)pci_register_device(bus, "PIIX3", sizeof(PIIX3State),
-                                          -1, NULL, NULL);
-    register_savevm("PIIX3", 0, 1, generic_pci_save, generic_pci_load, d);
-
-    piix3_state = d;
-    pci_conf = d->dev.config;
-
-    pci_conf[0x00] = 0x86; // Intel
-    pci_conf[0x01] = 0x80;
-    pci_conf[0x02] = 0x00; // 82371SB PIIX3 PCI-to-ISA bridge (Step A1)
-    pci_conf[0x03] = 0x70;
-    pci_conf[0x0a] = 0x01; // class_sub = PCI_ISA
-    pci_conf[0x0b] = 0x06; // class_base = PCI_bridge
-    pci_conf[0x0e] = 0x80; // header_type = PCI_multifunction, generic
-
-    piix3_reset(d);
-}
-
-/* PREP pci init */
-
-static inline void set_config(PCIBus *s, target_phys_addr_t addr)
-{
-    int devfn, i;
-
-    for(i = 0; i < 11; i++) {
-        if ((addr & (1 << (11 + i))) != 0)
-            break;
-    }
-    devfn = ((addr >> 8) & 7) | (i << 3);
-    s->config_reg = 0x80000000 | (addr & 0xfc) | (devfn << 8);
-}
-
-static void PPC_PCIIO_writeb (void *opaque, target_phys_addr_t addr, uint32_t 
val)
-{
-    PCIBus *s = opaque;
-    set_config(s, addr);
-    pci_data_write(s, addr, val, 1);
-}
-
-static void PPC_PCIIO_writew (void *opaque, target_phys_addr_t addr, uint32_t 
val)
-{
-    PCIBus *s = opaque;
-    set_config(s, addr);
-#ifdef TARGET_WORDS_BIGENDIAN
-    val = bswap16(val);
-#endif
-    pci_data_write(s, addr, val, 2);
-}
-
-static void PPC_PCIIO_writel (void *opaque, target_phys_addr_t addr, uint32_t 
val)
-{
-    PCIBus *s = opaque;
-    set_config(s, addr);
-#ifdef TARGET_WORDS_BIGENDIAN
-    val = bswap32(val);
-#endif
-    pci_data_write(s, addr, val, 4);
-}
-
-static uint32_t PPC_PCIIO_readb (void *opaque, target_phys_addr_t addr)
-{
-    PCIBus *s = opaque;
-    uint32_t val;
-    set_config(s, addr);
-    val = pci_data_read(s, addr, 1);
-    return val;
-}
-
-static uint32_t PPC_PCIIO_readw (void *opaque, target_phys_addr_t addr)
-{
-    PCIBus *s = opaque;
-    uint32_t val;
-    set_config(s, addr);
-    val = pci_data_read(s, addr, 2);
-#ifdef TARGET_WORDS_BIGENDIAN
-    val = bswap16(val);
-#endif
-    return val;
-}
-
-static uint32_t PPC_PCIIO_readl (void *opaque, target_phys_addr_t addr)
-{
-    PCIBus *s = opaque;
-    uint32_t val;
-    set_config(s, addr);
-    val = pci_data_read(s, addr, 4);
-#ifdef TARGET_WORDS_BIGENDIAN
-    val = bswap32(val);
-#endif
-    return val;
-}
-
-static CPUWriteMemoryFunc *PPC_PCIIO_write[] = {
-    &PPC_PCIIO_writeb,
-    &PPC_PCIIO_writew,
-    &PPC_PCIIO_writel,
-};
-
-static CPUReadMemoryFunc *PPC_PCIIO_read[] = {
-    &PPC_PCIIO_readb,
-    &PPC_PCIIO_readw,
-    &PPC_PCIIO_readl,
-};
-
-static void prep_set_irq(PCIDevice *d, int irq_num, int level)
-{
-    /* XXX: we do not simulate the hardware - we rely on the BIOS to
-       set correctly for irq line field */
-    pic_set_irq(d->config[PCI_INTERRUPT_LINE], level);
-}
-
-PCIBus *pci_prep_init(void)
-{
-    PCIBus *s;
-    PCIDevice *d;
-    int PPC_io_memory;
-
-    s = pci_register_bus();
-    s->set_irq = prep_set_irq;
-
-    register_ioport_write(0xcf8, 4, 4, pci_addr_writel, s);
-    register_ioport_read(0xcf8, 4, 4, pci_addr_readl, s);
-
-    register_ioport_write(0xcfc, 4, 1, pci_data_writeb, s);
-    register_ioport_write(0xcfc, 4, 2, pci_data_writew, s);
-    register_ioport_write(0xcfc, 4, 4, pci_data_writel, s);
-    register_ioport_read(0xcfc, 4, 1, pci_data_readb, s);
-    register_ioport_read(0xcfc, 4, 2, pci_data_readw, s);
-    register_ioport_read(0xcfc, 4, 4, pci_data_readl, s);
-
-    PPC_io_memory = cpu_register_io_memory(0, PPC_PCIIO_read, 
-                                           PPC_PCIIO_write, s);
-    cpu_register_physical_memory(0x80800000, 0x00400000, PPC_io_memory);
-
-    /* PCI host bridge */ 
-    d = pci_register_device(s, "PREP Host Bridge - Motorola Raven", 
-                            sizeof(PCIDevice), 0, NULL, NULL);
-    d->config[0x00] = 0x57; // vendor_id : Motorola
-    d->config[0x01] = 0x10;
-    d->config[0x02] = 0x01; // device_id : Raven
-    d->config[0x03] = 0x48;
-    d->config[0x08] = 0x00; // revision
-    d->config[0x0A] = 0x00; // class_sub = pci host
-    d->config[0x0B] = 0x06; // class_base = PCI_bridge
-    d->config[0x0C] = 0x08; // cache_line_size
-    d->config[0x0D] = 0x10; // latency_timer
-    d->config[0x0E] = 0x00; // header_type
-    d->config[0x34] = 0x00; // capabilities_pointer
-
-    return s;
-}
-
-
-/* Grackle PCI host */
-static void pci_grackle_config_writel (void *opaque, target_phys_addr_t addr,
-                                       uint32_t val)
-{
-    PCIBus *s = opaque;
-#ifdef TARGET_WORDS_BIGENDIAN
-    val = bswap32(val);
-#endif
-    s->config_reg = val;
-}
-
-static uint32_t pci_grackle_config_readl (void *opaque, target_phys_addr_t 
addr)
-{
-    PCIBus *s = opaque;
-    uint32_t val;
-
-    val = s->config_reg;
-#ifdef TARGET_WORDS_BIGENDIAN
-    val = bswap32(val);
-#endif
-    return val;
-}
-
-static CPUWriteMemoryFunc *pci_grackle_config_write[] = {
-    &pci_grackle_config_writel,
-    &pci_grackle_config_writel,
-    &pci_grackle_config_writel,
-};
-
-static CPUReadMemoryFunc *pci_grackle_config_read[] = {
-    &pci_grackle_config_readl,
-    &pci_grackle_config_readl,
-    &pci_grackle_config_readl,
-};
-
-static void pci_grackle_writeb (void *opaque, target_phys_addr_t addr,
-                                uint32_t val)
-{
-    PCIBus *s = opaque;
-    pci_data_write(s, addr, val, 1);
-}
-
-static void pci_grackle_writew (void *opaque, target_phys_addr_t addr,
-                                uint32_t val)
-{
-    PCIBus *s = opaque;
-#ifdef TARGET_WORDS_BIGENDIAN
-    val = bswap16(val);
-#endif
-    pci_data_write(s, addr, val, 2);
-}
-
-static void pci_grackle_writel (void *opaque, target_phys_addr_t addr,
-                                uint32_t val)
-{
-    PCIBus *s = opaque;
-#ifdef TARGET_WORDS_BIGENDIAN
-    val = bswap32(val);
-#endif
-    pci_data_write(s, addr, val, 4);
-}
-
-static uint32_t pci_grackle_readb (void *opaque, target_phys_addr_t addr)
-{
-    PCIBus *s = opaque;
-    uint32_t val;
-    val = pci_data_read(s, addr, 1);
-    return val;
-}
-
-static uint32_t pci_grackle_readw (void *opaque, target_phys_addr_t addr)
-{
-    PCIBus *s = opaque;
-    uint32_t val;
-    val = pci_data_read(s, addr, 2);
-#ifdef TARGET_WORDS_BIGENDIAN
-    val = bswap16(val);
-#endif
-    return val;
-}
-
-static uint32_t pci_grackle_readl (void *opaque, target_phys_addr_t addr)
-{
-    PCIBus *s = opaque;
-    uint32_t val;
-
-    val = pci_data_read(s, addr, 4);
-#ifdef TARGET_WORDS_BIGENDIAN
-    val = bswap32(val);
-#endif
-    return val;
-}
-
-static CPUWriteMemoryFunc *pci_grackle_write[] = {
-    &pci_grackle_writeb,
-    &pci_grackle_writew,
-    &pci_grackle_writel,
-};
-
-static CPUReadMemoryFunc *pci_grackle_read[] = {
-    &pci_grackle_readb,
-    &pci_grackle_readw,
-    &pci_grackle_readl,
-};
-
-void pci_set_pic(PCIBus *bus, SetIRQFunc *set_irq, void *irq_opaque)
-{
-    bus->low_set_irq = set_irq;
-    bus->irq_opaque = irq_opaque;
-}
-
-/* XXX: we do not simulate the hardware - we rely on the BIOS to
-   set correctly for irq line field */
-static void pci_set_irq_simple(PCIDevice *d, int irq_num, int level)
-{
-    PCIBus *s = d->bus;
-    s->low_set_irq(s->irq_opaque, d->config[PCI_INTERRUPT_LINE], level);
-}
-
-PCIBus *pci_grackle_init(uint32_t base)
-{
-    PCIBus *s;
-    PCIDevice *d;
-    int pci_mem_config, pci_mem_data;
-
-    s = pci_register_bus();
-    s->set_irq = pci_set_irq_simple;
-
-    pci_mem_config = cpu_register_io_memory(0, pci_grackle_config_read, 
-                                            pci_grackle_config_write, s);
-    pci_mem_data = cpu_register_io_memory(0, pci_grackle_read,
-                                          pci_grackle_write, s);
-    cpu_register_physical_memory(base, 0x1000, pci_mem_config);
-    cpu_register_physical_memory(base + 0x00200000, 0x1000, pci_mem_data);
-    d = pci_register_device(s, "Grackle host bridge", sizeof(PCIDevice), 
-                            0, NULL, NULL);
-    d->config[0x00] = 0x57; // vendor_id
-    d->config[0x01] = 0x10;
-    d->config[0x02] = 0x02; // device_id
-    d->config[0x03] = 0x00;
-    d->config[0x08] = 0x00; // revision
-    d->config[0x09] = 0x01;
-    d->config[0x0a] = 0x00; // class_sub = host
-    d->config[0x0b] = 0x06; // class_base = PCI_bridge
-    d->config[0x0e] = 0x00; // header_type
-
-    d->config[0x18] = 0x00;  // primary_bus
-    d->config[0x19] = 0x01;  // secondary_bus
-    d->config[0x1a] = 0x00;  // subordinate_bus
-    d->config[0x1c] = 0x00;
-    d->config[0x1d] = 0x00;
-    
-    d->config[0x20] = 0x00; // memory_base
-    d->config[0x21] = 0x00;
-    d->config[0x22] = 0x01; // memory_limit
-    d->config[0x23] = 0x00;
-    
-    d->config[0x24] = 0x00; // prefetchable_memory_base
-    d->config[0x25] = 0x00;
-    d->config[0x26] = 0x00; // prefetchable_memory_limit
-    d->config[0x27] = 0x00;
-
-#if 0
-    /* PCI2PCI bridge same values as PearPC - check this */
-    d->config[0x00] = 0x11; // vendor_id
-    d->config[0x01] = 0x10;
-    d->config[0x02] = 0x26; // device_id
-    d->config[0x03] = 0x00;
-    d->config[0x08] = 0x02; // revision
-    d->config[0x0a] = 0x04; // class_sub = pci2pci
-    d->config[0x0b] = 0x06; // class_base = PCI_bridge
-    d->config[0x0e] = 0x01; // header_type
-
-    d->config[0x18] = 0x0;  // primary_bus
-    d->config[0x19] = 0x1;  // secondary_bus
-    d->config[0x1a] = 0x1;  // subordinate_bus
-    d->config[0x1c] = 0x10; // io_base
-    d->config[0x1d] = 0x20; // io_limit
-    
-    d->config[0x20] = 0x80; // memory_base
-    d->config[0x21] = 0x80;
-    d->config[0x22] = 0x90; // memory_limit
-    d->config[0x23] = 0x80;
-    
-    d->config[0x24] = 0x00; // prefetchable_memory_base
-    d->config[0x25] = 0x84;
-    d->config[0x26] = 0x00; // prefetchable_memory_limit
-    d->config[0x27] = 0x85;
-#endif
-    return s;
-}
-
-/* Uninorth PCI host (for all Mac99 and newer machines */
-static void pci_unin_main_config_writel (void *opaque, target_phys_addr_t addr,
-                                         uint32_t val)
-{
-    PCIBus *s = opaque;
-    int i;
-
-#ifdef TARGET_WORDS_BIGENDIAN
-    val = bswap32(val);
-#endif
-
-    for (i = 11; i < 32; i++) {
-        if ((val & (1 << i)) != 0)
-            break;
-    }
-#if 0
-    s->config_reg = 0x80000000 | (1 << 16) | (val & 0x7FC) | (i << 11);
-#else
-    s->config_reg = 0x80000000 | (0 << 16) | (val & 0x7FC) | (i << 11);
-#endif
-}
-
-static uint32_t pci_unin_main_config_readl (void *opaque,
-                                            target_phys_addr_t addr)
-{
-    PCIBus *s = opaque;
-    uint32_t val;
-    int devfn;
-
-    devfn = (s->config_reg >> 8) & 0xFF;
-    val = (1 << (devfn >> 3)) | ((devfn & 0x07) << 8) | (s->config_reg & 0xFC);
-#ifdef TARGET_WORDS_BIGENDIAN
-    val = bswap32(val);
-#endif
-
-    return val;
-}
-
-static CPUWriteMemoryFunc *pci_unin_main_config_write[] = {
-    &pci_unin_main_config_writel,
-    &pci_unin_main_config_writel,
-    &pci_unin_main_config_writel,
-};
-
-static CPUReadMemoryFunc *pci_unin_main_config_read[] = {
-    &pci_unin_main_config_readl,
-    &pci_unin_main_config_readl,
-    &pci_unin_main_config_readl,
-};
-
-static void pci_unin_main_writeb (void *opaque, target_phys_addr_t addr,
-                                  uint32_t val)
-{
-    PCIBus *s = opaque;
-    pci_data_write(s, addr & 7, val, 1);
-}
-
-static void pci_unin_main_writew (void *opaque, target_phys_addr_t addr,
-                                  uint32_t val)
-{
-    PCIBus *s = opaque;
-#ifdef TARGET_WORDS_BIGENDIAN
-    val = bswap16(val);
-#endif
-    pci_data_write(s, addr & 7, val, 2);
-}
-
-static void pci_unin_main_writel (void *opaque, target_phys_addr_t addr,
-                                uint32_t val)
-{
-    PCIBus *s = opaque;
-#ifdef TARGET_WORDS_BIGENDIAN
-    val = bswap32(val);
-#endif
-    pci_data_write(s, addr & 7, val, 4);
-}
-
-static uint32_t pci_unin_main_readb (void *opaque, target_phys_addr_t addr)
-{
-    PCIBus *s = opaque;
-    uint32_t val;
-
-    val = pci_data_read(s, addr & 7, 1);
-
-    return val;
-}
-
-static uint32_t pci_unin_main_readw (void *opaque, target_phys_addr_t addr)
-{
-    PCIBus *s = opaque;
-    uint32_t val;
-
-    val = pci_data_read(s, addr & 7, 2);
-#ifdef TARGET_WORDS_BIGENDIAN
-    val = bswap16(val);
-#endif
-
-    return val;
-}
-
-static uint32_t pci_unin_main_readl (void *opaque, target_phys_addr_t addr)
-{
-    PCIBus *s = opaque;
-    uint32_t val;
-
-    val = pci_data_read(s, addr, 4);
-#ifdef TARGET_WORDS_BIGENDIAN
-    val = bswap32(val);
-#endif
-
-    return val;
-}
-
-static CPUWriteMemoryFunc *pci_unin_main_write[] = {
-    &pci_unin_main_writeb,
-    &pci_unin_main_writew,
-    &pci_unin_main_writel,
-};
-
-static CPUReadMemoryFunc *pci_unin_main_read[] = {
-    &pci_unin_main_readb,
-    &pci_unin_main_readw,
-    &pci_unin_main_readl,
-};
-
-#if 0
-
-static void pci_unin_config_writel (void *opaque, target_phys_addr_t addr,
-                                    uint32_t val)
-{
-    PCIBus *s = opaque;
-
-#ifdef TARGET_WORDS_BIGENDIAN
-    val = bswap32(val);
-#endif
-    s->config_reg = 0x80000000 | (val & ~0x00000001);
-}
-
-static uint32_t pci_unin_config_readl (void *opaque,
-                                       target_phys_addr_t addr)
-{
-    PCIBus *s = opaque;
-    uint32_t val;
-
-    val = (s->config_reg | 0x00000001) & ~0x80000000;
-#ifdef TARGET_WORDS_BIGENDIAN
-    val = bswap32(val);
-#endif
-
-    return val;
-}
-
-static CPUWriteMemoryFunc *pci_unin_config_write[] = {
-    &pci_unin_config_writel,
-    &pci_unin_config_writel,
-    &pci_unin_config_writel,
-};
-
-static CPUReadMemoryFunc *pci_unin_config_read[] = {
-    &pci_unin_config_readl,
-    &pci_unin_config_readl,
-    &pci_unin_config_readl,
-};
-
-static void pci_unin_writeb (void *opaque, target_phys_addr_t addr,
-                             uint32_t val)
-{
-    PCIBus *s = opaque;
-    pci_data_write(s, addr & 3, val, 1);
-}
-
-static void pci_unin_writew (void *opaque, target_phys_addr_t addr,
-                             uint32_t val)
-{
-    PCIBus *s = opaque;
-#ifdef TARGET_WORDS_BIGENDIAN
-    val = bswap16(val);
-#endif
-    pci_data_write(s, addr & 3, val, 2);
-}
-
-static void pci_unin_writel (void *opaque, target_phys_addr_t addr,
-                             uint32_t val)
-{
-    PCIBus *s = opaque;
-#ifdef TARGET_WORDS_BIGENDIAN
-    val = bswap32(val);
-#endif
-    pci_data_write(s, addr & 3, val, 4);
-}
-
-static uint32_t pci_unin_readb (void *opaque, target_phys_addr_t addr)
-{
-    PCIBus *s = opaque;
-    uint32_t val;
-
-    val = pci_data_read(s, addr & 3, 1);
-
-    return val;
-}
-
-static uint32_t pci_unin_readw (void *opaque, target_phys_addr_t addr)
-{
-    PCIBus *s = opaque;
-    uint32_t val;
-
-    val = pci_data_read(s, addr & 3, 2);
-#ifdef TARGET_WORDS_BIGENDIAN
-    val = bswap16(val);
-#endif
-
-    return val;
-}
-
-static uint32_t pci_unin_readl (void *opaque, target_phys_addr_t addr)
-{
-    PCIBus *s = opaque;
-    uint32_t val;
-
-    val = pci_data_read(s, addr & 3, 4);
-#ifdef TARGET_WORDS_BIGENDIAN
-    val = bswap32(val);
-#endif
-
-    return val;
-}
-
-static CPUWriteMemoryFunc *pci_unin_write[] = {
-    &pci_unin_writeb,
-    &pci_unin_writew,
-    &pci_unin_writel,
-};
-
-static CPUReadMemoryFunc *pci_unin_read[] = {
-    &pci_unin_readb,
-    &pci_unin_readw,
-    &pci_unin_readl,
-};
-#endif
-
-PCIBus *pci_pmac_init(void)
-{
-    PCIBus *s;
-    PCIDevice *d;
-    int pci_mem_config, pci_mem_data;
-
-    /* Use values found on a real PowerMac */
-    /* Uninorth main bus */
-    s = pci_register_bus();
-    s->set_irq = pci_set_irq_simple;
-
-    pci_mem_config = cpu_register_io_memory(0, pci_unin_main_config_read, 
-                                            pci_unin_main_config_write, s);
-    pci_mem_data = cpu_register_io_memory(0, pci_unin_main_read,
-                                          pci_unin_main_write, s);
-    cpu_register_physical_memory(0xf2800000, 0x1000, pci_mem_config);
-    cpu_register_physical_memory(0xf2c00000, 0x1000, pci_mem_data);
-    s->devfn_min = 11 << 3;
-    d = pci_register_device(s, "Uni-north main", sizeof(PCIDevice), 
-                            11 << 3, NULL, NULL);
-    d->config[0x00] = 0x6b; // vendor_id : Apple
-    d->config[0x01] = 0x10;
-    d->config[0x02] = 0x1F; // device_id
-    d->config[0x03] = 0x00;
-    d->config[0x08] = 0x00; // revision
-    d->config[0x0A] = 0x00; // class_sub = pci host
-    d->config[0x0B] = 0x06; // class_base = PCI_bridge
-    d->config[0x0C] = 0x08; // cache_line_size
-    d->config[0x0D] = 0x10; // latency_timer
-    d->config[0x0E] = 0x00; // header_type
-    d->config[0x34] = 0x00; // capabilities_pointer
-
-#if 0 // XXX: not activated as PPC BIOS doesn't handle mutiple buses properly
-    /* pci-to-pci bridge */
-    d = pci_register_device("Uni-north bridge", sizeof(PCIDevice), 0, 13 << 3,
-                            NULL, NULL);
-    d->config[0x00] = 0x11; // vendor_id : TI
-    d->config[0x01] = 0x10;
-    d->config[0x02] = 0x26; // device_id
-    d->config[0x03] = 0x00;
-    d->config[0x08] = 0x05; // revision
-    d->config[0x0A] = 0x04; // class_sub = pci2pci
-    d->config[0x0B] = 0x06; // class_base = PCI_bridge
-    d->config[0x0C] = 0x08; // cache_line_size
-    d->config[0x0D] = 0x20; // latency_timer
-    d->config[0x0E] = 0x01; // header_type
-
-    d->config[0x18] = 0x01; // primary_bus
-    d->config[0x19] = 0x02; // secondary_bus
-    d->config[0x1A] = 0x02; // subordinate_bus
-    d->config[0x1B] = 0x20; // secondary_latency_timer
-    d->config[0x1C] = 0x11; // io_base
-    d->config[0x1D] = 0x01; // io_limit
-    d->config[0x20] = 0x00; // memory_base
-    d->config[0x21] = 0x80;
-    d->config[0x22] = 0x00; // memory_limit
-    d->config[0x23] = 0x80;
-    d->config[0x24] = 0x01; // prefetchable_memory_base
-    d->config[0x25] = 0x80;
-    d->config[0x26] = 0xF1; // prefectchable_memory_limit
-    d->config[0x27] = 0x7F;
-    // d->config[0x34] = 0xdc // capabilities_pointer
-#endif
-#if 0 // XXX: not needed for now
-    /* Uninorth AGP bus */
-    s = &pci_bridge[1];
-    pci_mem_config = cpu_register_io_memory(0, pci_unin_config_read, 
-                                            pci_unin_config_write, s);
-    pci_mem_data = cpu_register_io_memory(0, pci_unin_read,
-                                          pci_unin_write, s);
-    cpu_register_physical_memory(0xf0800000, 0x1000, pci_mem_config);
-    cpu_register_physical_memory(0xf0c00000, 0x1000, pci_mem_data);
-
-    d = pci_register_device("Uni-north AGP", sizeof(PCIDevice), 0, 11 << 3,
-                            NULL, NULL);
-    d->config[0x00] = 0x6b; // vendor_id : Apple
-    d->config[0x01] = 0x10;
-    d->config[0x02] = 0x20; // device_id
-    d->config[0x03] = 0x00;
-    d->config[0x08] = 0x00; // revision
-    d->config[0x0A] = 0x00; // class_sub = pci host
-    d->config[0x0B] = 0x06; // class_base = PCI_bridge
-    d->config[0x0C] = 0x08; // cache_line_size
-    d->config[0x0D] = 0x10; // latency_timer
-    d->config[0x0E] = 0x00; // header_type
-    //    d->config[0x34] = 0x80; // capabilities_pointer
-#endif
-
-#if 0 // XXX: not needed for now
-    /* Uninorth internal bus */
-    s = &pci_bridge[2];
-    pci_mem_config = cpu_register_io_memory(0, pci_unin_config_read, 
-                                            pci_unin_config_write, s);
-    pci_mem_data = cpu_register_io_memory(0, pci_unin_read,
-                                          pci_unin_write, s);
-    cpu_register_physical_memory(0xf4800000, 0x1000, pci_mem_config);
-    cpu_register_physical_memory(0xf4c00000, 0x1000, pci_mem_data);
-
-    d = pci_register_device("Uni-north internal", sizeof(PCIDevice),
-                            3, 11 << 3, NULL, NULL);
-    d->config[0x00] = 0x6b; // vendor_id : Apple
-    d->config[0x01] = 0x10;
-    d->config[0x02] = 0x1E; // device_id
-    d->config[0x03] = 0x00;
-    d->config[0x08] = 0x00; // revision
-    d->config[0x0A] = 0x00; // class_sub = pci host
-    d->config[0x0B] = 0x06; // class_base = PCI_bridge
-    d->config[0x0C] = 0x08; // cache_line_size
-    d->config[0x0D] = 0x10; // latency_timer
-    d->config[0x0E] = 0x00; // header_type
-    d->config[0x34] = 0x00; // capabilities_pointer
-#endif
-    return s;
-}
-
-/* Ultrasparc APB PCI host */
-static void pci_apb_config_writel (void *opaque, target_phys_addr_t addr,
-                                         uint32_t val)
-{
-    PCIBus *s = opaque;
-    int i;
-
-    for (i = 11; i < 32; i++) {
-        if ((val & (1 << i)) != 0)
-            break;
-    }
-    s->config_reg = 0x80000000 | (1 << 16) | (val & 0x7FC) | (i << 11);
-}
-
-static uint32_t pci_apb_config_readl (void *opaque,
-                                            target_phys_addr_t addr)
-{
-    PCIBus *s = opaque;
-    uint32_t val;
-    int devfn;
-
-    devfn = (s->config_reg >> 8) & 0xFF;
-    val = (1 << (devfn >> 3)) | ((devfn & 0x07) << 8) | (s->config_reg & 0xFC);
-    return val;
-}
-
-static CPUWriteMemoryFunc *pci_apb_config_write[] = {
-    &pci_apb_config_writel,
-    &pci_apb_config_writel,
-    &pci_apb_config_writel,
-};
-
-static CPUReadMemoryFunc *pci_apb_config_read[] = {
-    &pci_apb_config_readl,
-    &pci_apb_config_readl,
-    &pci_apb_config_readl,
-};
-
-static void apb_config_writel (void *opaque, target_phys_addr_t addr,
-                              uint32_t val)
-{
-    //PCIBus *s = opaque;
-
-    switch (addr & 0x3f) {
-    case 0x00: // Control/Status
-    case 0x10: // AFSR
-    case 0x18: // AFAR
-    case 0x20: // Diagnostic
-    case 0x28: // Target address space
-       // XXX
-    default:
-       break;
-    }
-}
-
-static uint32_t apb_config_readl (void *opaque,
-                                 target_phys_addr_t addr)
-{
-    //PCIBus *s = opaque;
-    uint32_t val;
-
-    switch (addr & 0x3f) {
-    case 0x00: // Control/Status
-    case 0x10: // AFSR
-    case 0x18: // AFAR
-    case 0x20: // Diagnostic
-    case 0x28: // Target address space
-       // XXX
-    default:
-       val = 0;
-       break;
-    }
-    return val;
-}
-
-static CPUWriteMemoryFunc *apb_config_write[] = {
-    &apb_config_writel,
-    &apb_config_writel,
-    &apb_config_writel,
-};
-
-static CPUReadMemoryFunc *apb_config_read[] = {
-    &apb_config_readl,
-    &apb_config_readl,
-    &apb_config_readl,
-};
-
-static void pci_apb_writeb (void *opaque, target_phys_addr_t addr,
-                                  uint32_t val)
-{
-    PCIBus *s = opaque;
-
-    pci_data_write(s, addr & 7, val, 1);
-}
-
-static void pci_apb_writew (void *opaque, target_phys_addr_t addr,
-                                  uint32_t val)
-{
-    PCIBus *s = opaque;
-
-    pci_data_write(s, addr & 7, val, 2);
-}
-
-static void pci_apb_writel (void *opaque, target_phys_addr_t addr,
-                                uint32_t val)
-{
-    PCIBus *s = opaque;
-
-    pci_data_write(s, addr & 7, val, 4);
-}
-
-static uint32_t pci_apb_readb (void *opaque, target_phys_addr_t addr)
-{
-    PCIBus *s = opaque;
-    uint32_t val;
-
-    val = pci_data_read(s, addr & 7, 1);
-    return val;
-}
-
-static uint32_t pci_apb_readw (void *opaque, target_phys_addr_t addr)
-{
-    PCIBus *s = opaque;
-    uint32_t val;
-
-    val = pci_data_read(s, addr & 7, 2);
-    return val;
-}
-
-static uint32_t pci_apb_readl (void *opaque, target_phys_addr_t addr)
-{
-    PCIBus *s = opaque;
-    uint32_t val;
-
-    val = pci_data_read(s, addr, 4);
-    return val;
-}
-
-static CPUWriteMemoryFunc *pci_apb_write[] = {
-    &pci_apb_writeb,
-    &pci_apb_writew,
-    &pci_apb_writel,
-};
-
-static CPUReadMemoryFunc *pci_apb_read[] = {
-    &pci_apb_readb,
-    &pci_apb_readw,
-    &pci_apb_readl,
-};
-
-static void pci_apb_iowriteb (void *opaque, target_phys_addr_t addr,
-                                  uint32_t val)
-{
-    cpu_outb(NULL, addr & 0xffff, val);
-}
-
-static void pci_apb_iowritew (void *opaque, target_phys_addr_t addr,
-                                  uint32_t val)
-{
-    cpu_outw(NULL, addr & 0xffff, val);
-}
-
-static void pci_apb_iowritel (void *opaque, target_phys_addr_t addr,
-                                uint32_t val)
-{
-    cpu_outl(NULL, addr & 0xffff, val);
-}
-
-static uint32_t pci_apb_ioreadb (void *opaque, target_phys_addr_t addr)
-{
-    uint32_t val;
-
-    val = cpu_inb(NULL, addr & 0xffff);
-    return val;
-}
-
-static uint32_t pci_apb_ioreadw (void *opaque, target_phys_addr_t addr)
-{
-    uint32_t val;
-
-    val = cpu_inw(NULL, addr & 0xffff);
-    return val;
-}
-
-static uint32_t pci_apb_ioreadl (void *opaque, target_phys_addr_t addr)
-{
-    uint32_t val;
-
-    val = cpu_inl(NULL, addr & 0xffff);
-    return val;
-}
-
-static CPUWriteMemoryFunc *pci_apb_iowrite[] = {
-    &pci_apb_iowriteb,
-    &pci_apb_iowritew,
-    &pci_apb_iowritel,
-};
-
-static CPUReadMemoryFunc *pci_apb_ioread[] = {
-    &pci_apb_ioreadb,
-    &pci_apb_ioreadw,
-    &pci_apb_ioreadl,
-};
-
-PCIBus *pci_apb_init(target_ulong special_base, target_ulong mem_base)
-{
-    PCIBus *s;
-    PCIDevice *d;
-    int pci_mem_config, pci_mem_data, apb_config, pci_ioport;
-
-    /* Ultrasparc APB main bus */
-    s = pci_register_bus();
-    s->set_irq = pci_set_irq_simple;
-
-    pci_mem_config = cpu_register_io_memory(0, pci_apb_config_read,
-                                            pci_apb_config_write, s);
-    apb_config = cpu_register_io_memory(0, apb_config_read,
-                                       apb_config_write, s);
-    pci_mem_data = cpu_register_io_memory(0, pci_apb_read,
-                                          pci_apb_write, s);
-    pci_ioport = cpu_register_io_memory(0, pci_apb_ioread,
-                                          pci_apb_iowrite, s);
-
-    cpu_register_physical_memory(special_base + 0x2000ULL, 0x40, apb_config);
-    cpu_register_physical_memory(special_base + 0x1000000ULL, 0x10, 
pci_mem_config);
-    cpu_register_physical_memory(special_base + 0x2000000ULL, 0x10000, 
pci_ioport);
-    cpu_register_physical_memory(mem_base, 0x10000000, pci_mem_data); // XXX 
size should be 4G-prom
-
-    d = pci_register_device(s, "Advanced PCI Bus", sizeof(PCIDevice), 
-                            -1, NULL, NULL);
-    d->config[0x00] = 0x8e; // vendor_id : Sun
-    d->config[0x01] = 0x10;
-    d->config[0x02] = 0x00; // device_id
-    d->config[0x03] = 0xa0;
-    d->config[0x04] = 0x06; // command = bus master, pci mem
-    d->config[0x05] = 0x00;
-    d->config[0x06] = 0xa0; // status = fast back-to-back, 66MHz, no error
-    d->config[0x07] = 0x03; // status = medium devsel
-    d->config[0x08] = 0x00; // revision
-    d->config[0x09] = 0x00; // programming i/f
-    d->config[0x0A] = 0x00; // class_sub = pci host
-    d->config[0x0B] = 0x06; // class_base = PCI_bridge
-    d->config[0x0D] = 0x10; // latency_timer
-    d->config[0x0E] = 0x00; // header_type
-    return s;
-}
-
 /***********************************************************/
 /* generic PCI irq support */
 
@@ -1547,34 +403,46 @@ void pci_set_irq(PCIDevice *pci_dev, int
 void pci_set_irq(PCIDevice *pci_dev, int irq_num, int level)
 {
     PCIBus *bus = pci_dev->bus;
-    bus->set_irq(pci_dev, irq_num, level);
+    bus->set_irq(pci_dev, bus->irq_opaque, irq_num, level);
 }
 
 /***********************************************************/
 /* monitor info on PCI */
 
+typedef struct {
+    uint16_t class;
+    const char *desc;
+} pci_class_desc;
+
+static pci_class_desc pci_class_descriptions[] = 
+{
+    { 0x0101, "IDE controller"},
+    { 0x0200, "Ethernet controller"},
+    { 0x0300, "VGA controller"},
+    { 0x0600, "Host bridge"},
+    { 0x0601, "ISA bridge"},
+    { 0x0604, "PCI bridge"},
+    { 0x0c03, "USB controller"},
+    { 0, NULL}
+};
+
 static void pci_info_device(PCIDevice *d)
 {
     int i, class;
     PCIIORegion *r;
+    pci_class_desc *desc;
 
     term_printf("  Bus %2d, device %3d, function %d:\n",
            d->bus->bus_num, d->devfn >> 3, d->devfn & 7);
     class = le16_to_cpu(*((uint16_t *)(d->config + PCI_CLASS_DEVICE)));
     term_printf("    ");
-    switch(class) {
-    case 0x0101:
-        term_printf("IDE controller");
-        break;
-    case 0x0200:
-        term_printf("Ethernet controller");
-        break;
-    case 0x0300:
-        term_printf("VGA controller");
-        break;
-    default:
+    desc = pci_class_descriptions;
+    while (desc->desc && class != desc->class)
+        desc++;
+    if (desc->desc) {
+        term_printf("%s", desc->desc);
+    } else {
         term_printf("Class %04x", class);
-        break;
     }
     term_printf(": PCI device %04x:%04x\n",
            le16_to_cpu(*((uint16_t *)(d->config + PCI_VENDOR_ID))),
@@ -1598,7 +466,7 @@ static void pci_info_device(PCIDevice *d
     }
 }
 
-void pci_info(void)
+void pci_for_each_device(void (*fn)(PCIDevice *d))
 {
     PCIBus *bus = first_bus;
     PCIDevice *d;
@@ -1608,253 +476,14 @@ void pci_info(void)
         for(devfn = 0; devfn < 256; devfn++) {
             d = bus->devices[devfn];
             if (d)
-                pci_info_device(d);
-        }
-    }
-}
-
-/***********************************************************/
-/* XXX: the following should be moved to the PC BIOS */
-
-static __attribute__((unused)) uint32_t isa_inb(uint32_t addr)
-{
-    return cpu_inb(NULL, addr);
-}
-
-static void isa_outb(uint32_t val, uint32_t addr)
-{
-    cpu_outb(NULL, addr, val);
-}
-
-static __attribute__((unused)) uint32_t isa_inw(uint32_t addr)
-{
-    return cpu_inw(NULL, addr);
-}
-
-static __attribute__((unused)) void isa_outw(uint32_t val, uint32_t addr)
-{
-    cpu_outw(NULL, addr, val);
-}
-
-static __attribute__((unused)) uint32_t isa_inl(uint32_t addr)
-{
-    return cpu_inl(NULL, addr);
-}
-
-static __attribute__((unused)) void isa_outl(uint32_t val, uint32_t addr)
-{
-    cpu_outl(NULL, addr, val);
-}
-
-static void pci_config_writel(PCIDevice *d, uint32_t addr, uint32_t val)
-{
-    PCIBus *s = d->bus;
-    s->config_reg = 0x80000000 | (s->bus_num << 16) | 
-        (d->devfn << 8) | addr;
-    pci_data_write(s, 0, val, 4);
-}
-
-static void pci_config_writew(PCIDevice *d, uint32_t addr, uint32_t val)
-{
-    PCIBus *s = d->bus;
-    s->config_reg = 0x80000000 | (s->bus_num << 16) | 
-        (d->devfn << 8) | (addr & ~3);
-    pci_data_write(s, addr & 3, val, 2);
-}
-
-static void pci_config_writeb(PCIDevice *d, uint32_t addr, uint32_t val)
-{
-    PCIBus *s = d->bus;
-    s->config_reg = 0x80000000 | (s->bus_num << 16) | 
-        (d->devfn << 8) | (addr & ~3);
-    pci_data_write(s, addr & 3, val, 1);
-}
-
-static __attribute__((unused)) uint32_t pci_config_readl(PCIDevice *d, 
uint32_t addr)
-{
-    PCIBus *s = d->bus;
-    s->config_reg = 0x80000000 | (s->bus_num << 16) | 
-        (d->devfn << 8) | addr;
-    return pci_data_read(s, 0, 4);
-}
-
-static uint32_t pci_config_readw(PCIDevice *d, uint32_t addr)
-{
-    PCIBus *s = d->bus;
-    s->config_reg = 0x80000000 | (s->bus_num << 16) | 
-        (d->devfn << 8) | (addr & ~3);
-    return pci_data_read(s, addr & 3, 2);
-}
-
-static uint32_t pci_config_readb(PCIDevice *d, uint32_t addr)
-{
-    PCIBus *s = d->bus;
-    s->config_reg = 0x80000000 | (s->bus_num << 16) | 
-        (d->devfn << 8) | (addr & ~3);
-    return pci_data_read(s, addr & 3, 1);
-}
-
-static uint32_t pci_bios_io_addr;
-static uint32_t pci_bios_mem_addr;
-/* host irqs corresponding to PCI irqs A-D */
-static uint8_t pci_irqs[4] = { 10, 11, 10, 11 };
-
-static void pci_set_io_region_addr(PCIDevice *d, int region_num, uint32_t addr)
-{
-    PCIIORegion *r;
-    uint16_t cmd;
-    uint32_t ofs;
-
-    if ( region_num == PCI_ROM_SLOT ) {
-        ofs = 0x30;
-    }else{
-        ofs = 0x10 + region_num * 4;
-    }
-
-    pci_config_writel(d, ofs, addr);
-    r = &d->io_regions[region_num];
-
-    /* enable memory mappings */
-    cmd = pci_config_readw(d, PCI_COMMAND);
-    if ( region_num == PCI_ROM_SLOT )
-        cmd |= 2;
-    else if (r->type & PCI_ADDRESS_SPACE_IO)
-        cmd |= 1;
-    else
-        cmd |= 2;
-    pci_config_writew(d, PCI_COMMAND, cmd);
-}
-
-static void pci_bios_init_device(PCIDevice *d)
-{
-    int class;
-    PCIIORegion *r;
-    uint32_t *paddr;
-    int i, pin, pic_irq, vendor_id, device_id;
-
-    class = pci_config_readw(d, PCI_CLASS_DEVICE);
-    vendor_id = pci_config_readw(d, PCI_VENDOR_ID);
-    device_id = pci_config_readw(d, PCI_DEVICE_ID);
-    switch(class) {
-    case 0x0101:
-        if (vendor_id == 0x8086 && device_id == 0x7010) {
-            /* PIIX3 IDE */
-            pci_config_writew(d, 0x40, 0x8000); // enable IDE0
-            pci_config_writew(d, 0x42, 0x8000); // enable IDE1
-            goto default_map;
-        } else {
-            /* IDE: we map it as in ISA mode */
-            pci_set_io_region_addr(d, 0, 0x1f0);
-            pci_set_io_region_addr(d, 1, 0x3f4);
-            pci_set_io_region_addr(d, 2, 0x170);
-            pci_set_io_region_addr(d, 3, 0x374);
-        }
-        break;
-       case 0x0680:
-       if (vendor_id == 0x8086 && device_id == 0x7113) {
-          // PIIX4 ACPI PM 
-        pci_config_writew(d, 0x20, 0x0000); // NO smb bus IO enable in PIIX4
-        pci_config_writew(d, 0x22, 0x0000); 
-        goto default_map;
-       }
-         break;
-
-    case 0x0300:
-        if (vendor_id != 0x1234)
-            goto default_map;
-        /* VGA: map frame buffer to default Bochs VBE address */
-        pci_set_io_region_addr(d, 0, 0xE0000000);
-        break;
-
-    case 0x0800:
-        /* PIC */
-        vendor_id = pci_config_readw(d, PCI_VENDOR_ID);
-        device_id = pci_config_readw(d, PCI_DEVICE_ID);
-        if (vendor_id == 0x1014) {
-            /* IBM */
-            if (device_id == 0x0046 || device_id == 0xFFFF) {
-                /* MPIC & MPIC2 */
-                pci_set_io_region_addr(d, 0, 0x80800000 + 0x00040000);
-            }
-        }
-        break;
-    case 0xff00:
-        if (vendor_id == 0x0106b &&
-            (device_id == 0x0017 || device_id == 0x0022)) {
-            /* macio bridge */
-            pci_set_io_region_addr(d, 0, 0x80800000);
-        }
-        break;
-    default:
-    default_map:
-        /* default memory mappings */
-        for(i = 0; i < PCI_NUM_REGIONS; i++) {
-            r = &d->io_regions[i];
-            if (r->size) {
-                if (r->type & PCI_ADDRESS_SPACE_IO)
-                    paddr = &pci_bios_io_addr;
-                else
-                    paddr = &pci_bios_mem_addr;
-                *paddr = (*paddr + r->size - 1) & ~(r->size - 1);
-                pci_set_io_region_addr(d, i, *paddr);
-                *paddr += r->size;
-            }
-        }
-        break;
-    }
-
-    /* map the interrupt */
-    pin = pci_config_readb(d, PCI_INTERRUPT_PIN);
-    if (pin != 0) {
-        pin = pci_slot_get_pirq(d, pin - 1);
-        pic_irq = pci_irqs[pin];
-        pci_config_writeb(d, PCI_INTERRUPT_LINE, pic_irq);
-    }
-    if (class== 0x0680&& vendor_id == 0x8086 && device_id == 0x7113) {
-         // PIIX4 ACPI PM
-       pci_config_writew(d, 0x20, 0x0000); // NO smb bus IO enable in PIIX4
-       pci_config_writew(d, 0x22, 0x0000);
-       pci_config_writew(d, 0x3c, 0x0009); // Hardcodeed IRQ9
-       pci_config_writew(d, 0x3d, 0x0001);
-    }
-}
-
-/*
- * This function initializes the PCI devices as a normal PCI BIOS
- * would do. It is provided just in case the BIOS has no support for
- * PCI.
- */
-void pci_bios_init(void)
-{
-    PCIBus *bus;
-    PCIDevice *d;
-    int devfn, i, irq;
-    uint8_t elcr[2];
-
-    pci_bios_io_addr = 0xc000;
-    pci_bios_mem_addr = 0xf0000000;
-
-    /* activate IRQ mappings */
-    elcr[0] = 0x00;
-    elcr[1] = 0x00;
-    for(i = 0; i < 4; i++) {
-        irq = pci_irqs[i];
-        /* set to trigger level */
-        elcr[irq >> 3] |= (1 << (irq & 7));
-        /* activate irq remapping in PIIX */
-        pci_config_writeb((PCIDevice *)piix3_state, 0x60 + i, irq);
-    }
-    isa_outb(elcr[0], 0x4d0);
-    isa_outb(elcr[1], 0x4d1);
-
-    bus = first_bus;
-    if (bus) {
-        for(devfn = 0; devfn < 256; devfn++) {
-            d = bus->devices[devfn];
-            if (d)
-                pci_bios_init_device(d);
-        }
-    }
+                fn(d);
+        }
+    }
+}
+
+void pci_info(void)
+{
+    pci_for_each_device(pci_info_device);
 }
 
 /* Initialize a PCI NIC.  */
@@ -1864,6 +493,8 @@ void pci_nic_init(PCIBus *bus, NICInfo *
         pci_ne2000_init(bus, nd);
     } else if (strcmp(nd->model, "rtl8139") == 0) {
         pci_rtl8139_init(bus, nd);
+    } else if (strcmp(nd->model, "pcnet") == 0) {
+        pci_pcnet_init(bus, nd);
     } else {
         fprintf(stderr, "qemu: Unsupported NIC: %s\n", nd->model);
         exit (1);
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/hw/pcspk.c
--- a/tools/ioemu/hw/pcspk.c    Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/hw/pcspk.c    Wed Aug 09 08:34:06 2006 -0600
@@ -95,7 +95,7 @@ int pcspk_audio_init(AudioState *audio)
 int pcspk_audio_init(AudioState *audio)
 {
     PCSpkState *s = &pcspk_state;
-    audsettings_t as = {PCSPK_SAMPLE_RATE, 1, AUD_FMT_U8};
+    audsettings_t as = {PCSPK_SAMPLE_RATE, 1, AUD_FMT_U8, 0};
 
     if (!audio) {
         AUD_log(s_spk, "No audio state\n");
@@ -103,7 +103,7 @@ int pcspk_audio_init(AudioState *audio)
     }
     AUD_register_card(audio, s_spk, &s->card);
 
-    s->voice = AUD_open_out(&s->card, s->voice, s_spk, s, pcspk_callback, &as, 
0);
+    s->voice = AUD_open_out(&s->card, s->voice, s_spk, s, pcspk_callback, &as);
     if (!s->voice) {
         AUD_log(s_spk, "Could not open voice\n");
         return -1;
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/hw/piix4acpi.c
--- a/tools/ioemu/hw/piix4acpi.c        Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/hw/piix4acpi.c        Wed Aug 09 08:34:06 2006 -0600
@@ -24,26 +24,26 @@
  */
 
 #include "vl.h"
-#define FREQUENCE_PMTIMER  3753425
+#define FREQUENCE_PMTIMER  3579545
 /* acpi register bit define here  */
 
-/* PM1_STS                                             */
-#define TMROF_STS        (1 << 0)
-#define BM_STS                   (1 << 4)
-#define GBL_STS          (1 << 5)
-#define PWRBTN_STS       (1 << 8)
-#define RTC_STS          (1 << 10)
+/* PM1_STS */
+#define TMROF_STS         (1 << 0)
+#define BM_STS            (1 << 4)
+#define GBL_STS           (1 << 5)
+#define PWRBTN_STS        (1 << 8)
+#define RTC_STS           (1 << 10)
 #define PRBTNOR_STS       (1 << 11)
-#define WAK_STS          (1 << 15)
-/* PM1_EN                                              */
+#define WAK_STS           (1 << 15)
+/* PM1_EN */
 #define TMROF_EN          (1 << 0)
 #define GBL_EN            (1 << 5)
 #define PWRBTN_EN         (1 << 8)
-#define RTC_EN           (1 << 10)
-/* PM1_CNT                                             */
+#define RTC_EN            (1 << 10)
+/* PM1_CNT */
 #define SCI_EN            (1 << 0)
 #define GBL_RLS           (1 << 2)
-#define SLP_EN           (1 << 13)
+#define SLP_EN            (1 << 13)
 
 /* Bits of PM1a register define here  */
 #define SLP_TYP_MASK    0x1C00
@@ -51,14 +51,6 @@
 
 typedef struct AcpiDeviceState AcpiDeviceState;
 AcpiDeviceState *acpi_device_table;
-
-/* Bits of PM1a register define here  */
-typedef struct PMTState {
-    uint32_t count;
-    int irq;
-    uint64_t next_pm_time;
-    QEMUTimer *pm_timer;
-}PMTState;
 
 typedef struct PM1Event_BLK {
     uint16_t pm1_status; /* pm1a_EVT_BLK */
@@ -72,83 +64,10 @@ typedef struct PCIAcpiState {
     uint16_t pm1_enable; /* pm1a_EVT_BLK+2 */
     uint16_t pm1_control; /* pm1a_ECNT_BLK */
     uint32_t pm1_timer; /* pmtmr_BLK */
+    uint64_t old_vmck_ticks; /* using vm_clock counter */
 } PCIAcpiState;
 
-static PMTState *pmtimer_state;
 static PCIAcpiState *acpi_state;
-
-static void pmtimer_save(QEMUFile *f, void *opaque)
-{
-    PMTState *s = opaque;
-
-    qemu_put_be32s(f, &s->count);
-    qemu_put_be32s(f, &s->irq);
-    qemu_put_be64s(f, &s->next_pm_time);
-    qemu_put_timer(f, s->pm_timer);
-}
-
-static int pmtimer_load(QEMUFile *f, void *opaque, int version_id)
-{
-    PMTState *s = opaque;
-
-    if (version_id != 1)
-        return -EINVAL;
-    qemu_get_be32s(f, &s->count);
-    qemu_get_be32s(f, &s->irq);
-    qemu_get_be64s(f, &s->next_pm_time);
-    qemu_get_timer(f, s->pm_timer);
-    return 0;
-}
-
-static inline void acpi_set_irq(PCIAcpiState *s)
-{
-/* no real SCI event need for now, so comment the following line out */
-/*  pic_set_irq(s->irq, 1); */
-    printf("acpi_set_irq: s->irq %x \n",s->irq);
-}
-
-static void pm_timer_update(void *opaque)
-{
-    PMTState *s = opaque;
-    s->next_pm_time = qemu_get_clock(vm_clock) +
-        muldiv64(1, ticks_per_sec,FREQUENCE_PMTIMER);
-    qemu_mod_timer(s->pm_timer, s->next_pm_time);
-    acpi_state->pm1_timer ++;
-
-    /* If pm timer is zero then reset it to zero. */
-    if (acpi_state->pm1_timer >= 0x1000000) {
-/*      printf("pm_timerupdate: timer overflow: %x \n", 
acpi_state->pm1_timer); */
-
-        acpi_state->pm1_timer = 0;
-        acpi_state->pm1_status =   acpi_state->pm1_status | TMROF_STS;
-        /* If TMROF_EN is set then send the irq. */
-        if ((acpi_state->pm1_enable & TMROF_EN) == TMROF_EN) {
-            acpi_set_irq(acpi_state);
-            acpi_state->pm1_enable = 0x00; /* only need one time...*/
-        }
-    }
-    s->count = acpi_state->pm1_timer;
-}
-
-static PMTState *pmtimer_init(void)
-{
-    PMTState *s;
-
-    s = qemu_mallocz(sizeof(PMTState));
-    if (!s)
-        return NULL;
-
-    /* s->irq = irq;    */
-
-    s->pm_timer = qemu_new_timer(vm_clock, pm_timer_update, s);
-
-    s->count = 0;
-    s->next_pm_time = qemu_get_clock(vm_clock) + muldiv64(1, 
ticks_per_sec,FREQUENCE_PMTIMER) + 1;
-    qemu_mod_timer(s->pm_timer, s->next_pm_time);
-
-    register_savevm("pm timer", 1, 1, pmtimer_save, pmtimer_load, s);
-    return s;
-}
 
 static void acpi_reset(PCIAcpiState *s)
 {
@@ -162,6 +81,7 @@ static void acpi_reset(PCIAcpiState *s)
     s->pm1_enable = 0x00;    /* TMROF_EN should cleared */
     s->pm1_control = SCI_EN; /* SCI_EN */
     s->pm1_timer = 0;
+    s->old_vmck_ticks = qemu_get_clock(vm_clock);
 }
 
 /*byte access  */
@@ -173,8 +93,8 @@ static void acpiPm1Status_writeb(void *o
         s->pm1_status = s->pm1_status&!TMROF_STS;
 
     if ((val&GBL_STS)==GBL_STS)
-        s->pm1_status = s->pm1_status&!GBL_STS;     
-    
+        s->pm1_status = s->pm1_status&!GBL_STS;
+
 /*     printf("acpiPm1Status_writeb \n addr %x val:%x pm1_status:%x \n", addr, 
val,s->pm1_status); */
 }
 
@@ -193,7 +113,7 @@ static void acpiPm1StatusP1_writeb(void 
 {
     PCIAcpiState *s = opaque;
 
-     s->pm1_status = (val<<8)||(s->pm1_status);
+    s->pm1_status = (val<<8)||(s->pm1_status);
 /*     printf("acpiPm1StatusP1_writeb \n addr %x val:%x\n", addr, val); */
 }
 
@@ -305,7 +225,7 @@ static void acpiPm1Status_writew(void *o
         s->pm1_status = s->pm1_status&!TMROF_STS;
 
     if ((val&GBL_STS)==GBL_STS)
-        s->pm1_status = s->pm1_status&!GBL_STS;     
+        s->pm1_status = s->pm1_status&!GBL_STS;
 
 /*    printf("acpiPm1Status_writew \n addr %x val:%x pm1_status:%x \n", addr, 
val,s->pm1_status); */
 }
@@ -384,7 +304,7 @@ static uint32_t acpiPm1Event_readl(void 
 {
     PCIAcpiState *s = opaque;
     uint32_t val;
-    
+
     val = s->pm1_status|(s->pm1_enable<<16);
 /*    printf("acpiPm1Event_readl \n addr %x val:%x\n", addr, val);    */
 
@@ -396,17 +316,21 @@ static void acpiPm1Timer_writel(void *op
     PCIAcpiState *s = opaque;
 
     s->pm1_timer = val;
-/*    printf("acpiPm1Timer_writel \n addr %x val:%x\n", addr, val); */
+    s->old_vmck_ticks = qemu_get_clock(vm_clock) +
+        muldiv64(val, FREQUENCE_PMTIMER, ticks_per_sec);
 }
 
 static uint32_t acpiPm1Timer_readl(void *opaque, uint32_t addr)
 {
     PCIAcpiState *s = opaque;
-    uint32_t val;
-
-    val = s->pm1_timer;
-/*    printf("acpiPm1Timer_readl \n addr %x val:%x\n", addr, val); */
-    return val;
+    int64_t current_vmck_ticks = qemu_get_clock(vm_clock);
+    int64_t vmck_ticks_delta = current_vmck_ticks - s->old_vmck_ticks;
+
+    if (s->old_vmck_ticks)
+        s->pm1_timer += muldiv64(vmck_ticks_delta, FREQUENCE_PMTIMER,
+                                 ticks_per_sec);
+    s->old_vmck_ticks = current_vmck_ticks;
+    return s->pm1_timer;
 }
 
 static void acpi_map(PCIDevice *pci_dev, int region_num,
@@ -414,7 +338,7 @@ static void acpi_map(PCIDevice *pci_dev,
 {
     PCIAcpiState *d = (PCIAcpiState *)pci_dev;
 
-    printf("register acpi io \n");
+    printf("register acpi io\n");
 
     /* Byte access */
     register_ioport_write(addr, 1, 1, acpiPm1Status_writeb, d);
@@ -430,14 +354,14 @@ static void acpi_map(PCIDevice *pci_dev,
     register_ioport_write(addr + 4, 1, 1, acpiPm1Control_writeb, d);
     register_ioport_read(addr + 4, 1, 1, acpiPm1Control_readb, d);
     register_ioport_write(addr + 4 + 1, 1, 1, acpiPm1ControlP1_writeb, d);
-    register_ioport_read(addr + 4 +1, 1, 1, acpiPm1ControlP1_readb, d);        
+    register_ioport_read(addr + 4 +1, 1, 1, acpiPm1ControlP1_readb, d);
 
     /* Word access */
     register_ioport_write(addr, 2, 2, acpiPm1Status_writew, d);
     register_ioport_read(addr, 2, 2, acpiPm1Status_readw, d);
 
     register_ioport_write(addr + 2, 2, 2, acpiPm1Enable_writew, d);
-    register_ioport_read(addr + 2, 2, 2, acpiPm1Enable_readw, d); 
+    register_ioport_read(addr + 2, 2, 2, acpiPm1Enable_readw, d);
 
     register_ioport_write(addr + 4, 2, 2, acpiPm1Control_writew, d);
     register_ioport_read(addr + 4, 2, 2, acpiPm1Control_readw, d);
@@ -445,14 +369,13 @@ static void acpi_map(PCIDevice *pci_dev,
     /* DWord access */
     register_ioport_write(addr, 4, 4, acpiPm1Event_writel, d);
     register_ioport_read(addr, 4, 4, acpiPm1Event_readl, d);
-               
+
     register_ioport_write(addr + 8, 4, 4, acpiPm1Timer_writel, d);
     register_ioport_read(addr + 8, 4, 4, acpiPm1Timer_readl, d);
 }
-                                                                               
                        
 
 /* PIIX4 acpi pci configuration space, func 3 */
-void pci_piix4_acpi_init(PCIBus *bus)
+void pci_piix4_acpi_init(PCIBus *bus, int devfn)
 {
     PCIAcpiState *d;
     uint8_t *pci_conf;
@@ -460,7 +383,7 @@ void pci_piix4_acpi_init(PCIBus *bus)
     /* register a function 3 of PIIX4 */
     d = (PCIAcpiState *)pci_register_device(
         bus, "PIIX4 ACPI", sizeof(PCIAcpiState),
-        ((PCIDevice *)piix3_state)->devfn + 3, NULL, NULL);
+        devfn, NULL, NULL);
 
     acpi_state = d;
     pci_conf = d->dev.config;
@@ -478,7 +401,5 @@ void pci_piix4_acpi_init(PCIBus *bus)
     pci_register_io_region((PCIDevice *)d, 4, 0x10,
                            PCI_ADDRESS_SPACE_IO, acpi_map);
 
-    pmtimer_state = pmtimer_init();
-
-    acpi_reset (d);
-}
+    acpi_reset(d);
+}
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/hw/pl050.c
--- a/tools/ioemu/hw/pl050.c    Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/hw/pl050.c    Wed Aug 09 08:34:06 2006 -0600
@@ -1,5 +1,5 @@
 /* 
- * Arm PrimeCell PL050 Kyeboard / Mouse Interface
+ * Arm PrimeCell PL050 Keyboard / Mouse Interface
  *
  * Copyright (c) 2006 CodeSourcery.
  * Written by Paul Brook
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/hw/ppc_chrp.c
--- a/tools/ioemu/hw/ppc_chrp.c Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/hw/ppc_chrp.c Wed Aug 09 08:34:06 2006 -0600
@@ -415,19 +415,18 @@ static void ppc_chrp_init(int ram_size, 
 
     if (is_heathrow) {
         isa_mem_base = 0x80000000;
-        pci_bus = pci_grackle_init(0xfec00000);
         
         /* Register 2 MB of ISA IO space */
         PPC_io_memory = cpu_register_io_memory(0, PPC_io_read, PPC_io_write, 
NULL);
         cpu_register_physical_memory(0xfe000000, 0x00200000, PPC_io_memory);
         
         /* init basic PC hardware */
+        pic = heathrow_pic_init(&heathrow_pic_mem_index);
+        set_irq = heathrow_pic_set_irq;
+        pci_bus = pci_grackle_init(0xfec00000, pic);
         vga_initialize(pci_bus, ds, phys_ram_base + ram_size, 
                        ram_size, vga_ram_size,
                        vga_bios_offset, vga_bios_size);
-        pic = heathrow_pic_init(&heathrow_pic_mem_index);
-        set_irq = heathrow_pic_set_irq;
-        pci_set_pic(pci_bus, set_irq, pic);
 
         /* XXX: suppress that */
         isa_pic = pic_init(pic_irq_request, NULL);
@@ -462,7 +461,6 @@ static void ppc_chrp_init(int ram_size, 
         arch_name = "HEATHROW";
     } else {
         isa_mem_base = 0x80000000;
-        pci_bus = pci_pmac_init();
         
         /* Register 8 MB of ISA IO space */
         PPC_io_memory = cpu_register_io_memory(0, PPC_io_read, PPC_io_write, 
NULL);
@@ -472,13 +470,13 @@ static void ppc_chrp_init(int ram_size, 
         unin_memory = cpu_register_io_memory(0, unin_read, unin_write, NULL);
         cpu_register_physical_memory(0xf8000000, 0x00001000, unin_memory);
 
+        pic = openpic_init(NULL, &openpic_mem_index, 1, &env);
+        set_irq = openpic_set_irq;
+        pci_bus = pci_pmac_init(pic);
         /* init basic PC hardware */
         vga_initialize(pci_bus, ds, phys_ram_base + ram_size,
                        ram_size, vga_ram_size,
                        vga_bios_offset, vga_bios_size);
-        pic = openpic_init(NULL, &openpic_mem_index, 1, &env);
-        set_irq = openpic_set_irq;
-        pci_set_pic(pci_bus, set_irq, pic);
 
         /* XXX: suppress that */
         isa_pic = pic_init(pic_irq_request, NULL);
@@ -508,7 +506,11 @@ static void ppc_chrp_init(int ram_size, 
         
         arch_name = "MAC99";
     }
-    
+
+    if (usb_enabled) {
+        usb_ohci_init(pci_bus, 3, -1);
+    }
+
     if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8)
         graphic_depth = 15;
 
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/hw/ppc_prep.c
--- a/tools/ioemu/hw/ppc_prep.c Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/hw/ppc_prep.c Wed Aug 09 08:34:06 2006 -0600
@@ -665,6 +665,10 @@ static void ppc_prep_init(int ram_size, 
     cpu_register_physical_memory(0xFEFF0000, 0x1000, PPC_io_memory);
 #endif
 
+    if (usb_enabled) {
+        usb_ohci_init(pci_bus, 3, -1);
+    }
+
     nvram = m48t59_init(8, 0, 0x0074, NVRAM_SIZE, 59);
     if (nvram == NULL)
         return;
diff -r bfc69471550e -r 54550e85f25a tools/ioemu/hw/rtl8139.c
--- a/tools/ioemu/hw/rtl8139.c  Wed Aug 09 08:01:52 2006 -0600
+++ b/tools/ioemu/hw/rtl8139.c  Wed Aug 09 08:34:06 2006 -0600
@@ -23,14 +23,32 @@
  
  * Modifications:
  *  2006-Jan-28  Mark Malakanov :   TSAD and CSCR implementation (for Windows 
driver)
- *                 
+ * 
+ *  2006-Apr-28  Juergen Lock   :   EEPROM emulation changes for FreeBSD driver
+ *                                  HW revision ID changes for FreeBSD driver
+ * 
+ *  2006-Jul-01  Igor Kovalenko :   Implemented loopback mode for FreeBSD 
driver
+ *                                  Corrected packet transfer reassembly 
routine for 8139C+ mode
+ *                                  Rearranged debugging print statements
+ *                                  Implemented PCI timer interrupt (disabled 
by default)
+ *                                  Implemented Tally Counters, increased VM 
load/save version
+ *                                  Implemented IP/TCP/UDP checksum task 
offloading
+ *
+ *  2006-Jul-04  Igor Kovalenko :   Implemented TCP segmentation offloading
+ *                                  Fixed MTU=1500 for produced ethernet frames
+ *
+ *  2006-Jul-09  Igor Kovalenko :   Fixed TCP header length calculation while 
processing
+ *                                  segmentation offloading
+ *                                  Removed slirp.h dependency
+ *                                  Added rx/tx buffer reset when enabling 
rx/tx operation
  */
 
 #include "vl.h"
-
 
 /* debug RTL8139 card */
 //#define DEBUG_RTL8139 1
+
+#define PCI_FREQUENCY 33000000L
 
 /* debug RTL8139 card C+ mode only */
 //#define DEBUG_RTL8139CP 1
@@ -39,6 +57,8 @@
    ignored by most drivers, disabled by default */
 //#define RTL8139_CALCULATE_RXCRC 1
 
+/* Uncomment to enable on-board timer interrupts */
+//#define RTL8139_ONBOARD_TIMER 1
 
 #if defined(RTL8139_CALCULATE_RXCRC)
 /* For crc32 */
@@ -52,12 +72,19 @@
 #define MOD2(input, size) \
     ( ( input ) & ( size - 1 )  )
 
+#if defined (DEBUG_RTL8139)
+#  define DEBUG_PRINT(x) do { printf x ; } while (0)
+#else
+#  define DEBUG_PRINT(x)
+#endif
+
 /* Symbolic offsets to registers. */
 enum RTL8139_registers {
     MAC0 = 0,        /* Ethernet hardware address. */
     MAR0 = 8,        /* Multicast filter. */
-    TxStatus0 = 0x10,    /* Transmit status (Four 32bit registers). */
-    TxAddr0 = 0x20,        /* Tx descriptors (also four 32bit). */
+    TxStatus0 = 0x10,/* Transmit status (Four 32bit registers). C mode only */
+                     /* Dump Tally Conter control register(64bit). C+ mode 
only */
+    TxAddr0 = 0x20,  /* Tx descriptors (also four 32bit). */
     RxBuf = 0x30,
     ChipCmd = 0x37,
     RxBufPtr = 0x38,
@@ -115,8 +142,10 @@ enum ChipCmdBits {
 
 /* C+ mode */
 enum CplusCmdBits {
-    CPlusRxEnb = 0x0002,
-    CPlusTxEnb = 0x0001,
+    CPlusRxVLAN   = 0x0040, /* enable receive VLAN detagging */
+    CPlusRxChkSum = 0x0020, /* enable receive checksum offloading */
+    CPlusRxEnb    = 0x0002,
+    CPlusTxEnb    = 0x0001,
 };
 
 /* Interrupt register bits, using my own meaningful names. */
@@ -315,6 +344,11 @@ enum chip_flags {
     (b30<<30 | b29<<29 | b28<<28 | b27<<27 | b26<<26 | b23<<23 | b22<<22)
 #define HW_REVID_MASK    HW_REVID(1, 1, 1, 1, 1, 1, 1)
 
+#define RTL8139_PCI_REVID_8139      0x10
+#define RTL8139_PCI_REVID_8139CPLUS 0x20
+
+#define RTL8139_PCI_REVID           RTL8139_PCI_REVID_8139CPLUS
+
 /* Size is 64 * 16bit words */
 #define EEPROM_9346_ADDR_BITS 6
 #define EEPROM_9346_SIZE  (1 << EEPROM_9346_ADDR_BITS)
@@ -356,11 +390,41 @@ typedef struct EEprom9346
     uint8_t eedo;
 } EEprom9346;
 
+typedef struct RTL8139TallyCounters
+{
+    /* Tally counters */
+    uint64_t   TxOk;
+    uint64_t   RxOk;
+    uint64_t   TxERR;
+    uint32_t   RxERR;
+    uint16_t   MissPkt;
+    uint16_t   FAE;
+    uint32_t   Tx1Col;
+    uint32_t   TxMCol;
+    uint64_t   RxOkPhy;
+    uint64_t   RxOkBrd;
+    uint32_t   RxOkMul;
+    uint16_t   TxAbt;
+    uint16_t   TxUndrn;
+} RTL8139TallyCounters;
+
+/* Clears all tally counters */
+static void RTL8139TallyCounters_clear(RTL8139TallyCounters* counters);
+
+/* Writes tally counters to specified physical memory address */
+static void RTL8139TallyCounters_physical_memory_write(target_phys_addr_t 
tc_addr, RTL8139TallyCounters* counters);
+
+/* Loads values of tally counters from VM state file */
+static void RTL8139TallyCounters_load(QEMUFile* f, RTL8139TallyCounters 
*tally_counters);
+
+/* Saves values of tally counters to VM state file */
+static void RTL8139TallyCounters_save(QEMUFile* f, RTL8139TallyCounters 
*tally_counters);
+
 typedef struct RTL8139State {
     uint8_t phys[8]; /* mac address */
     uint8_t mult[8]; /* multicast mask array */
 
-    uint32_t TxStatus[4]; /* TxStatus0 */
+    uint32_t TxStatus[4]; /* TxStatus0 in C mode*/ /* also DTCCR[0] and 
DTCCR[1] in C+ mode */
     uint32_t TxAddr[4];   /* TxAddr0 */
     uint32_t RxBuf;       /* Receive buffer */
     uint32_t RxBufferSize;/* internal variable, receive ring buffer size in C 
mode */
@@ -414,14 +478,27 @@ typedef struct RTL8139State {
     uint32_t   RxRingAddrHI;
 
     EEprom9346 eeprom;
-    
+
+    uint32_t   TCTR;
+    uint32_t   TimerInt;
+    int64_t    TCTR_base;
+
+    /* Tally counters */
+    RTL8139TallyCounters tally_counters;
+
+    /* Non-persistent data */
+    uint8_t   *cplus_txbuffer;
+    int        cplus_txbuffer_len;
+    int        cplus_txbuffer_offset;
+
+    /* PCI interrupt timer */
+    QEMUTimer *timer;
+
 } RTL8139State;
 
 void prom9346_decode_command(EEprom9346 *eeprom, uint8_t command)
 {
-#if defined(DEBUG_RTL8139)
-    printf("RTL8139: eeprom command 0x%02x\n", command);
-#endif
+    DEBUG_PRINT(("RTL8139: eeprom command 0x%02x\n", command));
 
     switch (command & Chip9346_op_mask)
     {
@@ -432,10 +509,8 @@ void prom9346_decode_command(EEprom9346 
             eeprom->eedo = 0;
             eeprom->tick = 0;
             eeprom->mode = Chip9346_data_read;
-#if defined(DEBUG_RTL8139)
-            printf("RTL8139: eeprom read from address 0x%02x data=0x%04x\n",
-                   eeprom->address, eeprom->output);
-#endif
+            DEBUG_PRINT(("RTL8139: eeprom read from address 0x%02x 
data=0x%04x\n",
+                   eeprom->address, eeprom->output));
         }
         break;
 
@@ -445,10 +520,8 @@ void prom9346_decode_command(EEprom9346 
             eeprom->input = 0;
             eeprom->tick = 0;
             eeprom->mode = Chip9346_none; /* Chip9346_data_write */
-#if defined(DEBUG_RTL8139)
-            printf("RTL8139: eeprom begin write to address 0x%02x\n",
-                   eeprom->address);
-#endif
+            DEBUG_PRINT(("RTL8139: eeprom begin write to address 0x%02x\n",
+                   eeprom->address));
         }
         break;
         default:
@@ -456,19 +529,13 @@ void prom9346_decode_command(EEprom9346 
             switch (command & Chip9346_op_ext_mask)
             {
                 case Chip9346_op_write_enable:
-#if defined(DEBUG_RTL8139)
-                    printf("RTL8139: eeprom write enabled\n");
-#endif
+                    DEBUG_PRINT(("RTL8139: eeprom write enabled\n"));
                     break;
                 case Chip9346_op_write_all:
-#if defined(DEBUG_RTL8139)
-                    printf("RTL8139: eeprom begin write all\n");
-#endif
+                    DEBUG_PRINT(("RTL8139: eeprom begin write all\n"));
                     break;
                 case Chip9346_op_write_disable:
-#if defined(DEBUG_RTL8139)
-                    printf("RTL8139: eeprom write disabled\n");
-#endif
+                    DEBUG_PRINT(("RTL8139: eeprom write disabled\n"));
                     break;
             }
             break;
@@ -481,9 +548,7 @@ void prom9346_shift_clock(EEprom9346 *ee
 
     ++ eeprom->tick;
 
-#if defined(DEBUG_RTL8139)
-    printf("eeprom: tick %d eedi=%d eedo=%d\n", eeprom->tick, eeprom->eedi, 
eeprom->eedo);
-#endif
+    DEBUG_PRINT(("eeprom: tick %d eedi=%d eedo=%d\n", eeprom->tick, 
eeprom->eedi, eeprom->eedo));
 
     switch (eeprom->mode)
     {
@@ -493,9 +558,7 @@ void prom9346_shift_clock(EEprom9346 *ee
                 eeprom->mode = Chip9346_read_command;
                 eeprom->tick = 0;
                 eeprom->input = 0;
-#if defined(DEBUG_RTL8139)
-                printf("eeprom: +++ synchronized, begin command read\n");
-#endif
+                DEBUG_PRINT(("eeprom: +++ synchronized, begin command 
read\n"));
             }
             break;
 
@@ -512,14 +575,24 @@ void prom9346_shift_clock(EEprom9346 *ee
             eeprom->output <<= 1;
             if (eeprom->tick == 16)
             {
+#if 1
+        // the FreeBSD drivers (rl and re) don't explicitly toggle
+        // CS between reads (or does setting Cfg9346 to 0 count too?),
+        // so we need to enter wait-for-command state here
+                eeprom->mode = Chip9346_enter_command_mode;
+                eeprom->input = 0;
+                eeprom->tick = 0;
+
+                DEBUG_PRINT(("eeprom: +++ end of read, awaiting next 
command\n"));
+#else
+        // original behaviour
                 ++eeprom->address;
                 eeprom->address &= EEPROM_9346_ADDR_MASK;
                 eeprom->output = eeprom->contents[eeprom->address];
                 eeprom->tick = 0;
 
-#if defined(DEBUG_RTL8139)
-                printf("eeprom: +++ read next address 0x%02x data=0x%04x\n",
-                       eeprom->address, eeprom->output);
+                DEBUG_PRINT(("eeprom: +++ read next address 0x%02x 
data=0x%04x\n",
+                       eeprom->address, eeprom->output));
 #endif
             }
             break;
@@ -528,10 +601,9 @@ void prom9346_shift_clock(EEprom9346 *ee
             eeprom->input = (eeprom->input << 1) | (bit & 1);
             if (eeprom->tick == 16)
             {
-#if defined(DEBUG_RTL8139)
-            printf("RTL8139: eeprom write to address 0x%02x data=0x%04x\n",
-                   eeprom->address, eeprom->input);
-#endif
+                DEBUG_PRINT(("RTL8139: eeprom write to address 0x%02x 
data=0x%04x\n",
+                       eeprom->address, eeprom->input));
+
                 eeprom->contents[eeprom->address] = eeprom->input;
                 eeprom->mode = Chip9346_none; /* waiting for next command 
after CS cycle */
                 eeprom->tick = 0;
@@ -548,10 +620,9 @@ void prom9346_shift_clock(EEprom9346 *ee
                 {
                     eeprom->contents[i] = eeprom->input;
                 }
-#if defined(DEBUG_RTL8139)
-                printf("RTL8139: eeprom filled with data=0x%04x\n",
-                       eeprom->input);
-#endif
+                DEBUG_PRINT(("RTL8139: eeprom filled with data=0x%04x\n",
+                       eeprom->input));
+
                 eeprom->mode = Chip9346_enter_command_mode;
                 eeprom->tick = 0;
                 eeprom->input = 0;
@@ -582,9 +653,8 @@ void prom9346_set_wire(RTL8139State *s, 
     eeprom->eesk = eesk;
     eeprom->eedi = eedi;
 
-#if defined(DEBUG_RTL8139)
-    printf("eeprom: +++ wires CS=%d SK=%d DI=%d DO=%d\n", eeprom->eecs, 
eeprom->eesk, eeprom->eedi, eeprom->eedo);
-#endif
+    DEBUG_PRINT(("eeprom: +++ wires CS=%d SK=%d DI=%d DO=%d\n",
+                 eeprom->eecs, eeprom->eesk, eeprom->eedi, eeprom->eedo));
 
     if (!old_eecs && eecs)
     {
@@ -594,17 +664,12 @@ void prom9346_set_wire(RTL8139State *s, 
         eeprom->output = 0;
         eeprom->mode = Chip9346_enter_command_mode;
 
-#if defined(DEBUG_RTL8139)
-        printf("=== eeprom: begin access, enter command mode\n");
-#endif
-
+        DEBUG_PRINT(("=== eeprom: begin access, enter command mode\n"));
     }
 
     if (!eecs)
     {
-#if defined(DEBUG_RTL8139)
-        printf("=== eeprom: end access\n");
-#endif
+        DEBUG_PRINT(("=== eeprom: end access\n"));
         return;
     }
 
@@ -619,10 +684,10 @@ static void rtl8139_update_irq(RTL8139St
 {
     int isr;
     isr = (s->IntrStatus & s->IntrMask) & 0xffff;
-#if defined(DEBUG_RTL8139)
-    printf("RTL8139: Set IRQ line %d to %d (%04x %04x)\n",
-       s->irq, isr ? 1 : 0, s->IntrStatus, s->IntrMask);
-#endif
+
+    DEBUG_PRINT(("RTL8139: Set IRQ line %d to %d (%04x %04x)\n",
+       s->irq, isr ? 1 : 0, s->IntrStatus, s->IntrMask));
+
     if (s->irq == 16) {
         /* PCI irq */
         pci_set_irq(s->pci_dev, 0, (isr != 0));
@@ -691,9 +756,7 @@ static void rtl8139_write_buffer(RTL8139
         /* write packet data */
         if (wrapped && s->RxBufferSize < 65536 && !rtl8139_RxWrap(s))
         {
-    #if defined(DEBUG_RTL8139)
-            printf(">>> RTL8139: rx packet wrapped in buffer at %d\n", 
size-wrapped);
-    #endif
+            DEBUG_PRINT((">>> RTL8139: rx packet wrapped in buffer at %d\n", 
size-wrapped));
 
             if (size > wrapped)
             {
@@ -751,7 +814,7 @@ static int rtl8139_can_receive(void *opa
     }
 }
 
-static void rtl8139_receive(void *opaque, const uint8_t *buf, int size)
+static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int 
do_interrupt)
 {
     RTL8139State *s = opaque;
 
@@ -761,16 +824,12 @@ static void rtl8139_receive(void *opaque
     static const uint8_t broadcast_macaddr[6] = 
         { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
 
-#if defined(DEBUG_RTL8139)
-    printf(">>> RTL8139: received len=%d\n", size);
-#endif
+    DEBUG_PRINT((">>> RTL8139: received len=%d\n", size));
 
     /* test if board clock is stopped */
     if (!s->clock_enabled)
     {
-#if defined(DEBUG_RTL8139)
-        printf("RTL8139: stopped ==========================\n");
-#endif
+        DEBUG_PRINT(("RTL8139: stopped ==========================\n"));
         return;
     }
 
@@ -778,42 +837,44 @@ static void rtl8139_receive(void *opaque
 
     if (!rtl8139_receiver_enabled(s))
     {
-#if defined(DEBUG_RTL8139)
-        printf("RTL8139: receiver disabled ================\n");
-#endif
+        DEBUG_PRINT(("RTL8139: receiver disabled ================\n"));
         return;
     }
 
     /* XXX: check this */
     if (s->RxConfig & AcceptAllPhys) {
         /* promiscuous: receive all */
-#if defined(DEBUG_RTL8139)
-        printf(">>> RTL8139: packet received in promiscuous mode\n");
-#endif
+        DEBUG_PRINT((">>> RTL8139: packet received in promiscuous mode\n"));
 
     } else {
         if (!memcmp(buf,  broadcast_macaddr, 6)) {
             /* broadcast address */
             if (!(s->RxConfig & AcceptBroadcast))
             {
-#if defined(DEBUG_RTL8139)
-                printf(">>> RTL8139: broadcast packet rejected\n");
-#endif
+                DEBUG_PRINT((">>> RTL8139: broadcast packet rejected\n"));
+
+                /* update tally counter */
+                ++s->tally_counters.RxERR;
+
                 return;
             }
 
             packet_header |= RxBroadcast;
 
-#if defined(DEBUG_RTL8139)
-            printf(">>> RTL8139: broadcast packet received\n");
-#endif
+            DEBUG_PRINT((">>> RTL8139: broadcast packet received\n"));
+
+            /* update tally counter */
+            ++s->tally_counters.RxOkBrd;
+
         } else if (buf[0] & 0x01) {
             /* multicast */
             if (!(s->RxConfig & AcceptMulticast))
             {
-#if defined(DEBUG_RTL8139)
-                printf(">>> RTL8139: multicast packet rejected\n");
-#endif
+                DEBUG_PRINT((">>> RTL8139: multicast packet rejected\n"));
+
+                /* update tally counter */
+                ++s->tally_counters.RxERR;
+
                 return;
             }
 
@@ -821,17 +882,21 @@ static void rtl8139_receive(void *opaque
 
             if (!(s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7))))
             {
-#if defined(DEBUG_RTL8139)
-                printf(">>> RTL8139: multicast address mismatch\n");
-#endif
+                DEBUG_PRINT((">>> RTL8139: multicast address mismatch\n"));
+
+                /* update tally counter */
+                ++s->tally_counters.RxERR;
+
                 return;
             }
 
             packet_header |= RxMulticast;
 
-#if defined(DEBUG_RTL8139)
-            printf(">>> RTL8139: multicast packet received\n");
-#endif
+            DEBUG_PRINT((">>> RTL8139: multicast packet received\n"));
+
+            /* update tally counter */
+            ++s->tally_counters.RxOkMul;
+
         } else if (s->phys[0] == buf[0] &&
                    s->phys[1] == buf[1] &&                   
                    s->phys[2] == buf[2] &&            
@@ -841,23 +906,28 @@ static void rtl8139_receive(void *opaque
             /* match */
             if (!(s->RxConfig & AcceptMyPhys))
             {
-#if defined(DEBUG_RTL8139)
-                printf(">>> RTL8139: rejecting physical address matching 
packet\n");
-#endif
+                DEBUG_PRINT((">>> RTL8139: rejecting physical address matching 
packet\n"));
+
+                /* update tally counter */
+                ++s->tally_counters.RxERR;
+
                 return;
             }
 
             packet_header |= RxPhysical;
 
-#if defined(DEBUG_RTL8139)
-            printf(">>> RTL8139: physical address matching packet received\n");
-#endif
+            DEBUG_PRINT((">>> RTL8139: physical address matching packet 
received\n"));
+
+            /* update tally counter */
+            ++s->tally_counters.RxOkPhy;
 
         } else {
 
-#if defined(DEBUG_RTL8139)
-                printf(">>> RTL8139: unknown packet\n");
-#endif
+            DEBUG_PRINT((">>> RTL8139: unknown packet\n"));
+
+            /* update tally counter */
+            ++s->tally_counters.RxERR;
+
             return;
         }
     }
@@ -872,9 +942,7 @@ static void rtl8139_receive(void *opaque
 
     if (rtl8139_cp_receiver_enabled(s))
     {
-#if defined(DEBUG_RTL8139)
-        printf("RTL8139: in C+ Rx mode ================\n");
-#endif
+        DEBUG_PRINT(("RTL8139: in C+ Rx mode ================\n"));
 
         /* begin C+ receiver mode */
 
@@ -897,10 +965,8 @@ static void rtl8139_receive(void *opaque
         cplus_rx_ring_desc = rtl8139_addr64(s->RxRingAddrLO, s->RxRingAddrHI);
         cplus_rx_ring_desc += 16 * descriptor;
 
-#ifdef DEBUG_RTL8139
-        printf("RTL8139: +++ C+ mode reading RX descriptor %d from host memory 
at %08x %08x = 0x%8lx\n",
-               descriptor, s->RxRingAddrHI, s->RxRingAddrLO, 
cplus_rx_ring_desc);
-#endif
+        DEBUG_PRINT(("RTL8139: +++ C+ mode reading RX descriptor %d from host 
memory at %08x %08x = %016" PRIx64 "\n",
+               descriptor, s->RxRingAddrHI, s->RxRingAddrLO, 
(uint64_t)cplus_rx_ring_desc));
 
         uint32_t val, rxdw0,rxdw1,rxbufLO,rxbufHI;
 
@@ -913,33 +979,41 @@ static void rtl8139_receive(void *opaque
         cpu_physical_memory_read(cplus_rx_ring_desc+12, (uint8_t *)&val, 4);
         rxbufHI = le32_to_cpu(val);
 
-#ifdef DEBUG_RTL8139
-        printf("RTL8139: +++ C+ mode RX descriptor %d %08x %08x %08x %08x\n",
+        DEBUG_PRINT(("RTL8139: +++ C+ mode RX descriptor %d %08x %08x %08x 
%08x\n",
                descriptor,
-               rxdw0, rxdw1, rxbufLO, rxbufHI);
-#endif
+               rxdw0, rxdw1, rxbufLO, rxbufHI));
 
         if (!(rxdw0 & CP_RX_OWN))
         {
-#if defined(DEBUG_RTL8139)
-            printf("RTL8139: C+ Rx mode : descriptor %d is owned by host\n", 
descriptor);
-#endif
+            DEBUG_PRINT(("RTL8139: C+ Rx mode : descriptor %d is owned by 
host\n", descriptor));
+
             s->IntrStatus |= RxOverflow;
             ++s->RxMissed;
+
+            /* update tally counter */
+            ++s->tally_counters.RxERR;
+            ++s->tally_counters.MissPkt;
+
             rtl8139_update_irq(s);
             return;
         }
 
         uint32_t rx_space = rxdw0 & CP_RX_BUFFER_SIZE_MASK;
 
+        /* TODO: scatter the packet over available receive ring descriptors 
space */
+
         if (size+4 > rx_space)
         {
-#if defined(DEBUG_RTL8139)
-            printf("RTL8139: C+ Rx mode : descriptor %d size %d received %d + 
4\n",
-                   descriptor, rx_space, size);
-#endif
+            DEBUG_PRINT(("RTL8139: C+ Rx mode : descriptor %d size %d received 
%d + 4\n",
+                   descriptor, rx_space, size));
+
             s->IntrStatus |= RxOverflow;
             ++s->RxMissed;
+
+            /* update tally counter */
+            ++s->tally_counters.RxERR;
+            ++s->tally_counters.MissPkt;
+
             rtl8139_update_irq(s);
             return;
         }
@@ -948,6 +1022,11 @@ static void rtl8139_receive(void *opaque
 
         /* receive/copy to target memory */
         cpu_physical_memory_write( rx_addr, buf, size );
+
+        if (s->CpCmd & CPlusRxChkSum)
+        {
+            /* do some packet checksumming */
+        }
 
         /* write checksum */
 #if defined (RTL8139_CALCULATE_RXCRC)
@@ -1008,6 +1087,9 @@ static void rtl8139_receive(void *opaque
         val = cpu_to_le32(rxdw1);
         cpu_physical_memory_write(cplus_rx_ring_desc+4,  (uint8_t *)&val, 4);
 
+        /* update tally counter */
+        ++s->tally_counters.RxOk;
+
         /* seek to next Rx descriptor */
         if (rxdw0 & CP_RX_EOR)
         {
@@ -1018,16 +1100,13 @@ static void rtl8139_receive(void *opaque
             ++s->currCPlusRxDesc;
         }
 
-#if defined(DEBUG_RTL8139)
-        printf("RTL8139: done C+ Rx mode ----------------\n");
-#endif
+        DEBUG_PRINT(("RTL8139: done C+ Rx mode ----------------\n"));
 
     }
     else
     {
-#if defined(DEBUG_RTL8139)
-        printf("RTL8139: in ring Rx mode ================\n");
-#endif
+        DEBUG_PRINT(("RTL8139: in ring Rx mode ================\n"));
+
         /* begin ring receiver mode */
         int avail = MOD2(s->RxBufferSize + s->RxBufPtr - s->RxBufAddr, 
s->RxBufferSize);
 
@@ -1035,10 +1114,9 @@ static void rtl8139_receive(void *opaque
 
         if (avail != 0 && size + 8 >= avail)
         {
-#if defined(DEBUG_RTL8139)
-            printf("rx overflow: rx buffer length %d head 0x%04x read 0x%04x 
=== available 0x%04x need 0x%04x\n",
-                   s->RxBufferSize, s->RxBufAddr, s->RxBufPtr, avail, size + 
8);
-#endif
+            DEBUG_PRINT(("rx overflow: rx buffer length %d head 0x%04x read 
0x%04x === available 0x%04x need 0x%04x\n",
+                   s->RxBufferSize, s->RxBufAddr, s->RxBufPtr, avail, size + 
8));
+
             s->IntrStatus |= RxOverflow;
             ++s->RxMissed;
             rtl8139_update_irq(s);
@@ -1070,15 +1148,21 @@ static void rtl8139_receive(void *opaque
 
         /* now we can signal we have received something */
 
-#if defined(DEBUG_RTL8139)
-        printf("   received: rx buffer length %d head 0x%04x read 0x%04x\n",
-               s->RxBufferSize, s->RxBufAddr, s->RxBufPtr);
-#endif
-
+        DEBUG_PRINT(("   received: rx buffer length %d head 0x%04x read 
0x%04x\n",
+               s->RxBufferSize, s->RxBufAddr, s->RxBufPtr));
     }
 
     s->IntrStatus |= RxOK;
-    rtl8139_update_irq(s);
+
+    if (do_interrupt)
+    {
+        rtl8139_update_irq(s);
+    }
+}
+
+static void rtl8139_receive(void *opaque, const uint8_t *buf, int size)
+{
+    rtl8139_do_receive(opaque, buf, size, 1);
 }
 
 static void rtl8139_reset_rxring(RTL8139State *s, uint32_t bufferSize)
@@ -1103,6 +1187,11 @@ static void rtl8139_reset(RTL8139State *
 
     /* prepare eeprom */
     s->eeprom.contents[0] = 0x8129;
+#if 1
+    // PCI vendor and device ID should be mirrored here
+    s->eeprom.contents[1] = 0x10ec;
+    s->eeprom.contents[2] = 0x8139;
+#endif
     memcpy(&s->eeprom.contents[7], s->macaddr, 6);
 
     /* mark all status registers as owned by host */
@@ -1129,7 +1218,7 @@ static void rtl8139_reset(RTL8139State *
 //    s->TxConfig |= HW_REVID(1, 0, 0, 0, 0, 0, 0); // RTL-8139  HasHltClk
     s->clock_enabled = 0;
 #else
-    s->TxConfig |= HW_REVID(1, 1, 1, 0, 1, 0, 0); // RTL-8139C HasLWake
+    s->TxConfig |= HW_REVID(1, 1, 1, 0, 1, 1, 0); // RTL-8139C+ HasLWake
     s->clock_enabled = 1;
 #endif
 
@@ -1157,34 +1246,137 @@ static void rtl8139_reset(RTL8139State *
     s->NWayAdvert    = 0x05e1; /* all modes, full duplex */
     s->NWayLPAR      = 0x05e1; /* all modes, full duplex */
     s->NWayExpansion = 0x0001; /* autonegotiation supported */
+
+    /* also reset timer and disable timer interrupt */
+    s->TCTR = 0;
+    s->TimerInt = 0;
+    s->TCTR_base = 0;
+
+    /* reset tally counters */
+    RTL8139TallyCounters_clear(&s->tally_counters);
+}
+
+void RTL8139TallyCounters_clear(RTL8139TallyCounters* counters)
+{
+    counters->TxOk = 0;
+    counters->RxOk = 0;
+    counters->TxERR = 0;
+    counters->RxERR = 0;
+    counters->MissPkt = 0;
+    counters->FAE = 0;
+    counters->Tx1Col = 0;

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog