ia64/xen-unstable

changeset 10732:b450f21472a0

Add qemu 0.8.1 based ioemu.

Signed-off-by: Christian Limpach <Christian.Limpach@xensource.com>
author chris@kneesaa.uk.xensource.com
date Wed Jul 12 19:16:10 2006 +0100 (2006-07-12)
parents bd68ce5a3f0c
children 6d8f2d78d7c8
files .hgignore tools/ioemu/.cvsignore tools/ioemu/COPYING tools/ioemu/COPYING.LIB tools/ioemu/CVS/Entries tools/ioemu/CVS/Repository tools/ioemu/CVS/Root tools/ioemu/CVS/Tag tools/ioemu/Changelog tools/ioemu/LICENSE tools/ioemu/Makefile tools/ioemu/Makefile.target tools/ioemu/README tools/ioemu/README.distrib tools/ioemu/TODO tools/ioemu/VERSION tools/ioemu/a.out.h tools/ioemu/aes.c tools/ioemu/aes.h tools/ioemu/audio/CVS/Entries tools/ioemu/audio/CVS/Repository tools/ioemu/audio/CVS/Root tools/ioemu/audio/CVS/Tag tools/ioemu/audio/alsaaudio.c tools/ioemu/audio/audio.c tools/ioemu/audio/audio.h tools/ioemu/audio/audio_int.h tools/ioemu/audio/audio_template.h tools/ioemu/audio/coreaudio.c tools/ioemu/audio/dsound_template.h tools/ioemu/audio/dsoundaudio.c tools/ioemu/audio/fmodaudio.c tools/ioemu/audio/mixeng.c tools/ioemu/audio/mixeng.h tools/ioemu/audio/mixeng_template.h tools/ioemu/audio/noaudio.c tools/ioemu/audio/ossaudio.c tools/ioemu/audio/rate_template.h tools/ioemu/audio/sdlaudio.c tools/ioemu/audio/sys-queue.h tools/ioemu/audio/wavaudio.c tools/ioemu/block-bochs.c tools/ioemu/block-cloop.c tools/ioemu/block-cow.c tools/ioemu/block-dmg.c tools/ioemu/block-qcow.c tools/ioemu/block-vmdk.c tools/ioemu/block-vpc.c tools/ioemu/block-vvfat.c tools/ioemu/block.c tools/ioemu/block_int.h tools/ioemu/bswap.h tools/ioemu/cocoa.m tools/ioemu/configure tools/ioemu/console.c tools/ioemu/cpu-all.h tools/ioemu/cpu-defs.h tools/ioemu/cpu-exec.c tools/ioemu/dis-asm.h tools/ioemu/disas.c tools/ioemu/disas.h tools/ioemu/dyngen-exec.h tools/ioemu/dyngen-op.h tools/ioemu/dyngen.c tools/ioemu/dyngen.h tools/ioemu/elf.h tools/ioemu/elf_ops.h tools/ioemu/exec-all.h tools/ioemu/exec.c tools/ioemu/fpu/CVS/Entries tools/ioemu/fpu/CVS/Repository tools/ioemu/fpu/CVS/Root tools/ioemu/fpu/CVS/Tag tools/ioemu/fpu/softfloat-macros.h tools/ioemu/fpu/softfloat-native.c tools/ioemu/fpu/softfloat-native.h tools/ioemu/fpu/softfloat-specialize.h tools/ioemu/fpu/softfloat.c tools/ioemu/fpu/softfloat.h tools/ioemu/gdbstub.c tools/ioemu/gdbstub.h tools/ioemu/hw/CVS/Entries tools/ioemu/hw/CVS/Repository tools/ioemu/hw/CVS/Root tools/ioemu/hw/CVS/Tag tools/ioemu/hw/adb.c tools/ioemu/hw/adlib.c tools/ioemu/hw/apic.c tools/ioemu/hw/arm_boot.c tools/ioemu/hw/arm_pic.c tools/ioemu/hw/arm_pic.h tools/ioemu/hw/arm_timer.c tools/ioemu/hw/cirrus_vga.c tools/ioemu/hw/cirrus_vga_rop.h tools/ioemu/hw/cirrus_vga_rop2.h tools/ioemu/hw/cuda.c tools/ioemu/hw/dma.c tools/ioemu/hw/es1370.c tools/ioemu/hw/esp.c tools/ioemu/hw/fdc.c tools/ioemu/hw/fmopl.c tools/ioemu/hw/fmopl.h tools/ioemu/hw/heathrow_pic.c tools/ioemu/hw/i8254.c tools/ioemu/hw/i8259.c tools/ioemu/hw/ide.c tools/ioemu/hw/integratorcp.c tools/ioemu/hw/iommu.c tools/ioemu/hw/lance.c tools/ioemu/hw/m48t59.c tools/ioemu/hw/m48t59.h tools/ioemu/hw/mc146818rtc.c tools/ioemu/hw/mips_r4k.c tools/ioemu/hw/ne2000.c tools/ioemu/hw/openpic.c tools/ioemu/hw/parallel.c tools/ioemu/hw/pc.c tools/ioemu/hw/pci.c tools/ioemu/hw/pckbd.c tools/ioemu/hw/pcspk.c tools/ioemu/hw/piix4acpi.c tools/ioemu/hw/pl011.c tools/ioemu/hw/pl050.c tools/ioemu/hw/pl080.c tools/ioemu/hw/pl110.c tools/ioemu/hw/pl110_template.h tools/ioemu/hw/pl190.c tools/ioemu/hw/ppc.c tools/ioemu/hw/ppc_chrp.c tools/ioemu/hw/ppc_prep.c tools/ioemu/hw/ps2.c tools/ioemu/hw/rtl8139.c tools/ioemu/hw/sb16.c tools/ioemu/hw/serial.c tools/ioemu/hw/sh7750.c tools/ioemu/hw/sh7750_regnames.c tools/ioemu/hw/sh7750_regnames.h tools/ioemu/hw/sh7750_regs.h tools/ioemu/hw/shix.c tools/ioemu/hw/slavio_intctl.c tools/ioemu/hw/slavio_misc.c tools/ioemu/hw/slavio_serial.c tools/ioemu/hw/slavio_timer.c tools/ioemu/hw/smc91c111.c tools/ioemu/hw/sun4m.c tools/ioemu/hw/sun4u.c tools/ioemu/hw/tc58128.c tools/ioemu/hw/tcx.c tools/ioemu/hw/usb-hid.c tools/ioemu/hw/usb-hub.c tools/ioemu/hw/usb-uhci.c tools/ioemu/hw/usb.c tools/ioemu/hw/usb.h tools/ioemu/hw/versatilepb.c tools/ioemu/hw/vga.c tools/ioemu/hw/vga_int.h tools/ioemu/hw/vga_template.h tools/ioemu/i386-dis.c tools/ioemu/i386-vl.ld tools/ioemu/i386.ld tools/ioemu/ia64.ld tools/ioemu/keymaps.c tools/ioemu/keymaps/CVS/Entries tools/ioemu/keymaps/CVS/Repository tools/ioemu/keymaps/CVS/Root tools/ioemu/keymaps/CVS/Tag tools/ioemu/keymaps/ar tools/ioemu/keymaps/common tools/ioemu/keymaps/da tools/ioemu/keymaps/de tools/ioemu/keymaps/de-ch tools/ioemu/keymaps/en-gb tools/ioemu/keymaps/en-us tools/ioemu/keymaps/es tools/ioemu/keymaps/et tools/ioemu/keymaps/fi tools/ioemu/keymaps/fo tools/ioemu/keymaps/fr tools/ioemu/keymaps/fr-be tools/ioemu/keymaps/fr-ca tools/ioemu/keymaps/fr-ch tools/ioemu/keymaps/hr tools/ioemu/keymaps/hu tools/ioemu/keymaps/is tools/ioemu/keymaps/it tools/ioemu/keymaps/ja tools/ioemu/keymaps/lt tools/ioemu/keymaps/lv tools/ioemu/keymaps/mk tools/ioemu/keymaps/modifiers tools/ioemu/keymaps/nl tools/ioemu/keymaps/nl-be tools/ioemu/keymaps/no tools/ioemu/keymaps/pl tools/ioemu/keymaps/pt tools/ioemu/keymaps/pt-br tools/ioemu/keymaps/ru tools/ioemu/keymaps/sl tools/ioemu/keymaps/sv tools/ioemu/keymaps/th tools/ioemu/keymaps/tr tools/ioemu/kqemu.c tools/ioemu/kqemu.h tools/ioemu/loader.c tools/ioemu/monitor.c tools/ioemu/osdep.c tools/ioemu/osdep.h tools/ioemu/patches/acpi-poweroff-support tools/ioemu/patches/acpi-support tools/ioemu/patches/acpi-timer-support tools/ioemu/patches/domain-destroy tools/ioemu/patches/domain-reset tools/ioemu/patches/domain-timeoffset tools/ioemu/patches/hypervisor-pit tools/ioemu/patches/ide-hd-multithread tools/ioemu/patches/qemu-64bit tools/ioemu/patches/qemu-bugfixes tools/ioemu/patches/qemu-cleanup tools/ioemu/patches/qemu-dm tools/ioemu/patches/qemu-hvm-banner tools/ioemu/patches/qemu-infrastructure tools/ioemu/patches/qemu-logging tools/ioemu/patches/qemu-no-apic tools/ioemu/patches/qemu-nobios tools/ioemu/patches/qemu-smp tools/ioemu/patches/qemu-target-i386-dm tools/ioemu/patches/qemu-timer tools/ioemu/patches/sdl-mouse-invisible-wall tools/ioemu/patches/serial-non-block tools/ioemu/patches/series tools/ioemu/patches/shadow-vram tools/ioemu/patches/shared-vram tools/ioemu/patches/support-xm-console tools/ioemu/patches/vnc-cleanup tools/ioemu/patches/vnc-fixes tools/ioemu/patches/xen-build tools/ioemu/patches/xen-domain-name tools/ioemu/patches/xen-domid tools/ioemu/patches/xen-mm tools/ioemu/patches/xen-network tools/ioemu/pc-bios/CVS/Entries tools/ioemu/pc-bios/CVS/Repository tools/ioemu/pc-bios/CVS/Root tools/ioemu/pc-bios/CVS/Tag tools/ioemu/pc-bios/Makefile tools/ioemu/pc-bios/README tools/ioemu/pc-bios/bios.diff tools/ioemu/pc-bios/linux_boot.S tools/ioemu/pc-bios/ohw.diff tools/ioemu/pc-bios/proll.patch tools/ioemu/pc-bios/vgabios.diff tools/ioemu/qemu-binfmt-conf.sh tools/ioemu/qemu-doc.texi tools/ioemu/qemu-img.c tools/ioemu/qemu-img.texi tools/ioemu/qemu-tech.texi tools/ioemu/qemu_socket.h tools/ioemu/readline.c tools/ioemu/sdl.c tools/ioemu/sdl_keysym.h tools/ioemu/softmmu_exec.h tools/ioemu/softmmu_header.h tools/ioemu/softmmu_template.h tools/ioemu/tap-win32.c tools/ioemu/target-i386-dm/cpu.h tools/ioemu/target-i386-dm/exec-dm.c tools/ioemu/target-i386-dm/helper2.c tools/ioemu/target-i386-dm/i8259-dm.c tools/ioemu/target-i386-dm/qemu-dm.debug tools/ioemu/target-i386-dm/qemu-ifup tools/ioemu/target-i386/CVS/Entries tools/ioemu/target-i386/CVS/Repository tools/ioemu/target-i386/CVS/Root tools/ioemu/target-i386/CVS/Tag tools/ioemu/target-i386/cpu.h tools/ioemu/target-i386/exec.h tools/ioemu/target-i386/helper.c tools/ioemu/target-i386/helper2.c tools/ioemu/target-i386/op.c tools/ioemu/target-i386/opreg_template.h tools/ioemu/target-i386/ops_mem.h tools/ioemu/target-i386/ops_sse.h tools/ioemu/target-i386/ops_template.h tools/ioemu/target-i386/ops_template_mem.h tools/ioemu/target-i386/translate-copy.c tools/ioemu/target-i386/translate.c tools/ioemu/tests/.cvsignore tools/ioemu/tests/CVS/Entries tools/ioemu/tests/CVS/Repository tools/ioemu/tests/CVS/Root tools/ioemu/tests/CVS/Tag tools/ioemu/tests/Makefile tools/ioemu/tests/hello-arm.c tools/ioemu/tests/hello-i386.c tools/ioemu/tests/linux-test.c tools/ioemu/tests/qruncom.c tools/ioemu/tests/runcom.c tools/ioemu/tests/sha1.c tools/ioemu/tests/test-i386-code16.S tools/ioemu/tests/test-i386-muldiv.h tools/ioemu/tests/test-i386-shift.h tools/ioemu/tests/test-i386-vm86.S tools/ioemu/tests/test-i386.c tools/ioemu/tests/test-i386.h tools/ioemu/tests/test_path.c tools/ioemu/tests/testthread.c tools/ioemu/texi2pod.pl tools/ioemu/thunk.c tools/ioemu/thunk.h tools/ioemu/translate-all.c tools/ioemu/translate-op.c tools/ioemu/usb-linux.c tools/ioemu/vgafont.h tools/ioemu/vl.c tools/ioemu/vl.h tools/ioemu/vnc.c tools/ioemu/vnc_keysym.h tools/ioemu/vnchextile.h tools/ioemu/x86_64.ld
line diff
     1.1 --- a/.hgignore	Wed Jul 12 19:16:07 2006 +0100
     1.2 +++ b/.hgignore	Wed Jul 12 19:16:10 2006 +0100
     1.3 @@ -123,12 +123,18 @@
     1.4  ^tools/firmware/vmxassist/roms\.h$
     1.5  ^tools/firmware/vmxassist/vmxassist$
     1.6  ^tools/firmware/vmxassist/vmxloader$
     1.7 -^tools/ioemu/config-host\..*$
     1.8 -^tools/ioemu/keysym_adapter_sdl\.h$
     1.9 -^tools/ioemu/keysym_adapter_vnc\.h$
    1.10 -^tools/ioemu/target-.*/Makefile$
    1.11 -^tools/ioemu/target-.*/config\..*$
    1.12 -^tools/ioemu/target-.*/qemu-dm$
    1.13 +^tools/ioemu/\.pc/.*$
    1.14 +^tools/ioemu/config-host\.h$
    1.15 +^tools/ioemu/config-host\.mak$
    1.16 +^tools/ioemu/i386-dm/config\.h$
    1.17 +^tools/ioemu/i386-dm/config\.mak$
    1.18 +^tools/ioemu/i386-dm/qemu-dm$
    1.19 +^tools/ioemu/qemu-doc\.html$
    1.20 +^tools/ioemu/qemu-img\.1$
    1.21 +^tools/ioemu/qemu-img\.pod$
    1.22 +^tools/ioemu/qemu-tech\.html$
    1.23 +^tools/ioemu/qemu\.1$
    1.24 +^tools/ioemu/qemu\.pod$
    1.25  ^tools/libxc/xen/.*$
    1.26  ^tools/misc/cpuperf/cpuperf-perfcntr$
    1.27  ^tools/misc/cpuperf/cpuperf-xen$
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/tools/ioemu/.cvsignore	Wed Jul 12 19:16:10 2006 +0100
     2.3 @@ -0,0 +1,29 @@
     2.4 +arm-user
     2.5 +arm-softmmu
     2.6 +armeb-user
     2.7 +config-host.*
     2.8 +dyngen
     2.9 +i386
    2.10 +i386-softmmu
    2.11 +i386-user
    2.12 +ppc-softmmu
    2.13 +ppc64-softmmu
    2.14 +ppc-user
    2.15 +qemu-doc.html
    2.16 +qemu-tech.html
    2.17 +qemu.1
    2.18 +qemu.pod
    2.19 +qemu-img.1
    2.20 +qemu-img.pod
    2.21 +sparc-user
    2.22 +qemu-img
    2.23 +sparc-softmmu
    2.24 +x86_64-softmmu
    2.25 +sparc64-user
    2.26 +sparc64-softmmu
    2.27 +mips-softmmu
    2.28 +mipsel-softmmu
    2.29 +mips-user
    2.30 +mipsel-user
    2.31 +sh4-user
    2.32 +sh4-softmmu
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/ioemu/COPYING	Wed Jul 12 19:16:10 2006 +0100
     3.3 @@ -0,0 +1,339 @@
     3.4 +		    GNU GENERAL PUBLIC LICENSE
     3.5 +		       Version 2, June 1991
     3.6 +
     3.7 + Copyright (C) 1989, 1991 Free Software Foundation, Inc.
     3.8 +                          675 Mass Ave, Cambridge, MA 02139, USA
     3.9 + Everyone is permitted to copy and distribute verbatim copies
    3.10 + of this license document, but changing it is not allowed.
    3.11 +
    3.12 +			    Preamble
    3.13 +
    3.14 +  The licenses for most software are designed to take away your
    3.15 +freedom to share and change it.  By contrast, the GNU General Public
    3.16 +License is intended to guarantee your freedom to share and change free
    3.17 +software--to make sure the software is free for all its users.  This
    3.18 +General Public License applies to most of the Free Software
    3.19 +Foundation's software and to any other program whose authors commit to
    3.20 +using it.  (Some other Free Software Foundation software is covered by
    3.21 +the GNU Library General Public License instead.)  You can apply it to
    3.22 +your programs, too.
    3.23 +
    3.24 +  When we speak of free software, we are referring to freedom, not
    3.25 +price.  Our General Public Licenses are designed to make sure that you
    3.26 +have the freedom to distribute copies of free software (and charge for
    3.27 +this service if you wish), that you receive source code or can get it
    3.28 +if you want it, that you can change the software or use pieces of it
    3.29 +in new free programs; and that you know you can do these things.
    3.30 +
    3.31 +  To protect your rights, we need to make restrictions that forbid
    3.32 +anyone to deny you these rights or to ask you to surrender the rights.
    3.33 +These restrictions translate to certain responsibilities for you if you
    3.34 +distribute copies of the software, or if you modify it.
    3.35 +
    3.36 +  For example, if you distribute copies of such a program, whether
    3.37 +gratis or for a fee, you must give the recipients all the rights that
    3.38 +you have.  You must make sure that they, too, receive or can get the
    3.39 +source code.  And you must show them these terms so they know their
    3.40 +rights.
    3.41 +
    3.42 +  We protect your rights with two steps: (1) copyright the software, and
    3.43 +(2) offer you this license which gives you legal permission to copy,
    3.44 +distribute and/or modify the software.
    3.45 +
    3.46 +  Also, for each author's protection and ours, we want to make certain
    3.47 +that everyone understands that there is no warranty for this free
    3.48 +software.  If the software is modified by someone else and passed on, we
    3.49 +want its recipients to know that what they have is not the original, so
    3.50 +that any problems introduced by others will not reflect on the original
    3.51 +authors' reputations.
    3.52 +
    3.53 +  Finally, any free program is threatened constantly by software
    3.54 +patents.  We wish to avoid the danger that redistributors of a free
    3.55 +program will individually obtain patent licenses, in effect making the
    3.56 +program proprietary.  To prevent this, we have made it clear that any
    3.57 +patent must be licensed for everyone's free use or not licensed at all.
    3.58 +
    3.59 +  The precise terms and conditions for copying, distribution and
    3.60 +modification follow.
    3.61 +
    3.62 +		    GNU GENERAL PUBLIC LICENSE
    3.63 +   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
    3.64 +
    3.65 +  0. This License applies to any program or other work which contains
    3.66 +a notice placed by the copyright holder saying it may be distributed
    3.67 +under the terms of this General Public License.  The "Program", below,
    3.68 +refers to any such program or work, and a "work based on the Program"
    3.69 +means either the Program or any derivative work under copyright law:
    3.70 +that is to say, a work containing the Program or a portion of it,
    3.71 +either verbatim or with modifications and/or translated into another
    3.72 +language.  (Hereinafter, translation is included without limitation in
    3.73 +the term "modification".)  Each licensee is addressed as "you".
    3.74 +
    3.75 +Activities other than copying, distribution and modification are not
    3.76 +covered by this License; they are outside its scope.  The act of
    3.77 +running the Program is not restricted, and the output from the Program
    3.78 +is covered only if its contents constitute a work based on the
    3.79 +Program (independent of having been made by running the Program).
    3.80 +Whether that is true depends on what the Program does.
    3.81 +
    3.82 +  1. You may copy and distribute verbatim copies of the Program's
    3.83 +source code as you receive it, in any medium, provided that you
    3.84 +conspicuously and appropriately publish on each copy an appropriate
    3.85 +copyright notice and disclaimer of warranty; keep intact all the
    3.86 +notices that refer to this License and to the absence of any warranty;
    3.87 +and give any other recipients of the Program a copy of this License
    3.88 +along with the Program.
    3.89 +
    3.90 +You may charge a fee for the physical act of transferring a copy, and
    3.91 +you may at your option offer warranty protection in exchange for a fee.
    3.92 +
    3.93 +  2. You may modify your copy or copies of the Program or any portion
    3.94 +of it, thus forming a work based on the Program, and copy and
    3.95 +distribute such modifications or work under the terms of Section 1
    3.96 +above, provided that you also meet all of these conditions:
    3.97 +
    3.98 +    a) You must cause the modified files to carry prominent notices
    3.99 +    stating that you changed the files and the date of any change.
   3.100 +
   3.101 +    b) You must cause any work that you distribute or publish, that in
   3.102 +    whole or in part contains or is derived from the Program or any
   3.103 +    part thereof, to be licensed as a whole at no charge to all third
   3.104 +    parties under the terms of this License.
   3.105 +
   3.106 +    c) If the modified program normally reads commands interactively
   3.107 +    when run, you must cause it, when started running for such
   3.108 +    interactive use in the most ordinary way, to print or display an
   3.109 +    announcement including an appropriate copyright notice and a
   3.110 +    notice that there is no warranty (or else, saying that you provide
   3.111 +    a warranty) and that users may redistribute the program under
   3.112 +    these conditions, and telling the user how to view a copy of this
   3.113 +    License.  (Exception: if the Program itself is interactive but
   3.114 +    does not normally print such an announcement, your work based on
   3.115 +    the Program is not required to print an announcement.)
   3.116 +
   3.117 +These requirements apply to the modified work as a whole.  If
   3.118 +identifiable sections of that work are not derived from the Program,
   3.119 +and can be reasonably considered independent and separate works in
   3.120 +themselves, then this License, and its terms, do not apply to those
   3.121 +sections when you distribute them as separate works.  But when you
   3.122 +distribute the same sections as part of a whole which is a work based
   3.123 +on the Program, the distribution of the whole must be on the terms of
   3.124 +this License, whose permissions for other licensees extend to the
   3.125 +entire whole, and thus to each and every part regardless of who wrote it.
   3.126 +
   3.127 +Thus, it is not the intent of this section to claim rights or contest
   3.128 +your rights to work written entirely by you; rather, the intent is to
   3.129 +exercise the right to control the distribution of derivative or
   3.130 +collective works based on the Program.
   3.131 +
   3.132 +In addition, mere aggregation of another work not based on the Program
   3.133 +with the Program (or with a work based on the Program) on a volume of
   3.134 +a storage or distribution medium does not bring the other work under
   3.135 +the scope of this License.
   3.136 +
   3.137 +  3. You may copy and distribute the Program (or a work based on it,
   3.138 +under Section 2) in object code or executable form under the terms of
   3.139 +Sections 1 and 2 above provided that you also do one of the following:
   3.140 +
   3.141 +    a) Accompany it with the complete corresponding machine-readable
   3.142 +    source code, which must be distributed under the terms of Sections
   3.143 +    1 and 2 above on a medium customarily used for software interchange; or,
   3.144 +
   3.145 +    b) Accompany it with a written offer, valid for at least three
   3.146 +    years, to give any third party, for a charge no more than your
   3.147 +    cost of physically performing source distribution, a complete
   3.148 +    machine-readable copy of the corresponding source code, to be
   3.149 +    distributed under the terms of Sections 1 and 2 above on a medium
   3.150 +    customarily used for software interchange; or,
   3.151 +
   3.152 +    c) Accompany it with the information you received as to the offer
   3.153 +    to distribute corresponding source code.  (This alternative is
   3.154 +    allowed only for noncommercial distribution and only if you
   3.155 +    received the program in object code or executable form with such
   3.156 +    an offer, in accord with Subsection b above.)
   3.157 +
   3.158 +The source code for a work means the preferred form of the work for
   3.159 +making modifications to it.  For an executable work, complete source
   3.160 +code means all the source code for all modules it contains, plus any
   3.161 +associated interface definition files, plus the scripts used to
   3.162 +control compilation and installation of the executable.  However, as a
   3.163 +special exception, the source code distributed need not include
   3.164 +anything that is normally distributed (in either source or binary
   3.165 +form) with the major components (compiler, kernel, and so on) of the
   3.166 +operating system on which the executable runs, unless that component
   3.167 +itself accompanies the executable.
   3.168 +
   3.169 +If distribution of executable or object code is made by offering
   3.170 +access to copy from a designated place, then offering equivalent
   3.171 +access to copy the source code from the same place counts as
   3.172 +distribution of the source code, even though third parties are not
   3.173 +compelled to copy the source along with the object code.
   3.174 +
   3.175 +  4. You may not copy, modify, sublicense, or distribute the Program
   3.176 +except as expressly provided under this License.  Any attempt
   3.177 +otherwise to copy, modify, sublicense or distribute the Program is
   3.178 +void, and will automatically terminate your rights under this License.
   3.179 +However, parties who have received copies, or rights, from you under
   3.180 +this License will not have their licenses terminated so long as such
   3.181 +parties remain in full compliance.
   3.182 +
   3.183 +  5. You are not required to accept this License, since you have not
   3.184 +signed it.  However, nothing else grants you permission to modify or
   3.185 +distribute the Program or its derivative works.  These actions are
   3.186 +prohibited by law if you do not accept this License.  Therefore, by
   3.187 +modifying or distributing the Program (or any work based on the
   3.188 +Program), you indicate your acceptance of this License to do so, and
   3.189 +all its terms and conditions for copying, distributing or modifying
   3.190 +the Program or works based on it.
   3.191 +
   3.192 +  6. Each time you redistribute the Program (or any work based on the
   3.193 +Program), the recipient automatically receives a license from the
   3.194 +original licensor to copy, distribute or modify the Program subject to
   3.195 +these terms and conditions.  You may not impose any further
   3.196 +restrictions on the recipients' exercise of the rights granted herein.
   3.197 +You are not responsible for enforcing compliance by third parties to
   3.198 +this License.
   3.199 +
   3.200 +  7. If, as a consequence of a court judgment or allegation of patent
   3.201 +infringement or for any other reason (not limited to patent issues),
   3.202 +conditions are imposed on you (whether by court order, agreement or
   3.203 +otherwise) that contradict the conditions of this License, they do not
   3.204 +excuse you from the conditions of this License.  If you cannot
   3.205 +distribute so as to satisfy simultaneously your obligations under this
   3.206 +License and any other pertinent obligations, then as a consequence you
   3.207 +may not distribute the Program at all.  For example, if a patent
   3.208 +license would not permit royalty-free redistribution of the Program by
   3.209 +all those who receive copies directly or indirectly through you, then
   3.210 +the only way you could satisfy both it and this License would be to
   3.211 +refrain entirely from distribution of the Program.
   3.212 +
   3.213 +If any portion of this section is held invalid or unenforceable under
   3.214 +any particular circumstance, the balance of the section is intended to
   3.215 +apply and the section as a whole is intended to apply in other
   3.216 +circumstances.
   3.217 +
   3.218 +It is not the purpose of this section to induce you to infringe any
   3.219 +patents or other property right claims or to contest validity of any
   3.220 +such claims; this section has the sole purpose of protecting the
   3.221 +integrity of the free software distribution system, which is
   3.222 +implemented by public license practices.  Many people have made
   3.223 +generous contributions to the wide range of software distributed
   3.224 +through that system in reliance on consistent application of that
   3.225 +system; it is up to the author/donor to decide if he or she is willing
   3.226 +to distribute software through any other system and a licensee cannot
   3.227 +impose that choice.
   3.228 +
   3.229 +This section is intended to make thoroughly clear what is believed to
   3.230 +be a consequence of the rest of this License.
   3.231 +
   3.232 +  8. If the distribution and/or use of the Program is restricted in
   3.233 +certain countries either by patents or by copyrighted interfaces, the
   3.234 +original copyright holder who places the Program under this License
   3.235 +may add an explicit geographical distribution limitation excluding
   3.236 +those countries, so that distribution is permitted only in or among
   3.237 +countries not thus excluded.  In such case, this License incorporates
   3.238 +the limitation as if written in the body of this License.
   3.239 +
   3.240 +  9. The Free Software Foundation may publish revised and/or new versions
   3.241 +of the General Public License from time to time.  Such new versions will
   3.242 +be similar in spirit to the present version, but may differ in detail to
   3.243 +address new problems or concerns.
   3.244 +
   3.245 +Each version is given a distinguishing version number.  If the Program
   3.246 +specifies a version number of this License which applies to it and "any
   3.247 +later version", you have the option of following the terms and conditions
   3.248 +either of that version or of any later version published by the Free
   3.249 +Software Foundation.  If the Program does not specify a version number of
   3.250 +this License, you may choose any version ever published by the Free Software
   3.251 +Foundation.
   3.252 +
   3.253 +  10. If you wish to incorporate parts of the Program into other free
   3.254 +programs whose distribution conditions are different, write to the author
   3.255 +to ask for permission.  For software which is copyrighted by the Free
   3.256 +Software Foundation, write to the Free Software Foundation; we sometimes
   3.257 +make exceptions for this.  Our decision will be guided by the two goals
   3.258 +of preserving the free status of all derivatives of our free software and
   3.259 +of promoting the sharing and reuse of software generally.
   3.260 +
   3.261 +			    NO WARRANTY
   3.262 +
   3.263 +  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
   3.264 +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
   3.265 +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
   3.266 +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
   3.267 +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
   3.268 +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
   3.269 +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
   3.270 +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
   3.271 +REPAIR OR CORRECTION.
   3.272 +
   3.273 +  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
   3.274 +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
   3.275 +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
   3.276 +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
   3.277 +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
   3.278 +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
   3.279 +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
   3.280 +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
   3.281 +POSSIBILITY OF SUCH DAMAGES.
   3.282 +
   3.283 +		     END OF TERMS AND CONDITIONS
   3.284 +
   3.285 +	    How to Apply These Terms to Your New Programs
   3.286 +
   3.287 +  If you develop a new program, and you want it to be of the greatest
   3.288 +possible use to the public, the best way to achieve this is to make it
   3.289 +free software which everyone can redistribute and change under these terms.
   3.290 +
   3.291 +  To do so, attach the following notices to the program.  It is safest
   3.292 +to attach them to the start of each source file to most effectively
   3.293 +convey the exclusion of warranty; and each file should have at least
   3.294 +the "copyright" line and a pointer to where the full notice is found.
   3.295 +
   3.296 +    <one line to give the program's name and a brief idea of what it does.>
   3.297 +    Copyright (C) 19yy  <name of author>
   3.298 +
   3.299 +    This program is free software; you can redistribute it and/or modify
   3.300 +    it under the terms of the GNU General Public License as published by
   3.301 +    the Free Software Foundation; either version 2 of the License, or
   3.302 +    (at your option) any later version.
   3.303 +
   3.304 +    This program is distributed in the hope that it will be useful,
   3.305 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   3.306 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   3.307 +    GNU General Public License for more details.
   3.308 +
   3.309 +    You should have received a copy of the GNU General Public License
   3.310 +    along with this program; if not, write to the Free Software
   3.311 +    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   3.312 +
   3.313 +Also add information on how to contact you by electronic and paper mail.
   3.314 +
   3.315 +If the program is interactive, make it output a short notice like this
   3.316 +when it starts in an interactive mode:
   3.317 +
   3.318 +    Gnomovision version 69, Copyright (C) 19yy name of author
   3.319 +    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
   3.320 +    This is free software, and you are welcome to redistribute it
   3.321 +    under certain conditions; type `show c' for details.
   3.322 +
   3.323 +The hypothetical commands `show w' and `show c' should show the appropriate
   3.324 +parts of the General Public License.  Of course, the commands you use may
   3.325 +be called something other than `show w' and `show c'; they could even be
   3.326 +mouse-clicks or menu items--whatever suits your program.
   3.327 +
   3.328 +You should also get your employer (if you work as a programmer) or your
   3.329 +school, if any, to sign a "copyright disclaimer" for the program, if
   3.330 +necessary.  Here is a sample; alter the names:
   3.331 +
   3.332 +  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
   3.333 +  `Gnomovision' (which makes passes at compilers) written by James Hacker.
   3.334 +
   3.335 +  <signature of Ty Coon>, 1 April 1989
   3.336 +  Ty Coon, President of Vice
   3.337 +
   3.338 +This General Public License does not permit incorporating your program into
   3.339 +proprietary programs.  If your program is a subroutine library, you may
   3.340 +consider it more useful to permit linking proprietary applications with the
   3.341 +library.  If this is what you want to do, use the GNU Library General
   3.342 +Public License instead of this License.
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/tools/ioemu/COPYING.LIB	Wed Jul 12 19:16:10 2006 +0100
     4.3 @@ -0,0 +1,504 @@
     4.4 +		  GNU LESSER GENERAL PUBLIC LICENSE
     4.5 +		       Version 2.1, February 1999
     4.6 +
     4.7 + Copyright (C) 1991, 1999 Free Software Foundation, Inc.
     4.8 +     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
     4.9 + Everyone is permitted to copy and distribute verbatim copies
    4.10 + of this license document, but changing it is not allowed.
    4.11 +
    4.12 +[This is the first released version of the Lesser GPL.  It also counts
    4.13 + as the successor of the GNU Library Public License, version 2, hence
    4.14 + the version number 2.1.]
    4.15 +
    4.16 +			    Preamble
    4.17 +
    4.18 +  The licenses for most software are designed to take away your
    4.19 +freedom to share and change it.  By contrast, the GNU General Public
    4.20 +Licenses are intended to guarantee your freedom to share and change
    4.21 +free software--to make sure the software is free for all its users.
    4.22 +
    4.23 +  This license, the Lesser General Public License, applies to some
    4.24 +specially designated software packages--typically libraries--of the
    4.25 +Free Software Foundation and other authors who decide to use it.  You
    4.26 +can use it too, but we suggest you first think carefully about whether
    4.27 +this license or the ordinary General Public License is the better
    4.28 +strategy to use in any particular case, based on the explanations below.
    4.29 +
    4.30 +  When we speak of free software, we are referring to freedom of use,
    4.31 +not price.  Our General Public Licenses are designed to make sure that
    4.32 +you have the freedom to distribute copies of free software (and charge
    4.33 +for this service if you wish); that you receive source code or can get
    4.34 +it if you want it; that you can change the software and use pieces of
    4.35 +it in new free programs; and that you are informed that you can do
    4.36 +these things.
    4.37 +
    4.38 +  To protect your rights, we need to make restrictions that forbid
    4.39 +distributors to deny you these rights or to ask you to surrender these
    4.40 +rights.  These restrictions translate to certain responsibilities for
    4.41 +you if you distribute copies of the library or if you modify it.
    4.42 +
    4.43 +  For example, if you distribute copies of the library, whether gratis
    4.44 +or for a fee, you must give the recipients all the rights that we gave
    4.45 +you.  You must make sure that they, too, receive or can get the source
    4.46 +code.  If you link other code with the library, you must provide
    4.47 +complete object files to the recipients, so that they can relink them
    4.48 +with the library after making changes to the library and recompiling
    4.49 +it.  And you must show them these terms so they know their rights.
    4.50 +
    4.51 +  We protect your rights with a two-step method: (1) we copyright the
    4.52 +library, and (2) we offer you this license, which gives you legal
    4.53 +permission to copy, distribute and/or modify the library.
    4.54 +
    4.55 +  To protect each distributor, we want to make it very clear that
    4.56 +there is no warranty for the free library.  Also, if the library is
    4.57 +modified by someone else and passed on, the recipients should know
    4.58 +that what they have is not the original version, so that the original
    4.59 +author's reputation will not be affected by problems that might be
    4.60 +introduced by others.
    4.61 +
    4.62 +  Finally, software patents pose a constant threat to the existence of
    4.63 +any free program.  We wish to make sure that a company cannot
    4.64 +effectively restrict the users of a free program by obtaining a
    4.65 +restrictive license from a patent holder.  Therefore, we insist that
    4.66 +any patent license obtained for a version of the library must be
    4.67 +consistent with the full freedom of use specified in this license.
    4.68 +
    4.69 +  Most GNU software, including some libraries, is covered by the
    4.70 +ordinary GNU General Public License.  This license, the GNU Lesser
    4.71 +General Public License, applies to certain designated libraries, and
    4.72 +is quite different from the ordinary General Public License.  We use
    4.73 +this license for certain libraries in order to permit linking those
    4.74 +libraries into non-free programs.
    4.75 +
    4.76 +  When a program is linked with a library, whether statically or using
    4.77 +a shared library, the combination of the two is legally speaking a
    4.78 +combined work, a derivative of the original library.  The ordinary
    4.79 +General Public License therefore permits such linking only if the
    4.80 +entire combination fits its criteria of freedom.  The Lesser General
    4.81 +Public License permits more lax criteria for linking other code with
    4.82 +the library.
    4.83 +
    4.84 +  We call this license the "Lesser" General Public License because it
    4.85 +does Less to protect the user's freedom than the ordinary General
    4.86 +Public License.  It also provides other free software developers Less
    4.87 +of an advantage over competing non-free programs.  These disadvantages
    4.88 +are the reason we use the ordinary General Public License for many
    4.89 +libraries.  However, the Lesser license provides advantages in certain
    4.90 +special circumstances.
    4.91 +
    4.92 +  For example, on rare occasions, there may be a special need to
    4.93 +encourage the widest possible use of a certain library, so that it becomes
    4.94 +a de-facto standard.  To achieve this, non-free programs must be
    4.95 +allowed to use the library.  A more frequent case is that a free
    4.96 +library does the same job as widely used non-free libraries.  In this
    4.97 +case, there is little to gain by limiting the free library to free
    4.98 +software only, so we use the Lesser General Public License.
    4.99 +
   4.100 +  In other cases, permission to use a particular library in non-free
   4.101 +programs enables a greater number of people to use a large body of
   4.102 +free software.  For example, permission to use the GNU C Library in
   4.103 +non-free programs enables many more people to use the whole GNU
   4.104 +operating system, as well as its variant, the GNU/Linux operating
   4.105 +system.
   4.106 +
   4.107 +  Although the Lesser General Public License is Less protective of the
   4.108 +users' freedom, it does ensure that the user of a program that is
   4.109 +linked with the Library has the freedom and the wherewithal to run
   4.110 +that program using a modified version of the Library.
   4.111 +
   4.112 +  The precise terms and conditions for copying, distribution and
   4.113 +modification follow.  Pay close attention to the difference between a
   4.114 +"work based on the library" and a "work that uses the library".  The
   4.115 +former contains code derived from the library, whereas the latter must
   4.116 +be combined with the library in order to run.
   4.117 +
   4.118 +		  GNU LESSER GENERAL PUBLIC LICENSE
   4.119 +   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
   4.120 +
   4.121 +  0. This License Agreement applies to any software library or other
   4.122 +program which contains a notice placed by the copyright holder or
   4.123 +other authorized party saying it may be distributed under the terms of
   4.124 +this Lesser General Public License (also called "this License").
   4.125 +Each licensee is addressed as "you".
   4.126 +
   4.127 +  A "library" means a collection of software functions and/or data
   4.128 +prepared so as to be conveniently linked with application programs
   4.129 +(which use some of those functions and data) to form executables.
   4.130 +
   4.131 +  The "Library", below, refers to any such software library or work
   4.132 +which has been distributed under these terms.  A "work based on the
   4.133 +Library" means either the Library or any derivative work under
   4.134 +copyright law: that is to say, a work containing the Library or a
   4.135 +portion of it, either verbatim or with modifications and/or translated
   4.136 +straightforwardly into another language.  (Hereinafter, translation is
   4.137 +included without limitation in the term "modification".)
   4.138 +
   4.139 +  "Source code" for a work means the preferred form of the work for
   4.140 +making modifications to it.  For a library, complete source code means
   4.141 +all the source code for all modules it contains, plus any associated
   4.142 +interface definition files, plus the scripts used to control compilation
   4.143 +and installation of the library.
   4.144 +
   4.145 +  Activities other than copying, distribution and modification are not
   4.146 +covered by this License; they are outside its scope.  The act of
   4.147 +running a program using the Library is not restricted, and output from
   4.148 +such a program is covered only if its contents constitute a work based
   4.149 +on the Library (independent of the use of the Library in a tool for
   4.150 +writing it).  Whether that is true depends on what the Library does
   4.151 +and what the program that uses the Library does.
   4.152 +  
   4.153 +  1. You may copy and distribute verbatim copies of the Library's
   4.154 +complete source code as you receive it, in any medium, provided that
   4.155 +you conspicuously and appropriately publish on each copy an
   4.156 +appropriate copyright notice and disclaimer of warranty; keep intact
   4.157 +all the notices that refer to this License and to the absence of any
   4.158 +warranty; and distribute a copy of this License along with the
   4.159 +Library.
   4.160 +
   4.161 +  You may charge a fee for the physical act of transferring a copy,
   4.162 +and you may at your option offer warranty protection in exchange for a
   4.163 +fee.
   4.164 +
   4.165 +  2. You may modify your copy or copies of the Library or any portion
   4.166 +of it, thus forming a work based on the Library, and copy and
   4.167 +distribute such modifications or work under the terms of Section 1
   4.168 +above, provided that you also meet all of these conditions:
   4.169 +
   4.170 +    a) The modified work must itself be a software library.
   4.171 +
   4.172 +    b) You must cause the files modified to carry prominent notices
   4.173 +    stating that you changed the files and the date of any change.
   4.174 +
   4.175 +    c) You must cause the whole of the work to be licensed at no
   4.176 +    charge to all third parties under the terms of this License.
   4.177 +
   4.178 +    d) If a facility in the modified Library refers to a function or a
   4.179 +    table of data to be supplied by an application program that uses
   4.180 +    the facility, other than as an argument passed when the facility
   4.181 +    is invoked, then you must make a good faith effort to ensure that,
   4.182 +    in the event an application does not supply such function or
   4.183 +    table, the facility still operates, and performs whatever part of
   4.184 +    its purpose remains meaningful.
   4.185 +
   4.186 +    (For example, a function in a library to compute square roots has
   4.187 +    a purpose that is entirely well-defined independent of the
   4.188 +    application.  Therefore, Subsection 2d requires that any
   4.189 +    application-supplied function or table used by this function must
   4.190 +    be optional: if the application does not supply it, the square
   4.191 +    root function must still compute square roots.)
   4.192 +
   4.193 +These requirements apply to the modified work as a whole.  If
   4.194 +identifiable sections of that work are not derived from the Library,
   4.195 +and can be reasonably considered independent and separate works in
   4.196 +themselves, then this License, and its terms, do not apply to those
   4.197 +sections when you distribute them as separate works.  But when you
   4.198 +distribute the same sections as part of a whole which is a work based
   4.199 +on the Library, the distribution of the whole must be on the terms of
   4.200 +this License, whose permissions for other licensees extend to the
   4.201 +entire whole, and thus to each and every part regardless of who wrote
   4.202 +it.
   4.203 +
   4.204 +Thus, it is not the intent of this section to claim rights or contest
   4.205 +your rights to work written entirely by you; rather, the intent is to
   4.206 +exercise the right to control the distribution of derivative or
   4.207 +collective works based on the Library.
   4.208 +
   4.209 +In addition, mere aggregation of another work not based on the Library
   4.210 +with the Library (or with a work based on the Library) on a volume of
   4.211 +a storage or distribution medium does not bring the other work under
   4.212 +the scope of this License.
   4.213 +
   4.214 +  3. You may opt to apply the terms of the ordinary GNU General Public
   4.215 +License instead of this License to a given copy of the Library.  To do
   4.216 +this, you must alter all the notices that refer to this License, so
   4.217 +that they refer to the ordinary GNU General Public License, version 2,
   4.218 +instead of to this License.  (If a newer version than version 2 of the
   4.219 +ordinary GNU General Public License has appeared, then you can specify
   4.220 +that version instead if you wish.)  Do not make any other change in
   4.221 +these notices.
   4.222 +
   4.223 +  Once this change is made in a given copy, it is irreversible for
   4.224 +that copy, so the ordinary GNU General Public License applies to all
   4.225 +subsequent copies and derivative works made from that copy.
   4.226 +
   4.227 +  This option is useful when you wish to copy part of the code of
   4.228 +the Library into a program that is not a library.
   4.229 +
   4.230 +  4. You may copy and distribute the Library (or a portion or
   4.231 +derivative of it, under Section 2) in object code or executable form
   4.232 +under the terms of Sections 1 and 2 above provided that you accompany
   4.233 +it with the complete corresponding machine-readable source code, which
   4.234 +must be distributed under the terms of Sections 1 and 2 above on a
   4.235 +medium customarily used for software interchange.
   4.236 +
   4.237 +  If distribution of object code is made by offering access to copy
   4.238 +from a designated place, then offering equivalent access to copy the
   4.239 +source code from the same place satisfies the requirement to
   4.240 +distribute the source code, even though third parties are not
   4.241 +compelled to copy the source along with the object code.
   4.242 +
   4.243 +  5. A program that contains no derivative of any portion of the
   4.244 +Library, but is designed to work with the Library by being compiled or
   4.245 +linked with it, is called a "work that uses the Library".  Such a
   4.246 +work, in isolation, is not a derivative work of the Library, and
   4.247 +therefore falls outside the scope of this License.
   4.248 +
   4.249 +  However, linking a "work that uses the Library" with the Library
   4.250 +creates an executable that is a derivative of the Library (because it
   4.251 +contains portions of the Library), rather than a "work that uses the
   4.252 +library".  The executable is therefore covered by this License.
   4.253 +Section 6 states terms for distribution of such executables.
   4.254 +
   4.255 +  When a "work that uses the Library" uses material from a header file
   4.256 +that is part of the Library, the object code for the work may be a
   4.257 +derivative work of the Library even though the source code is not.
   4.258 +Whether this is true is especially significant if the work can be
   4.259 +linked without the Library, or if the work is itself a library.  The
   4.260 +threshold for this to be true is not precisely defined by law.
   4.261 +
   4.262 +  If such an object file uses only numerical parameters, data
   4.263 +structure layouts and accessors, and small macros and small inline
   4.264 +functions (ten lines or less in length), then the use of the object
   4.265 +file is unrestricted, regardless of whether it is legally a derivative
   4.266 +work.  (Executables containing this object code plus portions of the
   4.267 +Library will still fall under Section 6.)
   4.268 +
   4.269 +  Otherwise, if the work is a derivative of the Library, you may
   4.270 +distribute the object code for the work under the terms of Section 6.
   4.271 +Any executables containing that work also fall under Section 6,
   4.272 +whether or not they are linked directly with the Library itself.
   4.273 +
   4.274 +  6. As an exception to the Sections above, you may also combine or
   4.275 +link a "work that uses the Library" with the Library to produce a
   4.276 +work containing portions of the Library, and distribute that work
   4.277 +under terms of your choice, provided that the terms permit
   4.278 +modification of the work for the customer's own use and reverse
   4.279 +engineering for debugging such modifications.
   4.280 +
   4.281 +  You must give prominent notice with each copy of the work that the
   4.282 +Library is used in it and that the Library and its use are covered by
   4.283 +this License.  You must supply a copy of this License.  If the work
   4.284 +during execution displays copyright notices, you must include the
   4.285 +copyright notice for the Library among them, as well as a reference
   4.286 +directing the user to the copy of this License.  Also, you must do one
   4.287 +of these things:
   4.288 +
   4.289 +    a) Accompany the work with the complete corresponding
   4.290 +    machine-readable source code for the Library including whatever
   4.291 +    changes were used in the work (which must be distributed under
   4.292 +    Sections 1 and 2 above); and, if the work is an executable linked
   4.293 +    with the Library, with the complete machine-readable "work that
   4.294 +    uses the Library", as object code and/or source code, so that the
   4.295 +    user can modify the Library and then relink to produce a modified
   4.296 +    executable containing the modified Library.  (It is understood
   4.297 +    that the user who changes the contents of definitions files in the
   4.298 +    Library will not necessarily be able to recompile the application
   4.299 +    to use the modified definitions.)
   4.300 +
   4.301 +    b) Use a suitable shared library mechanism for linking with the
   4.302 +    Library.  A suitable mechanism is one that (1) uses at run time a
   4.303 +    copy of the library already present on the user's computer system,
   4.304 +    rather than copying library functions into the executable, and (2)
   4.305 +    will operate properly with a modified version of the library, if
   4.306 +    the user installs one, as long as the modified version is
   4.307 +    interface-compatible with the version that the work was made with.
   4.308 +
   4.309 +    c) Accompany the work with a written offer, valid for at
   4.310 +    least three years, to give the same user the materials
   4.311 +    specified in Subsection 6a, above, for a charge no more
   4.312 +    than the cost of performing this distribution.
   4.313 +
   4.314 +    d) If distribution of the work is made by offering access to copy
   4.315 +    from a designated place, offer equivalent access to copy the above
   4.316 +    specified materials from the same place.
   4.317 +
   4.318 +    e) Verify that the user has already received a copy of these
   4.319 +    materials or that you have already sent this user a copy.
   4.320 +
   4.321 +  For an executable, the required form of the "work that uses the
   4.322 +Library" must include any data and utility programs needed for
   4.323 +reproducing the executable from it.  However, as a special exception,
   4.324 +the materials to be distributed need not include anything that is
   4.325 +normally distributed (in either source or binary form) with the major
   4.326 +components (compiler, kernel, and so on) of the operating system on
   4.327 +which the executable runs, unless that component itself accompanies
   4.328 +the executable.
   4.329 +
   4.330 +  It may happen that this requirement contradicts the license
   4.331 +restrictions of other proprietary libraries that do not normally
   4.332 +accompany the operating system.  Such a contradiction means you cannot
   4.333 +use both them and the Library together in an executable that you
   4.334 +distribute.
   4.335 +
   4.336 +  7. You may place library facilities that are a work based on the
   4.337 +Library side-by-side in a single library together with other library
   4.338 +facilities not covered by this License, and distribute such a combined
   4.339 +library, provided that the separate distribution of the work based on
   4.340 +the Library and of the other library facilities is otherwise
   4.341 +permitted, and provided that you do these two things:
   4.342 +
   4.343 +    a) Accompany the combined library with a copy of the same work
   4.344 +    based on the Library, uncombined with any other library
   4.345 +    facilities.  This must be distributed under the terms of the
   4.346 +    Sections above.
   4.347 +
   4.348 +    b) Give prominent notice with the combined library of the fact
   4.349 +    that part of it is a work based on the Library, and explaining
   4.350 +    where to find the accompanying uncombined form of the same work.
   4.351 +
   4.352 +  8. You may not copy, modify, sublicense, link with, or distribute
   4.353 +the Library except as expressly provided under this License.  Any
   4.354 +attempt otherwise to copy, modify, sublicense, link with, or
   4.355 +distribute the Library is void, and will automatically terminate your
   4.356 +rights under this License.  However, parties who have received copies,
   4.357 +or rights, from you under this License will not have their licenses
   4.358 +terminated so long as such parties remain in full compliance.
   4.359 +
   4.360 +  9. You are not required to accept this License, since you have not
   4.361 +signed it.  However, nothing else grants you permission to modify or
   4.362 +distribute the Library or its derivative works.  These actions are
   4.363 +prohibited by law if you do not accept this License.  Therefore, by
   4.364 +modifying or distributing the Library (or any work based on the
   4.365 +Library), you indicate your acceptance of this License to do so, and
   4.366 +all its terms and conditions for copying, distributing or modifying
   4.367 +the Library or works based on it.
   4.368 +
   4.369 +  10. Each time you redistribute the Library (or any work based on the
   4.370 +Library), the recipient automatically receives a license from the
   4.371 +original licensor to copy, distribute, link with or modify the Library
   4.372 +subject to these terms and conditions.  You may not impose any further
   4.373 +restrictions on the recipients' exercise of the rights granted herein.
   4.374 +You are not responsible for enforcing compliance by third parties with
   4.375 +this License.
   4.376 +
   4.377 +  11. If, as a consequence of a court judgment or allegation of patent
   4.378 +infringement or for any other reason (not limited to patent issues),
   4.379 +conditions are imposed on you (whether by court order, agreement or
   4.380 +otherwise) that contradict the conditions of this License, they do not
   4.381 +excuse you from the conditions of this License.  If you cannot
   4.382 +distribute so as to satisfy simultaneously your obligations under this
   4.383 +License and any other pertinent obligations, then as a consequence you
   4.384 +may not distribute the Library at all.  For example, if a patent
   4.385 +license would not permit royalty-free redistribution of the Library by
   4.386 +all those who receive copies directly or indirectly through you, then
   4.387 +the only way you could satisfy both it and this License would be to
   4.388 +refrain entirely from distribution of the Library.
   4.389 +
   4.390 +If any portion of this section is held invalid or unenforceable under any
   4.391 +particular circumstance, the balance of the section is intended to apply,
   4.392 +and the section as a whole is intended to apply in other circumstances.
   4.393 +
   4.394 +It is not the purpose of this section to induce you to infringe any
   4.395 +patents or other property right claims or to contest validity of any
   4.396 +such claims; this section has the sole purpose of protecting the
   4.397 +integrity of the free software distribution system which is
   4.398 +implemented by public license practices.  Many people have made
   4.399 +generous contributions to the wide range of software distributed
   4.400 +through that system in reliance on consistent application of that
   4.401 +system; it is up to the author/donor to decide if he or she is willing
   4.402 +to distribute software through any other system and a licensee cannot
   4.403 +impose that choice.
   4.404 +
   4.405 +This section is intended to make thoroughly clear what is believed to
   4.406 +be a consequence of the rest of this License.
   4.407 +
   4.408 +  12. If the distribution and/or use of the Library is restricted in
   4.409 +certain countries either by patents or by copyrighted interfaces, the
   4.410 +original copyright holder who places the Library under this License may add
   4.411 +an explicit geographical distribution limitation excluding those countries,
   4.412 +so that distribution is permitted only in or among countries not thus
   4.413 +excluded.  In such case, this License incorporates the limitation as if
   4.414 +written in the body of this License.
   4.415 +
   4.416 +  13. The Free Software Foundation may publish revised and/or new
   4.417 +versions of the Lesser General Public License from time to time.
   4.418 +Such new versions will be similar in spirit to the present version,
   4.419 +but may differ in detail to address new problems or concerns.
   4.420 +
   4.421 +Each version is given a distinguishing version number.  If the Library
   4.422 +specifies a version number of this License which applies to it and
   4.423 +"any later version", you have the option of following the terms and
   4.424 +conditions either of that version or of any later version published by
   4.425 +the Free Software Foundation.  If the Library does not specify a
   4.426 +license version number, you may choose any version ever published by
   4.427 +the Free Software Foundation.
   4.428 +
   4.429 +  14. If you wish to incorporate parts of the Library into other free
   4.430 +programs whose distribution conditions are incompatible with these,
   4.431 +write to the author to ask for permission.  For software which is
   4.432 +copyrighted by the Free Software Foundation, write to the Free
   4.433 +Software Foundation; we sometimes make exceptions for this.  Our
   4.434 +decision will be guided by the two goals of preserving the free status
   4.435 +of all derivatives of our free software and of promoting the sharing
   4.436 +and reuse of software generally.
   4.437 +
   4.438 +			    NO WARRANTY
   4.439 +
   4.440 +  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
   4.441 +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
   4.442 +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
   4.443 +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
   4.444 +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
   4.445 +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   4.446 +PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
   4.447 +LIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
   4.448 +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
   4.449 +
   4.450 +  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
   4.451 +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
   4.452 +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
   4.453 +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
   4.454 +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
   4.455 +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
   4.456 +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
   4.457 +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
   4.458 +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
   4.459 +DAMAGES.
   4.460 +
   4.461 +		     END OF TERMS AND CONDITIONS
   4.462 +
   4.463 +           How to Apply These Terms to Your New Libraries
   4.464 +
   4.465 +  If you develop a new library, and you want it to be of the greatest
   4.466 +possible use to the public, we recommend making it free software that
   4.467 +everyone can redistribute and change.  You can do so by permitting
   4.468 +redistribution under these terms (or, alternatively, under the terms of the
   4.469 +ordinary General Public License).
   4.470 +
   4.471 +  To apply these terms, attach the following notices to the library.  It is
   4.472 +safest to attach them to the start of each source file to most effectively
   4.473 +convey the exclusion of warranty; and each file should have at least the
   4.474 +"copyright" line and a pointer to where the full notice is found.
   4.475 +
   4.476 +    <one line to give the library's name and a brief idea of what it does.>
   4.477 +    Copyright (C) <year>  <name of author>
   4.478 +
   4.479 +    This library is free software; you can redistribute it and/or
   4.480 +    modify it under the terms of the GNU Lesser General Public
   4.481 +    License as published by the Free Software Foundation; either
   4.482 +    version 2 of the License, or (at your option) any later version.
   4.483 +
   4.484 +    This library is distributed in the hope that it will be useful,
   4.485 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
   4.486 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   4.487 +    Lesser General Public License for more details.
   4.488 +
   4.489 +    You should have received a copy of the GNU Lesser General Public
   4.490 +    License along with this library; if not, write to the Free Software
   4.491 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   4.492 +
   4.493 +Also add information on how to contact you by electronic and paper mail.
   4.494 +
   4.495 +You should also get your employer (if you work as a programmer) or your
   4.496 +school, if any, to sign a "copyright disclaimer" for the library, if
   4.497 +necessary.  Here is a sample; alter the names:
   4.498 +
   4.499 +  Yoyodyne, Inc., hereby disclaims all copyright interest in the
   4.500 +  library `Frob' (a library for tweaking knobs) written by James Random Hacker.
   4.501 +
   4.502 +  <signature of Ty Coon>, 1 April 1990
   4.503 +  Ty Coon, President of Vice
   4.504 +
   4.505 +That's all there is to it!
   4.506 +
   4.507 +
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/tools/ioemu/CVS/Entries	Wed Jul 12 19:16:10 2006 +0100
     5.3 @@ -0,0 +1,109 @@
     5.4 +D/audio////
     5.5 +D/hw////
     5.6 +D/linux-user////
     5.7 +D/pc-bios////
     5.8 +D/slirp////
     5.9 +D/target-arm////
    5.10 +D/target-i386////
    5.11 +D/target-ppc////
    5.12 +D/target-sparc////
    5.13 +D/tests////
    5.14 +D/fpu////
    5.15 +D/keymaps////
    5.16 +D/target-mips////
    5.17 +/.cvsignore/1.13/Thu May 25 18:22:25 2006//Trelease_0_8_1
    5.18 +/COPYING/1.1/Wed May 17 14:47:01 2006//Trelease_0_8_1
    5.19 +/COPYING.LIB/1.2/Wed May 17 14:47:01 2006//Trelease_0_8_1
    5.20 +/Changelog/1.116/Thu May 25 18:22:25 2006//Trelease_0_8_1
    5.21 +/LICENSE/1.2/Sat Feb 12 14:45:23 2005//Trelease_0_8_1
    5.22 +/Makefile/1.99/Thu May 25 18:22:25 2006//Trelease_0_8_1
    5.23 +/Makefile.target/1.107/Thu May 25 18:22:25 2006//Trelease_0_8_1
    5.24 +/README/1.12/Wed May 24 10:40:08 2006//Trelease_0_8_1
    5.25 +/README.distrib/1.2/Wed May 17 14:47:01 2006//Trelease_0_8_1
    5.26 +/TODO/1.38/Thu May 25 18:22:25 2006//Trelease_0_8_1
    5.27 +/VERSION/1.28/Thu May 25 18:22:25 2006//Trelease_0_8_1
    5.28 +/a.out.h/1.2/Wed May 24 10:40:08 2006//Trelease_0_8_1
    5.29 +/aes.c/1.1/Wed May 17 14:47:01 2006//Trelease_0_8_1
    5.30 +/aes.h/1.1/Wed May 17 14:47:01 2006//Trelease_0_8_1
    5.31 +/alpha-dis.c/1.3/Thu May 25 18:22:25 2006//Trelease_0_8_1
    5.32 +/alpha.ld/1.1/Wed May 17 14:47:01 2006//Trelease_0_8_1
    5.33 +/arm-dis.c/1.3/Wed May 24 10:40:08 2006//Trelease_0_8_1
    5.34 +/arm.ld/1.1/Wed May 17 14:47:01 2006//Trelease_0_8_1
    5.35 +/block-bochs.c/1.1/Tue Apr 26 21:34:00 2005//Trelease_0_8_1
    5.36 +/block-cloop.c/1.3/Thu May 25 18:22:25 2006//Trelease_0_8_1
    5.37 +/block-cow.c/1.5/Thu May 25 12:38:49 2006//Trelease_0_8_1
    5.38 +/block-dmg.c/1.4/Thu May 25 18:22:25 2006//Trelease_0_8_1
    5.39 +/block-qcow.c/1.6/Thu May 25 18:22:25 2006//Trelease_0_8_1
    5.40 +/block-vmdk.c/1.7/Thu May 25 18:22:25 2006//Trelease_0_8_1
    5.41 +/block-vpc.c/1.2/Thu May 25 12:38:49 2006//Trelease_0_8_1
    5.42 +/block-vvfat.c/1.5/Thu May 25 18:22:25 2006//Trelease_0_8_1
    5.43 +/block.c/1.26/Thu May 25 18:22:26 2006//Trelease_0_8_1
    5.44 +/block_int.h/1.4/Thu May 25 18:22:26 2006//Trelease_0_8_1
    5.45 +/bswap.h/1.5/Wed May 17 14:47:01 2006//Trelease_0_8_1
    5.46 +/cocoa.m/1.8/Thu May 25 18:22:26 2006//Trelease_0_8_1
    5.47 +/configure/1.100/Thu May 25 18:22:26 2006//Trelease_0_8_1
    5.48 +/console.c/1.5/Thu May 25 18:22:26 2006//Trelease_0_8_1
    5.49 +/cpu-all.h/1.54/Thu May 25 18:22:26 2006//Trelease_0_8_1
    5.50 +/cpu-defs.h/1.15/Thu May 25 18:22:26 2006//Trelease_0_8_1
    5.51 +/cpu-exec.c/1.78/Thu May 25 18:22:26 2006//Trelease_0_8_1
    5.52 +/dis-asm.h/1.11/Thu May 25 18:22:26 2006//Trelease_0_8_1
    5.53 +/disas.c/1.30/Thu May 25 18:22:26 2006//Trelease_0_8_1
    5.54 +/disas.h/1.7/Thu May 25 18:22:26 2006//Trelease_0_8_1
    5.55 +/dyngen-exec.h/1.27/Thu May 25 18:22:26 2006//Trelease_0_8_1
    5.56 +/dyngen-op.h/1.1/Mon Jan  3 23:40:55 2005//Trelease_0_8_1
    5.57 +/dyngen.c/1.42/Thu May 25 18:22:26 2006//Trelease_0_8_1
    5.58 +/dyngen.h/1.10/Thu May 25 18:22:26 2006//Trelease_0_8_1
    5.59 +/elf.h/1.6/Thu May 25 12:38:50 2006//Trelease_0_8_1
    5.60 +/elf_ops.h/1.3/Tue May  2 20:54:12 2006//Trelease_0_8_1
    5.61 +/exec-all.h/1.47/Thu May 25 18:22:26 2006//Trelease_0_8_1
    5.62 +/exec.c/1.79/Thu May 25 18:22:26 2006//Trelease_0_8_1
    5.63 +/gdbstub.c/1.36/Thu May 25 18:22:26 2006//Trelease_0_8_1
    5.64 +/gdbstub.h/1.2/Tue Apr 26 20:42:36 2005//Trelease_0_8_1
    5.65 +/i386-dis.c/1.5/Wed May 17 14:47:01 2006//Trelease_0_8_1
    5.66 +/i386-vl.ld/1.3/Wed May 17 14:47:01 2006//Trelease_0_8_1
    5.67 +/i386.ld/1.2/Wed May 17 14:47:01 2006//Trelease_0_8_1
    5.68 +/ia64.ld/1.1/Thu Apr  7 22:20:28 2005//Trelease_0_8_1
    5.69 +/keymaps.c/1.2/Thu May 25 18:22:26 2006//Trelease_0_8_1
    5.70 +/kqemu.c/1.10/Thu May 25 18:22:26 2006//Trelease_0_8_1
    5.71 +/kqemu.h/1.1/Wed Feb  8 22:39:17 2006//Trelease_0_8_1
    5.72 +/linux-2.6.9-qemu-fast.patch/1.1/Wed Dec  8 23:48:11 2004//Trelease_0_8_1
    5.73 +/loader.c/1.2/Wed Apr 26 22:05:26 2006//Trelease_0_8_1
    5.74 +/m68k-dis.c/1.1/Sun Nov  6 16:52:11 2005//Trelease_0_8_1
    5.75 +/m68k.ld/1.1/Wed May 17 14:47:01 2006//Trelease_0_8_1
    5.76 +/mips-dis.c/1.3/Thu May 25 18:22:28 2006//Trelease_0_8_1
    5.77 +/monitor.c/1.48/Thu May 25 18:22:28 2006//Trelease_0_8_1
    5.78 +/osdep.c/1.10/Wed May 24 10:40:10 2006//Trelease_0_8_1
    5.79 +/osdep.h/1.5/Wed May 24 10:40:10 2006//Trelease_0_8_1
    5.80 +/ppc-dis.c/1.7/Thu May 25 12:38:51 2006//Trelease_0_8_1
    5.81 +/ppc.ld/1.2/Thu May 25 12:38:51 2006//Trelease_0_8_1
    5.82 +/qemu-binfmt-conf.sh/1.4/Thu May 25 18:22:28 2006//Trelease_0_8_1
    5.83 +/qemu-doc.texi/1.87/Thu May 25 18:22:29 2006//Trelease_0_8_1
    5.84 +/qemu-img.c/1.8/Thu May 25 12:38:51 2006//Trelease_0_8_1
    5.85 +/qemu-img.texi/1.2/Thu May 25 12:38:51 2006//Trelease_0_8_1
    5.86 +/qemu-tech.texi/1.9/Thu May 25 18:22:29 2006//Trelease_0_8_1
    5.87 +/qemu_socket.h/1.1/Sun Apr 30 22:53:25 2006//Trelease_0_8_1
    5.88 +/readline.c/1.1/Tue May 23 19:16:56 2006//Trelease_0_8_1
    5.89 +/s390.ld/1.1/Wed May 17 14:47:01 2006//Trelease_0_8_1
    5.90 +/sdl.c/1.26/Thu May 25 18:22:29 2006//Trelease_0_8_1
    5.91 +/sdl_keysym.h/1.3/Tue Mar  1 21:43:41 2005//Trelease_0_8_1
    5.92 +/sh4-dis.c/1.1/Thu Apr 27 21:05:14 2006//Trelease_0_8_1
    5.93 +/softmmu_exec.h/1.1/Sun Oct 30 18:16:26 2005//Trelease_0_8_1
    5.94 +/softmmu_header.h/1.13/Thu May 25 18:22:29 2006//Trelease_0_8_1
    5.95 +/softmmu_template.h/1.16/Thu May 25 18:22:29 2006//Trelease_0_8_1
    5.96 +/sparc-dis.c/1.2/Thu May 25 18:22:29 2006//Trelease_0_8_1
    5.97 +/sparc.ld/1.1/Wed May 17 14:47:01 2006//Trelease_0_8_1
    5.98 +/tap-win32.c/1.2/Sun Feb 19 12:40:00 2006//Trelease_0_8_1
    5.99 +/texi2pod.pl/1.1/Wed May 17 14:47:02 2006//Trelease_0_8_1
   5.100 +/thunk.c/1.6/Wed May 24 10:40:10 2006//Trelease_0_8_1
   5.101 +/thunk.h/1.13/Wed May 17 14:47:02 2006//Trelease_0_8_1
   5.102 +/translate-all.c/1.14/Thu May 25 18:22:29 2006//Trelease_0_8_1
   5.103 +/translate-op.c/1.1/Sun Mar 13 16:53:06 2005//Trelease_0_8_1
   5.104 +/usb-linux.c/1.4/Sat Mar 11 18:03:38 2006//Trelease_0_8_1
   5.105 +/vgafont.h/1.1/Wed May 17 14:47:02 2006//Trelease_0_8_1
   5.106 +/vl.c/1.184/Thu May 25 18:22:30 2006//Trelease_0_8_1
   5.107 +/vl.h/1.116/Thu May 25 18:22:30 2006//Trelease_0_8_1
   5.108 +/vnc.c/1.4/Mon May  1 21:44:22 2006//Trelease_0_8_1
   5.109 +/vnc_keysym.h/1.1/Sun Apr 30 21:28:36 2006//Trelease_0_8_1
   5.110 +/vnchextile.h/1.1/Sun Apr 30 21:28:36 2006//Trelease_0_8_1
   5.111 +/x86_64.ld/1.1/Thu Jan  6 20:50:00 2005//Trelease_0_8_1
   5.112 +D/target-sh4////
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/tools/ioemu/CVS/Repository	Wed Jul 12 19:16:10 2006 +0100
     6.3 @@ -0,0 +1,1 @@
     6.4 +qemu
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/tools/ioemu/CVS/Root	Wed Jul 12 19:16:10 2006 +0100
     7.3 @@ -0,0 +1,1 @@
     7.4 +:pserver:anonymous@cvs.savannah.nongnu.org:/sources/qemu
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/tools/ioemu/CVS/Tag	Wed Jul 12 19:16:10 2006 +0100
     8.3 @@ -0,0 +1,1 @@
     8.4 +Nrelease_0_8_1
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/tools/ioemu/Changelog	Wed Jul 12 19:16:10 2006 +0100
     9.3 @@ -0,0 +1,376 @@
     9.4 +version 0.8.1:
     9.5 +
     9.6 +  - USB tablet support (Brad Campbell, Anthony Liguori)
     9.7 +  - win32 host serial support (Kazu)
     9.8 +  - PC speaker support (Joachim Henke)
     9.9 +  - IDE LBA48 support (Jens Axboe)
    9.10 +  - SSE3 support
    9.11 +  - Solaris port (Ben Taylor)
    9.12 +  - Preliminary SH4 target (Samuel Tardieu)
    9.13 +  - VNC server (Anthony Liguori)
    9.14 +  - slirp fixes (Ed Swierk et al.)
    9.15 +  - USB fixes
    9.16 +  - ARM Versatile Platform Baseboard emulation (Paul Brook)
    9.17 +
    9.18 +version 0.8.0:
    9.19 +
    9.20 +  - ARM system emulation: Arm Integrator/CP board with an arm1026ej-s
    9.21 +    cpu (Paul Brook)
    9.22 +  - SMP support
    9.23 +  - Mac OS X cocoa improvements (Mike Kronenberg)
    9.24 +  - Mac OS X CoreAudio driver (Mike Kronenberg)
    9.25 +  - DirectSound driver (malc)
    9.26 +  - ALSA audio driver (malc)
    9.27 +  - new audio options: '-soundhw' and '-audio-help' (malc)
    9.28 +  - ES1370 PCI audio device (malc)
    9.29 +  - Initial USB support
    9.30 +  - Linux host serial port access
    9.31 +  - Linux host low level parallel port access
    9.32 +  - New network emulation code supporting VLANs.
    9.33 +  - MIPS and MIPSel User Linux emulation
    9.34 +  - MIPS fixes to boot Linux (Daniel Jacobowitz)
    9.35 +  - NX bit support
    9.36 +  - Initial SPARC SMP support (Blue Swirl)
    9.37 +  - Major overhaul of the virtual FAT driver for read/write support
    9.38 +    (Johannes Schindelin)
    9.39 +
    9.40 +version 0.7.2:
    9.41 +  
    9.42 +  - x86_64 fixes (Win2000 and Linux 2.6 boot in 32 bit)
    9.43 +  - merge self modifying code handling in dirty ram page mecanism.
    9.44 +  - MIPS fixes (Ralf Baechle)
    9.45 +  - better user net performances
    9.46 +
    9.47 +version 0.7.1:
    9.48 +
    9.49 +  - read-only Virtual FAT support (Johannes Schindelin)
    9.50 +  - Windows 2000 install disk full hack (original idea from Vladimir
    9.51 +    N. Oleynik)
    9.52 +  - VMDK disk image creation (Filip Navara)
    9.53 +  - SPARC64 progress (Blue Swirl)
    9.54 +  - initial MIPS support (Jocelyn mayer)
    9.55 +  - MIPS improvements (Ralf Baechle)
    9.56 +  - 64 bit fixes in user networking (initial patch by Gwenole Beauchesne)
    9.57 +  - IOAPIC support (Filip Navara)
    9.58 +
    9.59 +version 0.7.0:
    9.60 +
    9.61 +  - better BIOS translation and HDD geometry auto-detection
    9.62 +  - user mode networking bug fix
    9.63 +  - undocumented FPU ops support
    9.64 +  - Cirrus VGA: support for 1280x1024x[8,15,16] modes
    9.65 +  - 'pidfile' option
    9.66 +  - .dmg disk image format support (Johannes Schindelin)
    9.67 +  - keymaps support (initial patch by Johannes Schindelin)
    9.68 +  - big endian ARM support (Lennert Buytenhek)
    9.69 +  - added generic 64 bit target support
    9.70 +  - x86_64 target support
    9.71 +  - initial APIC support
    9.72 +  - MMX/SSE/SSE2/PNI support
    9.73 +  - PC parallel port support (Mark Jonckheere)
    9.74 +  - initial SPARC64 support (Blue Swirl)
    9.75 +  - SPARC target boots Linux (Blue Swirl)
    9.76 +  - armv5te user mode support (Paul Brook)
    9.77 +  - ARM VFP support (Paul Brook)
    9.78 +  - ARM "Angel" semihosting syscalls (Paul Brook)
    9.79 +  - user mode gdb stub support (Paul Brook)
    9.80 +  - Samba 3 support
    9.81 +  - initial Cocoa support (Pierre d'Herbemont)
    9.82 +  - generic FPU emulation code
    9.83 +  - Virtual PC read-only disk image support (Alex Beregszaszi)
    9.84 +
    9.85 +version 0.6.1:
    9.86 +
    9.87 +  - Mac OS X port (Pierre d'Herbemont)
    9.88 +  - Virtual console support
    9.89 +  - Better monitor line edition
    9.90 +  - New block device layer 
    9.91 +  - New 'qcow' growable disk image support with AES encryption and
    9.92 +    transparent decompression
    9.93 +  - VMware 3 and 4 read-only disk image support (untested)
    9.94 +  - Support for up to 4 serial ports
    9.95 +  - TFTP server support (Magnus Damm)
    9.96 +  - Port redirection support in user mode networking
    9.97 +  - Support for not executable data sections
    9.98 +  - Compressed loop disk image support (Johannes Schindelin)
    9.99 +  - Level triggered IRQ fix (aka NE2000 PCI performance fix) (Steve
   9.100 +    Wormley)
   9.101 +  - Fixed Fedora Core 2 problems (now you can run qemu without any
   9.102 +    LD_ASSUME_KERNEL tricks on FC2)
   9.103 +  - DHCP fix for Windows (accept DHCPREQUEST alone)
   9.104 +  - SPARC system emulation (Blue Swirl)
   9.105 +  - Automatic Samba configuration for host file access from Windows.
   9.106 +  - '-loadvm' and '-full-screen' options
   9.107 +  - ne2000 savevm support (Johannes Schindelin)
   9.108 +  - Ctrl-Alt is now the default grab key. Ctrl-Alt-[0-9] switches to
   9.109 +    the virtual consoles.
   9.110 +  - BIOS floppy fix for NT4 (Mike Nordell, Derek Fawcus, Volker Ruppert)
   9.111 +  - Floppy fixes for NT4 and NT5 (Mike Nordell)
   9.112 +  - NT4 IDE fixes (Ben Pfaf, Mike Nordell)
   9.113 +  - SDL Audio support and SB16 fixes (malc)
   9.114 +  - ENTER instruction bug fix (initial patch by Stefan Kisdaroczi)
   9.115 +  - VGA font change fix
   9.116 +  - VGA read-only CRTC register fix
   9.117 +
   9.118 +version 0.6.0:
   9.119 +
   9.120 +  - minimalist FPU exception support (NetBSD FPU probe fix)
   9.121 +  - cr0.ET fix (Win95 boot)
   9.122 +  - *BSD port (Markus Niemisto)
   9.123 +  - I/O access fix (signaled by Mark Jonckheere)
   9.124 +  - IDE drives serial number fix (Mike Nordell)
   9.125 +  - int13 CDROM BIOS fix (aka Solaris x86 install CD fix)
   9.126 +  - int15, ah=86 BIOS fix (aka Solaris x86 hardware probe hang up fix)
   9.127 +  - BSR/BSF "undefined behaviour" fix
   9.128 +  - vmdk2raw: convert VMware disk images to raw images
   9.129 +  - PCI support
   9.130 +  - NE2K PCI support
   9.131 +  - dummy VGA PCI support
   9.132 +  - VGA font selection fix (Daniel Serpell)
   9.133 +  - PIC reset fix (Hidemi KAWAI)
   9.134 +  - PIC spurious irq support (aka Solaris install bug)
   9.135 +  - added '-localtime' option
   9.136 +  - Cirrus CL-GD54xx VGA support (initial patch by Makoto Suzuki (suzu))
   9.137 +  - APM and system shutdown support
   9.138 +  - Fixed system reset
   9.139 +  - Support for other PC BIOSes
   9.140 +  - Initial PowerMac hardware emulation
   9.141 +  - PowerMac/PREP OpenFirmware compatible BIOS (Jocelyn Mayer)
   9.142 +  - initial IDE BMDMA support (needed for Darwin x86)
   9.143 +  - Set the default memory size for PC emulation to 128 MB
   9.144 +
   9.145 +version 0.5.5:
   9.146 +
   9.147 +  - SDL full screen support (initial patch by malc)
   9.148 +  - VGA support on PowerPC PREP
   9.149 +  - VBE fixes (Matthew Mastracci)
   9.150 +  - PIT fixes (aka Win98 hardware probe and "VGA slowness" bug)
   9.151 +  - IDE master only fixes (aka Win98 CD-ROM probe bug)
   9.152 +  - ARM load/store half word fix (Ulrich Hecht)
   9.153 +  - FDC fixes for Win98
   9.154 +
   9.155 +version 0.5.4:
   9.156 +  
   9.157 +  - qemu-fast fixes
   9.158 +  - BIOS area protection fix (aka EMM386.EXE fix) (Mike Nordell)
   9.159 +  - keyboard/mouse fix (Mike Nordell)
   9.160 +  - IDE fixes (Linux did not recognized slave drivers)
   9.161 +  - VM86 EIP masking fix (aka NT5 install fix) (Mike Nordell)
   9.162 +  - QEMU can now boot a PowerPC Linux kernel (Jocelyn Mayer)
   9.163 +  - User mode network stack
   9.164 +  - imul imm8 fix + 0x82 opcode support (Hidemi KAWAI)
   9.165 +  - precise self modifying code (aka BeOS install bug)
   9.166 +
   9.167 +version 0.5.3:
   9.168 +
   9.169 +  - added Bochs VESA VBE support
   9.170 +  - VGA memory map mode 3 access fix (OS/2 install fix)
   9.171 +  - IDE fixes (Jens Axboe)
   9.172 +  - CPU interrupt fixes
   9.173 +  - fixed various TLB invalidation cases (NT install)
   9.174 +  - fixed cr0.WP semantics (XP install)
   9.175 +  - direct chaining support for SPARC and PowerPC (faster)
   9.176 +  - ARM NWFPE support (initial patch by Ulrich Hecht)
   9.177 +  - added specific x86 to x86 translator (close to native performance
   9.178 +    in qemu-i386 and qemu-fast)
   9.179 +  - shm syscalls support (Paul McKerras)
   9.180 +  - added accurate CR0.MP/ME/TS emulation
   9.181 +  - fixed DMA memory write access (Win95 boot floppy fix)
   9.182 +  - graphical x86 linux loader
   9.183 +  - command line monitor 
   9.184 +  - generic removable device support
   9.185 +  - support of CD-ROM change
   9.186 +  - multiple network interface support
   9.187 +  - initial x86-64 host support (Gwenole Beauchesne)
   9.188 +  - lret to outer priviledge fix (OS/2 install fix)
   9.189 +  - task switch fixes (SkyOS boot)
   9.190 +  - VM save/restore commands
   9.191 +  - new timer API
   9.192 +  - more precise RTC emulation (periodic timers + time updates)
   9.193 +  - Win32 port (initial patch by Kazu)
   9.194 +
   9.195 +version 0.5.2:
   9.196 +
   9.197 +  - improved soft MMU speed (assembly functions and specializing)
   9.198 +  - improved multitasking speed by avoiding flushing TBs when
   9.199 +    switching tasks
   9.200 +  - improved qemu-fast speed
   9.201 +  - improved self modifying code handling (big performance gain in
   9.202 +    softmmu mode).
   9.203 +  - fixed IO checking
   9.204 +  - fixed CD-ROM detection (win98 install CD)
   9.205 +  - fixed addseg real mode bug (GRUB boot fix)
   9.206 +  - added ROM memory support (win98 boot)
   9.207 +  - fixed 'call Ev' in case of paging exception
   9.208 +  - updated the script 'qemu-binfmt-conf.sh' to use QEMU automagically
   9.209 +    when launching executables for the supported target CPUs.
   9.210 +  - PowerPC system emulation update (Jocelyn Mayer)
   9.211 +  - PC floppy emulation and DMA fixes (Jocelyn Mayer)
   9.212 +  - polled mode for PIC (Jocelyn Mayer)
   9.213 +  - fixed PTE dirty bit handling
   9.214 +  - fixed xadd same reg bug
   9.215 +  - fixed cmpxchg exception safeness
   9.216 +  - access to virtual memory in gdb stub
   9.217 +  - task gate and NT flag fixes
   9.218 +  - eflags optimisation fix for string operations
   9.219 +
   9.220 +version 0.5.1:
   9.221 +  
   9.222 +  - float access fixes when using soft mmu
   9.223 +  - PC emulation support on PowerPC
   9.224 +  - A20 support
   9.225 +  - IDE CD-ROM emulation
   9.226 +  - ARM fixes (Ulrich Hecht)
   9.227 +  - SB16 emulation (malc)
   9.228 +  - IRET and INT fixes in VM86 mode with IOPL=3
   9.229 +  - Port I/Os use TSS io map
   9.230 +  - Full task switching/task gate support
   9.231 +  - added verr, verw, arpl, fcmovxx
   9.232 +  - PowerPC target support (Jocelyn Mayer)
   9.233 +  - Major SPARC target fixes (dynamically linked programs begin to work)
   9.234 +
   9.235 +version 0.5.0:
   9.236 +  
   9.237 +  - full hardware level VGA emulation
   9.238 +  - graphical display with SDL
   9.239 +  - added PS/2 mouse and keyboard emulation
   9.240 +  - popw (%esp) fix
   9.241 +  - mov to/from segment data width fix
   9.242 +  - added real mode support
   9.243 +  - added Bochs BIOS and LGPL'ed VGA BIOS loader in qemu
   9.244 +  - m68k host port (Richard Zidlicky)
   9.245 +  - partial soft MMU support for memory mapped I/Os
   9.246 +  - multi-target build
   9.247 +  - fixed: no error code in hardware interrupts
   9.248 +  - fixed: pop ss, mov ss, x and sti disable hardware irqs for the next insn
   9.249 +  - correct single stepping thru string operations
   9.250 +  - preliminary SPARC target support (Thomas M. Ogrisegg)
   9.251 +  - tun-fd option (Rusty Russell)
   9.252 +  - automatic IDE geometry detection
   9.253 +  - renamed 'vl' to qemu[-fast] and user qemu to qemu-{cpu}.
   9.254 +  - added man page
   9.255 +  - added full soft mmu mode to launch unpatched OSes.
   9.256 +
   9.257 +version 0.4.3:
   9.258 +
   9.259 +  - x86 exception fix in case of nop instruction.
   9.260 +  - gcc 3.2.2 bug workaround (RedHat 9 fix)
   9.261 +  - sparc and Alpha host fixes
   9.262 +  - many ARM target fixes: 'ls' and 'bash' can be launched.
   9.263 +
   9.264 +version 0.4.2:
   9.265 +
   9.266 + - many exception handling fixes (can compile a Linux kernel inside vl)
   9.267 + - IDE emulation support
   9.268 + - initial GDB stub support
   9.269 + - deferred update support for disk images (Rusty Russell)
   9.270 + - accept User Mode Linux Copy On Write disk images
   9.271 + - SMP kernels can at least be booted
   9.272 +
   9.273 +version 0.4.1:
   9.274 +  
   9.275 + - more accurate timer support in vl.
   9.276 + - more reliable NE2000 probe in vl.
   9.277 + - added 2.5.66 kernel in vl-test.
   9.278 + - added VLTMPDIR environment variable in vl.
   9.279 +
   9.280 +version 0.4:
   9.281 +
   9.282 + - initial support for ring 0 x86 processor emulation
   9.283 + - fixed signal handling for correct dosemu DPMI emulation
   9.284 + - fast x86 MMU emulation with mmap()
   9.285 + - fixed popl (%esp) case
   9.286 + - Linux kernel can be executed by QEMU with the 'vl' command.
   9.287 +
   9.288 +version 0.3:
   9.289 +
   9.290 + - initial support for ARM emulation
   9.291 + - added fnsave, frstor, fnstenv, fldenv FPU instructions
   9.292 + - added FPU register save in signal emulation
   9.293 + - initial ARM port
   9.294 + - Sparc and Alpha ports work on the regression test
   9.295 + - generic ioctl number conversion
   9.296 + - fixed ioctl type conversion
   9.297 +
   9.298 +version 0.2:
   9.299 +
   9.300 + - PowerPC disassembly and ELF symbols output (Rusty Russell)
   9.301 + - flock support (Rusty Russell)
   9.302 + - ugetrlimit support (Rusty Russell)
   9.303 + - fstat64 fix (Rusty Russell)
   9.304 + - initial Alpha port (Falk Hueffner)
   9.305 + - initial IA64 port (Matt Wilson)
   9.306 + - initial Sparc and Sparc64 port (David S. Miller)
   9.307 + - added HLT instruction
   9.308 + - LRET instruction fix.
   9.309 + - added GPF generation for I/Os.
   9.310 + - added INT3 and TF flag support.
   9.311 + - SHL instruction C flag fix.
   9.312 + - mmap emulation for host page size > 4KB
   9.313 + - self-modifying code support
   9.314 + - better VM86 support (dosemu works on non trivial programs)
   9.315 + - precise exception support (EIP is computed correctly in most cases)
   9.316 + - more precise LDT/GDT/IDT emulation
   9.317 + - faster segment load in vm86 mode
   9.318 + - direct chaining of basic blocks (faster emulation)
   9.319 +
   9.320 +version 0.1.6:
   9.321 +
   9.322 + - automatic library search system. QEMU can now work with unpatched
   9.323 +   ELF dynamic loader and libc (Rusty Russell).
   9.324 + - ISO C warning fixes (Alistair Strachan)
   9.325 + - first self-virtualizable version (works only as long as the
   9.326 +   translation cache is not flushed)
   9.327 + - RH9 fixes
   9.328 +
   9.329 +version 0.1.5:
   9.330 +
   9.331 + - ppc64 support + personality() patch (Rusty Russell)
   9.332 + - first Alpha CPU patches (Falk Hueffner)
   9.333 + - removed bfd.h dependancy
   9.334 + - fixed shrd, shld, idivl and divl on PowerPC.
   9.335 + - fixed buggy glibc PowerPC rint() function (test-i386 passes now on PowerPC).
   9.336 +
   9.337 +version 0.1.4:
   9.338 +
   9.339 + - more accurate VM86 emulation (can launch small DOS 16 bit
   9.340 +   executables in wine).
   9.341 + - fixed push/pop fs/gs
   9.342 + - added iret instruction.
   9.343 + - added times() syscall and SIOCATMARK ioctl.
   9.344 +
   9.345 +version 0.1.3:
   9.346 +
   9.347 + - S390 support (Ulrich Weigand)
   9.348 + - glibc 2.3.x compile fix (Ulrich Weigand)
   9.349 + - socketcall endian fix (Ulrich Weigand)
   9.350 + - struct sockaddr endian fix (Ulrich Weigand)
   9.351 + - sendmsg/recvmsg endian fix (Ulrich Weigand)
   9.352 + - execve endian fix (Ulrich Weigand)
   9.353 + - fdset endian fix (Ulrich Weigand)
   9.354 + - partial setsockopt syscall support (Ulrich Weigand)
   9.355 + - more accurate pushf/popf emulation
   9.356 + - first partial vm86() syscall support (can be used with runcom example).
   9.357 + - added bound, cmpxchg8b, cpuid instructions
   9.358 + - added 16 bit addressing support/override for string operations
   9.359 + - poll() fix
   9.360 + 
   9.361 +version 0.1.2:
   9.362 +
   9.363 + - compile fixes
   9.364 + - xlat instruction
   9.365 + - xchg instruction memory lock
   9.366 + - added simple vm86 example (not working with QEMU yet). The 54 byte
   9.367 +   DOS executable 'pi_10.com' program was released by Bertram
   9.368 +   Felgenhauer (more information at http://www.boo.net/~jasonp/pipage.html).
   9.369 +
   9.370 +version 0.1.1:
   9.371 +
   9.372 + - glibc 2.2 compilation fixes
   9.373 + - added -s and -L options
   9.374 + - binary distribution of x86 glibc and wine
   9.375 + - big endian fixes in ELF loader and getdents.
   9.376 +
   9.377 +version 0.1:
   9.378 +
   9.379 + - initial public release.
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/tools/ioemu/LICENSE	Wed Jul 12 19:16:10 2006 +0100
    10.3 @@ -0,0 +1,12 @@
    10.4 +The following points clarify the QEMU licenses:
    10.5 +
    10.6 +1) The QEMU virtual CPU core library (libqemu.a) and the QEMU PC
    10.7 +   system emulator are released under the GNU Lesser General Public
    10.8 +   License.
    10.9 +
   10.10 +2) The Linux user mode QEMU emulator is released under the GNU General
   10.11 +   Public License.
   10.12 +
   10.13 +3) QEMU is a trademark of Fabrice Bellard.
   10.14 +
   10.15 +Fabrice Bellard.
   10.16 \ No newline at end of file
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/tools/ioemu/Makefile	Wed Jul 12 19:16:10 2006 +0100
    11.3 @@ -0,0 +1,149 @@
    11.4 +XEN_ROOT=../..
    11.5 +include $(XEN_ROOT)/tools/Rules.mk
    11.6 +
    11.7 +include config-host.mak
    11.8 +
    11.9 +CFLAGS+=-Wall -O2 -g -fno-strict-aliasing -I.
   11.10 +ifdef CONFIG_DARWIN
   11.11 +CFLAGS+= -mdynamic-no-pic
   11.12 +endif
   11.13 +LDFLAGS=-g
   11.14 +LIBS=
   11.15 +DEFINES+=-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
   11.16 +TOOLS=qemu-img$(EXESUF)
   11.17 +ifdef CONFIG_STATIC
   11.18 +LDFLAGS+=-static
   11.19 +endif
   11.20 +ifdef BUILD_DOCS
   11.21 +DOCS=qemu-doc.html qemu-tech.html qemu.1 qemu-img.1
   11.22 +else
   11.23 +DOCS=
   11.24 +endif
   11.25 +
   11.26 +all: $(DOCS)
   11.27 +	for d in $(TARGET_DIRS); do \
   11.28 +	$(MAKE) -C $$d $@ || exit 1 ; \
   11.29 +        done
   11.30 +
   11.31 +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
   11.32 +	$(CC) -DQEMU_TOOL $(CFLAGS) $(LDFLAGS) $(DEFINES) -o $@ $^ -lz $(LIBS)
   11.33 +
   11.34 +dyngen$(EXESUF): dyngen.c
   11.35 +	$(HOST_CC) $(CFLAGS) $(DEFINES) -o $@ $^
   11.36 +
   11.37 +clean:
   11.38 +# avoid old build problems by removing potentially incorrect old files
   11.39 +	rm -f config.mak config.h op-i386.h opc-i386.h gen-op-i386.h op-arm.h opc-arm.h gen-op-arm.h 
   11.40 +	rm -f *.o *.a $(TOOLS) dyngen$(EXESUF) TAGS *.pod *~ */*~
   11.41 +	$(MAKE) -C tests clean
   11.42 +	for d in $(TARGET_DIRS); do \
   11.43 +	$(MAKE) -C $$d $@ || exit 1 ; \
   11.44 +        done
   11.45 +
   11.46 +distclean: clean
   11.47 +	rm -f config-host.mak config-host.h $(DOCS)
   11.48 +	for d in $(TARGET_DIRS); do \
   11.49 +	rm -rf $$d || exit 1 ; \
   11.50 +        done
   11.51 +
   11.52 +KEYMAPS=da     en-gb  et  fr     fr-ch  is  lt  modifiers  no  pt-br  sv \
   11.53 +ar      de     en-us  fi  fr-be  hr     it  lv  nl         pl  ru     th \
   11.54 +common  de-ch  es     fo  fr-ca  hu     ja  mk  nl-be      pt  sl     tr
   11.55 +
   11.56 +install-doc: $(DOCS)
   11.57 +	mkdir -p "$(DESTDIR)$(docdir)"
   11.58 +	$(INSTALL) -m 644 qemu-doc.html  qemu-tech.html "$(DESTDIR)$(docdir)"
   11.59 +ifndef CONFIG_WIN32
   11.60 +	mkdir -p "$(DESTDIR)$(mandir)/man1"
   11.61 +	$(INSTALL) qemu.1 qemu-img.1 "$(DESTDIR)$(mandir)/man1"
   11.62 +endif
   11.63 +
   11.64 +install: all $(if $(BUILD_DOCS),install-doc)
   11.65 +	mkdir -p "$(DESTDIR)$(bindir)"
   11.66 +#	$(INSTALL) -m 755 -s $(TOOLS) "$(DESTDIR)$(bindir)"
   11.67 +#	mkdir -p "$(DESTDIR)$(datadir)"
   11.68 +#	for x in bios.bin vgabios.bin vgabios-cirrus.bin ppc_rom.bin \
   11.69 +#			video.x proll.elf linux_boot.bin; do \
   11.70 +#		$(INSTALL) -m 644 $(SRC_PATH)/pc-bios/$$x "$(DESTDIR)$(datadir)"; \
   11.71 +#	done
   11.72 +ifndef CONFIG_WIN32
   11.73 +	mkdir -p "$(DESTDIR)$(datadir)/keymaps"
   11.74 +	for x in $(KEYMAPS); do \
   11.75 +		$(INSTALL) -m 644 $(SRC_PATH)/keymaps/$$x "$(DESTDIR)$(datadir)/keymaps"; \
   11.76 +	done
   11.77 +endif
   11.78 +	for d in $(TARGET_DIRS); do \
   11.79 +	$(MAKE) -C $$d $@ || exit 1 ; \
   11.80 +        done
   11.81 +
   11.82 +# various test targets
   11.83 +test speed test2: all
   11.84 +	$(MAKE) -C tests $@
   11.85 +
   11.86 +TAGS: 
   11.87 +	etags *.[ch] tests/*.[ch]
   11.88 +
   11.89 +cscope:
   11.90 +	rm -f ./cscope.*
   11.91 +	find . -name "*.[ch]" -print > ./cscope.files
   11.92 +	cscope -b
   11.93 +
   11.94 +# documentation
   11.95 +%.html: %.texi
   11.96 +	texi2html -monolithic -number $<
   11.97 +
   11.98 +%.info: %.texi
   11.99 +	makeinfo $< -o $@
  11.100 +
  11.101 +%.dvi: %.texi
  11.102 +	texi2dvi $<
  11.103 +
  11.104 +qemu.1: qemu-doc.texi
  11.105 +	perl -w $(SRC_PATH)/texi2pod.pl $< qemu.pod
  11.106 +	pod2man --section=1 --center=" " --release=" " qemu.pod > $@
  11.107 +
  11.108 +qemu-img.1: qemu-img.texi
  11.109 +	perl -w $(SRC_PATH)/texi2pod.pl $< qemu-img.pod
  11.110 +	pod2man --section=1 --center=" " --release=" " qemu-img.pod > $@
  11.111 +
  11.112 +FILE=qemu-$(shell cat VERSION)
  11.113 +
  11.114 +# tar release (use 'make -k tar' on a checkouted tree)
  11.115 +tar:
  11.116 +	rm -rf /tmp/$(FILE)
  11.117 +	cp -r . /tmp/$(FILE)
  11.118 +	( cd /tmp ; tar zcvf ~/$(FILE).tar.gz $(FILE) --exclude CVS )
  11.119 +	rm -rf /tmp/$(FILE)
  11.120 +
  11.121 +# generate a binary distribution
  11.122 +tarbin:
  11.123 +	( cd / ; tar zcvf ~/qemu-$(VERSION)-i386.tar.gz \
  11.124 +	$(bindir)/qemu \
  11.125 +	$(bindir)/qemu-system-ppc \
  11.126 +	$(bindir)/qemu-system-sparc \
  11.127 +	$(bindir)/qemu-system-x86_64 \
  11.128 +	$(bindir)/qemu-system-mips \
  11.129 +	$(bindir)/qemu-system-mipsel \
  11.130 +	$(bindir)/qemu-system-arm \
  11.131 +	$(bindir)/qemu-i386 \
  11.132 +        $(bindir)/qemu-arm \
  11.133 +        $(bindir)/qemu-armeb \
  11.134 +        $(bindir)/qemu-sparc \
  11.135 +        $(bindir)/qemu-ppc \
  11.136 +        $(bindir)/qemu-mips \
  11.137 +        $(bindir)/qemu-mipsel \
  11.138 +        $(bindir)/qemu-img \
  11.139 +	$(datadir)/bios.bin \
  11.140 +	$(datadir)/vgabios.bin \
  11.141 +	$(datadir)/vgabios-cirrus.bin \
  11.142 +	$(datadir)/ppc_rom.bin \
  11.143 +	$(datadir)/video.x \
  11.144 +	$(datadir)/proll.elf \
  11.145 +	$(datadir)/linux_boot.bin \
  11.146 +	$(docdir)/qemu-doc.html \
  11.147 +	$(docdir)/qemu-tech.html \
  11.148 +	$(mandir)/man1/qemu.1 $(mandir)/man1/qemu-img.1 )
  11.149 +
  11.150 +ifneq ($(wildcard .depend),)
  11.151 +include .depend
  11.152 +endif
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/tools/ioemu/Makefile.target	Wed Jul 12 19:16:10 2006 +0100
    12.3 @@ -0,0 +1,531 @@
    12.4 +include config.mak
    12.5 +
    12.6 +XEN_ROOT=../../..
    12.7 +include $(XEN_ROOT)/tools/Rules.mk
    12.8 +
    12.9 +TARGET_BASE_ARCH:=$(TARGET_ARCH)
   12.10 +ifeq ($(TARGET_ARCH), x86_64)
   12.11 +TARGET_BASE_ARCH:=i386
   12.12 +endif
   12.13 +ifeq ($(TARGET_ARCH), ppc64)
   12.14 +TARGET_BASE_ARCH:=ppc
   12.15 +endif
   12.16 +ifeq ($(TARGET_ARCH), sparc64)
   12.17 +TARGET_BASE_ARCH:=sparc
   12.18 +endif
   12.19 +TARGET_PATH=$(SRC_PATH)/target-$(TARGET_BASE_ARCH)$(TARGET_SUB)
   12.20 +VPATH=$(SRC_PATH):$(TARGET_PATH):$(SRC_PATH)/hw:$(SRC_PATH)/audio
   12.21 +DEFINES=-I. -I.. -I$(TARGET_PATH) -I$(SRC_PATH)
   12.22 +DEFINES+= -I$(XEN_ROOT)/tools/libxc
   12.23 +DEFINES+= -I$(XEN_ROOT)/tools/xenstore
   12.24 +ifdef CONFIG_USER_ONLY
   12.25 +VPATH+=:$(SRC_PATH)/linux-user
   12.26 +DEFINES+=-I$(SRC_PATH)/linux-user -I$(SRC_PATH)/linux-user/$(TARGET_ARCH)
   12.27 +endif
   12.28 +CFLAGS+=-Wall -O2 -g -fno-strict-aliasing
   12.29 +SSE2 := $(call test-gcc-flag,$(CC),-msse2)
   12.30 +ifeq ($(SSE2),-msse2)
   12.31 +CFLAGS += -DUSE_SSE2=1 -msse2
   12.32 +endif
   12.33 +CFLAGS+= $(LOCAL_CFLAGS)
   12.34 +#CFLAGS+=-Werror
   12.35 +LDFLAGS=-g
   12.36 +LIBS=
   12.37 +HELPER_CFLAGS=$(CFLAGS)
   12.38 +DYNGEN=../dyngen$(EXESUF)
   12.39 +# user emulator name
   12.40 +TARGET_ARCH2=$(TARGET_ARCH)
   12.41 +ifeq ($(TARGET_ARCH),arm)
   12.42 +  ifeq ($(TARGET_WORDS_BIGENDIAN),yes)
   12.43 +    TARGET_ARCH2=armeb
   12.44 +  endif
   12.45 +endif
   12.46 +ifeq ($(TARGET_ARCH),mips)
   12.47 +  ifneq ($(TARGET_WORDS_BIGENDIAN),yes)
   12.48 +    TARGET_ARCH2=mipsel
   12.49 +  endif
   12.50 +endif
   12.51 +QEMU_USER=qemu-$(TARGET_ARCH2)
   12.52 +# system emulator name
   12.53 +ifdef CONFIG_SOFTMMU
   12.54 +ifeq ($(TARGET_ARCH), i386)
   12.55 +QEMU_SYSTEM=qemu$(EXESUF)
   12.56 +else
   12.57 +QEMU_SYSTEM=qemu-system-$(TARGET_ARCH2)$(EXESUF)
   12.58 +endif
   12.59 +else
   12.60 +QEMU_SYSTEM=qemu-fast
   12.61 +endif
   12.62 +
   12.63 +QEMU_SYSTEM=qemu-dm
   12.64 +
   12.65 +ifdef CONFIG_USER_ONLY
   12.66 +PROGS=$(QEMU_USER)
   12.67 +else
   12.68 +PROGS+=$(QEMU_SYSTEM)
   12.69 +ifndef CONFIG_SOFTMMU
   12.70 +CONFIG_STATIC=y
   12.71 +endif
   12.72 +endif # !CONFIG_USER_ONLY
   12.73 +
   12.74 +ifdef CONFIG_STATIC
   12.75 +LDFLAGS+=-static
   12.76 +endif
   12.77 +
   12.78 +ifeq ($(ARCH),i386)
   12.79 +CFLAGS+=-fomit-frame-pointer
   12.80 +OP_CFLAGS=$(CFLAGS) -mpreferred-stack-boundary=2
   12.81 +ifeq ($(HAVE_GCC3_OPTIONS),yes)
   12.82 +OP_CFLAGS+= -falign-functions=0 -fno-gcse
   12.83 +else
   12.84 +OP_CFLAGS+= -malign-functions=0
   12.85 +endif
   12.86 +
   12.87 +ifdef TARGET_GPROF
   12.88 +USE_I386_LD=y
   12.89 +endif
   12.90 +ifdef CONFIG_STATIC
   12.91 +USE_I386_LD=y
   12.92 +endif
   12.93 +ifdef USE_I386_LD
   12.94 +LDFLAGS+=-Wl,-T,$(SRC_PATH)/i386.ld
   12.95 +else
   12.96 +# WARNING: this LDFLAGS is _very_ tricky : qemu is an ELF shared object
   12.97 +# that the kernel ELF loader considers as an executable. I think this
   12.98 +# is the simplest way to make it self virtualizable!
   12.99 +LDFLAGS+=-Wl,-shared
  12.100 +endif
  12.101 +endif
  12.102 +
  12.103 +ifeq ($(ARCH),x86_64)
  12.104 +OP_CFLAGS=$(CFLAGS) -falign-functions=0
  12.105 +LDFLAGS+=-Wl,-T,$(SRC_PATH)/x86_64.ld
  12.106 +endif
  12.107 +
  12.108 +ifeq ($(ARCH),ppc)
  12.109 +CFLAGS+= -D__powerpc__
  12.110 +OP_CFLAGS=$(CFLAGS)
  12.111 +LDFLAGS+=-Wl,-T,$(SRC_PATH)/ppc.ld
  12.112 +endif
  12.113 +
  12.114 +ifeq ($(ARCH),s390)
  12.115 +OP_CFLAGS=$(CFLAGS)
  12.116 +LDFLAGS+=-Wl,-T,$(SRC_PATH)/s390.ld
  12.117 +endif
  12.118 +
  12.119 +ifeq ($(ARCH),sparc)
  12.120 +CFLAGS+=-m32 -ffixed-g1 -ffixed-g2 -ffixed-g3 -ffixed-g6
  12.121 +LDFLAGS+=-m32
  12.122 +OP_CFLAGS=$(CFLAGS) -fno-delayed-branch -ffixed-i0
  12.123 +HELPER_CFLAGS=$(CFLAGS) -ffixed-i0 -mflat
  12.124 +# -static is used to avoid g1/g3 usage by the dynamic linker
  12.125 +LDFLAGS+=-Wl,-T,$(SRC_PATH)/sparc.ld -static
  12.126 +endif
  12.127 +
  12.128 +ifeq ($(ARCH),sparc64)
  12.129 +CFLAGS+=-m64 -ffixed-g1 -ffixed-g2 -ffixed-g3 -ffixed-g6
  12.130 +LDFLAGS+=-m64
  12.131 +OP_CFLAGS=$(CFLAGS) -fno-delayed-branch -ffixed-i0
  12.132 +endif
  12.133 +
  12.134 +ifeq ($(ARCH),alpha)
  12.135 +# -msmall-data is not used because we want two-instruction relocations
  12.136 +# for the constant constructions
  12.137 +OP_CFLAGS=-Wall -O2 -g
  12.138 +# Ensure there's only a single GP
  12.139 +CFLAGS += -msmall-data
  12.140 +LDFLAGS+=-Wl,-T,$(SRC_PATH)/alpha.ld
  12.141 +endif
  12.142 +
  12.143 +ifeq ($(ARCH),ia64)
  12.144 +CFLAGS += -mno-sdata
  12.145 +OP_CFLAGS=$(CFLAGS)
  12.146 +LDFLAGS+=-Wl,-G0 -Wl,-T,$(SRC_PATH)/ia64.ld
  12.147 +endif
  12.148 +
  12.149 +ifeq ($(ARCH),arm)
  12.150 +OP_CFLAGS=$(CFLAGS) -mno-sched-prolog -fno-omit-frame-pointer
  12.151 +LDFLAGS+=-Wl,-T,$(SRC_PATH)/arm.ld
  12.152 +endif
  12.153 +
  12.154 +ifeq ($(ARCH),m68k)
  12.155 +OP_CFLAGS=$(CFLAGS) -fomit-frame-pointer
  12.156 +LDFLAGS+=-Wl,-T,m68k.ld
  12.157 +endif
  12.158 +
  12.159 +ifeq ($(HAVE_GCC3_OPTIONS),yes)
  12.160 +# very important to generate a return at the end of every operation
  12.161 +OP_CFLAGS+=-fno-reorder-blocks -fno-optimize-sibling-calls
  12.162 +endif
  12.163 +
  12.164 +ifeq ($(CONFIG_DARWIN),yes)
  12.165 +OP_CFLAGS+= -mdynamic-no-pic
  12.166 +LIBS+=-lmx
  12.167 +endif
  12.168 +
  12.169 +#########################################################
  12.170 +
  12.171 +DEFINES+=-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
  12.172 +LIBS+=-lm
  12.173 +LIBS+=-L../../libxc -lxenctrl -lxenguest
  12.174 +LIBS+=-L../../xenstore -lxenstore
  12.175 +LIBS+=-lpthread
  12.176 +ifndef CONFIG_USER_ONLY
  12.177 +LIBS+=-lz
  12.178 +endif
  12.179 +ifdef CONFIG_WIN32
  12.180 +LIBS+=-lwinmm -lws2_32 -liphlpapi
  12.181 +endif
  12.182 +ifdef CONFIG_SOLARIS
  12.183 +LIBS+=-lsocket -lnsl -lresolv
  12.184 +endif
  12.185 +
  12.186 +# profiling code
  12.187 +ifdef TARGET_GPROF
  12.188 +LDFLAGS+=-p
  12.189 +main.o: CFLAGS+=-p
  12.190 +endif
  12.191 +
  12.192 +OBJS= elfload.o main.o syscall.o mmap.o signal.o path.o osdep.o thunk.o 
  12.193 +ifeq ($(TARGET_ARCH), i386)
  12.194 +OBJS+= vm86.o
  12.195 +endif
  12.196 +ifeq ($(TARGET_ARCH), arm)
  12.197 +OBJS+=nwfpe/fpa11.o nwfpe/fpa11_cpdo.o \
  12.198 +nwfpe/fpa11_cpdt.o nwfpe/fpa11_cprt.o nwfpe/fpopcode.o nwfpe/single_cpdo.o \
  12.199 + nwfpe/double_cpdo.o nwfpe/extended_cpdo.o arm-semi.o
  12.200 +endif
  12.201 +SRCS:= $(OBJS:.o=.c)
  12.202 +OBJS+= libqemu.a
  12.203 +
  12.204 +# cpu emulator library
  12.205 +LIBOBJS=exec.o kqemu.o translate-op.o translate-all.o cpu-exec.o\
  12.206 +        translate.o op.o 
  12.207 +ifdef CONFIG_SOFTFLOAT
  12.208 +LIBOBJS+=fpu/softfloat.o
  12.209 +else
  12.210 +LIBOBJS+=fpu/softfloat-native.o
  12.211 +endif
  12.212 +DEFINES+=-I$(SRC_PATH)/fpu
  12.213 +
  12.214 +ifeq ($(TARGET_ARCH), i386)
  12.215 +LIBOBJS+=helper.o helper2.o
  12.216 +ifeq ($(ARCH), i386)
  12.217 +LIBOBJS+=translate-copy.o
  12.218 +endif
  12.219 +endif
  12.220 +
  12.221 +ifeq ($(TARGET_ARCH), x86_64)
  12.222 +LIBOBJS+=helper.o helper2.o
  12.223 +endif
  12.224 +
  12.225 +ifeq ($(TARGET_BASE_ARCH), ppc)
  12.226 +LIBOBJS+= op_helper.o helper.o
  12.227 +endif
  12.228 +
  12.229 +ifeq ($(TARGET_ARCH), mips)
  12.230 +LIBOBJS+= op_helper.o helper.o
  12.231 +endif
  12.232 +
  12.233 +ifeq ($(TARGET_BASE_ARCH), sparc)
  12.234 +LIBOBJS+= op_helper.o helper.o
  12.235 +endif
  12.236 +
  12.237 +ifeq ($(TARGET_BASE_ARCH), arm)
  12.238 +LIBOBJS+= op_helper.o helper.o
  12.239 +endif
  12.240 +
  12.241 +ifeq ($(TARGET_BASE_ARCH), sh4)
  12.242 +LIBOBJS+= op_helper.o helper.o
  12.243 +endif
  12.244 +
  12.245 +# NOTE: the disassembler code is only needed for debugging
  12.246 +LIBOBJS+=disas.o 
  12.247 +ifeq ($(findstring i386, $(TARGET_ARCH) $(ARCH)),i386)
  12.248 +USE_I386_DIS=y
  12.249 +endif
  12.250 +ifeq ($(findstring x86_64, $(TARGET_ARCH) $(ARCH)),x86_64)
  12.251 +USE_I386_DIS=y
  12.252 +endif
  12.253 +ifdef USE_I386_DIS
  12.254 +LIBOBJS+=i386-dis.o
  12.255 +endif
  12.256 +ifeq ($(findstring alpha, $(TARGET_ARCH) $(ARCH)),alpha)
  12.257 +LIBOBJS+=alpha-dis.o
  12.258 +endif
  12.259 +ifeq ($(findstring ppc, $(TARGET_BASE_ARCH) $(ARCH)),ppc)
  12.260 +LIBOBJS+=ppc-dis.o
  12.261 +endif
  12.262 +ifeq ($(findstring mips, $(TARGET_ARCH) $(ARCH)),mips)
  12.263 +LIBOBJS+=mips-dis.o
  12.264 +endif
  12.265 +ifeq ($(findstring sparc, $(TARGET_BASE_ARCH) $(ARCH)),sparc)
  12.266 +LIBOBJS+=sparc-dis.o
  12.267 +endif
  12.268 +ifeq ($(findstring arm, $(TARGET_ARCH) $(ARCH)),arm)
  12.269 +LIBOBJS+=arm-dis.o
  12.270 +endif
  12.271 +ifeq ($(findstring m68k, $(TARGET_ARCH) $(ARCH)),m68k)
  12.272 +LIBOBJS+=m68k-dis.o
  12.273 +endif
  12.274 +ifeq ($(findstring sh4, $(TARGET_ARCH) $(ARCH)),sh4)
  12.275 +LIBOBJS+=sh4-dis.o
  12.276 +endif
  12.277 +
  12.278 +ifdef CONFIG_GDBSTUB
  12.279 +OBJS+=gdbstub.o
  12.280 +endif
  12.281 +
  12.282 +# qemu-dm objects
  12.283 +LIBOBJS=helper2.o exec-dm.o i8259-dm.o
  12.284 +
  12.285 +all: $(PROGS)
  12.286 +
  12.287 +$(QEMU_USER): $(OBJS)
  12.288 +	$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^  $(LIBS)
  12.289 +ifeq ($(ARCH),alpha)
  12.290 +# Mark as 32 bit binary, i. e. it will be mapped into the low 31 bit of
  12.291 +# the address space (31 bit so sign extending doesn't matter)
  12.292 +	echo -ne '\001\000\000\000' | dd of=qemu bs=1 seek=48 count=4 conv=notrunc
  12.293 +endif
  12.294 +
  12.295 +# must use static linking to avoid leaving stuff in virtual address space
  12.296 +VL_OBJS=vl.o osdep.o block.o readline.o monitor.o pci.o console.o
  12.297 +VL_OBJS+=block-cow.o block-qcow.o aes.o block-vmdk.o block-cloop.o block-dmg.o block-bochs.o block-vpc.o block-vvfat.o
  12.298 +ifdef CONFIG_WIN32
  12.299 +VL_OBJS+=tap-win32.o
  12.300 +endif
  12.301 +
  12.302 +SOUND_HW = sb16.o es1370.o
  12.303 +AUDIODRV = audio.o noaudio.o wavaudio.o
  12.304 +ifdef CONFIG_SDL
  12.305 +AUDIODRV += sdlaudio.o
  12.306 +endif
  12.307 +ifdef CONFIG_OSS
  12.308 +AUDIODRV += ossaudio.o
  12.309 +endif
  12.310 +ifdef CONFIG_COREAUDIO
  12.311 +AUDIODRV += coreaudio.o
  12.312 +endif
  12.313 +ifdef CONFIG_ALSA
  12.314 +AUDIODRV += alsaaudio.o
  12.315 +LIBS += -lasound
  12.316 +endif
  12.317 +ifdef CONFIG_DSOUND
  12.318 +AUDIODRV += dsoundaudio.o
  12.319 +LIBS += -lole32 -ldxguid
  12.320 +endif
  12.321 +ifdef CONFIG_FMOD
  12.322 +AUDIODRV += fmodaudio.o
  12.323 +audio.o fmodaudio.o: DEFINES := -I$(CONFIG_FMOD_INC) $(DEFINES)
  12.324 +LIBS += $(CONFIG_FMOD_LIB)
  12.325 +endif
  12.326 +ifdef CONFIG_ADLIB
  12.327 +SOUND_HW += fmopl.o adlib.o
  12.328 +endif
  12.329 +
  12.330 +# USB layer
  12.331 +VL_OBJS+= usb.o usb-hub.o usb-uhci.o usb-linux.o usb-hid.o
  12.332 +
  12.333 +# PCI network cards
  12.334 +VL_OBJS+= ne2000.o rtl8139.o
  12.335 +
  12.336 +ifeq ($(TARGET_BASE_ARCH), i386)
  12.337 +# Hardware support
  12.338 +VL_OBJS+= ide.o pckbd.o ps2.o vga.o $(SOUND_HW) dma.o $(AUDIODRV)
  12.339 +VL_OBJS+= fdc.o mc146818rtc.o serial.o pc.o
  12.340 +VL_OBJS+= cirrus_vga.o mixeng.o parallel.o
  12.341 +VL_OBJS+= piix4acpi.o
  12.342 +DEFINES += -DHAS_AUDIO
  12.343 +endif
  12.344 +ifeq ($(TARGET_BASE_ARCH), ppc)
  12.345 +VL_OBJS+= ppc.o ide.o pckbd.o ps2.o vga.o $(SOUND_HW) dma.o $(AUDIODRV)
  12.346 +VL_OBJS+= mc146818rtc.o serial.o i8259.o i8254.o fdc.o m48t59.o
  12.347 +VL_OBJS+= ppc_prep.o ppc_chrp.o cuda.o adb.o openpic.o heathrow_pic.o mixeng.o
  12.348 +DEFINES += -DHAS_AUDIO
  12.349 +endif
  12.350 +ifeq ($(TARGET_ARCH), mips)
  12.351 +VL_OBJS+= mips_r4k.o dma.o vga.o serial.o i8254.o i8259.o
  12.352 +#VL_OBJS+= #ide.o pckbd.o fdc.o m48t59.o
  12.353 +endif
  12.354 +ifeq ($(TARGET_BASE_ARCH), sparc)
  12.355 +ifeq ($(TARGET_ARCH), sparc64)
  12.356 +VL_OBJS+= sun4u.o ide.o pckbd.o ps2.o vga.o
  12.357 +VL_OBJS+= fdc.o mc146818rtc.o serial.o m48t59.o
  12.358 +VL_OBJS+= cirrus_vga.o parallel.o
  12.359 +else
  12.360 +VL_OBJS+= sun4m.o tcx.o lance.o iommu.o m48t59.o slavio_intctl.o
  12.361 +VL_OBJS+= slavio_timer.o slavio_serial.o slavio_misc.o fdc.o esp.o
  12.362 +endif
  12.363 +endif
  12.364 +ifeq ($(TARGET_BASE_ARCH), arm)
  12.365 +VL_OBJS+= integratorcp.o versatilepb.o ps2.o smc91c111.o arm_pic.o arm_timer.o
  12.366 +VL_OBJS+= arm_boot.o pl011.o pl050.o pl080.o pl110.o pl190.o
  12.367 +endif
  12.368 +ifeq ($(TARGET_BASE_ARCH), sh4)
  12.369 +VL_OBJS+= shix.o sh7750.o sh7750_regnames.o tc58128.o
  12.370 +endif
  12.371 +ifdef CONFIG_GDBSTUB
  12.372 +VL_OBJS+=gdbstub.o 
  12.373 +endif
  12.374 +ifdef CONFIG_SDL
  12.375 +VL_OBJS+=sdl.o
  12.376 +endif
  12.377 +VL_OBJS+=vnc.o
  12.378 +ifdef CONFIG_COCOA
  12.379 +VL_OBJS+=cocoa.o
  12.380 +COCOA_LIBS=-F/System/Library/Frameworks -framework Cocoa -framework IOKit
  12.381 +ifdef CONFIG_COREAUDIO
  12.382 +COCOA_LIBS+=-framework CoreAudio
  12.383 +endif
  12.384 +endif
  12.385 +ifdef CONFIG_SLIRP
  12.386 +DEFINES+=-I$(SRC_PATH)/slirp
  12.387 +SLIRP_OBJS=cksum.o if.o ip_icmp.o ip_input.o ip_output.o \
  12.388 +slirp.o mbuf.o misc.o sbuf.o socket.o tcp_input.o tcp_output.o \
  12.389 +tcp_subr.o tcp_timer.o udp.o bootp.o debug.o tftp.o
  12.390 +VL_OBJS+=$(addprefix slirp/, $(SLIRP_OBJS))
  12.391 +endif
  12.392 +
  12.393 +VL_LDFLAGS=
  12.394 +# specific flags are needed for non soft mmu emulator
  12.395 +ifdef CONFIG_STATIC
  12.396 +VL_LDFLAGS+=-static
  12.397 +endif
  12.398 +ifndef CONFIG_SOFTMMU
  12.399 +VL_LDFLAGS+=-Wl,-T,$(SRC_PATH)/i386-vl.ld 
  12.400 +endif
  12.401 +ifndef CONFIG_DARWIN
  12.402 +ifndef CONFIG_WIN32
  12.403 +ifndef CONFIG_SOLARIS
  12.404 +VL_LIBS=-lutil
  12.405 +endif
  12.406 +endif
  12.407 +endif
  12.408 +ifdef TARGET_GPROF
  12.409 +vl.o: CFLAGS+=-p
  12.410 +VL_LDFLAGS+=-p
  12.411 +endif
  12.412 +
  12.413 +ifeq ($(ARCH),ia64)
  12.414 +VL_LDFLAGS+=-Wl,-G0 -Wl,-T,$(SRC_PATH)/ia64.ld
  12.415 +endif
  12.416 +
  12.417 +ifdef CONFIG_WIN32
  12.418 +SDL_LIBS := $(filter-out -mwindows, $(SDL_LIBS)) -mconsole
  12.419 +endif
  12.420 +
  12.421 +$(QEMU_SYSTEM): $(VL_OBJS) libqemu.a
  12.422 +	$(CC) $(VL_LDFLAGS) -o $@ $^ $(LIBS) $(SDL_LIBS) $(COCOA_LIBS) $(VL_LIBS)
  12.423 +
  12.424 +cocoa.o: cocoa.m
  12.425 +	$(CC) $(CFLAGS) $(DEFINES) -c -o $@ $<
  12.426 +
  12.427 +sdl.o: sdl.c keymaps.c sdl_keysym.h
  12.428 +	$(CC) $(CFLAGS) $(DEFINES) $(SDL_CFLAGS) -c -o $@ $<
  12.429 +
  12.430 +vnc.o: vnc.c keymaps.c sdl_keysym.h vnchextile.h
  12.431 +	$(CC) $(CFLAGS) $(DEFINES) -c -o $@ $<
  12.432 +
  12.433 +sdlaudio.o: sdlaudio.c
  12.434 +	$(CC) $(CFLAGS) $(DEFINES) $(SDL_CFLAGS) -c -o $@ $<
  12.435 +
  12.436 +depend: $(SRCS)
  12.437 +	$(CC) -MM $(CFLAGS) $(DEFINES) $^ 1>.depend
  12.438 +
  12.439 +vldepend: $(VL_OBJS:.o=.c)
  12.440 +	$(CC) -MM $(CFLAGS) $(DEFINES) $^ 1>.depend
  12.441 +
  12.442 +# libqemu 
  12.443 +
  12.444 +libqemu.a: $(LIBOBJS)
  12.445 +	rm -f $@
  12.446 +	$(AR) rcs $@ $(LIBOBJS)
  12.447 +
  12.448 +translate.o: translate.c gen-op.h opc.h cpu.h
  12.449 +
  12.450 +translate-all.o: translate-all.c opc.h cpu.h
  12.451 +
  12.452 +translate-op.o: translate-all.c op.h opc.h cpu.h
  12.453 +
  12.454 +op.h: op.o $(DYNGEN)
  12.455 +	$(DYNGEN) -o $@ $<
  12.456 +
  12.457 +opc.h: op.o $(DYNGEN)
  12.458 +	$(DYNGEN) -c -o $@ $<
  12.459 +
  12.460 +gen-op.h: op.o $(DYNGEN)
  12.461 +	$(DYNGEN) -g -o $@ $<
  12.462 +
  12.463 +op.o: op.c
  12.464 +	$(CC) $(OP_CFLAGS) $(DEFINES) -c -o $@ $<
  12.465 +
  12.466 +helper.o: helper.c
  12.467 +	$(CC) $(HELPER_CFLAGS) $(DEFINES) -c -o $@ $<
  12.468 +
  12.469 +ifeq ($(TARGET_BASE_ARCH), i386)
  12.470 +op.o: op.c opreg_template.h ops_template.h ops_template_mem.h ops_mem.h ops_sse.h
  12.471 +endif
  12.472 +
  12.473 +ifeq ($(TARGET_ARCH), arm)
  12.474 +op.o: op.c op_template.h
  12.475 +pl110.o: pl110_template.h
  12.476 +endif
  12.477 +
  12.478 +ifeq ($(TARGET_BASE_ARCH), sparc)
  12.479 +op.o: op.c op_template.h op_mem.h fop_template.h fbranch_template.h
  12.480 +magic_load.o: elf_op.h
  12.481 +endif
  12.482 +
  12.483 +ifeq ($(TARGET_BASE_ARCH), ppc)
  12.484 +op.o: op.c op_template.h op_mem.h
  12.485 +op_helper.o: op_helper_mem.h
  12.486 +translate.o: translate.c translate_init.c
  12.487 +endif
  12.488 +
  12.489 +ifeq ($(TARGET_ARCH), mips)
  12.490 +op.o: op.c op_template.c op_mem.c
  12.491 +op_helper.o: op_helper_mem.c
  12.492 +endif
  12.493 +
  12.494 +loader.o: loader.c elf_ops.h
  12.495 +
  12.496 +ifeq ($(TARGET_ARCH), sh4)
  12.497 +op.o: op.c op_mem.c cpu.h
  12.498 +op_helper.o: op_helper.c exec.h cpu.h
  12.499 +helper.o: helper.c exec.h cpu.h
  12.500 +sh7750.o: sh7750.c sh7750_regs.h sh7750_regnames.h cpu.h
  12.501 +shix.o: shix.c sh7750_regs.h sh7750_regnames.h
  12.502 +sh7750_regnames.o: sh7750_regnames.c sh7750_regnames.h sh7750_regs.h
  12.503 +tc58128.o: tc58128.c
  12.504 +endif
  12.505 +
  12.506 +%.o: %.c
  12.507 +	$(CC) $(CFLAGS) $(DEFINES) -c -o $@ $<
  12.508 +
  12.509 +%.o: %.S
  12.510 +	$(CC) $(DEFINES) -c -o $@ $<
  12.511 +
  12.512 +clean:
  12.513 +	rm -f *.o  *.a *~ $(PROGS) gen-op.h opc.h op.h nwfpe/*.o slirp/*.o fpu/*.o
  12.514 +
  12.515 +distclean: clean
  12.516 +	rm -rf config.mak config.h
  12.517 +
  12.518 +install: all 
  12.519 +	mkdir -p "$(DESTDIR)$(bindir)" "$(DESTDIR)$(configdir)"
  12.520 +ifneq ($(PROGS),)
  12.521 +	$(INSTALL) -m 755 -s $(PROGS) "$(DESTDIR)$(bindir)"
  12.522 +endif
  12.523 +	install -m 755 $(TARGET_PATH)/qemu-dm.debug "$(DESTDIR)$(bindir)"
  12.524 +	install -m 755 $(TARGET_PATH)/qemu-ifup "$(DESTDIR)$(configdir)"
  12.525 +
  12.526 +ifneq ($(wildcard .depend),)
  12.527 +include .depend
  12.528 +endif
  12.529 +
  12.530 +ifeq (1, 0)
  12.531 +audio.o sdlaudio.o dsoundaudio.o ossaudio.o wavaudio.o noaudio.o \
  12.532 +fmodaudio.o alsaaudio.o mixeng.o sb16.o es1370.o gus.o adlib.o: \
  12.533 +CFLAGS := $(CFLAGS) -Wall -Werror -W -Wsign-compare
  12.534 +endif
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/tools/ioemu/README	Wed Jul 12 19:16:10 2006 +0100
    13.3 @@ -0,0 +1,3 @@
    13.4 +Read the documentation in qemu-doc.html.
    13.5 +
    13.6 +Fabrice Bellard.
    13.7 \ No newline at end of file
    14.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.2 +++ b/tools/ioemu/README.distrib	Wed Jul 12 19:16:10 2006 +0100
    14.3 @@ -0,0 +1,16 @@
    14.4 +Information about the various packages used to build the current qemu
    14.5 +x86 binary distribution:
    14.6 +
    14.7 +* gcc 2.95.2 was used for the build. A glibc 2.1.3 Debian distribution
    14.8 +  was used to get most of the binary packages.
    14.9 +
   14.10 +* wine-20020411 tarball
   14.11 +
   14.12 +  ./configure --prefix=/usr/local/wine-i386
   14.13 +  
   14.14 +  All exe and libs were stripped. Some compile time tools and the
   14.15 +  includes were deleted.
   14.16 +
   14.17 +* ldconfig was launched to build the library links:
   14.18 +
   14.19 +  qemu-i386 /usr/gnemul/qemu-i386/bin/ldconfig-i386 -C /usr/gnemul/qemu-i386/etc/ld.so.cache
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/tools/ioemu/TODO	Wed Jul 12 19:16:10 2006 +0100
    15.3 @@ -0,0 +1,61 @@
    15.4 +short term:
    15.5 +----------
    15.6 +- support variable tsc freq
    15.7 +- cpu_interrupt() win32/SMP fix
    15.8 +- USB host async
    15.9 +- IDE async
   15.10 +- debug option in 'configure' script + disable -fomit-frame-pointer
   15.11 +- Precise VGA timings for old games/demos (malc patch)
   15.12 +- merge PIC spurious interrupt patch
   15.13 +- merge Solaris patch
   15.14 +- warning for OS/2: must not use 128 MB memory (merge bochs cmos patch ?)
   15.15 +- config file (at least for windows/Mac OS X)
   15.16 +- commit message if execution of code in IO memory
   15.17 +- update doc: PCI infos.
   15.18 +- VNC patch + Synaptic patch.
   15.19 +- basic VGA optimizations
   15.20 +- physical memory cache (reduce qemu-fast address space size to about 32 MB)
   15.21 +- better code fetch (different exception handling + CS.limit support)
   15.22 +- do not resize vga if invalid size.
   15.23 +- avoid looping if only exceptions
   15.24 +- cycle counter for all archs
   15.25 +- TLB code protection support for PPC
   15.26 +- see openMosix Doc 
   15.27 +- disable SMC handling for ARM/SPARC/PPC (not finished)
   15.28 +- see undefined flags for BTx insn
   15.29 +- user/kernel PUSHL/POPL in helper.c
   15.30 +- keyboard output buffer filling timing emulation
   15.31 +- return UD exception if LOCK prefix incorrectly used
   15.32 +- test ldt limit < 7 ?
   15.33 +- tests for each target CPU
   15.34 +- fix CCOP optimisation
   15.35 +- fix all remaining thread lock issues (must put TBs in a specific invalid
   15.36 +  state, find a solution for tb_flush()).
   15.37 +- fix arm fpu rounding (at least for float->integer conversions)
   15.38 +
   15.39 +ppc specific:
   15.40 +------------
   15.41 +- TLB invalidate not needed if msr_pr changes
   15.42 +- SPR_ENCODE() not useful
   15.43 +- enable shift optimizations ?
   15.44 +
   15.45 +linux-user specific:
   15.46 +-------------------
   15.47 +- add IPC syscalls
   15.48 +- handle rare page fault cases (in particular if page fault in helpers or
   15.49 +  in syscall emulation code).
   15.50 +- more syscalls (in particular all 64 bit ones, IPCs, fix 64 bit
   15.51 +  issues, fix 16 bit uid issues)
   15.52 +- use page_unprotect_range in every suitable syscall to handle all
   15.53 +  cases of self modifying code.
   15.54 +- fix thread stack freeing (use kernel 2.5.x CLONE_CHILD_CLEARTID)
   15.55 +- use kernel traps for unaligned accesses on ARM ?
   15.56 +
   15.57 +
   15.58 +lower priority:
   15.59 +--------------
   15.60 +- int15 ah=86: use better timing
   15.61 +- suppress shift_mem ops
   15.62 +- fix some 16 bit sp push/pop overflow (pusha/popa, lcall lret)
   15.63 +- optimize FPU operations (evaluate x87 stack pointer statically)
   15.64 +- use -msoft-float on ARM
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/tools/ioemu/VERSION	Wed Jul 12 19:16:10 2006 +0100
    16.3 @@ -0,0 +1,1 @@
    16.4 +0.8.1
    16.5 \ No newline at end of file
    17.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    17.2 +++ b/tools/ioemu/a.out.h	Wed Jul 12 19:16:10 2006 +0100
    17.3 @@ -0,0 +1,431 @@
    17.4 +/* a.out.h
    17.5 +
    17.6 +   Copyright 1997, 1998, 1999, 2001 Red Hat, Inc.
    17.7 +
    17.8 +This file is part of Cygwin.
    17.9 +
   17.10 +This software is a copyrighted work licensed under the terms of the
   17.11 +Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
   17.12 +details. */
   17.13 +
   17.14 +#ifndef _A_OUT_H_
   17.15 +#define _A_OUT_H_
   17.16 +
   17.17 +#ifdef __cplusplus
   17.18 +extern "C" {
   17.19 +#endif
   17.20 +#define COFF_IMAGE_WITH_PE
   17.21 +#define COFF_LONG_SECTION_NAMES
   17.22 +
   17.23 +/*** coff information for Intel 386/486.  */
   17.24 +
   17.25 +
   17.26 +/********************** FILE HEADER **********************/
   17.27 +
   17.28 +struct external_filehdr {
   17.29 +  short f_magic;	/* magic number			*/
   17.30 +  short f_nscns;	/* number of sections		*/
   17.31 +  unsigned long f_timdat;	/* time & date stamp		*/
   17.32 +  unsigned long f_symptr;	/* file pointer to symtab	*/
   17.33 +  unsigned long f_nsyms;	/* number of symtab entries	*/
   17.34 +  short f_opthdr;	/* sizeof(optional hdr)		*/
   17.35 +  short f_flags;	/* flags			*/
   17.36 +};
   17.37 +
   17.38 +/* Bits for f_flags:
   17.39 + *	F_RELFLG	relocation info stripped from file
   17.40 + *	F_EXEC		file is executable (no unresolved external references)
   17.41 + *	F_LNNO		line numbers stripped from file
   17.42 + *	F_LSYMS		local symbols stripped from file
   17.43 + *	F_AR32WR	file has byte ordering of an AR32WR machine (e.g. vax)
   17.44 + */
   17.45 +
   17.46 +#define F_RELFLG	(0x0001)
   17.47 +#define F_EXEC		(0x0002)
   17.48 +#define F_LNNO		(0x0004)
   17.49 +#define F_LSYMS		(0x0008)
   17.50 +
   17.51 +
   17.52 +
   17.53 +#define	I386MAGIC	0x14c
   17.54 +#define I386PTXMAGIC	0x154
   17.55 +#define I386AIXMAGIC	0x175
   17.56 +
   17.57 +/* This is Lynx's all-platform magic number for executables. */
   17.58 +
   17.59 +#define LYNXCOFFMAGIC	0415
   17.60 +
   17.61 +#define I386BADMAG(x) (((x).f_magic != I386MAGIC) \
   17.62 +		       && (x).f_magic != I386AIXMAGIC \
   17.63 +		       && (x).f_magic != I386PTXMAGIC \
   17.64 +		       && (x).f_magic != LYNXCOFFMAGIC)
   17.65 +
   17.66 +#define	FILHDR	struct external_filehdr
   17.67 +#define	FILHSZ	20
   17.68 +
   17.69 +
   17.70 +/********************** AOUT "OPTIONAL HEADER"=
   17.71 + **********************/
   17.72 +
   17.73 +
   17.74 +typedef struct
   17.75 +{
   17.76 +  unsigned short magic;		/* type of file				*/
   17.77 +  unsigned short vstamp;	/* version stamp			*/
   17.78 +  unsigned long	tsize;		/* text size in bytes, padded to FW bdry*/
   17.79 +  unsigned long	dsize;		/* initialized data "  "		*/
   17.80 +  unsigned long	bsize;		/* uninitialized data "   "		*/
   17.81 +  unsigned long	entry;		/* entry pt.				*/
   17.82 +  unsigned long text_start;	/* base of text used for this file */
   17.83 +  unsigned long data_start;	/* base of data used for this file=
   17.84 + */
   17.85 +}
   17.86 +AOUTHDR;
   17.87 +
   17.88 +#define AOUTSZ 28
   17.89 +#define AOUTHDRSZ 28
   17.90 +
   17.91 +#define OMAGIC          0404    /* object files, eg as output */
   17.92 +#define ZMAGIC          0413    /* demand load format, eg normal ld output */
   17.93 +#define STMAGIC		0401	/* target shlib */
   17.94 +#define SHMAGIC		0443	/* host   shlib */
   17.95 +
   17.96 +
   17.97 +/* define some NT default values */
   17.98 +/*  #define NT_IMAGE_BASE        0x400000 moved to internal.h */
   17.99 +#define NT_SECTION_ALIGNMENT 0x1000
  17.100 +#define NT_FILE_ALIGNMENT    0x200
  17.101 +#define NT_DEF_RESERVE       0x100000
  17.102 +#define NT_DEF_COMMIT        0x1000
  17.103 +
  17.104 +/********************** SECTION HEADER **********************/
  17.105 +
  17.106 +
  17.107 +struct external_scnhdr {
  17.108 +  char		s_name[8];	/* section name			*/
  17.109 +  unsigned long	s_paddr;	/* physical address, offset
  17.110 +				   of last addr in scn */
  17.111 +  unsigned long	s_vaddr;	/* virtual address		*/
  17.112 +  unsigned long	s_size;		/* section size			*/
  17.113 +  unsigned long	s_scnptr;	/* file ptr to raw data for section */
  17.114 +  unsigned long	s_relptr;	/* file ptr to relocation	*/
  17.115 +  unsigned long	s_lnnoptr;	/* file ptr to line numbers	*/
  17.116 +  unsigned short s_nreloc;	/* number of relocation entries	*/
  17.117 +  unsigned short s_nlnno;	/* number of line number entries*/
  17.118 +  unsigned long	s_flags;	/* flags			*/
  17.119 +};
  17.120 +
  17.121 +#define	SCNHDR	struct external_scnhdr
  17.122 +#define	SCNHSZ	40
  17.123 +
  17.124 +/*
  17.125 + * names of "special" sections
  17.126 + */
  17.127 +#define _TEXT	".text"
  17.128 +#define _DATA	".data"
  17.129 +#define _BSS	".bss"
  17.130 +#define _COMMENT ".comment"
  17.131 +#define _LIB ".lib"
  17.132 +
  17.133 +/********************** LINE NUMBERS **********************/
  17.134 +
  17.135 +/* 1 line number entry for every "breakpointable" source line in a section.
  17.136 + * Line numbers are grouped on a per function basis; first entry in a function
  17.137 + * grouping will have l_lnno = 0 and in place of physical address will be the
  17.138 + * symbol table index of the function name.
  17.139 + */
  17.140 +struct external_lineno {
  17.141 +  union {
  17.142 +    unsigned long l_symndx; /* function name symbol index, iff l_lnno 0 */
  17.143 +    unsigned long l_paddr;	/* (physical) address of line number	*/
  17.144 +  } l_addr;
  17.145 +  unsigned short l_lnno;	/* line number		*/
  17.146 +};
  17.147 +
  17.148 +#define	LINENO	struct external_lineno
  17.149 +#define	LINESZ	6
  17.150 +
  17.151 +/********************** SYMBOLS **********************/
  17.152 +
  17.153 +#define E_SYMNMLEN	8	/* # characters in a symbol name	*/
  17.154 +#define E_FILNMLEN	14	/* # characters in a file name		*/
  17.155 +#define E_DIMNUM	4	/* # array dimensions in auxiliary entry */
  17.156 +
  17.157 +struct __attribute__((packed)) external_syment
  17.158 +{
  17.159 +  union {
  17.160 +    char e_name[E_SYMNMLEN];
  17.161 +    struct {
  17.162 +      unsigned long e_zeroes;
  17.163 +      unsigned long e_offset;
  17.164 +    } e;
  17.165 +  } e;
  17.166 +  unsigned long e_value;
  17.167 +  unsigned short e_scnum;
  17.168 +  unsigned short e_type;
  17.169 +  char e_sclass[1];
  17.170 +  char e_numaux[1];
  17.171 +};
  17.172 +
  17.173 +#define N_BTMASK	(0xf)
  17.174 +#define N_TMASK		(0x30)
  17.175 +#define N_BTSHFT	(4)
  17.176 +#define N_TSHIFT	(2)
  17.177 +
  17.178 +union external_auxent {
  17.179 +  struct {
  17.180 +    unsigned long x_tagndx;	/* str, un, or enum tag indx */
  17.181 +    union {
  17.182 +      struct {
  17.183 +	unsigned short  x_lnno; /* declaration line number */
  17.184 +	unsigned short  x_size; /* str/union/array size */
  17.185 +      } x_lnsz;
  17.186 +      unsigned long x_fsize;	/* size of function */
  17.187 +    } x_misc;
  17.188 +    union {
  17.189 +      struct {			/* if ISFCN, tag, or .bb */
  17.190 +	unsigned long x_lnnoptr;/* ptr to fcn line # */
  17.191 +	unsigned long x_endndx;	/* entry ndx past block end */
  17.192 +      } x_fcn;
  17.193 +      struct {			/* if ISARY, up to 4 dimen. */
  17.194 +	char x_dimen[E_DIMNUM][2];
  17.195 +      } x_ary;
  17.196 +    } x_fcnary;
  17.197 +    unsigned short x_tvndx;	/* tv index */
  17.198 +  } x_sym;
  17.199 +
  17.200 +  union {
  17.201 +    char x_fname[E_FILNMLEN];
  17.202 +    struct {
  17.203 +      unsigned long x_zeroes;
  17.204 +      unsigned long x_offset;
  17.205 +    } x_n;
  17.206 +  } x_file;
  17.207 +
  17.208 +  struct {
  17.209 +    unsigned long x_scnlen;	/* section length */
  17.210 +    unsigned short x_nreloc;	/* # relocation entries */
  17.211 +    unsigned short x_nlinno;	/* # line numbers */
  17.212 +    unsigned long x_checksum;	/* section COMDAT checksum */
  17.213 +    unsigned short x_associated;/* COMDAT associated section index */
  17.214 +    char x_comdat[1];		/* COMDAT selection number */
  17.215 +  } x_scn;
  17.216 +
  17.217 +  struct {
  17.218 +    unsigned long x_tvfill;	/* tv fill value */
  17.219 +    unsigned short x_tvlen;	/* length of .tv */
  17.220 +    char x_tvran[2][2];		/* tv range */
  17.221 +  } x_tv;	/* info about .tv section (in auxent of symbol .tv)) */
  17.222 +
  17.223 +};
  17.224 +
  17.225 +#define	SYMENT	struct external_syment
  17.226 +#define	SYMESZ	18
  17.227 +#define	AUXENT	union external_auxent
  17.228 +#define	AUXESZ	18
  17.229 +
  17.230 +#define _ETEXT	"etext"
  17.231 +
  17.232 +/********************** RELOCATION DIRECTIVES **********************/
  17.233 +
  17.234 +struct external_reloc {
  17.235 +  char r_vaddr[4];
  17.236 +  char r_symndx[4];
  17.237 +  char r_type[2];
  17.238 +};
  17.239 +
  17.240 +#define RELOC struct external_reloc
  17.241 +#define RELSZ 10
  17.242 +
  17.243 +/* end of coff/i386.h */
  17.244 +
  17.245 +/* PE COFF header information */
  17.246 +
  17.247 +#ifndef _PE_H
  17.248 +#define _PE_H
  17.249 +
  17.250 +/* NT specific file attributes */
  17.251 +#define IMAGE_FILE_RELOCS_STRIPPED           0x0001
  17.252 +#define IMAGE_FILE_EXECUTABLE_IMAGE          0x0002
  17.253 +#define IMAGE_FILE_LINE_NUMS_STRIPPED        0x0004
  17.254 +#define IMAGE_FILE_LOCAL_SYMS_STRIPPED       0x0008
  17.255 +#define IMAGE_FILE_BYTES_REVERSED_LO         0x0080
  17.256 +#define IMAGE_FILE_32BIT_MACHINE             0x0100
  17.257 +#define IMAGE_FILE_DEBUG_STRIPPED            0x0200
  17.258 +#define IMAGE_FILE_SYSTEM                    0x1000
  17.259 +#define IMAGE_FILE_DLL                       0x2000
  17.260 +#define IMAGE_FILE_BYTES_REVERSED_HI         0x8000
  17.261 +
  17.262 +/* additional flags to be set for section headers to allow the NT loader to
  17.263 +   read and write to the section data (to replace the addresses of data in
  17.264 +   dlls for one thing); also to execute the section in .text's case=
  17.265 + */
  17.266 +#define IMAGE_SCN_MEM_DISCARDABLE 0x02000000
  17.267 +#define IMAGE_SCN_MEM_EXECUTE     0x20000000
  17.268 +#define IMAGE_SCN_MEM_READ        0x40000000
  17.269 +#define IMAGE_SCN_MEM_WRITE       0x80000000
  17.270 +
  17.271 +/*
  17.272 + * Section characteristics added for ppc-nt
  17.273 + */
  17.274 +
  17.275 +#define IMAGE_SCN_TYPE_NO_PAD                0x00000008  /* Reserved.  */
  17.276 +
  17.277 +#define IMAGE_SCN_CNT_CODE                   0x00000020  /* Section contains code. */
  17.278 +#define IMAGE_SCN_CNT_INITIALIZED_DATA       0x00000040  /* Section contains initialized data. */
  17.279 +#define IMAGE_SCN_CNT_UNINITIALIZED_DATA     0x00000080  /* Section contains uninitialized data. */
  17.280 +
  17.281 +#define IMAGE_SCN_LNK_OTHER                  0x00000100  /* Reserved.  */
  17.282 +#define IMAGE_SCN_LNK_INFO                   0x00000200  /* Section contains comments or some other type of information. */
  17.283 +#define IMAGE_SCN_LNK_REMOVE                 0x00000800  /* Section contents will not become part of image. */
  17.284 +#define IMAGE_SCN_LNK_COMDAT                 0x00001000  /* Section contents comdat. */
  17.285 +
  17.286 +#define IMAGE_SCN_MEM_FARDATA                0x00008000
  17.287 +
  17.288 +#define IMAGE_SCN_MEM_PURGEABLE              0x00020000
  17.289 +#define IMAGE_SCN_MEM_16BIT                  0x00020000
  17.290 +#define IMAGE_SCN_MEM_LOCKED                 0x00040000
  17.291 +#define IMAGE_SCN_MEM_PRELOAD                0x00080000
  17.292 +
  17.293 +#define IMAGE_SCN_ALIGN_1BYTES               0x00100000
  17.294 +#define IMAGE_SCN_ALIGN_2BYTES               0x00200000
  17.295 +#define IMAGE_SCN_ALIGN_4BYTES               0x00300000
  17.296 +#define IMAGE_SCN_ALIGN_8BYTES               0x00400000
  17.297 +#define IMAGE_SCN_ALIGN_16BYTES              0x00500000  /* Default alignment if no others are specified. */
  17.298 +#define IMAGE_SCN_ALIGN_32BYTES              0x00600000
  17.299 +#define IMAGE_SCN_ALIGN_64BYTES              0x00700000
  17.300 +
  17.301 +
  17.302 +#define IMAGE_SCN_LNK_NRELOC_OVFL            0x01000000  /* Section contains extended relocations. */
  17.303 +#define IMAGE_SCN_MEM_NOT_CACHED             0x04000000  /* Section is not cachable.               */
  17.304 +#define IMAGE_SCN_MEM_NOT_PAGED              0x08000000  /* Section is not pageable.               */
  17.305 +#define IMAGE_SCN_MEM_SHARED                 0x10000000  /* Section is shareable.                  */
  17.306 +
  17.307 +/* COMDAT selection codes.  */
  17.308 +
  17.309 +#define IMAGE_COMDAT_SELECT_NODUPLICATES     (1) /* Warn if duplicates.  */
  17.310 +#define IMAGE_COMDAT_SELECT_ANY		     (2) /* No warning.  */
  17.311 +#define IMAGE_COMDAT_SELECT_SAME_SIZE	     (3) /* Warn if different size.  */
  17.312 +#define IMAGE_COMDAT_SELECT_EXACT_MATCH	     (4) /* Warn if different.  */
  17.313 +#define IMAGE_COMDAT_SELECT_ASSOCIATIVE	     (5) /* Base on other section.  */
  17.314 +
  17.315 +/* Magic values that are true for all dos/nt implementations */
  17.316 +#define DOSMAGIC       0x5a4d
  17.317 +#define NT_SIGNATURE   0x00004550
  17.318 +
  17.319 +/* NT allows long filenames, we want to accommodate this.  This may break
  17.320 +     some of the bfd functions */
  17.321 +#undef  FILNMLEN
  17.322 +#define FILNMLEN	18	/* # characters in a file name		*/
  17.323 +
  17.324 +
  17.325 +#ifdef COFF_IMAGE_WITH_PE
  17.326 +/* The filehdr is only weired in images */
  17.327 +
  17.328 +#undef FILHDR
  17.329 +struct external_PE_filehdr
  17.330 +{
  17.331 +  /* DOS header fields */
  17.332 +  unsigned short e_magic;	/* Magic number, 0x5a4d */
  17.333 +  unsigned short e_cblp;	/* Bytes on last page of file, 0x90 */
  17.334 +  unsigned short e_cp;		/* Pages in file, 0x3 */
  17.335 +  unsigned short e_crlc;	/* Relocations, 0x0 */
  17.336 +  unsigned short e_cparhdr;	/* Size of header in paragraphs, 0x4 */
  17.337 +  unsigned short e_minalloc;	/* Minimum extra paragraphs needed, 0x0 */
  17.338 +  unsigned short e_maxalloc;	/* Maximum extra paragraphs needed, 0xFFFF */
  17.339 +  unsigned short e_ss;		/* Initial (relative) SS value, 0x0 */
  17.340 +  unsigned short e_sp;		/* Initial SP value, 0xb8 */
  17.341 +  unsigned short e_csum;	/* Checksum, 0x0 */
  17.342 +  unsigned short e_ip;		/* Initial IP value, 0x0 */
  17.343 +  unsigned short e_cs;		/* Initial (relative) CS value, 0x0 */
  17.344 +  unsigned short e_lfarlc;	/* File address of relocation table, 0x40 */
  17.345 +  unsigned short e_ovno;	/* Overlay number, 0x0 */
  17.346 +  char e_res[4][2];		/* Reserved words, all 0x0 */
  17.347 +  unsigned short e_oemid;	/* OEM identifier (for e_oeminfo), 0x0 */
  17.348 +  unsigned short e_oeminfo;	/* OEM information; e_oemid specific, 0x0 */
  17.349 +  char e_res2[10][2];		/* Reserved words, all 0x0 */
  17.350 +  unsigned long e_lfanew;	/* File address of new exe header, 0x80 */
  17.351 +  char dos_message[16][4];	/* other stuff, always follow DOS header */
  17.352 +  unsigned int nt_signature;	/* required NT signature, 0x4550 */
  17.353 +
  17.354 +  /* From standard header */
  17.355 +
  17.356 +  unsigned short f_magic;	/* magic number			*/
  17.357 +  unsigned short f_nscns;	/* number of sections		*/
  17.358 +  unsigned long f_timdat;	/* time & date stamp		*/
  17.359 +  unsigned long f_symptr;	/* file pointer to symtab	*/
  17.360 +  unsigned long f_nsyms;	/* number of symtab entries	*/
  17.361 +  unsigned short f_opthdr;	/* sizeof(optional hdr)		*/
  17.362 +  unsigned short f_flags;	/* flags			*/
  17.363 +};
  17.364 +
  17.365 +
  17.366 +#define FILHDR struct external_PE_filehdr
  17.367 +#undef FILHSZ
  17.368 +#define FILHSZ 152
  17.369 +
  17.370 +#endif
  17.371 +
  17.372 +typedef struct
  17.373 +{
  17.374 +  unsigned short magic;		/* type of file				*/
  17.375 +  unsigned short vstamp;	/* version stamp			*/
  17.376 +  unsigned long	tsize;		/* text size in bytes, padded to FW bdry*/
  17.377 +  unsigned long	dsize;		/* initialized data "  "		*/
  17.378 +  unsigned long	bsize;		/* uninitialized data "   "		*/
  17.379 +  unsigned long	entry;		/* entry pt.				*/
  17.380 +  unsigned long text_start;	/* base of text used for this file */
  17.381 +  unsigned long data_start;	/* base of all data used for this file */
  17.382 +
  17.383 +  /* NT extra fields; see internal.h for descriptions */
  17.384 +  unsigned long  ImageBase;
  17.385 +  unsigned long  SectionAlignment;
  17.386 +  unsigned long  FileAlignment;
  17.387 +  unsigned short  MajorOperatingSystemVersion;
  17.388 +  unsigned short  MinorOperatingSystemVersion;
  17.389 +  unsigned short  MajorImageVersion;
  17.390 +  unsigned short  MinorImageVersion;
  17.391 +  unsigned short  MajorSubsystemVersion;
  17.392 +  unsigned short  MinorSubsystemVersion;
  17.393 +  char  Reserved1[4];
  17.394 +  unsigned long  SizeOfImage;
  17.395 +  unsigned long  SizeOfHeaders;
  17.396 +  unsigned long  CheckSum;
  17.397 +  unsigned short Subsystem;
  17.398 +  unsigned short DllCharacteristics;
  17.399 +  unsigned long  SizeOfStackReserve;
  17.400 +  unsigned long  SizeOfStackCommit;
  17.401 +  unsigned long  SizeOfHeapReserve;
  17.402 +  unsigned long  SizeOfHeapCommit;
  17.403 +  unsigned long  LoaderFlags;
  17.404 +  unsigned long  NumberOfRvaAndSizes;
  17.405 +  /* IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; */
  17.406 +  char  DataDirectory[16][2][4]; /* 16 entries, 2 elements/entry, 4 chars */
  17.407 +
  17.408 +} PEAOUTHDR;
  17.409 +
  17.410 +
  17.411 +#undef AOUTSZ
  17.412 +#define AOUTSZ (AOUTHDRSZ + 196)
  17.413 +
  17.414 +#undef  E_FILNMLEN
  17.415 +#define E_FILNMLEN	18	/* # characters in a file name		*/
  17.416 +#endif
  17.417 +
  17.418 +/* end of coff/pe.h */
  17.419 +
  17.420 +#define DT_NON		(0)	/* no derived type */
  17.421 +#define DT_PTR		(1)	/* pointer */
  17.422 +#define DT_FCN		(2)	/* function */
  17.423 +#define DT_ARY		(3)	/* array */
  17.424 +
  17.425 +#define ISPTR(x)	(((x) & N_TMASK) == (DT_PTR << N_BTSHFT))
  17.426 +#define ISFCN(x)	(((x) & N_TMASK) == (DT_FCN << N_BTSHFT))
  17.427 +#define ISARY(x)	(((x) & N_TMASK) == (DT_ARY << N_BTSHFT))
  17.428 +
  17.429 +#ifdef __cplusplus
  17.430 +}
  17.431 +#endif
  17.432 +
  17.433 +#endif /* _A_OUT_H_ */
  17.434 +
    18.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    18.2 +++ b/tools/ioemu/aes.c	Wed Jul 12 19:16:10 2006 +0100
    18.3 @@ -0,0 +1,1317 @@
    18.4 +/**
    18.5 + * 
    18.6 + * aes.c - integrated in QEMU by Fabrice Bellard from the OpenSSL project.
    18.7 + */
    18.8 +/*
    18.9 + * rijndael-alg-fst.c
   18.10 + *
   18.11 + * @version 3.0 (December 2000)
   18.12 + *
   18.13 + * Optimised ANSI C code for the Rijndael cipher (now AES)
   18.14 + *
   18.15 + * @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be>
   18.16 + * @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be>
   18.17 + * @author Paulo Barreto <paulo.barreto@terra.com.br>
   18.18 + *
   18.19 + * This code is hereby placed in the public domain.
   18.20 + *
   18.21 + * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
   18.22 + * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
   18.23 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   18.24 + * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
   18.25 + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   18.26 + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   18.27 + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
   18.28 + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
   18.29 + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
   18.30 + * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
   18.31 + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   18.32 + */
   18.33 +#include "vl.h"
   18.34 +#include "aes.h"
   18.35 +
   18.36 +#define NDEBUG
   18.37 +#include <assert.h>
   18.38 +
   18.39 +typedef uint32_t u32;
   18.40 +typedef uint16_t u16;
   18.41 +typedef uint8_t u8;
   18.42 +
   18.43 +#define MAXKC   (256/32)
   18.44 +#define MAXKB   (256/8)
   18.45 +#define MAXNR   14
   18.46 +
   18.47 +/* This controls loop-unrolling in aes_core.c */
   18.48 +#undef FULL_UNROLL
   18.49 +# define GETU32(pt) (((u32)(pt)[0] << 24) ^ ((u32)(pt)[1] << 16) ^ ((u32)(pt)[2] <<  8) ^ ((u32)(pt)[3]))
   18.50 +# define PUTU32(ct, st) { (ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); (ct)[2] = (u8)((st) >>  8); (ct)[3] = (u8)(st); }
   18.51 +
   18.52 +/*
   18.53 +Te0[x] = S [x].[02, 01, 01, 03];
   18.54 +Te1[x] = S [x].[03, 02, 01, 01];
   18.55 +Te2[x] = S [x].[01, 03, 02, 01];
   18.56 +Te3[x] = S [x].[01, 01, 03, 02];
   18.57 +Te4[x] = S [x].[01, 01, 01, 01];
   18.58 +
   18.59 +Td0[x] = Si[x].[0e, 09, 0d, 0b];
   18.60 +Td1[x] = Si[x].[0b, 0e, 09, 0d];
   18.61 +Td2[x] = Si[x].[0d, 0b, 0e, 09];
   18.62 +Td3[x] = Si[x].[09, 0d, 0b, 0e];
   18.63 +Td4[x] = Si[x].[01, 01, 01, 01];
   18.64 +*/
   18.65 +
   18.66 +static const u32 Te0[256] = {
   18.67 +    0xc66363a5U, 0xf87c7c84U, 0xee777799U, 0xf67b7b8dU,
   18.68 +    0xfff2f20dU, 0xd66b6bbdU, 0xde6f6fb1U, 0x91c5c554U,
   18.69 +    0x60303050U, 0x02010103U, 0xce6767a9U, 0x562b2b7dU,
   18.70 +    0xe7fefe19U, 0xb5d7d762U, 0x4dababe6U, 0xec76769aU,
   18.71 +    0x8fcaca45U, 0x1f82829dU, 0x89c9c940U, 0xfa7d7d87U,
   18.72 +    0xeffafa15U, 0xb25959ebU, 0x8e4747c9U, 0xfbf0f00bU,
   18.73 +    0x41adadecU, 0xb3d4d467U, 0x5fa2a2fdU, 0x45afafeaU,
   18.74 +    0x239c9cbfU, 0x53a4a4f7U, 0xe4727296U, 0x9bc0c05bU,
   18.75 +    0x75b7b7c2U, 0xe1fdfd1cU, 0x3d9393aeU, 0x4c26266aU,
   18.76 +    0x6c36365aU, 0x7e3f3f41U, 0xf5f7f702U, 0x83cccc4fU,
   18.77 +    0x6834345cU, 0x51a5a5f4U, 0xd1e5e534U, 0xf9f1f108U,
   18.78 +    0xe2717193U, 0xabd8d873U, 0x62313153U, 0x2a15153fU,
   18.79 +    0x0804040cU, 0x95c7c752U, 0x46232365U, 0x9dc3c35eU,
   18.80 +    0x30181828U, 0x379696a1U, 0x0a05050fU, 0x2f9a9ab5U,
   18.81 +    0x0e070709U, 0x24121236U, 0x1b80809bU, 0xdfe2e23dU,
   18.82 +    0xcdebeb26U, 0x4e272769U, 0x7fb2b2cdU, 0xea75759fU,
   18.83 +    0x1209091bU, 0x1d83839eU, 0x582c2c74U, 0x341a1a2eU,
   18.84 +    0x361b1b2dU, 0xdc6e6eb2U, 0xb45a5aeeU, 0x5ba0a0fbU,
   18.85 +    0xa45252f6U, 0x763b3b4dU, 0xb7d6d661U, 0x7db3b3ceU,
   18.86 +    0x5229297bU, 0xdde3e33eU, 0x5e2f2f71U, 0x13848497U,
   18.87 +    0xa65353f5U, 0xb9d1d168U, 0x00000000U, 0xc1eded2cU,
   18.88 +    0x40202060U, 0xe3fcfc1fU, 0x79b1b1c8U, 0xb65b5bedU,
   18.89 +    0xd46a6abeU, 0x8dcbcb46U, 0x67bebed9U, 0x7239394bU,
   18.90 +    0x944a4adeU, 0x984c4cd4U, 0xb05858e8U, 0x85cfcf4aU,
   18.91 +    0xbbd0d06bU, 0xc5efef2aU, 0x4faaaae5U, 0xedfbfb16U,
   18.92 +    0x864343c5U, 0x9a4d4dd7U, 0x66333355U, 0x11858594U,
   18.93 +    0x8a4545cfU, 0xe9f9f910U, 0x04020206U, 0xfe7f7f81U,
   18.94 +    0xa05050f0U, 0x783c3c44U, 0x259f9fbaU, 0x4ba8a8e3U,
   18.95 +    0xa25151f3U, 0x5da3a3feU, 0x804040c0U, 0x058f8f8aU,
   18.96 +    0x3f9292adU, 0x219d9dbcU, 0x70383848U, 0xf1f5f504U,
   18.97 +    0x63bcbcdfU, 0x77b6b6c1U, 0xafdada75U, 0x42212163U,
   18.98 +    0x20101030U, 0xe5ffff1aU, 0xfdf3f30eU, 0xbfd2d26dU,
   18.99 +    0x81cdcd4cU, 0x180c0c14U, 0x26131335U, 0xc3ecec2fU,
  18.100 +    0xbe5f5fe1U, 0x359797a2U, 0x884444ccU, 0x2e171739U,
  18.101 +    0x93c4c457U, 0x55a7a7f2U, 0xfc7e7e82U, 0x7a3d3d47U,
  18.102 +    0xc86464acU, 0xba5d5de7U, 0x3219192bU, 0xe6737395U,
  18.103 +    0xc06060a0U, 0x19818198U, 0x9e4f4fd1U, 0xa3dcdc7fU,
  18.104 +    0x44222266U, 0x542a2a7eU, 0x3b9090abU, 0x0b888883U,
  18.105 +    0x8c4646caU, 0xc7eeee29U, 0x6bb8b8d3U, 0x2814143cU,
  18.106 +    0xa7dede79U, 0xbc5e5ee2U, 0x160b0b1dU, 0xaddbdb76U,
  18.107 +    0xdbe0e03bU, 0x64323256U, 0x743a3a4eU, 0x140a0a1eU,
  18.108 +    0x924949dbU, 0x0c06060aU, 0x4824246cU, 0xb85c5ce4U,
  18.109 +    0x9fc2c25dU, 0xbdd3d36eU, 0x43acacefU, 0xc46262a6U,
  18.110 +    0x399191a8U, 0x319595a4U, 0xd3e4e437U, 0xf279798bU,
  18.111 +    0xd5e7e732U, 0x8bc8c843U, 0x6e373759U, 0xda6d6db7U,
  18.112 +    0x018d8d8cU, 0xb1d5d564U, 0x9c4e4ed2U, 0x49a9a9e0U,
  18.113 +    0xd86c6cb4U, 0xac5656faU, 0xf3f4f407U, 0xcfeaea25U,
  18.114 +    0xca6565afU, 0xf47a7a8eU, 0x47aeaee9U, 0x10080818U,
  18.115 +    0x6fbabad5U, 0xf0787888U, 0x4a25256fU, 0x5c2e2e72U,
  18.116 +    0x381c1c24U, 0x57a6a6f1U, 0x73b4b4c7U, 0x97c6c651U,
  18.117 +    0xcbe8e823U, 0xa1dddd7cU, 0xe874749cU, 0x3e1f1f21U,
  18.118 +    0x964b4bddU, 0x61bdbddcU, 0x0d8b8b86U, 0x0f8a8a85U,
  18.119 +    0xe0707090U, 0x7c3e3e42U, 0x71b5b5c4U, 0xcc6666aaU,
  18.120 +    0x904848d8U, 0x06030305U, 0xf7f6f601U, 0x1c0e0e12U,
  18.121 +    0xc26161a3U, 0x6a35355fU, 0xae5757f9U, 0x69b9b9d0U,
  18.122 +    0x17868691U, 0x99c1c158U, 0x3a1d1d27U, 0x279e9eb9U,
  18.123 +    0xd9e1e138U, 0xebf8f813U, 0x2b9898b3U, 0x22111133U,
  18.124 +    0xd26969bbU, 0xa9d9d970U, 0x078e8e89U, 0x339494a7U,
  18.125 +    0x2d9b9bb6U, 0x3c1e1e22U, 0x15878792U, 0xc9e9e920U,
  18.126 +    0x87cece49U, 0xaa5555ffU, 0x50282878U, 0xa5dfdf7aU,
  18.127 +    0x038c8c8fU, 0x59a1a1f8U, 0x09898980U, 0x1a0d0d17U,
  18.128 +    0x65bfbfdaU, 0xd7e6e631U, 0x844242c6U, 0xd06868b8U,
  18.129 +    0x824141c3U, 0x299999b0U, 0x5a2d2d77U, 0x1e0f0f11U,
  18.130 +    0x7bb0b0cbU, 0xa85454fcU, 0x6dbbbbd6U, 0x2c16163aU,
  18.131 +};
  18.132 +static const u32 Te1[256] = {
  18.133 +    0xa5c66363U, 0x84f87c7cU, 0x99ee7777U, 0x8df67b7bU,
  18.134 +    0x0dfff2f2U, 0xbdd66b6bU, 0xb1de6f6fU, 0x5491c5c5U,
  18.135 +    0x50603030U, 0x03020101U, 0xa9ce6767U, 0x7d562b2bU,
  18.136 +    0x19e7fefeU, 0x62b5d7d7U, 0xe64dababU, 0x9aec7676U,
  18.137 +    0x458fcacaU, 0x9d1f8282U, 0x4089c9c9U, 0x87fa7d7dU,
  18.138 +    0x15effafaU, 0xebb25959U, 0xc98e4747U, 0x0bfbf0f0U,
  18.139 +    0xec41adadU, 0x67b3d4d4U, 0xfd5fa2a2U, 0xea45afafU,
  18.140 +    0xbf239c9cU, 0xf753a4a4U, 0x96e47272U, 0x5b9bc0c0U,
  18.141 +    0xc275b7b7U, 0x1ce1fdfdU, 0xae3d9393U, 0x6a4c2626U,
  18.142 +    0x5a6c3636U, 0x417e3f3fU, 0x02f5f7f7U, 0x4f83ccccU,
  18.143 +    0x5c683434U, 0xf451a5a5U, 0x34d1e5e5U, 0x08f9f1f1U,
  18.144 +    0x93e27171U, 0x73abd8d8U, 0x53623131U, 0x3f2a1515U,
  18.145 +    0x0c080404U, 0x5295c7c7U, 0x65462323U, 0x5e9dc3c3U,
  18.146 +    0x28301818U, 0xa1379696U, 0x0f0a0505U, 0xb52f9a9aU,
  18.147 +    0x090e0707U, 0x36241212U, 0x9b1b8080U, 0x3ddfe2e2U,
  18.148 +    0x26cdebebU, 0x694e2727U, 0xcd7fb2b2U, 0x9fea7575U,
  18.149 +    0x1b120909U, 0x9e1d8383U, 0x74582c2cU, 0x2e341a1aU,
  18.150 +    0x2d361b1bU, 0xb2dc6e6eU, 0xeeb45a5aU, 0xfb5ba0a0U,
  18.151 +    0xf6a45252U, 0x4d763b3bU, 0x61b7d6d6U, 0xce7db3b3U,
  18.152 +    0x7b522929U, 0x3edde3e3U, 0x715e2f2fU, 0x97138484U,
  18.153 +    0xf5a65353U, 0x68b9d1d1U, 0x00000000U, 0x2cc1ededU,
  18.154 +    0x60402020U, 0x1fe3fcfcU, 0xc879b1b1U, 0xedb65b5bU,
  18.155 +    0xbed46a6aU, 0x468dcbcbU, 0xd967bebeU, 0x4b723939U,
  18.156 +    0xde944a4aU, 0xd4984c4cU, 0xe8b05858U, 0x4a85cfcfU,
  18.157 +    0x6bbbd0d0U, 0x2ac5efefU, 0xe54faaaaU, 0x16edfbfbU,
  18.158 +    0xc5864343U, 0xd79a4d4dU, 0x55663333U, 0x94118585U,
  18.159 +    0xcf8a4545U, 0x10e9f9f9U, 0x06040202U, 0x81fe7f7fU,
  18.160 +    0xf0a05050U, 0x44783c3cU, 0xba259f9fU, 0xe34ba8a8U,
  18.161 +    0xf3a25151U, 0xfe5da3a3U, 0xc0804040U, 0x8a058f8fU,
  18.162 +    0xad3f9292U, 0xbc219d9dU, 0x48703838U, 0x04f1f5f5U,
  18.163 +    0xdf63bcbcU, 0xc177b6b6U, 0x75afdadaU, 0x63422121U,
  18.164 +    0x30201010U, 0x1ae5ffffU, 0x0efdf3f3U, 0x6dbfd2d2U,
  18.165 +    0x4c81cdcdU, 0x14180c0cU, 0x35261313U, 0x2fc3ececU,
  18.166 +    0xe1be5f5fU, 0xa2359797U, 0xcc884444U, 0x392e1717U,
  18.167 +    0x5793c4c4U, 0xf255a7a7U, 0x82fc7e7eU, 0x477a3d3dU,
  18.168 +    0xacc86464U, 0xe7ba5d5dU, 0x2b321919U, 0x95e67373U,
  18.169 +    0xa0c06060U, 0x98198181U, 0xd19e4f4fU, 0x7fa3dcdcU,
  18.170 +    0x66442222U, 0x7e542a2aU, 0xab3b9090U, 0x830b8888U,
  18.171 +    0xca8c4646U, 0x29c7eeeeU, 0xd36bb8b8U, 0x3c281414U,
  18.172 +    0x79a7dedeU, 0xe2bc5e5eU, 0x1d160b0bU, 0x76addbdbU,
  18.173 +    0x3bdbe0e0U, 0x56643232U, 0x4e743a3aU, 0x1e140a0aU,
  18.174 +    0xdb924949U, 0x0a0c0606U, 0x6c482424U, 0xe4b85c5cU,
  18.175 +    0x5d9fc2c2U, 0x6ebdd3d3U, 0xef43acacU, 0xa6c46262U,
  18.176 +    0xa8399191U, 0xa4319595U, 0x37d3e4e4U, 0x8bf27979U,
  18.177 +    0x32d5e7e7U, 0x438bc8c8U, 0x596e3737U, 0xb7da6d6dU,
  18.178 +    0x8c018d8dU, 0x64b1d5d5U, 0xd29c4e4eU, 0xe049a9a9U,
  18.179 +    0xb4d86c6cU, 0xfaac5656U, 0x07f3f4f4U, 0x25cfeaeaU,
  18.180 +    0xafca6565U, 0x8ef47a7aU, 0xe947aeaeU, 0x18100808U,
  18.181 +    0xd56fbabaU, 0x88f07878U, 0x6f4a2525U, 0x725c2e2eU,
  18.182 +    0x24381c1cU, 0xf157a6a6U, 0xc773b4b4U, 0x5197c6c6U,
  18.183 +    0x23cbe8e8U, 0x7ca1ddddU, 0x9ce87474U, 0x213e1f1fU,
  18.184 +    0xdd964b4bU, 0xdc61bdbdU, 0x860d8b8bU, 0x850f8a8aU,
  18.185 +    0x90e07070U, 0x427c3e3eU, 0xc471b5b5U, 0xaacc6666U,
  18.186 +    0xd8904848U, 0x05060303U, 0x01f7f6f6U, 0x121c0e0eU,
  18.187 +    0xa3c26161U, 0x5f6a3535U, 0xf9ae5757U, 0xd069b9b9U,
  18.188 +    0x91178686U, 0x5899c1c1U, 0x273a1d1dU, 0xb9279e9eU,
  18.189 +    0x38d9e1e1U, 0x13ebf8f8U, 0xb32b9898U, 0x33221111U,
  18.190 +    0xbbd26969U, 0x70a9d9d9U, 0x89078e8eU, 0xa7339494U,
  18.191 +    0xb62d9b9bU, 0x223c1e1eU, 0x92158787U, 0x20c9e9e9U,
  18.192 +    0x4987ceceU, 0xffaa5555U, 0x78502828U, 0x7aa5dfdfU,
  18.193 +    0x8f038c8cU, 0xf859a1a1U, 0x80098989U, 0x171a0d0dU,
  18.194 +    0xda65bfbfU, 0x31d7e6e6U, 0xc6844242U, 0xb8d06868U,
  18.195 +    0xc3824141U, 0xb0299999U, 0x775a2d2dU, 0x111e0f0fU,
  18.196 +    0xcb7bb0b0U, 0xfca85454U, 0xd66dbbbbU, 0x3a2c1616U,
  18.197 +};
  18.198 +static const u32 Te2[256] = {
  18.199 +    0x63a5c663U, 0x7c84f87cU, 0x7799ee77U, 0x7b8df67bU,
  18.200 +    0xf20dfff2U, 0x6bbdd66bU, 0x6fb1de6fU, 0xc55491c5U,
  18.201 +    0x30506030U, 0x01030201U, 0x67a9ce67U, 0x2b7d562bU,
  18.202 +    0xfe19e7feU, 0xd762b5d7U, 0xabe64dabU, 0x769aec76U,
  18.203 +    0xca458fcaU, 0x829d1f82U, 0xc94089c9U, 0x7d87fa7dU,
  18.204 +    0xfa15effaU, 0x59ebb259U, 0x47c98e47U, 0xf00bfbf0U,
  18.205 +    0xadec41adU, 0xd467b3d4U, 0xa2fd5fa2U, 0xafea45afU,
  18.206 +    0x9cbf239cU, 0xa4f753a4U, 0x7296e472U, 0xc05b9bc0U,
  18.207 +    0xb7c275b7U, 0xfd1ce1fdU, 0x93ae3d93U, 0x266a4c26U,
  18.208 +    0x365a6c36U, 0x3f417e3fU, 0xf702f5f7U, 0xcc4f83ccU,
  18.209 +    0x345c6834U, 0xa5f451a5U, 0xe534d1e5U, 0xf108f9f1U,
  18.210 +    0x7193e271U, 0xd873abd8U, 0x31536231U, 0x153f2a15U,
  18.211 +    0x040c0804U, 0xc75295c7U, 0x23654623U, 0xc35e9dc3U,
  18.212 +    0x18283018U, 0x96a13796U, 0x050f0a05U, 0x9ab52f9aU,
  18.213 +    0x07090e07U, 0x12362412U, 0x809b1b80U, 0xe23ddfe2U,
  18.214 +    0xeb26cdebU, 0x27694e27U, 0xb2cd7fb2U, 0x759fea75U,
  18.215 +    0x091b1209U, 0x839e1d83U, 0x2c74582cU, 0x1a2e341aU,
  18.216 +    0x1b2d361bU, 0x6eb2dc6eU, 0x5aeeb45aU, 0xa0fb5ba0U,
  18.217 +    0x52f6a452U, 0x3b4d763bU, 0xd661b7d6U, 0xb3ce7db3U,
  18.218 +    0x297b5229U, 0xe33edde3U, 0x2f715e2fU, 0x84971384U,
  18.219 +    0x53f5a653U, 0xd168b9d1U, 0x00000000U, 0xed2cc1edU,
  18.220 +    0x20604020U, 0xfc1fe3fcU, 0xb1c879b1U, 0x5bedb65bU,
  18.221 +    0x6abed46aU, 0xcb468dcbU, 0xbed967beU, 0x394b7239U,
  18.222 +    0x4ade944aU, 0x4cd4984cU, 0x58e8b058U, 0xcf4a85cfU,
  18.223 +    0xd06bbbd0U, 0xef2ac5efU, 0xaae54faaU, 0xfb16edfbU,
  18.224 +    0x43c58643U, 0x4dd79a4dU, 0x33556633U, 0x85941185U,
  18.225 +    0x45cf8a45U, 0xf910e9f9U, 0x02060402U, 0x7f81fe7fU,
  18.226 +    0x50f0a050U, 0x3c44783cU, 0x9fba259fU, 0xa8e34ba8U,
  18.227 +    0x51f3a251U, 0xa3fe5da3U, 0x40c08040U, 0x8f8a058fU,
  18.228 +    0x92ad3f92U, 0x9dbc219dU, 0x38487038U, 0xf504f1f5U,
  18.229 +    0xbcdf63bcU, 0xb6c177b6U, 0xda75afdaU, 0x21634221U,
  18.230 +    0x10302010U, 0xff1ae5ffU, 0xf30efdf3U, 0xd26dbfd2U,
  18.231 +    0xcd4c81cdU, 0x0c14180cU, 0x13352613U, 0xec2fc3ecU,
  18.232 +    0x5fe1be5fU, 0x97a23597U, 0x44cc8844U, 0x17392e17U,
  18.233 +    0xc45793c4U, 0xa7f255a7U, 0x7e82fc7eU, 0x3d477a3dU,
  18.234 +    0x64acc864U, 0x5de7ba5dU, 0x192b3219U, 0x7395e673U,
  18.235 +    0x60a0c060U, 0x81981981U, 0x4fd19e4fU, 0xdc7fa3dcU,
  18.236 +    0x22664422U, 0x2a7e542aU, 0x90ab3b90U, 0x88830b88U,
  18.237 +    0x46ca8c46U, 0xee29c7eeU, 0xb8d36bb8U, 0x143c2814U,
  18.238 +    0xde79a7deU, 0x5ee2bc5eU, 0x0b1d160bU, 0xdb76addbU,
  18.239 +    0xe03bdbe0U, 0x32566432U, 0x3a4e743aU, 0x0a1e140aU,
  18.240 +    0x49db9249U, 0x060a0c06U, 0x246c4824U, 0x5ce4b85cU,
  18.241 +    0xc25d9fc2U, 0xd36ebdd3U, 0xacef43acU, 0x62a6c462U,
  18.242 +    0x91a83991U, 0x95a43195U, 0xe437d3e4U, 0x798bf279U,
  18.243 +    0xe732d5e7U, 0xc8438bc8U, 0x37596e37U, 0x6db7da6dU,
  18.244 +    0x8d8c018dU, 0xd564b1d5U, 0x4ed29c4eU, 0xa9e049a9U,
  18.245 +    0x6cb4d86cU, 0x56faac56U, 0xf407f3f4U, 0xea25cfeaU,
  18.246 +    0x65afca65U, 0x7a8ef47aU, 0xaee947aeU, 0x08181008U,
  18.247 +    0xbad56fbaU, 0x7888f078U, 0x256f4a25U, 0x2e725c2eU,
  18.248 +    0x1c24381cU, 0xa6f157a6U, 0xb4c773b4U, 0xc65197c6U,
  18.249 +    0xe823cbe8U, 0xdd7ca1ddU, 0x749ce874U, 0x1f213e1fU,
  18.250 +    0x4bdd964bU, 0xbddc61bdU, 0x8b860d8bU, 0x8a850f8aU,
  18.251 +    0x7090e070U, 0x3e427c3eU, 0xb5c471b5U, 0x66aacc66U,
  18.252 +    0x48d89048U, 0x03050603U, 0xf601f7f6U, 0x0e121c0eU,
  18.253 +    0x61a3c261U, 0x355f6a35U, 0x57f9ae57U, 0xb9d069b9U,
  18.254 +    0x86911786U, 0xc15899c1U, 0x1d273a1dU, 0x9eb9279eU,
  18.255 +    0xe138d9e1U, 0xf813ebf8U, 0x98b32b98U, 0x11332211U,
  18.256 +    0x69bbd269U, 0xd970a9d9U, 0x8e89078eU, 0x94a73394U,
  18.257 +    0x9bb62d9bU, 0x1e223c1eU, 0x87921587U, 0xe920c9e9U,
  18.258 +    0xce4987ceU, 0x55ffaa55U, 0x28785028U, 0xdf7aa5dfU,
  18.259 +    0x8c8f038cU, 0xa1f859a1U, 0x89800989U, 0x0d171a0dU,
  18.260 +    0xbfda65bfU, 0xe631d7e6U, 0x42c68442U, 0x68b8d068U,
  18.261 +    0x41c38241U, 0x99b02999U, 0x2d775a2dU, 0x0f111e0fU,
  18.262 +    0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U,
  18.263 +};
  18.264 +static const u32 Te3[256] = {
  18.265 +
  18.266 +    0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U,
  18.267 +    0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U,
  18.268 +    0x30305060U, 0x01010302U, 0x6767a9ceU, 0x2b2b7d56U,
  18.269 +    0xfefe19e7U, 0xd7d762b5U, 0xababe64dU, 0x76769aecU,
  18.270 +    0xcaca458fU, 0x82829d1fU, 0xc9c94089U, 0x7d7d87faU,
  18.271 +    0xfafa15efU, 0x5959ebb2U, 0x4747c98eU, 0xf0f00bfbU,
  18.272 +    0xadadec41U, 0xd4d467b3U, 0xa2a2fd5fU, 0xafafea45U,
  18.273 +    0x9c9cbf23U, 0xa4a4f753U, 0x727296e4U, 0xc0c05b9bU,
  18.274 +    0xb7b7c275U, 0xfdfd1ce1U, 0x9393ae3dU, 0x26266a4cU,
  18.275 +    0x36365a6cU, 0x3f3f417eU, 0xf7f702f5U, 0xcccc4f83U,
  18.276 +    0x34345c68U, 0xa5a5f451U, 0xe5e534d1U, 0xf1f108f9U,
  18.277 +    0x717193e2U, 0xd8d873abU, 0x31315362U, 0x15153f2aU,
  18.278 +    0x04040c08U, 0xc7c75295U, 0x23236546U, 0xc3c35e9dU,
  18.279 +    0x18182830U, 0x9696a137U, 0x05050f0aU, 0x9a9ab52fU,
  18.280 +    0x0707090eU, 0x12123624U, 0x80809b1bU, 0xe2e23ddfU,
  18.281 +    0xebeb26cdU, 0x2727694eU, 0xb2b2cd7fU, 0x75759feaU,
  18.282 +    0x09091b12U, 0x83839e1dU, 0x2c2c7458U, 0x1a1a2e34U,
  18.283 +    0x1b1b2d36U, 0x6e6eb2dcU, 0x5a5aeeb4U, 0xa0a0fb5bU,
  18.284 +    0x5252f6a4U, 0x3b3b4d76U, 0xd6d661b7U, 0xb3b3ce7dU,
  18.285 +    0x29297b52U, 0xe3e33eddU, 0x2f2f715eU, 0x84849713U,
  18.286 +    0x5353f5a6U, 0xd1d168b9U, 0x00000000U, 0xeded2cc1U,
  18.287 +    0x20206040U, 0xfcfc1fe3U, 0xb1b1c879U, 0x5b5bedb6U,
  18.288 +    0x6a6abed4U, 0xcbcb468dU, 0xbebed967U, 0x39394b72U,
  18.289 +    0x4a4ade94U, 0x4c4cd498U, 0x5858e8b0U, 0xcfcf4a85U,
  18.290 +    0xd0d06bbbU, 0xefef2ac5U, 0xaaaae54fU, 0xfbfb16edU,
  18.291 +    0x4343c586U, 0x4d4dd79aU, 0x33335566U, 0x85859411U,
  18.292 +    0x4545cf8aU, 0xf9f910e9U, 0x02020604U, 0x7f7f81feU,
  18.293 +    0x5050f0a0U, 0x3c3c4478U, 0x9f9fba25U, 0xa8a8e34bU,
  18.294 +    0x5151f3a2U, 0xa3a3fe5dU, 0x4040c080U, 0x8f8f8a05U,
  18.295 +    0x9292ad3fU, 0x9d9dbc21U, 0x38384870U, 0xf5f504f1U,
  18.296 +    0xbcbcdf63U, 0xb6b6c177U, 0xdada75afU, 0x21216342U,
  18.297 +    0x10103020U, 0xffff1ae5U, 0xf3f30efdU, 0xd2d26dbfU,
  18.298 +    0xcdcd4c81U, 0x0c0c1418U, 0x13133526U, 0xecec2fc3U,
  18.299 +    0x5f5fe1beU, 0x9797a235U, 0x4444cc88U, 0x1717392eU,
  18.300 +    0xc4c45793U, 0xa7a7f255U, 0x7e7e82fcU, 0x3d3d477aU,
  18.301 +    0x6464acc8U, 0x5d5de7baU, 0x19192b32U, 0x737395e6U,
  18.302 +    0x6060a0c0U, 0x81819819U, 0x4f4fd19eU, 0xdcdc7fa3U,
  18.303 +    0x22226644U, 0x2a2a7e54U, 0x9090ab3bU, 0x8888830bU,
  18.304 +    0x4646ca8cU, 0xeeee29c7U, 0xb8b8d36bU, 0x14143c28U,
  18.305 +    0xdede79a7U, 0x5e5ee2bcU, 0x0b0b1d16U, 0xdbdb76adU,
  18.306 +    0xe0e03bdbU, 0x32325664U, 0x3a3a4e74U, 0x0a0a1e14U,
  18.307 +    0x4949db92U, 0x06060a0cU, 0x24246c48U, 0x5c5ce4b8U,
  18.308 +    0xc2c25d9fU, 0xd3d36ebdU, 0xacacef43U, 0x6262a6c4U,
  18.309 +    0x9191a839U, 0x9595a431U, 0xe4e437d3U, 0x79798bf2U,
  18.310 +    0xe7e732d5U, 0xc8c8438bU, 0x3737596eU, 0x6d6db7daU,
  18.311 +    0x8d8d8c01U, 0xd5d564b1U, 0x4e4ed29cU, 0xa9a9e049U,
  18.312 +    0x6c6cb4d8U, 0x5656faacU, 0xf4f407f3U, 0xeaea25cfU,
  18.313 +    0x6565afcaU, 0x7a7a8ef4U, 0xaeaee947U, 0x08081810U,
  18.314 +    0xbabad56fU, 0x787888f0U, 0x25256f4aU, 0x2e2e725cU,
  18.315 +    0x1c1c2438U, 0xa6a6f157U, 0xb4b4c773U, 0xc6c65197U,
  18.316 +    0xe8e823cbU, 0xdddd7ca1U, 0x74749ce8U, 0x1f1f213eU,
  18.317 +    0x4b4bdd96U, 0xbdbddc61U, 0x8b8b860dU, 0x8a8a850fU,
  18.318 +    0x707090e0U, 0x3e3e427cU, 0xb5b5c471U, 0x6666aaccU,
  18.319 +    0x4848d890U, 0x03030506U, 0xf6f601f7U, 0x0e0e121cU,
  18.320 +    0x6161a3c2U, 0x35355f6aU, 0x5757f9aeU, 0xb9b9d069U,
  18.321 +    0x86869117U, 0xc1c15899U, 0x1d1d273aU, 0x9e9eb927U,
  18.322 +    0xe1e138d9U, 0xf8f813ebU, 0x9898b32bU, 0x11113322U,
  18.323 +    0x6969bbd2U, 0xd9d970a9U, 0x8e8e8907U, 0x9494a733U,
  18.324 +    0x9b9bb62dU, 0x1e1e223cU, 0x87879215U, 0xe9e920c9U,
  18.325 +    0xcece4987U, 0x5555ffaaU, 0x28287850U, 0xdfdf7aa5U,
  18.326 +    0x8c8c8f03U, 0xa1a1f859U, 0x89898009U, 0x0d0d171aU,
  18.327 +    0xbfbfda65U, 0xe6e631d7U, 0x4242c684U, 0x6868b8d0U,
  18.328 +    0x4141c382U, 0x9999b029U, 0x2d2d775aU, 0x0f0f111eU,
  18.329 +    0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU,
  18.330 +};
  18.331 +static const u32 Te4[256] = {
  18.332 +    0x63636363U, 0x7c7c7c7cU, 0x77777777U, 0x7b7b7b7bU,
  18.333 +    0xf2f2f2f2U, 0x6b6b6b6bU, 0x6f6f6f6fU, 0xc5c5c5c5U,
  18.334 +    0x30303030U, 0x01010101U, 0x67676767U, 0x2b2b2b2bU,
  18.335 +    0xfefefefeU, 0xd7d7d7d7U, 0xababababU, 0x76767676U,
  18.336 +    0xcacacacaU, 0x82828282U, 0xc9c9c9c9U, 0x7d7d7d7dU,
  18.337 +    0xfafafafaU, 0x59595959U, 0x47474747U, 0xf0f0f0f0U,
  18.338 +    0xadadadadU, 0xd4d4d4d4U, 0xa2a2a2a2U, 0xafafafafU,
  18.339 +    0x9c9c9c9cU, 0xa4a4a4a4U, 0x72727272U, 0xc0c0c0c0U,
  18.340 +    0xb7b7b7b7U, 0xfdfdfdfdU, 0x93939393U, 0x26262626U,
  18.341 +    0x36363636U, 0x3f3f3f3fU, 0xf7f7f7f7U, 0xccccccccU,
  18.342 +    0x34343434U, 0xa5a5a5a5U, 0xe5e5e5e5U, 0xf1f1f1f1U,
  18.343 +    0x71717171U, 0xd8d8d8d8U, 0x31313131U, 0x15151515U,
  18.344 +    0x04040404U, 0xc7c7c7c7U, 0x23232323U, 0xc3c3c3c3U,
  18.345 +    0x18181818U, 0x96969696U, 0x05050505U, 0x9a9a9a9aU,
  18.346 +    0x07070707U, 0x12121212U, 0x80808080U, 0xe2e2e2e2U,
  18.347 +    0xebebebebU, 0x27272727U, 0xb2b2b2b2U, 0x75757575U,
  18.348 +    0x09090909U, 0x83838383U, 0x2c2c2c2cU, 0x1a1a1a1aU,
  18.349 +    0x1b1b1b1bU, 0x6e6e6e6eU, 0x5a5a5a5aU, 0xa0a0a0a0U,
  18.350 +    0x52525252U, 0x3b3b3b3bU, 0xd6d6d6d6U, 0xb3b3b3b3U,
  18.351 +    0x29292929U, 0xe3e3e3e3U, 0x2f2f2f2fU, 0x84848484U,
  18.352 +    0x53535353U, 0xd1d1d1d1U, 0x00000000U, 0xededededU,
  18.353 +    0x20202020U, 0xfcfcfcfcU, 0xb1b1b1b1U, 0x5b5b5b5bU,
  18.354 +    0x6a6a6a6aU, 0xcbcbcbcbU, 0xbebebebeU, 0x39393939U,
  18.355 +    0x4a4a4a4aU, 0x4c4c4c4cU, 0x58585858U, 0xcfcfcfcfU,
  18.356 +    0xd0d0d0d0U, 0xefefefefU, 0xaaaaaaaaU, 0xfbfbfbfbU,
  18.357 +    0x43434343U, 0x4d4d4d4dU, 0x33333333U, 0x85858585U,
  18.358 +    0x45454545U, 0xf9f9f9f9U, 0x02020202U, 0x7f7f7f7fU,
  18.359 +    0x50505050U, 0x3c3c3c3cU, 0x9f9f9f9fU, 0xa8a8a8a8U,
  18.360 +    0x51515151U, 0xa3a3a3a3U, 0x40404040U, 0x8f8f8f8fU,
  18.361 +    0x92929292U, 0x9d9d9d9dU, 0x38383838U, 0xf5f5f5f5U,
  18.362 +    0xbcbcbcbcU, 0xb6b6b6b6U, 0xdadadadaU, 0x21212121U,
  18.363 +    0x10101010U, 0xffffffffU, 0xf3f3f3f3U, 0xd2d2d2d2U,
  18.364 +    0xcdcdcdcdU, 0x0c0c0c0cU, 0x13131313U, 0xececececU,
  18.365 +    0x5f5f5f5fU, 0x97979797U, 0x44444444U, 0x17171717U,
  18.366 +    0xc4c4c4c4U, 0xa7a7a7a7U, 0x7e7e7e7eU, 0x3d3d3d3dU,
  18.367 +    0x64646464U, 0x5d5d5d5dU, 0x19191919U, 0x73737373U,
  18.368 +    0x60606060U, 0x81818181U, 0x4f4f4f4fU, 0xdcdcdcdcU,
  18.369 +    0x22222222U, 0x2a2a2a2aU, 0x90909090U, 0x88888888U,
  18.370 +    0x46464646U, 0xeeeeeeeeU, 0xb8b8b8b8U, 0x14141414U,
  18.371 +    0xdedededeU, 0x5e5e5e5eU, 0x0b0b0b0bU, 0xdbdbdbdbU,
  18.372 +    0xe0e0e0e0U, 0x32323232U, 0x3a3a3a3aU, 0x0a0a0a0aU,
  18.373 +    0x49494949U, 0x06060606U, 0x24242424U, 0x5c5c5c5cU,
  18.374 +    0xc2c2c2c2U, 0xd3d3d3d3U, 0xacacacacU, 0x62626262U,
  18.375 +    0x91919191U, 0x95959595U, 0xe4e4e4e4U, 0x79797979U,
  18.376 +    0xe7e7e7e7U, 0xc8c8c8c8U, 0x37373737U, 0x6d6d6d6dU,
  18.377 +    0x8d8d8d8dU, 0xd5d5d5d5U, 0x4e4e4e4eU, 0xa9a9a9a9U,
  18.378 +    0x6c6c6c6cU, 0x56565656U, 0xf4f4f4f4U, 0xeaeaeaeaU,
  18.379 +    0x65656565U, 0x7a7a7a7aU, 0xaeaeaeaeU, 0x08080808U,
  18.380 +    0xbabababaU, 0x78787878U, 0x25252525U, 0x2e2e2e2eU,
  18.381 +    0x1c1c1c1cU, 0xa6a6a6a6U, 0xb4b4b4b4U, 0xc6c6c6c6U,
  18.382 +    0xe8e8e8e8U, 0xddddddddU, 0x74747474U, 0x1f1f1f1fU,
  18.383 +    0x4b4b4b4bU, 0xbdbdbdbdU, 0x8b8b8b8bU, 0x8a8a8a8aU,
  18.384 +    0x70707070U, 0x3e3e3e3eU, 0xb5b5b5b5U, 0x66666666U,
  18.385 +    0x48484848U, 0x03030303U, 0xf6f6f6f6U, 0x0e0e0e0eU,
  18.386 +    0x61616161U, 0x35353535U, 0x57575757U, 0xb9b9b9b9U,
  18.387 +    0x86868686U, 0xc1c1c1c1U, 0x1d1d1d1dU, 0x9e9e9e9eU,
  18.388 +    0xe1e1e1e1U, 0xf8f8f8f8U, 0x98989898U, 0x11111111U,
  18.389 +    0x69696969U, 0xd9d9d9d9U, 0x8e8e8e8eU, 0x94949494U,
  18.390 +    0x9b9b9b9bU, 0x1e1e1e1eU, 0x87878787U, 0xe9e9e9e9U,
  18.391 +    0xcecececeU, 0x55555555U, 0x28282828U, 0xdfdfdfdfU,
  18.392 +    0x8c8c8c8cU, 0xa1a1a1a1U, 0x89898989U, 0x0d0d0d0dU,
  18.393 +    0xbfbfbfbfU, 0xe6e6e6e6U, 0x42424242U, 0x68686868U,
  18.394 +    0x41414141U, 0x99999999U, 0x2d2d2d2dU, 0x0f0f0f0fU,
  18.395 +    0xb0b0b0b0U, 0x54545454U, 0xbbbbbbbbU, 0x16161616U,
  18.396 +};
  18.397 +static const u32 Td0[256] = {
  18.398 +    0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U,
  18.399 +    0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U,
  18.400 +    0x2030fa55U, 0xad766df6U, 0x88cc7691U, 0xf5024c25U,
  18.401 +    0x4fe5d7fcU, 0xc52acbd7U, 0x26354480U, 0xb562a38fU,
  18.402 +    0xdeb15a49U, 0x25ba1b67U, 0x45ea0e98U, 0x5dfec0e1U,
  18.403 +    0xc32f7502U, 0x814cf012U, 0x8d4697a3U, 0x6bd3f9c6U,
  18.404 +    0x038f5fe7U, 0x15929c95U, 0xbf6d7aebU, 0x955259daU,
  18.405 +    0xd4be832dU, 0x587421d3U, 0x49e06929U, 0x8ec9c844U,
  18.406 +    0x75c2896aU, 0xf48e7978U, 0x99583e6bU, 0x27b971ddU,
  18.407 +    0xbee14fb6U, 0xf088ad17U, 0xc920ac66U, 0x7dce3ab4U,
  18.408 +    0x63df4a18U, 0xe51a3182U, 0x97513360U, 0x62537f45U,
  18.409 +    0xb16477e0U, 0xbb6bae84U, 0xfe81a01cU, 0xf9082b94U,
  18.410 +    0x70486858U, 0x8f45fd19U, 0x94de6c87U, 0x527bf8b7U,
  18.411 +    0xab73d323U, 0x724b02e2U, 0xe31f8f57U, 0x6655ab2aU,
  18.412 +    0xb2eb2807U, 0x2fb5c203U, 0x86c57b9aU, 0xd33708a5U,
  18.413 +    0x302887f2U, 0x23bfa5b2U, 0x02036abaU, 0xed16825cU,
  18.414 +    0x8acf1c2bU, 0xa779b492U, 0xf307f2f0U, 0x4e69e2a1U,
  18.415 +    0x65daf4cdU, 0x0605bed5U, 0xd134621fU, 0xc4a6fe8aU,
  18.416 +    0x342e539dU, 0xa2f355a0U, 0x058ae132U, 0xa4f6eb75U,
  18.417 +    0x0b83ec39U, 0x4060efaaU, 0x5e719f06U, 0xbd6e1051U,
  18.418 +    0x3e218af9U, 0x96dd063dU, 0xdd3e05aeU, 0x4de6bd46U,
  18.419 +    0x91548db5U, 0x71c45d05U, 0x0406d46fU, 0x605015ffU,
  18.420 +    0x1998fb24U, 0xd6bde997U, 0x894043ccU, 0x67d99e77U,
  18.421 +    0xb0e842bdU, 0x07898b88U, 0xe7195b38U, 0x79c8eedbU,
  18.422 +    0xa17c0a47U, 0x7c420fe9U, 0xf8841ec9U, 0x00000000U,
  18.423 +    0x09808683U, 0x322bed48U, 0x1e1170acU, 0x6c5a724eU,
  18.424 +    0xfd0efffbU, 0x0f853856U, 0x3daed51eU, 0x362d3927U,
  18.425 +    0x0a0fd964U, 0x685ca621U, 0x9b5b54d1U, 0x24362e3aU,
  18.426 +    0x0c0a67b1U, 0x9357e70fU, 0xb4ee96d2U, 0x1b9b919eU,
  18.427 +    0x80c0c54fU, 0x61dc20a2U, 0x5a774b69U, 0x1c121a16U,
  18.428 +    0xe293ba0aU, 0xc0a02ae5U, 0x3c22e043U, 0x121b171dU,
  18.429 +    0x0e090d0bU, 0xf28bc7adU, 0x2db6a8b9U, 0x141ea9c8U,
  18.430 +    0x57f11985U, 0xaf75074cU, 0xee99ddbbU, 0xa37f60fdU,
  18.431 +    0xf701269fU, 0x5c72f5bcU, 0x44663bc5U, 0x5bfb7e34U,
  18.432 +    0x8b432976U, 0xcb23c6dcU, 0xb6edfc68U, 0xb8e4f163U,
  18.433 +    0xd731dccaU, 0x42638510U, 0x13972240U, 0x84c61120U,
  18.434 +    0x854a247dU, 0xd2bb3df8U, 0xaef93211U, 0xc729a16dU,
  18.435 +    0x1d9e2f4bU, 0xdcb230f3U, 0x0d8652ecU, 0x77c1e3d0U,
  18.436 +    0x2bb3166cU, 0xa970b999U, 0x119448faU, 0x47e96422U,
  18.437 +    0xa8fc8cc4U, 0xa0f03f1aU, 0x567d2cd8U, 0x223390efU,
  18.438 +    0x87494ec7U, 0xd938d1c1U, 0x8ccaa2feU, 0x98d40b36U,
  18.439 +    0xa6f581cfU, 0xa57ade28U, 0xdab78e26U, 0x3fadbfa4U,
  18.440 +    0x2c3a9de4U, 0x5078920dU, 0x6a5fcc9bU, 0x547e4662U,
  18.441 +    0xf68d13c2U, 0x90d8b8e8U, 0x2e39f75eU, 0x82c3aff5U,
  18.442 +    0x9f5d80beU, 0x69d0937cU, 0x6fd52da9U, 0xcf2512b3U,
  18.443 +    0xc8ac993bU, 0x10187da7U, 0xe89c636eU, 0xdb3bbb7bU,
  18.444 +    0xcd267809U, 0x6e5918f4U, 0xec9ab701U, 0x834f9aa8U,
  18.445 +    0xe6956e65U, 0xaaffe67eU, 0x21bccf08U, 0xef15e8e6U,
  18.446 +    0xbae79bd9U, 0x4a6f36ceU, 0xea9f09d4U, 0x29b07cd6U,
  18.447 +    0x31a4b2afU, 0x2a3f2331U, 0xc6a59430U, 0x35a266c0U,
  18.448 +    0x744ebc37U, 0xfc82caa6U, 0xe090d0b0U, 0x33a7d815U,
  18.449 +    0xf104984aU, 0x41ecdaf7U, 0x7fcd500eU, 0x1791f62fU,
  18.450 +    0x764dd68dU, 0x43efb04dU, 0xccaa4d54U, 0xe49604dfU,
  18.451 +    0x9ed1b5e3U, 0x4c6a881bU, 0xc12c1fb8U, 0x4665517fU,
  18.452 +    0x9d5eea04U, 0x018c355dU, 0xfa877473U, 0xfb0b412eU,
  18.453 +    0xb3671d5aU, 0x92dbd252U, 0xe9105633U, 0x6dd64713U,
  18.454 +    0x9ad7618cU, 0x37a10c7aU, 0x59f8148eU, 0xeb133c89U,
  18.455 +    0xcea927eeU, 0xb761c935U, 0xe11ce5edU, 0x7a47b13cU,
  18.456 +    0x9cd2df59U, 0x55f2733fU, 0x1814ce79U, 0x73c737bfU,
  18.457 +    0x53f7cdeaU, 0x5ffdaa5bU, 0xdf3d6f14U, 0x7844db86U,
  18.458 +    0xcaaff381U, 0xb968c43eU, 0x3824342cU, 0xc2a3405fU,
  18.459 +    0x161dc372U, 0xbce2250cU, 0x283c498bU, 0xff0d9541U,
  18.460 +    0x39a80171U, 0x080cb3deU, 0xd8b4e49cU, 0x6456c190U,
  18.461 +    0x7bcb8461U, 0xd532b670U, 0x486c5c74U, 0xd0b85742U,
  18.462 +};
  18.463 +static const u32 Td1[256] = {
  18.464 +    0x5051f4a7U, 0x537e4165U, 0xc31a17a4U, 0x963a275eU,
  18.465 +    0xcb3bab6bU, 0xf11f9d45U, 0xabacfa58U, 0x934be303U,
  18.466 +    0x552030faU, 0xf6ad766dU, 0x9188cc76U, 0x25f5024cU,
  18.467 +    0xfc4fe5d7U, 0xd7c52acbU, 0x80263544U, 0x8fb562a3U,
  18.468 +    0x49deb15aU, 0x6725ba1bU, 0x9845ea0eU, 0xe15dfec0U,
  18.469 +    0x02c32f75U, 0x12814cf0U, 0xa38d4697U, 0xc66bd3f9U,
  18.470 +    0xe7038f5fU, 0x9515929cU, 0xebbf6d7aU, 0xda955259U,
  18.471 +    0x2dd4be83U, 0xd3587421U, 0x2949e069U, 0x448ec9c8U,
  18.472 +    0x6a75c289U, 0x78f48e79U, 0x6b99583eU, 0xdd27b971U,
  18.473 +    0xb6bee14fU, 0x17f088adU, 0x66c920acU, 0xb47dce3aU,
  18.474 +    0x1863df4aU, 0x82e51a31U, 0x60975133U, 0x4562537fU,
  18.475 +    0xe0b16477U, 0x84bb6baeU, 0x1cfe81a0U, 0x94f9082bU,
  18.476 +    0x58704868U, 0x198f45fdU, 0x8794de6cU, 0xb7527bf8U,
  18.477 +    0x23ab73d3U, 0xe2724b02U, 0x57e31f8fU, 0x2a6655abU,
  18.478 +    0x07b2eb28U, 0x032fb5c2U, 0x9a86c57bU, 0xa5d33708U,
  18.479 +    0xf2302887U, 0xb223bfa5U, 0xba02036aU, 0x5ced1682U,
  18.480 +    0x2b8acf1cU, 0x92a779b4U, 0xf0f307f2U, 0xa14e69e2U,
  18.481 +    0xcd65daf4U, 0xd50605beU, 0x1fd13462U, 0x8ac4a6feU,
  18.482 +    0x9d342e53U, 0xa0a2f355U, 0x32058ae1U, 0x75a4f6ebU,
  18.483 +    0x390b83ecU, 0xaa4060efU, 0x065e719fU, 0x51bd6e10U,
  18.484 +    0xf93e218aU, 0x3d96dd06U, 0xaedd3e05U, 0x464de6bdU,
  18.485 +    0xb591548dU, 0x0571c45dU, 0x6f0406d4U, 0xff605015U,
  18.486 +    0x241998fbU, 0x97d6bde9U, 0xcc894043U, 0x7767d99eU,
  18.487 +    0xbdb0e842U, 0x8807898bU, 0x38e7195bU, 0xdb79c8eeU,
  18.488 +    0x47a17c0aU, 0xe97c420fU, 0xc9f8841eU, 0x00000000U,
  18.489 +    0x83098086U, 0x48322bedU, 0xac1e1170U, 0x4e6c5a72U,
  18.490 +    0xfbfd0effU, 0x560f8538U, 0x1e3daed5U, 0x27362d39U,
  18.491 +    0x640a0fd9U, 0x21685ca6U, 0xd19b5b54U, 0x3a24362eU,
  18.492 +    0xb10c0a67U, 0x0f9357e7U, 0xd2b4ee96U, 0x9e1b9b91U,
  18.493 +    0x4f80c0c5U, 0xa261dc20U, 0x695a774bU, 0x161c121aU,
  18.494 +    0x0ae293baU, 0xe5c0a02aU, 0x433c22e0U, 0x1d121b17U,
  18.495 +    0x0b0e090dU, 0xadf28bc7U, 0xb92db6a8U, 0xc8141ea9U,
  18.496 +    0x8557f119U, 0x4caf7507U, 0xbbee99ddU, 0xfda37f60U,
  18.497 +    0x9ff70126U, 0xbc5c72f5U, 0xc544663bU, 0x345bfb7eU,
  18.498 +    0x768b4329U, 0xdccb23c6U, 0x68b6edfcU, 0x63b8e4f1U,
  18.499 +    0xcad731dcU, 0x10426385U, 0x40139722U, 0x2084c611U,
  18.500 +    0x7d854a24U, 0xf8d2bb3dU, 0x11aef932U, 0x6dc729a1U,
  18.501 +    0x4b1d9e2fU, 0xf3dcb230U, 0xec0d8652U, 0xd077c1e3U,
  18.502 +    0x6c2bb316U, 0x99a970b9U, 0xfa119448U, 0x2247e964U,
  18.503 +    0xc4a8fc8cU, 0x1aa0f03fU, 0xd8567d2cU, 0xef223390U,
  18.504 +    0xc787494eU, 0xc1d938d1U, 0xfe8ccaa2U, 0x3698d40bU,
  18.505 +    0xcfa6f581U, 0x28a57adeU, 0x26dab78eU, 0xa43fadbfU,
  18.506 +    0xe42c3a9dU, 0x0d507892U, 0x9b6a5fccU, 0x62547e46U,
  18.507 +    0xc2f68d13U, 0xe890d8b8U, 0x5e2e39f7U, 0xf582c3afU,
  18.508 +    0xbe9f5d80U, 0x7c69d093U, 0xa96fd52dU, 0xb3cf2512U,
  18.509 +    0x3bc8ac99U, 0xa710187dU, 0x6ee89c63U, 0x7bdb3bbbU,
  18.510 +    0x09cd2678U, 0xf46e5918U, 0x01ec9ab7U, 0xa8834f9aU,
  18.511 +    0x65e6956eU, 0x7eaaffe6U, 0x0821bccfU, 0xe6ef15e8U,
  18.512 +    0xd9bae79bU, 0xce4a6f36U, 0xd4ea9f09U, 0xd629b07cU,
  18.513 +    0xaf31a4b2U, 0x312a3f23U, 0x30c6a594U, 0xc035a266U,
  18.514 +    0x37744ebcU, 0xa6fc82caU, 0xb0e090d0U, 0x1533a7d8U,
  18.515 +    0x4af10498U, 0xf741ecdaU, 0x0e7fcd50U, 0x2f1791f6U,
  18.516 +    0x8d764dd6U, 0x4d43efb0U, 0x54ccaa4dU, 0xdfe49604U,
  18.517 +    0xe39ed1b5U, 0x1b4c6a88U, 0xb8c12c1fU, 0x7f466551U,
  18.518 +    0x049d5eeaU, 0x5d018c35U, 0x73fa8774U, 0x2efb0b41U,
  18.519 +    0x5ab3671dU, 0x5292dbd2U, 0x33e91056U, 0x136dd647U,
  18.520 +    0x8c9ad761U, 0x7a37a10cU, 0x8e59f814U, 0x89eb133cU,
  18.521 +    0xeecea927U, 0x35b761c9U, 0xede11ce5U, 0x3c7a47b1U,
  18.522 +    0x599cd2dfU, 0x3f55f273U, 0x791814ceU, 0xbf73c737U,
  18.523 +    0xea53f7cdU, 0x5b5ffdaaU, 0x14df3d6fU, 0x867844dbU,
  18.524 +    0x81caaff3U, 0x3eb968c4U, 0x2c382434U, 0x5fc2a340U,
  18.525 +    0x72161dc3U, 0x0cbce225U, 0x8b283c49U, 0x41ff0d95U,
  18.526 +    0x7139a801U, 0xde080cb3U, 0x9cd8b4e4U, 0x906456c1U,
  18.527 +    0x617bcb84U, 0x70d532b6U, 0x74486c5cU, 0x42d0b857U,
  18.528 +};
  18.529 +static const u32 Td2[256] = {
  18.530 +    0xa75051f4U, 0x65537e41U, 0xa4c31a17U, 0x5e963a27U,
  18.531 +    0x6bcb3babU, 0x45f11f9dU, 0x58abacfaU, 0x03934be3U,
  18.532 +    0xfa552030U, 0x6df6ad76U, 0x769188ccU, 0x4c25f502U,
  18.533 +    0xd7fc4fe5U, 0xcbd7c52aU, 0x44802635U, 0xa38fb562U,
  18.534 +    0x5a49deb1U, 0x1b6725baU, 0x0e9845eaU, 0xc0e15dfeU,
  18.535 +    0x7502c32fU, 0xf012814cU, 0x97a38d46U, 0xf9c66bd3U,
  18.536 +    0x5fe7038fU, 0x9c951592U, 0x7aebbf6dU, 0x59da9552U,
  18.537 +    0x832dd4beU, 0x21d35874U, 0x692949e0U, 0xc8448ec9U,
  18.538 +    0x896a75c2U, 0x7978f48eU, 0x3e6b9958U, 0x71dd27b9U,
  18.539 +    0x4fb6bee1U, 0xad17f088U, 0xac66c920U, 0x3ab47dceU,
  18.540 +    0x4a1863dfU, 0x3182e51aU, 0x33609751U, 0x7f456253U,
  18.541 +    0x77e0b164U, 0xae84bb6bU, 0xa01cfe81U, 0x2b94f908U,
  18.542 +    0x68587048U, 0xfd198f45U, 0x6c8794deU, 0xf8b7527bU,
  18.543 +    0xd323ab73U, 0x02e2724bU, 0x8f57e31fU, 0xab2a6655U,
  18.544 +    0x2807b2ebU, 0xc2032fb5U, 0x7b9a86c5U, 0x08a5d337U,
  18.545 +    0x87f23028U, 0xa5b223bfU, 0x6aba0203U, 0x825ced16U,
  18.546 +    0x1c2b8acfU, 0xb492a779U, 0xf2f0f307U, 0xe2a14e69U,
  18.547 +    0xf4cd65daU, 0xbed50605U, 0x621fd134U, 0xfe8ac4a6U,
  18.548 +    0x539d342eU, 0x55a0a2f3U, 0xe132058aU, 0xeb75a4f6U,
  18.549 +    0xec390b83U, 0xefaa4060U, 0x9f065e71U, 0x1051bd6eU,
  18.550 +
  18.551 +    0x8af93e21U, 0x063d96ddU, 0x05aedd3eU, 0xbd464de6U,
  18.552 +    0x8db59154U, 0x5d0571c4U, 0xd46f0406U, 0x15ff6050U,
  18.553 +    0xfb241998U, 0xe997d6bdU, 0x43cc8940U, 0x9e7767d9U,
  18.554 +    0x42bdb0e8U, 0x8b880789U, 0x5b38e719U, 0xeedb79c8U,
  18.555 +    0x0a47a17cU, 0x0fe97c42U, 0x1ec9f884U, 0x00000000U,
  18.556 +    0x86830980U, 0xed48322bU, 0x70ac1e11U, 0x724e6c5aU,
  18.557 +    0xfffbfd0eU, 0x38560f85U, 0xd51e3daeU, 0x3927362dU,
  18.558 +    0xd9640a0fU, 0xa621685cU, 0x54d19b5bU, 0x2e3a2436U,
  18.559 +    0x67b10c0aU, 0xe70f9357U, 0x96d2b4eeU, 0x919e1b9bU,
  18.560 +    0xc54f80c0U, 0x20a261dcU, 0x4b695a77U, 0x1a161c12U,
  18.561 +    0xba0ae293U, 0x2ae5c0a0U, 0xe0433c22U, 0x171d121bU,
  18.562 +    0x0d0b0e09U, 0xc7adf28bU, 0xa8b92db6U, 0xa9c8141eU,
  18.563 +    0x198557f1U, 0x074caf75U, 0xddbbee99U, 0x60fda37fU,
  18.564 +    0x269ff701U, 0xf5bc5c72U, 0x3bc54466U, 0x7e345bfbU,
  18.565 +    0x29768b43U, 0xc6dccb23U, 0xfc68b6edU, 0xf163b8e4U,
  18.566 +    0xdccad731U, 0x85104263U, 0x22401397U, 0x112084c6U,
  18.567 +    0x247d854aU, 0x3df8d2bbU, 0x3211aef9U, 0xa16dc729U,
  18.568 +    0x2f4b1d9eU, 0x30f3dcb2U, 0x52ec0d86U, 0xe3d077c1U,
  18.569 +    0x166c2bb3U, 0xb999a970U, 0x48fa1194U, 0x642247e9U,
  18.570 +    0x8cc4a8fcU, 0x3f1aa0f0U, 0x2cd8567dU, 0x90ef2233U,
  18.571 +    0x4ec78749U, 0xd1c1d938U, 0xa2fe8ccaU, 0x0b3698d4U,
  18.572 +    0x81cfa6f5U, 0xde28a57aU, 0x8e26dab7U, 0xbfa43fadU,
  18.573 +    0x9de42c3aU, 0x920d5078U, 0xcc9b6a5fU, 0x4662547eU,
  18.574 +    0x13c2f68dU, 0xb8e890d8U, 0xf75e2e39U, 0xaff582c3U,
  18.575 +    0x80be9f5dU, 0x937c69d0U, 0x2da96fd5U, 0x12b3cf25U,
  18.576 +    0x993bc8acU, 0x7da71018U, 0x636ee89cU, 0xbb7bdb3bU,
  18.577 +    0x7809cd26U, 0x18f46e59U, 0xb701ec9aU, 0x9aa8834fU,
  18.578 +    0x6e65e695U, 0xe67eaaffU, 0xcf0821bcU, 0xe8e6ef15U,
  18.579 +    0x9bd9bae7U, 0x36ce4a6fU, 0x09d4ea9fU, 0x7cd629b0U,
  18.580 +    0xb2af31a4U, 0x23312a3fU, 0x9430c6a5U, 0x66c035a2U,
  18.581 +    0xbc37744eU, 0xcaa6fc82U, 0xd0b0e090U, 0xd81533a7U,
  18.582 +    0x984af104U, 0xdaf741ecU, 0x500e7fcdU, 0xf62f1791U,
  18.583 +    0xd68d764dU, 0xb04d43efU, 0x4d54ccaaU, 0x04dfe496U,
  18.584 +    0xb5e39ed1U, 0x881b4c6aU, 0x1fb8c12cU, 0x517f4665U,
  18.585 +    0xea049d5eU, 0x355d018cU, 0x7473fa87U, 0x412efb0bU,
  18.586 +    0x1d5ab367U, 0xd25292dbU, 0x5633e910U, 0x47136dd6U,
  18.587 +    0x618c9ad7U, 0x0c7a37a1U, 0x148e59f8U, 0x3c89eb13U,
  18.588 +    0x27eecea9U, 0xc935b761U, 0xe5ede11cU, 0xb13c7a47U,
  18.589 +    0xdf599cd2U, 0x733f55f2U, 0xce791814U, 0x37bf73c7U,
  18.590 +    0xcdea53f7U, 0xaa5b5ffdU, 0x6f14df3dU, 0xdb867844U,
  18.591 +    0xf381caafU, 0xc43eb968U, 0x342c3824U, 0x405fc2a3U,
  18.592 +    0xc372161dU, 0x250cbce2U, 0x498b283cU, 0x9541ff0dU,
  18.593 +    0x017139a8U, 0xb3de080cU, 0xe49cd8b4U, 0xc1906456U,
  18.594 +    0x84617bcbU, 0xb670d532U, 0x5c74486cU, 0x5742d0b8U,
  18.595 +};
  18.596 +static const u32 Td3[256] = {
  18.597 +    0xf4a75051U, 0x4165537eU, 0x17a4c31aU, 0x275e963aU,
  18.598 +    0xab6bcb3bU, 0x9d45f11fU, 0xfa58abacU, 0xe303934bU,
  18.599 +    0x30fa5520U, 0x766df6adU, 0xcc769188U, 0x024c25f5U,
  18.600 +    0xe5d7fc4fU, 0x2acbd7c5U, 0x35448026U, 0x62a38fb5U,
  18.601 +    0xb15a49deU, 0xba1b6725U, 0xea0e9845U, 0xfec0e15dU,
  18.602 +    0x2f7502c3U, 0x4cf01281U, 0x4697a38dU, 0xd3f9c66bU,
  18.603 +    0x8f5fe703U, 0x929c9515U, 0x6d7aebbfU, 0x5259da95U,
  18.604 +    0xbe832dd4U, 0x7421d358U, 0xe0692949U, 0xc9c8448eU,
  18.605 +    0xc2896a75U, 0x8e7978f4U, 0x583e6b99U, 0xb971dd27U,
  18.606 +    0xe14fb6beU, 0x88ad17f0U, 0x20ac66c9U, 0xce3ab47dU,
  18.607 +    0xdf4a1863U, 0x1a3182e5U, 0x51336097U, 0x537f4562U,
  18.608 +    0x6477e0b1U, 0x6bae84bbU, 0x81a01cfeU, 0x082b94f9U,
  18.609 +    0x48685870U, 0x45fd198fU, 0xde6c8794U, 0x7bf8b752U,
  18.610 +    0x73d323abU, 0x4b02e272U, 0x1f8f57e3U, 0x55ab2a66U,
  18.611 +    0xeb2807b2U, 0xb5c2032fU, 0xc57b9a86U, 0x3708a5d3U,
  18.612 +    0x2887f230U, 0xbfa5b223U, 0x036aba02U, 0x16825cedU,
  18.613 +    0xcf1c2b8aU, 0x79b492a7U, 0x07f2f0f3U, 0x69e2a14eU,
  18.614 +    0xdaf4cd65U, 0x05bed506U, 0x34621fd1U, 0xa6fe8ac4U,
  18.615 +    0x2e539d34U, 0xf355a0a2U, 0x8ae13205U, 0xf6eb75a4U,
  18.616 +    0x83ec390bU, 0x60efaa40U, 0x719f065eU, 0x6e1051bdU,
  18.617 +    0x218af93eU, 0xdd063d96U, 0x3e05aeddU, 0xe6bd464dU,
  18.618 +    0x548db591U, 0xc45d0571U, 0x06d46f04U, 0x5015ff60U,
  18.619 +    0x98fb2419U, 0xbde997d6U, 0x4043cc89U, 0xd99e7767U,
  18.620 +    0xe842bdb0U, 0x898b8807U, 0x195b38e7U, 0xc8eedb79U,
  18.621 +    0x7c0a47a1U, 0x420fe97cU, 0x841ec9f8U, 0x00000000U,
  18.622 +    0x80868309U, 0x2bed4832U, 0x1170ac1eU, 0x5a724e6cU,
  18.623 +    0x0efffbfdU, 0x8538560fU, 0xaed51e3dU, 0x2d392736U,
  18.624 +    0x0fd9640aU, 0x5ca62168U, 0x5b54d19bU, 0x362e3a24U,
  18.625 +    0x0a67b10cU, 0x57e70f93U, 0xee96d2b4U, 0x9b919e1bU,
  18.626 +    0xc0c54f80U, 0xdc20a261U, 0x774b695aU, 0x121a161cU,
  18.627 +    0x93ba0ae2U, 0xa02ae5c0U, 0x22e0433cU, 0x1b171d12U,
  18.628 +    0x090d0b0eU, 0x8bc7adf2U, 0xb6a8b92dU, 0x1ea9c814U,
  18.629 +    0xf1198557U, 0x75074cafU, 0x99ddbbeeU, 0x7f60fda3U,
  18.630 +    0x01269ff7U, 0x72f5bc5cU, 0x663bc544U, 0xfb7e345bU,
  18.631 +    0x4329768bU, 0x23c6dccbU, 0xedfc68b6U, 0xe4f163b8U,
  18.632 +    0x31dccad7U, 0x63851042U, 0x97224013U, 0xc6112084U,
  18.633 +    0x4a247d85U, 0xbb3df8d2U, 0xf93211aeU, 0x29a16dc7U,
  18.634 +    0x9e2f4b1dU, 0xb230f3dcU, 0x8652ec0dU, 0xc1e3d077U,
  18.635 +    0xb3166c2bU, 0x70b999a9U, 0x9448fa11U, 0xe9642247U,
  18.636 +    0xfc8cc4a8U, 0xf03f1aa0U, 0x7d2cd856U, 0x3390ef22U,
  18.637 +    0x494ec787U, 0x38d1c1d9U, 0xcaa2fe8cU, 0xd40b3698U,
  18.638 +    0xf581cfa6U, 0x7ade28a5U, 0xb78e26daU, 0xadbfa43fU,
  18.639 +    0x3a9de42cU, 0x78920d50U, 0x5fcc9b6aU, 0x7e466254U,
  18.640 +    0x8d13c2f6U, 0xd8b8e890U, 0x39f75e2eU, 0xc3aff582U,
  18.641 +    0x5d80be9fU, 0xd0937c69U, 0xd52da96fU, 0x2512b3cfU,
  18.642 +    0xac993bc8U, 0x187da710U, 0x9c636ee8U, 0x3bbb7bdbU,
  18.643 +    0x267809cdU, 0x5918f46eU, 0x9ab701ecU, 0x4f9aa883U,
  18.644 +    0x956e65e6U, 0xffe67eaaU, 0xbccf0821U, 0x15e8e6efU,
  18.645 +    0xe79bd9baU, 0x6f36ce4aU, 0x9f09d4eaU, 0xb07cd629U,
  18.646 +    0xa4b2af31U, 0x3f23312aU, 0xa59430c6U, 0xa266c035U,
  18.647 +    0x4ebc3774U, 0x82caa6fcU, 0x90d0b0e0U, 0xa7d81533U,
  18.648 +    0x04984af1U, 0xecdaf741U, 0xcd500e7fU, 0x91f62f17U,
  18.649 +    0x4dd68d76U, 0xefb04d43U, 0xaa4d54ccU, 0x9604dfe4U,
  18.650 +    0xd1b5e39eU, 0x6a881b4cU, 0x2c1fb8c1U, 0x65517f46U,
  18.651 +    0x5eea049dU, 0x8c355d01U, 0x877473faU, 0x0b412efbU,
  18.652 +    0x671d5ab3U, 0xdbd25292U, 0x105633e9U, 0xd647136dU,
  18.653 +    0xd7618c9aU, 0xa10c7a37U, 0xf8148e59U, 0x133c89ebU,
  18.654 +    0xa927eeceU, 0x61c935b7U, 0x1ce5ede1U, 0x47b13c7aU,
  18.655 +    0xd2df599cU, 0xf2733f55U, 0x14ce7918U, 0xc737bf73U,
  18.656 +    0xf7cdea53U, 0xfdaa5b5fU, 0x3d6f14dfU, 0x44db8678U,
  18.657 +    0xaff381caU, 0x68c43eb9U, 0x24342c38U, 0xa3405fc2U,
  18.658 +    0x1dc37216U, 0xe2250cbcU, 0x3c498b28U, 0x0d9541ffU,
  18.659 +    0xa8017139U, 0x0cb3de08U, 0xb4e49cd8U, 0x56c19064U,
  18.660 +    0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U,
  18.661 +};
  18.662 +static const u32 Td4[256] = {
  18.663 +    0x52525252U, 0x09090909U, 0x6a6a6a6aU, 0xd5d5d5d5U,
  18.664 +    0x30303030U, 0x36363636U, 0xa5a5a5a5U, 0x38383838U,
  18.665 +    0xbfbfbfbfU, 0x40404040U, 0xa3a3a3a3U, 0x9e9e9e9eU,
  18.666 +    0x81818181U, 0xf3f3f3f3U, 0xd7d7d7d7U, 0xfbfbfbfbU,
  18.667 +    0x7c7c7c7cU, 0xe3e3e3e3U, 0x39393939U, 0x82828282U,
  18.668 +    0x9b9b9b9bU, 0x2f2f2f2fU, 0xffffffffU, 0x87878787U,
  18.669 +    0x34343434U, 0x8e8e8e8eU, 0x43434343U, 0x44444444U,
  18.670 +    0xc4c4c4c4U, 0xdedededeU, 0xe9e9e9e9U, 0xcbcbcbcbU,
  18.671 +    0x54545454U, 0x7b7b7b7bU, 0x94949494U, 0x32323232U,
  18.672 +    0xa6a6a6a6U, 0xc2c2c2c2U, 0x23232323U, 0x3d3d3d3dU,
  18.673 +    0xeeeeeeeeU, 0x4c4c4c4cU, 0x95959595U, 0x0b0b0b0bU,
  18.674 +    0x42424242U, 0xfafafafaU, 0xc3c3c3c3U, 0x4e4e4e4eU,
  18.675 +    0x08080808U, 0x2e2e2e2eU, 0xa1a1a1a1U, 0x66666666U,
  18.676 +    0x28282828U, 0xd9d9d9d9U, 0x24242424U, 0xb2b2b2b2U,
  18.677 +    0x76767676U, 0x5b5b5b5bU, 0xa2a2a2a2U, 0x49494949U,
  18.678 +    0x6d6d6d6dU, 0x8b8b8b8bU, 0xd1d1d1d1U, 0x25252525U,
  18.679 +    0x72727272U, 0xf8f8f8f8U, 0xf6f6f6f6U, 0x64646464U,
  18.680 +    0x86868686U, 0x68686868U, 0x98989898U, 0x16161616U,
  18.681 +    0xd4d4d4d4U, 0xa4a4a4a4U, 0x5c5c5c5cU, 0xccccccccU,
  18.682 +    0x5d5d5d5dU, 0x65656565U, 0xb6b6b6b6U, 0x92929292U,
  18.683 +    0x6c6c6c6cU, 0x70707070U, 0x48484848U, 0x50505050U,
  18.684 +    0xfdfdfdfdU, 0xededededU, 0xb9b9b9b9U, 0xdadadadaU,
  18.685 +    0x5e5e5e5eU, 0x15151515U, 0x46464646U, 0x57575757U,
  18.686 +    0xa7a7a7a7U, 0x8d8d8d8dU, 0x9d9d9d9dU, 0x84848484U,
  18.687 +    0x90909090U, 0xd8d8d8d8U, 0xababababU, 0x00000000U,
  18.688 +    0x8c8c8c8cU, 0xbcbcbcbcU, 0xd3d3d3d3U, 0x0a0a0a0aU,
  18.689 +    0xf7f7f7f7U, 0xe4e4e4e4U, 0x58585858U, 0x05050505U,
  18.690 +    0xb8b8b8b8U, 0xb3b3b3b3U, 0x45454545U, 0x06060606U,
  18.691 +    0xd0d0d0d0U, 0x2c2c2c2cU, 0x1e1e1e1eU, 0x8f8f8f8fU,
  18.692 +    0xcacacacaU, 0x3f3f3f3fU, 0x0f0f0f0fU, 0x02020202U,
  18.693 +    0xc1c1c1c1U, 0xafafafafU, 0xbdbdbdbdU, 0x03030303U,
  18.694 +    0x01010101U, 0x13131313U, 0x8a8a8a8aU, 0x6b6b6b6bU,
  18.695 +    0x3a3a3a3aU, 0x91919191U, 0x11111111U, 0x41414141U,
  18.696 +    0x4f4f4f4fU, 0x67676767U, 0xdcdcdcdcU, 0xeaeaeaeaU,
  18.697 +    0x97979797U, 0xf2f2f2f2U, 0xcfcfcfcfU, 0xcecececeU,
  18.698 +    0xf0f0f0f0U, 0xb4b4b4b4U, 0xe6e6e6e6U, 0x73737373U,
  18.699 +    0x96969696U, 0xacacacacU, 0x74747474U, 0x22222222U,
  18.700 +    0xe7e7e7e7U, 0xadadadadU, 0x35353535U, 0x85858585U,
  18.701 +    0xe2e2e2e2U, 0xf9f9f9f9U, 0x37373737U, 0xe8e8e8e8U,
  18.702 +    0x1c1c1c1cU, 0x75757575U, 0xdfdfdfdfU, 0x6e6e6e6eU,
  18.703 +    0x47474747U, 0xf1f1f1f1U, 0x1a1a1a1aU, 0x71717171U,
  18.704 +    0x1d1d1d1dU, 0x29292929U, 0xc5c5c5c5U, 0x89898989U,
  18.705 +    0x6f6f6f6fU, 0xb7b7b7b7U, 0x62626262U, 0x0e0e0e0eU,
  18.706 +    0xaaaaaaaaU, 0x18181818U, 0xbebebebeU, 0x1b1b1b1bU,
  18.707 +    0xfcfcfcfcU, 0x56565656U, 0x3e3e3e3eU, 0x4b4b4b4bU,
  18.708 +    0xc6c6c6c6U, 0xd2d2d2d2U, 0x79797979U, 0x20202020U,
  18.709 +    0x9a9a9a9aU, 0xdbdbdbdbU, 0xc0c0c0c0U, 0xfefefefeU,
  18.710 +    0x78787878U, 0xcdcdcdcdU, 0x5a5a5a5aU, 0xf4f4f4f4U,
  18.711 +    0x1f1f1f1fU, 0xddddddddU, 0xa8a8a8a8U, 0x33333333U,
  18.712 +    0x88888888U, 0x07070707U, 0xc7c7c7c7U, 0x31313131U,
  18.713 +    0xb1b1b1b1U, 0x12121212U, 0x10101010U, 0x59595959U,
  18.714 +    0x27272727U, 0x80808080U, 0xececececU, 0x5f5f5f5fU,
  18.715 +    0x60606060U, 0x51515151U, 0x7f7f7f7fU, 0xa9a9a9a9U,
  18.716 +    0x19191919U, 0xb5b5b5b5U, 0x4a4a4a4aU, 0x0d0d0d0dU,
  18.717 +    0x2d2d2d2dU, 0xe5e5e5e5U, 0x7a7a7a7aU, 0x9f9f9f9fU,
  18.718 +    0x93939393U, 0xc9c9c9c9U, 0x9c9c9c9cU, 0xefefefefU,
  18.719 +    0xa0a0a0a0U, 0xe0e0e0e0U, 0x3b3b3b3bU, 0x4d4d4d4dU,
  18.720 +    0xaeaeaeaeU, 0x2a2a2a2aU, 0xf5f5f5f5U, 0xb0b0b0b0U,
  18.721 +    0xc8c8c8c8U, 0xebebebebU, 0xbbbbbbbbU, 0x3c3c3c3cU,
  18.722 +    0x83838383U, 0x53535353U, 0x99999999U, 0x61616161U,
  18.723 +    0x17171717U, 0x2b2b2b2bU, 0x04040404U, 0x7e7e7e7eU,
  18.724 +    0xbabababaU, 0x77777777U, 0xd6d6d6d6U, 0x26262626U,
  18.725 +    0xe1e1e1e1U, 0x69696969U, 0x14141414U, 0x63636363U,
  18.726 +    0x55555555U, 0x21212121U, 0x0c0c0c0cU, 0x7d7d7d7dU,
  18.727 +};
  18.728 +static const u32 rcon[] = {
  18.729 +	0x01000000, 0x02000000, 0x04000000, 0x08000000,
  18.730 +	0x10000000, 0x20000000, 0x40000000, 0x80000000,
  18.731 +	0x1B000000, 0x36000000, /* for 128-bit blocks, Rijndael never uses more than 10 rcon values */
  18.732 +};
  18.733 +
  18.734 +/**
  18.735 + * Expand the cipher key into the encryption key schedule.
  18.736 + */
  18.737 +int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
  18.738 +			AES_KEY *key) {
  18.739 +
  18.740 +	u32 *rk;
  18.741 +   	int i = 0;
  18.742 +	u32 temp;
  18.743 +
  18.744 +	if (!userKey || !key)
  18.745 +		return -1;
  18.746 +	if (bits != 128 && bits != 192 && bits != 256)
  18.747 +		return -2;
  18.748 +
  18.749 +	rk = key->rd_key;
  18.750 +
  18.751 +	if (bits==128)
  18.752 +		key->rounds = 10;
  18.753 +	else if (bits==192)
  18.754 +		key->rounds = 12;
  18.755 +	else
  18.756 +		key->rounds = 14;
  18.757 +
  18.758 +	rk[0] = GETU32(userKey     );
  18.759 +	rk[1] = GETU32(userKey +  4);
  18.760 +	rk[2] = GETU32(userKey +  8);
  18.761 +	rk[3] = GETU32(userKey + 12);
  18.762 +	if (bits == 128) {
  18.763 +		while (1) {
  18.764 +			temp  = rk[3];
  18.765 +			rk[4] = rk[0] ^
  18.766 +				(Te4[(temp >> 16) & 0xff] & 0xff000000) ^
  18.767 +				(Te4[(temp >>  8) & 0xff] & 0x00ff0000) ^
  18.768 +				(Te4[(temp      ) & 0xff] & 0x0000ff00) ^
  18.769 +				(Te4[(temp >> 24)       ] & 0x000000ff) ^
  18.770 +				rcon[i];
  18.771 +			rk[5] = rk[1] ^ rk[4];
  18.772 +			rk[6] = rk[2] ^ rk[5];
  18.773 +			rk[7] = rk[3] ^ rk[6];
  18.774 +			if (++i == 10) {
  18.775 +				return 0;
  18.776 +			}
  18.777 +			rk += 4;
  18.778 +		}
  18.779 +	}
  18.780 +	rk[4] = GETU32(userKey + 16);
  18.781 +	rk[5] = GETU32(userKey + 20);
  18.782 +	if (bits == 192) {
  18.783 +		while (1) {
  18.784 +			temp = rk[ 5];
  18.785 +			rk[ 6] = rk[ 0] ^
  18.786 +				(Te4[(temp >> 16) & 0xff] & 0xff000000) ^
  18.787 +				(Te4[(temp >>  8) & 0xff] & 0x00ff0000) ^
  18.788 +				(Te4[(temp      ) & 0xff] & 0x0000ff00) ^
  18.789 +				(Te4[(temp >> 24)       ] & 0x000000ff) ^
  18.790 +				rcon[i];
  18.791 +			rk[ 7] = rk[ 1] ^ rk[ 6];
  18.792 +			rk[ 8] = rk[ 2] ^ rk[ 7];
  18.793 +			rk[ 9] = rk[ 3] ^ rk[ 8];
  18.794 +			if (++i == 8) {
  18.795 +				return 0;
  18.796 +			}
  18.797 +			rk[10] = rk[ 4] ^ rk[ 9];
  18.798 +			rk[11] = rk[ 5] ^ rk[10];
  18.799 +			rk += 6;
  18.800 +		}
  18.801 +	}
  18.802 +	rk[6] = GETU32(userKey + 24);
  18.803 +	rk[7] = GETU32(userKey + 28);
  18.804 +	if (bits == 256) {
  18.805 +		while (1) {
  18.806 +			temp = rk[ 7];
  18.807 +			rk[ 8] = rk[ 0] ^
  18.808 +				(Te4[(temp >> 16) & 0xff] & 0xff000000) ^
  18.809 +				(Te4[(temp >>  8) & 0xff] & 0x00ff0000) ^
  18.810 +				(Te4[(temp      ) & 0xff] & 0x0000ff00) ^
  18.811 +				(Te4[(temp >> 24)       ] & 0x000000ff) ^
  18.812 +				rcon[i];
  18.813 +			rk[ 9] = rk[ 1] ^ rk[ 8];
  18.814 +			rk[10] = rk[ 2] ^ rk[ 9];
  18.815 +			rk[11] = rk[ 3] ^ rk[10];
  18.816 +			if (++i == 7) {
  18.817 +				return 0;
  18.818 +			}
  18.819 +			temp = rk[11];
  18.820 +			rk[12] = rk[ 4] ^
  18.821 +				(Te4[(temp >> 24)       ] & 0xff000000) ^
  18.822 +				(Te4[(temp >> 16) & 0xff] & 0x00ff0000) ^
  18.823 +				(Te4[(temp >>  8) & 0xff] & 0x0000ff00) ^
  18.824 +				(Te4[(temp      ) & 0xff] & 0x000000ff);
  18.825 +			rk[13] = rk[ 5] ^ rk[12];
  18.826 +			rk[14] = rk[ 6] ^ rk[13];
  18.827 +			rk[15] = rk[ 7] ^ rk[14];
  18.828 +
  18.829 +			rk += 8;
  18.830 +        	}
  18.831 +	}
  18.832 +	return 0;
  18.833 +}
  18.834 +
  18.835 +/**
  18.836 + * Expand the cipher key into the decryption key schedule.
  18.837 + */
  18.838 +int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
  18.839 +			 AES_KEY *key) {
  18.840 +
  18.841 +        u32 *rk;
  18.842 +	int i, j, status;
  18.843 +	u32 temp;
  18.844 +
  18.845 +	/* first, start with an encryption schedule */
  18.846 +	status = AES_set_encrypt_key(userKey, bits, key);
  18.847 +	if (status < 0)
  18.848 +		return status;
  18.849 +
  18.850 +	rk = key->rd_key;
  18.851 +
  18.852 +	/* invert the order of the round keys: */
  18.853 +	for (i = 0, j = 4*(key->rounds); i < j; i += 4, j -= 4) {
  18.854 +		temp = rk[i    ]; rk[i    ] = rk[j    ]; rk[j    ] = temp;
  18.855 +		temp = rk[i + 1]; rk[i + 1] = rk[j + 1]; rk[j + 1] = temp;
  18.856 +		temp = rk[i + 2]; rk[i + 2] = rk[j + 2]; rk[j + 2] = temp;
  18.857 +		temp = rk[i + 3]; rk[i + 3] = rk[j + 3]; rk[j + 3] = temp;
  18.858 +	}
  18.859 +	/* apply the inverse MixColumn transform to all round keys but the first and the last: */
  18.860 +	for (i = 1; i < (key->rounds); i++) {
  18.861 +		rk += 4;
  18.862 +		rk[0] =
  18.863 +			Td0[Te4[(rk[0] >> 24)       ] & 0xff] ^
  18.864 +			Td1[Te4[(rk[0] >> 16) & 0xff] & 0xff] ^
  18.865 +			Td2[Te4[(rk[0] >>  8) & 0xff] & 0xff] ^
  18.866 +			Td3[Te4[(rk[0]      ) & 0xff] & 0xff];
  18.867 +		rk[1] =
  18.868 +			Td0[Te4[(rk[1] >> 24)       ] & 0xff] ^
  18.869 +			Td1[Te4[(rk[1] >> 16) & 0xff] & 0xff] ^
  18.870 +			Td2[Te4[(rk[1] >>  8) & 0xff] & 0xff] ^
  18.871 +			Td3[Te4[(rk[1]      ) & 0xff] & 0xff];
  18.872 +		rk[2] =
  18.873 +			Td0[Te4[(rk[2] >> 24)       ] & 0xff] ^
  18.874 +			Td1[Te4[(rk[2] >> 16) & 0xff] & 0xff] ^
  18.875 +			Td2[Te4[(rk[2] >>  8) & 0xff] & 0xff] ^
  18.876 +			Td3[Te4[(rk[2]      ) & 0xff] & 0xff];
  18.877 +		rk[3] =
  18.878 +			Td0[Te4[(rk[3] >> 24)       ] & 0xff] ^
  18.879 +			Td1[Te4[(rk[3] >> 16) & 0xff] & 0xff] ^
  18.880 +			Td2[Te4[(rk[3] >>  8) & 0xff] & 0xff] ^
  18.881 +			Td3[Te4[(rk[3]      ) & 0xff] & 0xff];
  18.882 +	}
  18.883 +	return 0;
  18.884 +}
  18.885 +
  18.886 +#ifndef AES_ASM
  18.887 +/*
  18.888 + * Encrypt a single block
  18.889 + * in and out can overlap
  18.890 + */
  18.891 +void AES_encrypt(const unsigned char *in, unsigned char *out,
  18.892 +		 const AES_KEY *key) {
  18.893 +
  18.894 +	const u32 *rk;
  18.895 +	u32 s0, s1, s2, s3, t0, t1, t2, t3;
  18.896 +#ifndef FULL_UNROLL
  18.897 +	int r;
  18.898 +#endif /* ?FULL_UNROLL */
  18.899 +
  18.900 +	assert(in && out && key);
  18.901 +	rk = key->rd_key;
  18.902 +
  18.903 +	/*
  18.904 +	 * map byte array block to cipher state
  18.905 +	 * and add initial round key:
  18.906 +	 */
  18.907 +	s0 = GETU32(in     ) ^ rk[0];
  18.908 +	s1 = GETU32(in +  4) ^ rk[1];
  18.909 +	s2 = GETU32(in +  8) ^ rk[2];
  18.910 +	s3 = GETU32(in + 12) ^ rk[3];
  18.911 +#ifdef FULL_UNROLL
  18.912 +	/* round 1: */
  18.913 +   	t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >>  8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[ 4];
  18.914 +   	t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >>  8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[ 5];
  18.915 +   	t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >>  8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[ 6];
  18.916 +   	t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >>  8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[ 7];
  18.917 +   	/* round 2: */
  18.918 +   	s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >>  8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[ 8];
  18.919 +   	s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >>  8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[ 9];
  18.920 +   	s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >>  8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[10];
  18.921 +   	s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >>  8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[11];
  18.922 +	/* round 3: */
  18.923 +   	t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >>  8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[12];
  18.924 +   	t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >>  8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[13];
  18.925 +   	t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >>  8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[14];
  18.926 +   	t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >>  8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[15];
  18.927 +   	/* round 4: */
  18.928 +   	s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >>  8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[16];
  18.929 +   	s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >>  8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[17];
  18.930 +   	s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >>  8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[18];
  18.931 +   	s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >>  8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[19];
  18.932 +	/* round 5: */
  18.933 +   	t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >>  8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[20];
  18.934 +   	t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >>  8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[21];
  18.935 +   	t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >>  8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[22];
  18.936 +   	t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >>  8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[23];
  18.937 +   	/* round 6: */
  18.938 +   	s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >>  8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[24];
  18.939 +   	s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >>  8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[25];
  18.940 +   	s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >>  8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[26];
  18.941 +   	s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >>  8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[27];
  18.942 +	/* round 7: */
  18.943 +   	t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >>  8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[28];
  18.944 +   	t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >>  8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[29];
  18.945 +   	t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >>  8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[30];
  18.946 +   	t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >>  8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[31];
  18.947 +   	/* round 8: */
  18.948 +   	s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >>  8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[32];
  18.949 +   	s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >>  8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[33];
  18.950 +   	s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >>  8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[34];
  18.951 +   	s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >>  8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[35];
  18.952 +	/* round 9: */
  18.953 +   	t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >>  8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[36];
  18.954 +   	t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >>  8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[37];
  18.955 +   	t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >>  8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[38];
  18.956 +   	t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >>  8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[39];
  18.957 +    if (key->rounds > 10) {
  18.958 +        /* round 10: */
  18.959 +        s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >>  8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[40];
  18.960 +        s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >>  8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[41];
  18.961 +        s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >>  8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[42];
  18.962 +        s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >>  8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[43];
  18.963 +        /* round 11: */
  18.964 +        t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >>  8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[44];
  18.965 +        t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >>  8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[45];
  18.966 +        t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >>  8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[46];
  18.967 +        t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >>  8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[47];
  18.968 +        if (key->rounds > 12) {
  18.969 +            /* round 12: */
  18.970 +            s0 = Te0[t0 >> 24] ^ Te1[(t1 >> 16) & 0xff] ^ Te2[(t2 >>  8) & 0xff] ^ Te3[t3 & 0xff] ^ rk[48];
  18.971 +            s1 = Te0[t1 >> 24] ^ Te1[(t2 >> 16) & 0xff] ^ Te2[(t3 >>  8) & 0xff] ^ Te3[t0 & 0xff] ^ rk[49];
  18.972 +            s2 = Te0[t2 >> 24] ^ Te1[(t3 >> 16) & 0xff] ^ Te2[(t0 >>  8) & 0xff] ^ Te3[t1 & 0xff] ^ rk[50];
  18.973 +            s3 = Te0[t3 >> 24] ^ Te1[(t0 >> 16) & 0xff] ^ Te2[(t1 >>  8) & 0xff] ^ Te3[t2 & 0xff] ^ rk[51];
  18.974 +            /* round 13: */
  18.975 +            t0 = Te0[s0 >> 24] ^ Te1[(s1 >> 16) & 0xff] ^ Te2[(s2 >>  8) & 0xff] ^ Te3[s3 & 0xff] ^ rk[52];
  18.976 +            t1 = Te0[s1 >> 24] ^ Te1[(s2 >> 16) & 0xff] ^ Te2[(s3 >>  8) & 0xff] ^ Te3[s0 & 0xff] ^ rk[53];
  18.977 +            t2 = Te0[s2 >> 24] ^ Te1[(s3 >> 16) & 0xff] ^ Te2[(s0 >>  8) & 0xff] ^ Te3[s1 & 0xff] ^ rk[54];
  18.978 +            t3 = Te0[s3 >> 24] ^ Te1[(s0 >> 16) & 0xff] ^ Te2[(s1 >>  8) & 0xff] ^ Te3[s2 & 0xff] ^ rk[55];
  18.979 +        }
  18.980 +    }
  18.981 +    rk += key->rounds << 2;
  18.982 +#else  /* !FULL_UNROLL */
  18.983 +    /*
  18.984 +     * Nr - 1 full rounds:
  18.985 +     */
  18.986 +    r = key->rounds >> 1;
  18.987 +    for (;;) {
  18.988 +        t0 =
  18.989 +            Te0[(s0 >> 24)       ] ^
  18.990 +            Te1[(s1 >> 16) & 0xff] ^
  18.991 +            Te2[(s2 >>  8) & 0xff] ^
  18.992 +            Te3[(s3      ) & 0xff] ^
  18.993 +            rk[4];
  18.994 +        t1 =
  18.995 +            Te0[(s1 >> 24)       ] ^
  18.996 +            Te1[(s2 >> 16) & 0xff] ^
  18.997 +            Te2[(s3 >>  8) & 0xff] ^
  18.998 +            Te3[(s0      ) & 0xff] ^
  18.999 +            rk[5];
 18.1000 +        t2 =
 18.1001 +            Te0[(s2 >> 24)       ] ^
 18.1002 +            Te1[(s3 >> 16) & 0xff] ^
 18.1003 +            Te2[(s0 >>  8) & 0xff] ^
 18.1004 +            Te3[(s1      ) & 0xff] ^
 18.1005 +            rk[6];
 18.1006 +        t3 =
 18.1007 +            Te0[(s3 >> 24)       ] ^
 18.1008 +            Te1[(s0 >> 16) & 0xff] ^
 18.1009 +            Te2[(s1 >>  8) & 0xff] ^
 18.1010 +            Te3[(s2      ) & 0xff] ^
 18.1011 +            rk[7];
 18.1012 +
 18.1013 +        rk += 8;
 18.1014 +        if (--r == 0) {
 18.1015 +            break;
 18.1016 +        }
 18.1017 +
 18.1018 +        s0 =
 18.1019 +            Te0[(t0 >> 24)       ] ^
 18.1020 +            Te1[(t1 >> 16) & 0xff] ^
 18.1021 +            Te2[(t2 >>  8) & 0xff] ^
 18.1022 +            Te3[(t3      ) & 0xff] ^
 18.1023 +            rk[0];
 18.1024 +        s1 =
 18.1025 +            Te0[(t1 >> 24)       ] ^
 18.1026 +            Te1[(t2 >> 16) & 0xff] ^
 18.1027 +            Te2[(t3 >>  8) & 0xff] ^
 18.1028 +            Te3[(t0      ) & 0xff] ^
 18.1029 +            rk[1];
 18.1030 +        s2 =
 18.1031 +            Te0[(t2 >> 24)       ] ^
 18.1032 +            Te1[(t3 >> 16) & 0xff] ^
 18.1033 +            Te2[(t0 >>  8) & 0xff] ^
 18.1034 +            Te3[(t1      ) & 0xff] ^
 18.1035 +            rk[2];
 18.1036 +        s3 =
 18.1037 +            Te0[(t3 >> 24)       ] ^
 18.1038 +            Te1[(t0 >> 16) & 0xff] ^
 18.1039 +            Te2[(t1 >>  8) & 0xff] ^
 18.1040 +            Te3[(t2      ) & 0xff] ^
 18.1041 +            rk[3];
 18.1042 +    }
 18.1043 +#endif /* ?FULL_UNROLL */
 18.1044 +    /*
 18.1045 +	 * apply last round and
 18.1046 +	 * map cipher state to byte array block:
 18.1047 +	 */
 18.1048 +	s0 =
 18.1049 +		(Te4[(t0 >> 24)       ] & 0xff000000) ^
 18.1050 +		(Te4[(t1 >> 16) & 0xff] & 0x00ff0000) ^
 18.1051 +		(Te4[(t2 >>  8) & 0xff] & 0x0000ff00) ^
 18.1052 +		(Te4[(t3      ) & 0xff] & 0x000000ff) ^
 18.1053 +		rk[0];
 18.1054 +	PUTU32(out     , s0);
 18.1055 +	s1 =
 18.1056 +		(Te4[(t1 >> 24)       ] & 0xff000000) ^
 18.1057 +		(Te4[(t2 >> 16) & 0xff] & 0x00ff0000) ^
 18.1058 +		(Te4[(t3 >>  8) & 0xff] & 0x0000ff00) ^
 18.1059 +		(Te4[(t0      ) & 0xff] & 0x000000ff) ^
 18.1060 +		rk[1];
 18.1061 +	PUTU32(out +  4, s1);
 18.1062 +	s2 =
 18.1063 +		(Te4[(t2 >> 24)       ] & 0xff000000) ^
 18.1064 +		(Te4[(t3 >> 16) & 0xff] & 0x00ff0000) ^
 18.1065 +		(Te4[(t0 >>  8) & 0xff] & 0x0000ff00) ^
 18.1066 +		(Te4[(t1      ) & 0xff] & 0x000000ff) ^
 18.1067 +		rk[2];
 18.1068 +	PUTU32(out +  8, s2);
 18.1069 +	s3 =
 18.1070 +		(Te4[(t3 >> 24)       ] & 0xff000000) ^
 18.1071 +		(Te4[(t0 >> 16) & 0xff] & 0x00ff0000) ^
 18.1072 +		(Te4[(t1 >>  8) & 0xff] & 0x0000ff00) ^
 18.1073 +		(Te4[(t2      ) & 0xff] & 0x000000ff) ^
 18.1074 +		rk[3];
 18.1075 +	PUTU32(out + 12, s3);
 18.1076 +}
 18.1077 +
 18.1078 +/*
 18.1079 + * Decrypt a single block
 18.1080 + * in and out can overlap
 18.1081 + */
 18.1082 +void AES_decrypt(const unsigned char *in, unsigned char *out,
 18.1083 +		 const AES_KEY *key) {
 18.1084 +
 18.1085 +	const u32 *rk;
 18.1086 +	u32 s0, s1, s2, s3, t0, t1, t2, t3;
 18.1087 +#ifndef FULL_UNROLL
 18.1088 +	int r;
 18.1089 +#endif /* ?FULL_UNROLL */
 18.1090 +
 18.1091 +	assert(in && out && key);
 18.1092 +	rk = key->rd_key;
 18.1093 +
 18.1094 +	/*
 18.1095 +	 * map byte array block to cipher state
 18.1096 +	 * and add initial round key:
 18.1097 +	 */
 18.1098 +    s0 = GETU32(in     ) ^ rk[0];
 18.1099 +    s1 = GETU32(in +  4) ^ rk[1];
 18.1100 +    s2 = GETU32(in +  8) ^ rk[2];
 18.1101 +    s3 = GETU32(in + 12) ^ rk[3];
 18.1102 +#ifdef FULL_UNROLL
 18.1103 +    /* round 1: */
 18.1104 +    t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >>  8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[ 4];
 18.1105 +    t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >>  8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[ 5];
 18.1106 +    t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >>  8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[ 6];
 18.1107 +    t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >>  8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[ 7];
 18.1108 +    /* round 2: */
 18.1109 +    s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >>  8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[ 8];
 18.1110 +    s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >>  8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[ 9];
 18.1111 +    s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >>  8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[10];
 18.1112 +    s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >>  8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[11];
 18.1113 +    /* round 3: */
 18.1114 +    t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >>  8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[12];
 18.1115 +    t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >>  8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[13];
 18.1116 +    t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >>  8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[14];
 18.1117 +    t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >>  8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[15];
 18.1118 +    /* round 4: */
 18.1119 +    s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >>  8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[16];
 18.1120 +    s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >>  8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[17];
 18.1121 +    s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >>  8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[18];
 18.1122 +    s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >>  8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[19];
 18.1123 +    /* round 5: */
 18.1124 +    t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >>  8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[20];
 18.1125 +    t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >>  8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[21];
 18.1126 +    t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >>  8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[22];
 18.1127 +    t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >>  8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[23];
 18.1128 +    /* round 6: */
 18.1129 +    s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >>  8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[24];
 18.1130 +    s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >>  8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[25];
 18.1131 +    s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >>  8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[26];
 18.1132 +    s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >>  8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[27];
 18.1133 +    /* round 7: */
 18.1134 +    t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >>  8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[28];
 18.1135 +    t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >>  8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[29];
 18.1136 +    t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >>  8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[30];
 18.1137 +    t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >>  8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[31];
 18.1138 +    /* round 8: */
 18.1139 +    s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >>  8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[32];
 18.1140 +    s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >>  8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[33];
 18.1141 +    s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >>  8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[34];
 18.1142 +    s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >>  8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[35];
 18.1143 +    /* round 9: */
 18.1144 +    t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >>  8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[36];
 18.1145 +    t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >>  8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[37];
 18.1146 +    t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >>  8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[38];
 18.1147 +    t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >>  8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[39];
 18.1148 +    if (key->rounds > 10) {
 18.1149 +        /* round 10: */
 18.1150 +        s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >>  8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[40];
 18.1151 +        s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >>  8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[41];
 18.1152 +        s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >>  8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[42];
 18.1153 +        s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >>  8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[43];
 18.1154 +        /* round 11: */
 18.1155 +        t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >>  8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[44];
 18.1156 +        t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >>  8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[45];
 18.1157 +        t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >>  8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[46];
 18.1158 +        t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >>  8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[47];
 18.1159 +        if (key->rounds > 12) {
 18.1160 +            /* round 12: */
 18.1161 +            s0 = Td0[t0 >> 24] ^ Td1[(t3 >> 16) & 0xff] ^ Td2[(t2 >>  8) & 0xff] ^ Td3[t1 & 0xff] ^ rk[48];
 18.1162 +            s1 = Td0[t1 >> 24] ^ Td1[(t0 >> 16) & 0xff] ^ Td2[(t3 >>  8) & 0xff] ^ Td3[t2 & 0xff] ^ rk[49];
 18.1163 +            s2 = Td0[t2 >> 24] ^ Td1[(t1 >> 16) & 0xff] ^ Td2[(t0 >>  8) & 0xff] ^ Td3[t3 & 0xff] ^ rk[50];
 18.1164 +            s3 = Td0[t3 >> 24] ^ Td1[(t2 >> 16) & 0xff] ^ Td2[(t1 >>  8) & 0xff] ^ Td3[t0 & 0xff] ^ rk[51];
 18.1165 +            /* round 13: */
 18.1166 +            t0 = Td0[s0 >> 24] ^ Td1[(s3 >> 16) & 0xff] ^ Td2[(s2 >>  8) & 0xff] ^ Td3[s1 & 0xff] ^ rk[52];
 18.1167 +            t1 = Td0[s1 >> 24] ^ Td1[(s0 >> 16) & 0xff] ^ Td2[(s3 >>  8) & 0xff] ^ Td3[s2 & 0xff] ^ rk[53];
 18.1168 +            t2 = Td0[s2 >> 24] ^ Td1[(s1 >> 16) & 0xff] ^ Td2[(s0 >>  8) & 0xff] ^ Td3[s3 & 0xff] ^ rk[54];
 18.1169 +            t3 = Td0[s3 >> 24] ^ Td1[(s2 >> 16) & 0xff] ^ Td2[(s1 >>  8) & 0xff] ^ Td3[s0 & 0xff] ^ rk[55];
 18.1170 +        }
 18.1171 +    }
 18.1172 +	rk += key->rounds << 2;
 18.1173 +#else  /* !FULL_UNROLL */
 18.1174 +    /*
 18.1175 +     * Nr - 1 full rounds:
 18.1176 +     */
 18.1177 +    r = key->rounds >> 1;
 18.1178 +    for (;;) {
 18.1179 +        t0 =
 18.1180 +            Td0[(s0 >> 24)       ] ^
 18.1181 +            Td1[(s3 >> 16) & 0xff] ^
 18.1182 +            Td2[(s2 >>  8) & 0xff] ^
 18.1183 +            Td3[(s1      ) & 0xff] ^
 18.1184 +            rk[4];
 18.1185 +        t1 =
 18.1186 +            Td0[(s1 >> 24)       ] ^
 18.1187 +            Td1[(s0 >> 16) & 0xff] ^
 18.1188 +            Td2[(s3 >>  8) & 0xff] ^
 18.1189 +            Td3[(s2      ) & 0xff] ^
 18.1190 +            rk[5];
 18.1191 +        t2 =
 18.1192 +            Td0[(s2 >> 24)       ] ^
 18.1193 +            Td1[(s1 >> 16) & 0xff] ^
 18.1194 +            Td2[(s0 >>  8) & 0xff] ^
 18.1195 +            Td3[(s3      ) & 0xff] ^
 18.1196 +            rk[6];
 18.1197 +        t3 =
 18.1198 +            Td0[(s3 >> 24)       ] ^
 18.1199 +            Td1[(s2 >> 16) & 0xff] ^
 18.1200 +            Td2[(s1 >>  8) & 0xff] ^
 18.1201 +            Td3[(s0      ) & 0xff] ^
 18.1202 +            rk[7];
 18.1203 +
 18.1204 +        rk += 8;
 18.1205 +        if (--r == 0) {
 18.1206 +            break;
 18.1207 +        }
 18.1208 +
 18.1209 +        s0 =
 18.1210 +            Td0[(t0 >> 24)       ] ^
 18.1211 +            Td1[(t3 >> 16) & 0xff] ^
 18.1212 +            Td2[(t2 >>  8) & 0xff] ^
 18.1213 +            Td3[(t1      ) & 0xff] ^
 18.1214 +            rk[0];
 18.1215 +        s1 =
 18.1216 +            Td0[(t1 >> 24)       ] ^
 18.1217 +            Td1[(t0 >> 16) & 0xff] ^
 18.1218 +            Td2[(t3 >>  8) & 0xff] ^
 18.1219 +            Td3[(t2      ) & 0xff] ^
 18.1220 +            rk[1];
 18.1221 +        s2 =
 18.1222 +            Td0[(t2 >> 24)       ] ^
 18.1223 +            Td1[(t1 >> 16) & 0xff] ^
 18.1224 +            Td2[(t0 >>  8) & 0xff] ^
 18.1225 +            Td3[(t3      ) & 0xff] ^
 18.1226 +            rk[2];
 18.1227 +        s3 =
 18.1228 +            Td0[(t3 >> 24)       ] ^
 18.1229 +            Td1[(t2 >> 16) & 0xff] ^
 18.1230 +            Td2[(t1 >>  8) & 0xff] ^
 18.1231 +            Td3[(t0      ) & 0xff] ^
 18.1232 +            rk[3];
 18.1233 +    }
 18.1234 +#endif /* ?FULL_UNROLL */
 18.1235 +    /*
 18.1236 +	 * apply last round and
 18.1237 +	 * map cipher state to byte array block:
 18.1238 +	 */
 18.1239 +   	s0 =
 18.1240 +   		(Td4[(t0 >> 24)       ] & 0xff000000) ^
 18.1241 +   		(Td4[(t3 >> 16) & 0xff] & 0x00ff0000) ^
 18.1242 +   		(Td4[(t2 >>  8) & 0xff] & 0x0000ff00) ^
 18.1243 +   		(Td4[(t1      ) & 0xff] & 0x000000ff) ^
 18.1244 +   		rk[0];
 18.1245 +	PUTU32(out     , s0);
 18.1246 +   	s1 =
 18.1247 +   		(Td4[(t1 >> 24)       ] & 0xff000000) ^
 18.1248 +   		(Td4[(t0 >> 16) & 0xff] & 0x00ff0000) ^
 18.1249 +   		(Td4[(t3 >>  8) & 0xff] & 0x0000ff00) ^
 18.1250 +   		(Td4[(t2      ) & 0xff] & 0x000000ff) ^
 18.1251 +   		rk[1];
 18.1252 +	PUTU32(out +  4, s1);
 18.1253 +   	s2 =
 18.1254 +   		(Td4[(t2 >> 24)       ] & 0xff000000) ^
 18.1255 +   		(Td4[(t1 >> 16) & 0xff] & 0x00ff0000) ^
 18.1256 +   		(Td4[(t0 >>  8) & 0xff] & 0x0000ff00) ^
 18.1257 +   		(Td4[(t3      ) & 0xff] & 0x000000ff) ^
 18.1258 +   		rk[2];
 18.1259 +	PUTU32(out +  8, s2);
 18.1260 +   	s3 =
 18.1261 +   		(Td4[(t3 >> 24)       ] & 0xff000000) ^
 18.1262 +   		(Td4[(t2 >> 16) & 0xff] & 0x00ff0000) ^
 18.1263 +   		(Td4[(t1 >>  8) & 0xff] & 0x0000ff00) ^
 18.1264 +   		(Td4[(t0      ) & 0xff] & 0x000000ff) ^
 18.1265 +   		rk[3];
 18.1266 +	PUTU32(out + 12, s3);
 18.1267 +}
 18.1268 +
 18.1269 +#endif /* AES_ASM */
 18.1270 +
 18.1271 +void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
 18.1272 +		     const unsigned long length, const AES_KEY *key,
 18.1273 +		     unsigned char *ivec, const int enc) 
 18.1274 +{
 18.1275 +
 18.1276 +	unsigned long n;
 18.1277 +	unsigned long len = length;
 18.1278 +	unsigned char tmp[AES_BLOCK_SIZE];
 18.1279 +
 18.1280 +	assert(in && out && key && ivec);
 18.1281 +
 18.1282 +	if (enc) {
 18.1283 +		while (len >= AES_BLOCK_SIZE) {
 18.1284 +			for(n=0; n < AES_BLOCK_SIZE; ++n)
 18.1285 +				tmp[n] = in[n] ^ ivec[n];
 18.1286 +			AES_encrypt(tmp, out, key);
 18.1287 +			memcpy(ivec, out, AES_BLOCK_SIZE);
 18.1288 +			len -= AES_BLOCK_SIZE;
 18.1289 +			in += AES_BLOCK_SIZE;
 18.1290 +			out += AES_BLOCK_SIZE;
 18.1291 +		}
 18.1292 +		if (len) {
 18.1293 +			for(n=0; n < len; ++n)
 18.1294 +				tmp[n] = in[n] ^ ivec[n];
 18.1295 +			for(n=len; n < AES_BLOCK_SIZE; ++n)
 18.1296 +				tmp[n] = ivec[n];
 18.1297 +			AES_encrypt(tmp, tmp, key);
 18.1298 +			memcpy(out, tmp, AES_BLOCK_SIZE);
 18.1299 +			memcpy(ivec, tmp, AES_BLOCK_SIZE);
 18.1300 +		}			
 18.1301 +	} else {
 18.1302 +		while (len >= AES_BLOCK_SIZE) {
 18.1303 +			memcpy(tmp, in, AES_BLOCK_SIZE);
 18.1304 +			AES_decrypt(in, out, key);
 18.1305 +			for(n=0; n < AES_BLOCK_SIZE; ++n)
 18.1306 +				out[n] ^= ivec[n];
 18.1307 +			memcpy(ivec, tmp, AES_BLOCK_SIZE);
 18.1308 +			len -= AES_BLOCK_SIZE;
 18.1309 +			in += AES_BLOCK_SIZE;
 18.1310 +			out += AES_BLOCK_SIZE;
 18.1311 +		}
 18.1312 +		if (len) {
 18.1313 +			memcpy(tmp, in, AES_BLOCK_SIZE);
 18.1314 +			AES_decrypt(tmp, tmp, key);
 18.1315 +			for(n=0; n < len; ++n)
 18.1316 +				out[n] = tmp[n] ^ ivec[n];
 18.1317 +			memcpy(ivec, tmp, AES_BLOCK_SIZE);
 18.1318 +		}			
 18.1319 +	}
 18.1320 +}
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/tools/ioemu/aes.h	Wed Jul 12 19:16:10 2006 +0100
    19.3 @@ -0,0 +1,26 @@
    19.4 +#ifndef QEMU_AES_H
    19.5 +#define QEMU_AES_H
    19.6 +
    19.7 +#define AES_MAXNR 14
    19.8 +#define AES_BLOCK_SIZE 16
    19.9 +
   19.10 +struct aes_key_st {
   19.11 +    uint32_t rd_key[4 *(AES_MAXNR + 1)];
   19.12 +    int rounds;
   19.13 +};
   19.14 +typedef struct aes_key_st AES_KEY;
   19.15 +
   19.16 +int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
   19.17 +	AES_KEY *key);
   19.18 +int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
   19.19 +	AES_KEY *key);
   19.20 +
   19.21 +void AES_encrypt(const unsigned char *in, unsigned char *out,
   19.22 +	const AES_KEY *key);
   19.23 +void AES_decrypt(const unsigned char *in, unsigned char *out,
   19.24 +	const AES_KEY *key);
   19.25 +void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
   19.26 +		     const unsigned long length, const AES_KEY *key,
   19.27 +		     unsigned char *ivec, const int enc);
   19.28 +
   19.29 +#endif
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/tools/ioemu/audio/CVS/Entries	Wed Jul 12 19:16:10 2006 +0100
    20.3 @@ -0,0 +1,19 @@
    20.4 +/alsaaudio.c/1.5/Sun Nov 20 18:53:05 2005//Trelease_0_8_1
    20.5 +/audio.c/1.9/Thu May 25 18:22:31 2006//Trelease_0_8_1
    20.6 +/audio.h/1.5/Thu May 25 18:22:31 2006//Trelease_0_8_1
    20.7 +/audio_int.h/1.7/Thu May 25 18:22:31 2006//Trelease_0_8_1
    20.8 +/audio_template.h/1.4/Sun Nov 20 16:24:34 2005//Trelease_0_8_1
    20.9 +/coreaudio.c/1.5/Sun Nov 20 18:53:42 2005//Trelease_0_8_1
   20.10 +/dsound_template.h/1.2/Sat Nov  5 18:55:27 2005//Trelease_0_8_1
   20.11 +/dsoundaudio.c/1.2/Sat Nov  5 18:55:27 2005//Trelease_0_8_1
   20.12 +/fmodaudio.c/1.5/Thu May 25 18:22:32 2006//Trelease_0_8_1
   20.13 +/mixeng.c/1.4/Thu May 25 18:22:32 2006//Trelease_0_8_1
   20.14 +/mixeng.h/1.2/Thu May 25 18:22:32 2006//Trelease_0_8_1
   20.15 +/mixeng_template.h/1.2/Thu May 25 18:22:32 2006//Trelease_0_8_1
   20.16 +/noaudio.c/1.4/Thu May 25 18:22:32 2006//Trelease_0_8_1
   20.17 +/ossaudio.c/1.9/Thu May 25 18:22:32 2006//Trelease_0_8_1
   20.18 +/rate_template.h/1.2/Sat Nov  5 18:55:27 2005//Trelease_0_8_1
   20.19 +/sdlaudio.c/1.6/Thu May 25 18:22:32 2006//Trelease_0_8_1
   20.20 +/sys-queue.h/1.1/Sun Oct 30 18:58:22 2005//Trelease_0_8_1
   20.21 +/wavaudio.c/1.6/Thu May 25 18:22:32 2006//Trelease_0_8_1
   20.22 +D
    21.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    21.2 +++ b/tools/ioemu/audio/CVS/Repository	Wed Jul 12 19:16:10 2006 +0100
    21.3 @@ -0,0 +1,1 @@
    21.4 +qemu/audio
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/tools/ioemu/audio/CVS/Root	Wed Jul 12 19:16:10 2006 +0100
    22.3 @@ -0,0 +1,1 @@
    22.4 +:pserver:anonymous@cvs.savannah.nongnu.org:/sources/qemu
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/tools/ioemu/audio/CVS/Tag	Wed Jul 12 19:16:10 2006 +0100
    23.3 @@ -0,0 +1,1 @@
    23.4 +Nrelease_0_8_1
    24.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    24.2 +++ b/tools/ioemu/audio/alsaaudio.c	Wed Jul 12 19:16:10 2006 +0100
    24.3 @@ -0,0 +1,981 @@
    24.4 +/*
    24.5 + * QEMU ALSA audio driver
    24.6 + *
    24.7 + * Copyright (c) 2005 Vassili Karpov (malc)
    24.8 + *
    24.9 + * Permission is hereby granted, free of charge, to any person obtaining a copy
   24.10 + * of this software and associated documentation files (the "Software"), to deal
   24.11 + * in the Software without restriction, including without limitation the rights
   24.12 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   24.13 + * copies of the Software, and to permit persons to whom the Software is
   24.14 + * furnished to do so, subject to the following conditions:
   24.15 + *
   24.16 + * The above copyright notice and this permission notice shall be included in
   24.17 + * all copies or substantial portions of the Software.
   24.18 + *
   24.19 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   24.20 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   24.21 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
   24.22 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   24.23 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   24.24 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   24.25 + * THE SOFTWARE.
   24.26 + */
   24.27 +#include <alsa/asoundlib.h>
   24.28 +#include "vl.h"
   24.29 +
   24.30 +#define AUDIO_CAP "alsa"
   24.31 +#include "audio_int.h"
   24.32 +
   24.33 +typedef struct ALSAVoiceOut {
   24.34 +    HWVoiceOut hw;
   24.35 +    void *pcm_buf;
   24.36 +    snd_pcm_t *handle;
   24.37 +} ALSAVoiceOut;
   24.38 +
   24.39 +typedef struct ALSAVoiceIn {
   24.40 +    HWVoiceIn hw;
   24.41 +    snd_pcm_t *handle;
   24.42 +    void *pcm_buf;
   24.43 +} ALSAVoiceIn;
   24.44 +
   24.45 +static struct {
   24.46 +    int size_in_usec_in;
   24.47 +    int size_in_usec_out;
   24.48 +    const char *pcm_name_in;
   24.49 +    const char *pcm_name_out;
   24.50 +    unsigned int buffer_size_in;
   24.51 +    unsigned int period_size_in;
   24.52 +    unsigned int buffer_size_out;
   24.53 +    unsigned int period_size_out;
   24.54 +    unsigned int threshold;
   24.55 +
   24.56 +    int buffer_size_in_overriden;
   24.57 +    int period_size_in_overriden;
   24.58 +
   24.59 +    int buffer_size_out_overriden;
   24.60 +    int period_size_out_overriden;
   24.61 +    int verbose;
   24.62 +} conf = {
   24.63 +#ifdef HIGH_LATENCY
   24.64 +    .size_in_usec_in = 1,
   24.65 +    .size_in_usec_out = 1,
   24.66 +#endif
   24.67 +    .pcm_name_out = "hw:0,0",
   24.68 +    .pcm_name_in = "hw:0,0",
   24.69 +#ifdef HIGH_LATENCY
   24.70 +    .buffer_size_in = 400000,
   24.71 +    .period_size_in = 400000 / 4,
   24.72 +    .buffer_size_out = 400000,
   24.73 +    .period_size_out = 400000 / 4,
   24.74 +#else
   24.75 +#define DEFAULT_BUFFER_SIZE 1024
   24.76 +#define DEFAULT_PERIOD_SIZE 256
   24.77 +    .buffer_size_in = DEFAULT_BUFFER_SIZE * 4,
   24.78 +    .period_size_in = DEFAULT_PERIOD_SIZE * 4,
   24.79 +    .buffer_size_out = DEFAULT_BUFFER_SIZE,
   24.80 +    .period_size_out = DEFAULT_PERIOD_SIZE,
   24.81 +    .buffer_size_in_overriden = 0,
   24.82 +    .buffer_size_out_overriden = 0,
   24.83 +    .period_size_in_overriden = 0,
   24.84 +    .period_size_out_overriden = 0,
   24.85 +#endif
   24.86 +    .threshold = 0,
   24.87 +    .verbose = 0
   24.88 +};
   24.89 +
   24.90 +struct alsa_params_req {
   24.91 +    int freq;
   24.92 +    audfmt_e fmt;
   24.93 +    int nchannels;
   24.94 +    unsigned int buffer_size;
   24.95 +    unsigned int period_size;
   24.96 +};
   24.97 +
   24.98 +struct alsa_params_obt {
   24.99 +    int freq;
  24.100 +    audfmt_e fmt;
  24.101 +    int nchannels;
  24.102 +    snd_pcm_uframes_t samples;
  24.103 +};
  24.104 +
  24.105 +static void GCC_FMT_ATTR (2, 3) alsa_logerr (int err, const char *fmt, ...)
  24.106 +{
  24.107 +    va_list ap;
  24.108 +
  24.109 +    va_start (ap, fmt);
  24.110 +    AUD_vlog (AUDIO_CAP, fmt, ap);
  24.111 +    va_end (ap);
  24.112 +
  24.113 +    AUD_log (AUDIO_CAP, "Reason: %s\n", snd_strerror (err));
  24.114 +}
  24.115 +
  24.116 +static void GCC_FMT_ATTR (3, 4) alsa_logerr2 (
  24.117 +    int err,
  24.118 +    const char *typ,
  24.119 +    const char *fmt,
  24.120 +    ...
  24.121 +    )
  24.122 +{
  24.123 +    va_list ap;
  24.124 +
  24.125 +    AUD_log (AUDIO_CAP, "Could not initialize %s\n", typ);
  24.126 +
  24.127 +    va_start (ap, fmt);
  24.128 +    AUD_vlog (AUDIO_CAP, fmt, ap);
  24.129 +    va_end (ap);
  24.130 +
  24.131 +    AUD_log (AUDIO_CAP, "Reason: %s\n", snd_strerror (err));
  24.132 +}
  24.133 +
  24.134 +static void alsa_anal_close (snd_pcm_t **handlep)
  24.135 +{
  24.136 +    int err = snd_pcm_close (*handlep);
  24.137 +    if (err) {
  24.138 +        alsa_logerr (err, "Failed to close PCM handle %p\n", *handlep);
  24.139 +    }
  24.140 +    *handlep = NULL;
  24.141 +}
  24.142 +
  24.143 +static int alsa_write (SWVoiceOut *sw, void *buf, int len)
  24.144 +{
  24.145 +    return audio_pcm_sw_write (sw, buf, len);
  24.146 +}
  24.147 +
  24.148 +static int aud_to_alsafmt (audfmt_e fmt)
  24.149 +{
  24.150 +    switch (fmt) {
  24.151 +    case AUD_FMT_S8:
  24.152 +        return SND_PCM_FORMAT_S8;
  24.153 +
  24.154 +    case AUD_FMT_U8:
  24.155 +        return SND_PCM_FORMAT_U8;
  24.156 +
  24.157 +    case AUD_FMT_S16:
  24.158 +        return SND_PCM_FORMAT_S16_LE;
  24.159 +
  24.160 +    case AUD_FMT_U16:
  24.161 +        return SND_PCM_FORMAT_U16_LE;
  24.162 +
  24.163 +    default:
  24.164 +        dolog ("Internal logic error: Bad audio format %d\n", fmt);
  24.165 +#ifdef DEBUG_AUDIO
  24.166 +        abort ();
  24.167 +#endif
  24.168 +        return SND_PCM_FORMAT_U8;
  24.169 +    }
  24.170 +}
  24.171 +
  24.172 +static int alsa_to_audfmt (int alsafmt, audfmt_e *fmt, int *endianness)
  24.173 +{
  24.174 +    switch (alsafmt) {
  24.175 +    case SND_PCM_FORMAT_S8:
  24.176 +        *endianness = 0;
  24.177 +        *fmt = AUD_FMT_S8;
  24.178 +        break;
  24.179 +
  24.180 +    case SND_PCM_FORMAT_U8:
  24.181 +        *endianness = 0;
  24.182 +        *fmt = AUD_FMT_U8;
  24.183 +        break;
  24.184 +
  24.185 +    case SND_PCM_FORMAT_S16_LE:
  24.186 +        *endianness = 0;
  24.187 +        *fmt = AUD_FMT_S16;
  24.188 +        break;
  24.189 +
  24.190 +    case SND_PCM_FORMAT_U16_LE:
  24.191 +        *endianness = 0;
  24.192 +        *fmt = AUD_FMT_U16;
  24.193 +        break;
  24.194 +
  24.195 +    case SND_PCM_FORMAT_S16_BE:
  24.196 +        *endianness = 1;
  24.197 +        *fmt = AUD_FMT_S16;
  24.198 +        break;
  24.199 +
  24.200 +    case SND_PCM_FORMAT_U16_BE:
  24.201 +        *endianness = 1;
  24.202 +        *fmt = AUD_FMT_U16;
  24.203 +        break;
  24.204 +
  24.205 +    default:
  24.206 +        dolog ("Unrecognized audio format %d\n", alsafmt);
  24.207 +        return -1;
  24.208 +    }
  24.209 +
  24.210 +    return 0;
  24.211 +}
  24.212 +
  24.213 +#if defined DEBUG_MISMATCHES || defined DEBUG
  24.214 +static void alsa_dump_info (struct alsa_params_req *req,
  24.215 +                            struct alsa_params_obt *obt)
  24.216 +{
  24.217 +    dolog ("parameter | requested value | obtained value\n");
  24.218 +    dolog ("format    |      %10d |     %10d\n", req->fmt, obt->fmt);
  24.219 +    dolog ("channels  |      %10d |     %10d\n",
  24.220 +           req->nchannels, obt->nchannels);
  24.221 +    dolog ("frequency |      %10d |     %10d\n", req->freq, obt->freq);
  24.222 +    dolog ("============================================\n");
  24.223 +    dolog ("requested: buffer size %d period size %d\n",
  24.224 +           req->buffer_size, req->period_size);
  24.225 +    dolog ("obtained: samples %ld\n", obt->samples);
  24.226 +}
  24.227 +#endif
  24.228 +
  24.229 +static void alsa_set_threshold (snd_pcm_t *handle, snd_pcm_uframes_t threshold)
  24.230 +{
  24.231 +    int err;
  24.232 +    snd_pcm_sw_params_t *sw_params;
  24.233 +
  24.234 +    snd_pcm_sw_params_alloca (&sw_params);
  24.235 +
  24.236 +    err = snd_pcm_sw_params_current (handle, sw_params);
  24.237 +    if (err < 0) {
  24.238 +        dolog ("Could not fully initialize DAC\n");
  24.239 +        alsa_logerr (err, "Failed to get current software parameters\n");
  24.240 +        return;
  24.241 +    }
  24.242 +
  24.243 +    err = snd_pcm_sw_params_set_start_threshold (handle, sw_params, threshold);
  24.244 +    if (err < 0) {
  24.245 +        dolog ("Could not fully initialize DAC\n");
  24.246 +        alsa_logerr (err, "Failed to set software threshold to %ld\n",
  24.247 +                     threshold);
  24.248 +        return;
  24.249 +    }
  24.250 +
  24.251 +    err = snd_pcm_sw_params (handle, sw_params);
  24.252 +    if (err < 0) {
  24.253 +        dolog ("Could not fully initialize DAC\n");
  24.254 +        alsa_logerr (err, "Failed to set software parameters\n");
  24.255 +        return;
  24.256 +    }
  24.257 +}
  24.258 +
  24.259 +static int alsa_open (int in, struct alsa_params_req *req,
  24.260 +                      struct alsa_params_obt *obt, snd_pcm_t **handlep)
  24.261 +{
  24.262 +    snd_pcm_t *handle;
  24.263 +    snd_pcm_hw_params_t *hw_params;
  24.264 +    int err, freq, nchannels;
  24.265 +    const char *pcm_name = in ? conf.pcm_name_in : conf.pcm_name_out;
  24.266 +    unsigned int period_size, buffer_size;
  24.267 +    snd_pcm_uframes_t obt_buffer_size;
  24.268 +    const char *typ = in ? "ADC" : "DAC";
  24.269 +
  24.270 +    freq = req->freq;
  24.271 +    period_size = req->period_size;
  24.272 +    buffer_size = req->buffer_size;
  24.273 +    nchannels = req->nchannels;
  24.274 +
  24.275 +    snd_pcm_hw_params_alloca (&hw_params);
  24.276 +
  24.277 +    err = snd_pcm_open (
  24.278 +        &handle,
  24.279 +        pcm_name,
  24.280 +        in ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK,
  24.281 +        SND_PCM_NONBLOCK
  24.282 +        );
  24.283 +    if (err < 0) {
  24.284 +        alsa_logerr2 (err, typ, "Failed to open `%s':\n", pcm_name);
  24.285 +        return -1;
  24.286 +    }
  24.287 +
  24.288 +    err = snd_pcm_hw_params_any (handle, hw_params);
  24.289 +    if (err < 0) {
  24.290 +        alsa_logerr2 (err, typ, "Failed to initialize hardware parameters\n");
  24.291 +        goto err;
  24.292 +    }
  24.293 +
  24.294 +    err = snd_pcm_hw_params_set_access (
  24.295 +        handle,
  24.296 +        hw_params,
  24.297 +        SND_PCM_ACCESS_RW_INTERLEAVED
  24.298 +        );
  24.299 +    if (err < 0) {
  24.300 +        alsa_logerr2 (err, typ, "Failed to set access type\n");
  24.301 +        goto err;
  24.302 +    }
  24.303 +
  24.304 +    err = snd_pcm_hw_params_set_format (handle, hw_params, req->fmt);
  24.305 +    if (err < 0) {
  24.306 +        alsa_logerr2 (err, typ, "Failed to set format %d\n", req->fmt);
  24.307 +        goto err;
  24.308 +    }
  24.309 +
  24.310 +    err = snd_pcm_hw_params_set_rate_near (handle, hw_params, &freq, 0);
  24.311 +    if (err < 0) {
  24.312 +        alsa_logerr2 (err, typ, "Failed to set frequency %d\n", req->freq);
  24.313 +        goto err;
  24.314 +    }
  24.315 +
  24.316 +    err = snd_pcm_hw_params_set_channels_near (
  24.317 +        handle,
  24.318 +        hw_params,
  24.319 +        &nchannels
  24.320 +        );
  24.321 +    if (err < 0) {
  24.322 +        alsa_logerr2 (err, typ, "Failed to set number of channels %d\n",
  24.323 +                      req->nchannels);
  24.324 +        goto err;
  24.325 +    }
  24.326 +
  24.327 +    if (nchannels != 1 && nchannels != 2) {
  24.328 +        alsa_logerr2 (err, typ,
  24.329 +                      "Can not handle obtained number of channels %d\n",
  24.330 +                      nchannels);
  24.331 +        goto err;
  24.332 +    }
  24.333 +
  24.334 +    if (!((in && conf.size_in_usec_in) || (!in && conf.size_in_usec_out))) {
  24.335 +        if (!buffer_size) {
  24.336 +            buffer_size = DEFAULT_BUFFER_SIZE;
  24.337 +            period_size= DEFAULT_PERIOD_SIZE;
  24.338 +        }
  24.339 +    }
  24.340 +
  24.341 +    if (buffer_size) {
  24.342 +        if ((in && conf.size_in_usec_in) || (!in && conf.size_in_usec_out)) {
  24.343 +            if (period_size) {
  24.344 +                err = snd_pcm_hw_params_set_period_time_near (
  24.345 +                    handle,
  24.346 +                    hw_params,
  24.347 +                    &period_size,
  24.348 +                    0
  24.349 +                    );
  24.350 +                if (err < 0) {
  24.351 +                    alsa_logerr2 (err, typ,
  24.352 +                                  "Failed to set period time %d\n",
  24.353 +                                  req->period_size);
  24.354 +                    goto err;
  24.355 +                }
  24.356 +            }
  24.357 +
  24.358 +            err = snd_pcm_hw_params_set_buffer_time_near (
  24.359 +                handle,
  24.360 +                hw_params,
  24.361 +                &buffer_size,
  24.362 +                0
  24.363 +                );
  24.364 +
  24.365 +            if (err < 0) {
  24.366 +                alsa_logerr2 (err, typ,
  24.367 +                              "Failed to set buffer time %d\n",
  24.368 +                              req->buffer_size);
  24.369 +                goto err;
  24.370 +            }
  24.371 +        }
  24.372 +        else {
  24.373 +            int dir;
  24.374 +            snd_pcm_uframes_t minval;
  24.375 +
  24.376 +            if (period_size) {
  24.377 +                minval = period_size;
  24.378 +                dir = 0;
  24.379 +
  24.380 +                err = snd_pcm_hw_params_get_period_size_min (
  24.381 +                    hw_params,
  24.382 +                    &minval,
  24.383 +                    &dir
  24.384 +                    );
  24.385 +                if (err < 0) {
  24.386 +                    alsa_logerr (
  24.387 +                        err,
  24.388 +                        "Could not get minmal period size for %s\n",
  24.389 +                        typ
  24.390 +                        );
  24.391 +                }
  24.392 +                else {
  24.393 +                    if (period_size < minval) {
  24.394 +                        if ((in && conf.period_size_in_overriden)
  24.395 +                            || (!in && conf.period_size_out_overriden)) {
  24.396 +                            dolog ("%s period size(%d) is less "
  24.397 +                                   "than minmal period size(%ld)\n",
  24.398 +                                   typ,
  24.399 +                                   period_size,
  24.400 +                                   minval);
  24.401 +                        }
  24.402 +                        period_size = minval;
  24.403 +                    }
  24.404 +                }
  24.405 +
  24.406 +                err = snd_pcm_hw_params_set_period_size (
  24.407 +                    handle,
  24.408 +                    hw_params,
  24.409 +                    period_size,
  24.410 +                    0
  24.411 +                    );
  24.412 +                if (err < 0) {
  24.413 +                    alsa_logerr2 (err, typ, "Failed to set period size %d\n",
  24.414 +                                  req->period_size);
  24.415 +                    goto err;
  24.416 +                }
  24.417 +            }
  24.418 +
  24.419 +            minval = buffer_size;
  24.420 +            err = snd_pcm_hw_params_get_buffer_size_min (
  24.421 +                hw_params,
  24.422 +                &minval
  24.423 +                );
  24.424 +            if (err < 0) {
  24.425 +                alsa_logerr (err, "Could not get minmal buffer size for %s\n",
  24.426 +                             typ);
  24.427 +            }
  24.428 +            else {
  24.429 +                if (buffer_size < minval) {
  24.430 +                    if ((in && conf.buffer_size_in_overriden)
  24.431 +                        || (!in && conf.buffer_size_out_overriden)) {
  24.432 +                        dolog (
  24.433 +                            "%s buffer size(%d) is less "
  24.434 +                            "than minimal buffer size(%ld)\n",
  24.435 +                            typ,
  24.436 +                            buffer_size,
  24.437 +                            minval
  24.438 +                            );
  24.439 +                    }
  24.440 +                    buffer_size = minval;
  24.441 +                }
  24.442 +            }
  24.443 +
  24.444 +            err = snd_pcm_hw_params_set_buffer_size (
  24.445 +                handle,
  24.446 +                hw_params,
  24.447 +                buffer_size
  24.448 +                );
  24.449 +            if (err < 0) {
  24.450 +                alsa_logerr2 (err, typ, "Failed to set buffer size %d\n",
  24.451 +                              req->buffer_size);
  24.452 +                goto err;
  24.453 +            }
  24.454 +        }
  24.455 +    }
  24.456 +    else {
  24.457 +        dolog ("warning: Buffer size is not set\n");
  24.458 +    }
  24.459 +
  24.460 +    err = snd_pcm_hw_params (handle, hw_params);
  24.461 +    if (err < 0) {
  24.462 +        alsa_logerr2 (err, typ, "Failed to apply audio parameters\n");
  24.463 +        goto err;
  24.464 +    }
  24.465 +
  24.466 +    err = snd_pcm_hw_params_get_buffer_size (hw_params, &obt_buffer_size);
  24.467 +    if (err < 0) {
  24.468 +        alsa_logerr2 (err, typ, "Failed to get buffer size\n");
  24.469 +        goto err;
  24.470 +    }
  24.471 +
  24.472 +    err = snd_pcm_prepare (handle);
  24.473 +    if (err < 0) {
  24.474 +        alsa_logerr2 (err, typ, "Could not prepare handle %p\n", handle);
  24.475 +        goto err;
  24.476 +    }
  24.477 +
  24.478 +    if (!in && conf.threshold) {
  24.479 +        snd_pcm_uframes_t threshold;
  24.480 +        int bytes_per_sec;
  24.481 +
  24.482 +        bytes_per_sec = freq
  24.483 +            << (nchannels == 2)
  24.484 +            << (req->fmt == AUD_FMT_S16 || req->fmt == AUD_FMT_U16);
  24.485 +
  24.486 +        threshold = (conf.threshold * bytes_per_sec) / 1000;
  24.487 +        alsa_set_threshold (handle, threshold);
  24.488 +    }
  24.489 +
  24.490 +    obt->fmt = req->fmt;
  24.491 +    obt->nchannels = nchannels;
  24.492 +    obt->freq = freq;
  24.493 +    obt->samples = obt_buffer_size;
  24.494 +    *handlep = handle;
  24.495 +
  24.496 +#if defined DEBUG_MISMATCHES || defined DEBUG
  24.497 +    if (obt->fmt != req->fmt ||
  24.498 +        obt->nchannels != req->nchannels ||
  24.499 +        obt->freq != req->freq) {
  24.500 +        dolog ("Audio paramters mismatch for %s\n", typ);
  24.501 +        alsa_dump_info (req, obt);
  24.502 +    }
  24.503 +#endif
  24.504 +
  24.505 +#ifdef DEBUG
  24.506 +    alsa_dump_info (req, obt);
  24.507 +#endif
  24.508 +    return 0;
  24.509 +
  24.510 + err:
  24.511 +    alsa_anal_close (&handle);
  24.512 +    return -1;
  24.513 +}
  24.514 +
  24.515 +static int alsa_recover (snd_pcm_t *handle)
  24.516 +{
  24.517 +    int err = snd_pcm_prepare (handle);
  24.518 +    if (err < 0) {
  24.519 +        alsa_logerr (err, "Failed to prepare handle %p\n", handle);
  24.520 +        return -1;
  24.521 +    }
  24.522 +    return 0;
  24.523 +}
  24.524 +
  24.525 +static snd_pcm_sframes_t alsa_get_avail (snd_pcm_t *handle)
  24.526 +{
  24.527 +    snd_pcm_sframes_t avail;
  24.528 +
  24.529 +    avail = snd_pcm_avail_update (handle);
  24.530 +    if (avail < 0) {
  24.531 +        if (avail == -EPIPE) {
  24.532 +            if (!alsa_recover (handle)) {
  24.533 +                avail = snd_pcm_avail_update (handle);
  24.534 +            }
  24.535 +        }
  24.536 +
  24.537 +        if (avail < 0) {
  24.538 +            alsa_logerr (avail,
  24.539 +                         "Could not obtain number of available frames\n");
  24.540 +            return -1;
  24.541 +        }
  24.542 +    }
  24.543 +
  24.544 +    return avail;
  24.545 +}
  24.546 +
  24.547 +static int alsa_run_out (HWVoiceOut *hw)
  24.548 +{
  24.549 +    ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw;
  24.550 +    int rpos, live, decr;
  24.551 +    int samples;
  24.552 +    uint8_t *dst;
  24.553 +    st_sample_t *src;
  24.554 +    snd_pcm_sframes_t avail;
  24.555 +
  24.556 +    live = audio_pcm_hw_get_live_out (hw);
  24.557 +    if (!live) {
  24.558 +        return 0;
  24.559 +    }
  24.560 +
  24.561 +    avail = alsa_get_avail (alsa->handle);
  24.562 +    if (avail < 0) {
  24.563 +        dolog ("Could not get number of available playback frames\n");
  24.564 +        return 0;
  24.565 +    }
  24.566 +
  24.567 +    decr = audio_MIN (live, avail);
  24.568 +    samples = decr;
  24.569 +    rpos = hw->rpos;
  24.570 +    while (samples) {
  24.571 +        int left_till_end_samples = hw->samples - rpos;
  24.572 +        int len = audio_MIN (samples, left_till_end_samples);
  24.573 +        snd_pcm_sframes_t written;
  24.574 +
  24.575 +        src = hw->mix_buf + rpos;
  24.576 +        dst = advance (alsa->pcm_buf, rpos << hw->info.shift);
  24.577 +
  24.578 +        hw->clip (dst, src, len);
  24.579 +
  24.580 +        while (len) {
  24.581 +            written = snd_pcm_writei (alsa->handle, dst, len);
  24.582 +
  24.583 +            if (written <= 0) {
  24.584 +                switch (written) {
  24.585 +                case 0:
  24.586 +                    if (conf.verbose) {
  24.587 +                        dolog ("Failed to write %d frames (wrote zero)\n", len);
  24.588 +                    }
  24.589 +                    goto exit;
  24.590 +
  24.591 +                case -EPIPE:
  24.592 +                    if (alsa_recover (alsa->handle)) {
  24.593 +                        alsa_logerr (written, "Failed to write %d frames\n",
  24.594 +                                     len);
  24.595 +                        goto exit;
  24.596 +                    }
  24.597 +                    if (conf.verbose) {
  24.598 +                        dolog ("Recovering from playback xrun\n");
  24.599 +                    }
  24.600 +                    continue;
  24.601 +
  24.602 +                case -EAGAIN:
  24.603 +                    goto exit;
  24.604 +
  24.605 +                default:
  24.606 +                    alsa_logerr (written, "Failed to write %d frames to %p\n",
  24.607 +                                 len, dst);
  24.608 +                    goto exit;
  24.609 +                }
  24.610 +            }
  24.611 +
  24.612 +            mixeng_clear (src, written);
  24.613 +            rpos = (rpos + written) % hw->samples;
  24.614 +            samples -= written;
  24.615 +            len -= written;
  24.616 +            dst = advance (dst, written << hw->info.shift);
  24.617 +            src += written;
  24.618 +        }
  24.619 +    }
  24.620 +
  24.621 + exit:
  24.622 +    hw->rpos = rpos;
  24.623 +    return decr;
  24.624 +}
  24.625 +
  24.626 +static void alsa_fini_out (HWVoiceOut *hw)
  24.627 +{
  24.628 +    ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw;
  24.629 +
  24.630 +    ldebug ("alsa_fini\n");
  24.631 +    alsa_anal_close (&alsa->handle);
  24.632 +
  24.633 +    if (alsa->pcm_buf) {
  24.634 +        qemu_free (alsa->pcm_buf);
  24.635 +        alsa->pcm_buf = NULL;
  24.636 +    }
  24.637 +}
  24.638 +
  24.639 +static int alsa_init_out (HWVoiceOut *hw, audsettings_t *as)
  24.640 +{
  24.641 +    ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw;
  24.642 +    struct alsa_params_req req;
  24.643 +    struct alsa_params_obt obt;
  24.644 +    audfmt_e effective_fmt;
  24.645 +    int endianness;
  24.646 +    int err;
  24.647 +    snd_pcm_t *handle;
  24.648 +    audsettings_t obt_as;
  24.649 +
  24.650 +    req.fmt = aud_to_alsafmt (as->fmt);
  24.651 +    req.freq = as->freq;
  24.652 +    req.nchannels = as->nchannels;
  24.653 +    req.period_size = conf.period_size_out;
  24.654 +    req.buffer_size = conf.buffer_size_out;
  24.655 +
  24.656 +    if (alsa_open (0, &req, &obt, &handle)) {
  24.657 +        return -1;
  24.658 +    }
  24.659 +
  24.660 +    err = alsa_to_audfmt (obt.fmt, &effective_fmt, &endianness);
  24.661 +    if (err) {
  24.662 +        alsa_anal_close (&handle);
  24.663 +        return -1;
  24.664 +    }
  24.665 +
  24.666 +    obt_as.freq = obt.freq;
  24.667 +    obt_as.nchannels = obt.nchannels;
  24.668 +    obt_as.fmt = effective_fmt;
  24.669 +
  24.670 +    audio_pcm_init_info (
  24.671 +        &hw->info,
  24.672 +        &obt_as,
  24.673 +        audio_need_to_swap_endian (endianness)
  24.674 +        );
  24.675 +    hw->samples = obt.samples;
  24.676 +
  24.677 +    alsa->pcm_buf = audio_calloc (AUDIO_FUNC, obt.samples, 1 << hw->info.shift);
  24.678 +    if (!alsa->pcm_buf) {
  24.679 +        dolog ("Could not allocate DAC buffer (%d samples, each %d bytes)\n",
  24.680 +               hw->samples, 1 << hw->info.shift);
  24.681 +        alsa_anal_close (&handle);
  24.682 +        return -1;
  24.683 +    }
  24.684 +
  24.685 +    alsa->handle = handle;
  24.686 +    return 0;
  24.687 +}
  24.688 +
  24.689 +static int alsa_voice_ctl (snd_pcm_t *handle, const char *typ, int pause)
  24.690 +{
  24.691 +    int err;
  24.692 +
  24.693 +    if (pause) {
  24.694 +        err = snd_pcm_drop (handle);
  24.695 +        if (err < 0) {
  24.696 +            alsa_logerr (err, "Could not stop %s\n", typ);
  24.697 +            return -1;
  24.698 +        }
  24.699 +    }
  24.700 +    else {
  24.701 +        err = snd_pcm_prepare (handle);
  24.702 +        if (err < 0) {
  24.703 +            alsa_logerr (err, "Could not prepare handle for %s\n", typ);
  24.704 +            return -1;
  24.705 +        }
  24.706 +    }
  24.707 +
  24.708 +    return 0;
  24.709 +}
  24.710 +
  24.711 +static int alsa_ctl_out (HWVoiceOut *hw, int cmd, ...)
  24.712 +{
  24.713 +    ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw;
  24.714 +
  24.715 +    switch (cmd) {
  24.716 +    case VOICE_ENABLE:
  24.717 +        ldebug ("enabling voice\n");
  24.718 +        return alsa_voice_ctl (alsa->handle, "playback", 0);
  24.719 +
  24.720 +    case VOICE_DISABLE:
  24.721 +        ldebug ("disabling voice\n");
  24.722 +        return alsa_voice_ctl (alsa->handle, "playback", 1);
  24.723 +    }
  24.724 +
  24.725 +    return -1;
  24.726 +}
  24.727 +
  24.728 +static int alsa_init_in (HWVoiceIn *hw, audsettings_t *as)
  24.729 +{
  24.730 +    ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw;
  24.731 +    struct alsa_params_req req;
  24.732 +    struct alsa_params_obt obt;
  24.733 +    int endianness;
  24.734 +    int err;
  24.735 +    audfmt_e effective_fmt;
  24.736 +    snd_pcm_t *handle;
  24.737 +    audsettings_t obt_as;
  24.738 +
  24.739 +    req.fmt = aud_to_alsafmt (as->fmt);
  24.740 +    req.freq = as->freq;
  24.741 +    req.nchannels = as->nchannels;
  24.742 +    req.period_size = conf.period_size_in;
  24.743 +    req.buffer_size = conf.buffer_size_in;
  24.744 +
  24.745 +    if (alsa_open (1, &req, &obt, &handle)) {
  24.746 +        return -1;
  24.747 +    }
  24.748 +
  24.749 +    err = alsa_to_audfmt (obt.fmt, &effective_fmt, &endianness);
  24.750 +    if (err) {
  24.751 +        alsa_anal_close (&handle);
  24.752 +        return -1;
  24.753 +    }
  24.754 +
  24.755 +    obt_as.freq = obt.freq;
  24.756 +    obt_as.nchannels = obt.nchannels;
  24.757 +    obt_as.fmt = effective_fmt;
  24.758 +
  24.759 +    audio_pcm_init_info (
  24.760 +        &hw->info,
  24.761 +        &obt_as,
  24.762 +        audio_need_to_swap_endian (endianness)
  24.763 +        );
  24.764 +    hw->samples = obt.samples;
  24.765 +
  24.766 +    alsa->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift);
  24.767 +    if (!alsa->pcm_buf) {
  24.768 +        dolog ("Could not allocate ADC buffer (%d samples, each %d bytes)\n",
  24.769 +               hw->samples, 1 << hw->info.shift);
  24.770 +        alsa_anal_close (&handle);
  24.771 +        return -1;
  24.772 +    }
  24.773 +
  24.774 +    alsa->handle = handle;
  24.775 +    return 0;
  24.776 +}
  24.777 +
  24.778 +static void alsa_fini_in (HWVoiceIn *hw)
  24.779 +{
  24.780 +    ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw;
  24.781 +
  24.782 +    alsa_anal_close (&alsa->handle);
  24.783 +
  24.784 +    if (alsa->pcm_buf) {
  24.785 +        qemu_free (alsa->pcm_buf);
  24.786 +        alsa->pcm_buf = NULL;
  24.787 +    }
  24.788 +}
  24.789 +
  24.790 +static int alsa_run_in (HWVoiceIn *hw)
  24.791 +{
  24.792 +    ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw;
  24.793 +    int hwshift = hw->info.shift;
  24.794 +    int i;
  24.795 +    int live = audio_pcm_hw_get_live_in (hw);
  24.796 +    int dead = hw->samples - live;
  24.797 +    int decr;
  24.798 +    struct {
  24.799 +        int add;
  24.800 +        int len;
  24.801 +    } bufs[2] = {
  24.802 +        { hw->wpos, 0 },
  24.803 +        { 0, 0 }
  24.804 +    };
  24.805 +    snd_pcm_sframes_t avail;
  24.806 +    snd_pcm_uframes_t read_samples = 0;
  24.807 +
  24.808 +    if (!dead) {
  24.809 +        return 0;
  24.810 +    }
  24.811 +
  24.812 +    avail = alsa_get_avail (alsa->handle);
  24.813 +    if (avail < 0) {
  24.814 +        dolog ("Could not get number of captured frames\n");
  24.815 +        return 0;
  24.816 +    }
  24.817 +
  24.818 +    if (!avail && (snd_pcm_state (alsa->handle) == SND_PCM_STATE_PREPARED)) {
  24.819 +        avail = hw->samples;
  24.820 +    }
  24.821 +
  24.822 +    decr = audio_MIN (dead, avail);
  24.823 +    if (!decr) {
  24.824 +        return 0;
  24.825 +    }
  24.826 +
  24.827 +    if (hw->wpos + decr > hw->samples) {
  24.828 +        bufs[0].len = (hw->samples - hw->wpos);
  24.829 +        bufs[1].len = (decr - (hw->samples - hw->wpos));
  24.830 +    }
  24.831 +    else {
  24.832 +        bufs[0].len = decr;
  24.833 +    }
  24.834 +
  24.835 +    for (i = 0; i < 2; ++i) {
  24.836 +        void *src;
  24.837 +        st_sample_t *dst;
  24.838 +        snd_pcm_sframes_t nread;
  24.839 +        snd_pcm_uframes_t len;
  24.840 +
  24.841 +        len = bufs[i].len;
  24.842 +
  24.843 +        src = advance (alsa->pcm_buf, bufs[i].add << hwshift);
  24.844 +        dst = hw->conv_buf + bufs[i].add;
  24.845 +
  24.846 +        while (len) {
  24.847 +            nread = snd_pcm_readi (alsa->handle, src, len);
  24.848 +
  24.849 +            if (nread <= 0) {
  24.850 +                switch (nread) {
  24.851 +                case 0:
  24.852 +                    if (conf.verbose) {
  24.853 +                        dolog ("Failed to read %ld frames (read zero)\n", len);
  24.854 +                    }
  24.855 +                    goto exit;
  24.856 +
  24.857 +                case -EPIPE:
  24.858 +                    if (alsa_recover (alsa->handle)) {
  24.859 +                        alsa_logerr (nread, "Failed to read %ld frames\n", len);
  24.860 +                        goto exit;
  24.861 +                    }
  24.862 +                    if (conf.verbose) {
  24.863 +                        dolog ("Recovering from capture xrun\n");
  24.864 +                    }
  24.865 +                    continue;
  24.866 +
  24.867 +                case -EAGAIN:
  24.868 +                    goto exit;
  24.869 +
  24.870 +                default:
  24.871 +                    alsa_logerr (
  24.872 +                        nread,
  24.873 +                        "Failed to read %ld frames from %p\n",
  24.874 +                        len,
  24.875 +                        src
  24.876 +                        );
  24.877 +                    goto exit;
  24.878 +                }
  24.879 +            }
  24.880 +
  24.881 +            hw->conv (dst, src, nread, &nominal_volume);
  24.882 +
  24.883 +            src = advance (src, nread << hwshift);
  24.884 +            dst += nread;
  24.885 +
  24.886 +            read_samples += nread;
  24.887 +            len -= nread;
  24.888 +        }
  24.889 +    }
  24.890 +
  24.891 + exit:
  24.892 +    hw->wpos = (hw->wpos + read_samples) % hw->samples;
  24.893 +    return read_samples;
  24.894 +}
  24.895 +
  24.896 +static int alsa_read (SWVoiceIn *sw, void *buf, int size)
  24.897 +{
  24.898 +    return audio_pcm_sw_read (sw, buf, size);
  24.899 +}
  24.900 +
  24.901 +static int alsa_ctl_in (HWVoiceIn *hw, int cmd, ...)
  24.902 +{
  24.903 +    ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw;
  24.904 +
  24.905 +    switch (cmd) {
  24.906 +    case VOICE_ENABLE:
  24.907 +        ldebug ("enabling voice\n");
  24.908 +        return alsa_voice_ctl (alsa->handle, "capture", 0);
  24.909 +
  24.910 +    case VOICE_DISABLE:
  24.911 +        ldebug ("disabling voice\n");
  24.912 +        return alsa_voice_ctl (alsa->handle, "capture", 1);
  24.913 +    }
  24.914 +
  24.915 +    return -1;
  24.916 +}
  24.917 +
  24.918 +static void *alsa_audio_init (void)
  24.919 +{
  24.920 +    return &conf;
  24.921 +}
  24.922 +
  24.923 +static void alsa_audio_fini (void *opaque)
  24.924 +{
  24.925 +    (void) opaque;
  24.926 +}
  24.927 +
  24.928 +static struct audio_option alsa_options[] = {
  24.929 +    {"DAC_SIZE_IN_USEC", AUD_OPT_BOOL, &conf.size_in_usec_out,
  24.930 +     "DAC period/buffer size in microseconds (otherwise in frames)", NULL, 0},
  24.931 +    {"DAC_PERIOD_SIZE", AUD_OPT_INT, &conf.period_size_out,
  24.932 +     "DAC period size", &conf.period_size_out_overriden, 0},
  24.933 +    {"DAC_BUFFER_SIZE", AUD_OPT_INT, &conf.buffer_size_out,
  24.934 +     "DAC buffer size", &conf.buffer_size_out_overriden, 0},
  24.935 +
  24.936 +    {"ADC_SIZE_IN_USEC", AUD_OPT_BOOL, &conf.size_in_usec_in,
  24.937 +     "ADC period/buffer size in microseconds (otherwise in frames)", NULL, 0},
  24.938 +    {"ADC_PERIOD_SIZE", AUD_OPT_INT, &conf.period_size_in,
  24.939 +     "ADC period size", &conf.period_size_in_overriden, 0},
  24.940 +    {"ADC_BUFFER_SIZE", AUD_OPT_INT, &conf.buffer_size_in,
  24.941 +     "ADC buffer size", &conf.buffer_size_in_overriden, 0},
  24.942 +
  24.943 +    {"THRESHOLD", AUD_OPT_INT, &conf.threshold,
  24.944 +     "(undocumented)", NULL, 0},
  24.945 +
  24.946 +    {"DAC_DEV", AUD_OPT_STR, &conf.pcm_name_out,
  24.947 +     "DAC device name (for instance dmix)", NULL, 0},
  24.948 +
  24.949 +    {"ADC_DEV", AUD_OPT_STR, &conf.pcm_name_in,
  24.950 +     "ADC device name", NULL, 0},
  24.951 +
  24.952 +    {"VERBOSE", AUD_OPT_BOOL, &conf.verbose,
  24.953 +     "Behave in a more verbose way", NULL, 0},
  24.954 +
  24.955 +    {NULL, 0, NULL, NULL, NULL, 0}
  24.956 +};
  24.957 +
  24.958 +static struct audio_pcm_ops alsa_pcm_ops = {
  24.959 +    alsa_init_out,
  24.960 +    alsa_fini_out,
  24.961 +    alsa_run_out,
  24.962 +    alsa_write,
  24.963 +    alsa_ctl_out,
  24.964 +
  24.965 +    alsa_init_in,
  24.966 +    alsa_fini_in,
  24.967 +    alsa_run_in,
  24.968 +    alsa_read,
  24.969 +    alsa_ctl_in
  24.970 +};
  24.971 +
  24.972 +struct audio_driver alsa_audio_driver = {
  24.973 +    INIT_FIELD (name           = ) "alsa",
  24.974 +    INIT_FIELD (descr          = ) "ALSA http://www.alsa-project.org",
  24.975 +    INIT_FIELD (options        = ) alsa_options,
  24.976 +    INIT_FIELD (init           = ) alsa_audio_init,
  24.977 +    INIT_FIELD (fini           = ) alsa_audio_fini,
  24.978 +    INIT_FIELD (pcm_ops        = ) &alsa_pcm_ops,
  24.979 +    INIT_FIELD (can_be_default = ) 1,
  24.980 +    INIT_FIELD (max_voices_out = ) INT_MAX,
  24.981 +    INIT_FIELD (max_voices_in  = ) INT_MAX,
  24.982 +    INIT_FIELD (voice_size_out = ) sizeof (ALSAVoiceOut),
  24.983 +    INIT_FIELD (voice_size_in  = ) sizeof (ALSAVoiceIn)
  24.984 +};
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/tools/ioemu/audio/audio.c	Wed Jul 12 19:16:10 2006 +0100
    25.3 @@ -0,0 +1,1481 @@
    25.4 +/*
    25.5 + * QEMU Audio subsystem
    25.6 + *
    25.7 + * Copyright (c) 2003-2005 Vassili Karpov (malc)
    25.8 + *
    25.9 + * Permission is hereby granted, free of charge, to any person obtaining a copy
   25.10 + * of this software and associated documentation files (the "Software"), to deal
   25.11 + * in the Software without restriction, including without limitation the rights
   25.12 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   25.13 + * copies of the Software, and to permit persons to whom the Software is
   25.14 + * furnished to do so, subject to the following conditions:
   25.15 + *
   25.16 + * The above copyright notice and this permission notice shall be included in
   25.17 + * all copies or substantial portions of the Software.
   25.18 + *
   25.19 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   25.20 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   25.21 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
   25.22 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   25.23 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   25.24 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   25.25 + * THE SOFTWARE.
   25.26 + */
   25.27 +#include "vl.h"
   25.28 +
   25.29 +#define AUDIO_CAP "audio"
   25.30 +#include "audio_int.h"
   25.31 +
   25.32 +/* #define DEBUG_PLIVE */
   25.33 +/* #define DEBUG_LIVE */
   25.34 +/* #define DEBUG_OUT */
   25.35 +
   25.36 +#define SW_NAME(sw) (sw)->name ? (sw)->name : "unknown"
   25.37 +
   25.38 +static struct audio_driver *drvtab[] = {
   25.39 +#ifdef CONFIG_OSS
   25.40 +    &oss_audio_driver,
   25.41 +#endif
   25.42 +#ifdef CONFIG_ALSA
   25.43 +    &alsa_audio_driver,
   25.44 +#endif
   25.45 +#ifdef CONFIG_COREAUDIO
   25.46 +    &coreaudio_audio_driver,
   25.47 +#endif
   25.48 +#ifdef CONFIG_DSOUND
   25.49 +    &dsound_audio_driver,
   25.50 +#endif
   25.51 +#ifdef CONFIG_FMOD
   25.52 +    &fmod_audio_driver,
   25.53 +#endif
   25.54 +#ifdef CONFIG_SDL
   25.55 +    &sdl_audio_driver,
   25.56 +#endif
   25.57 +    &no_audio_driver,
   25.58 +    &wav_audio_driver
   25.59 +};
   25.60 +
   25.61 +struct fixed_settings {
   25.62 +    int enabled;
   25.63 +    int nb_voices;
   25.64 +    int greedy;
   25.65 +    audsettings_t settings;
   25.66 +};
   25.67 +
   25.68 +static struct {
   25.69 +    struct fixed_settings fixed_out;
   25.70 +    struct fixed_settings fixed_in;
   25.71 +    union {
   25.72 +        int hz;
   25.73 +        int64_t ticks;
   25.74 +    } period;
   25.75 +    int plive;
   25.76 +    int log_to_monitor;
   25.77 +} conf = {
   25.78 +    {                           /* DAC fixed settings */
   25.79 +        1,                      /* enabled */
   25.80 +        1,                      /* nb_voices */
   25.81 +        1,                      /* greedy */
   25.82 +        {
   25.83 +            44100,              /* freq */
   25.84 +            2,                  /* nchannels */
   25.85 +            AUD_FMT_S16         /* fmt */
   25.86 +        }
   25.87 +    },
   25.88 +
   25.89 +    {                           /* ADC fixed settings */
   25.90 +        1,                      /* enabled */
   25.91 +        1,                      /* nb_voices */
   25.92 +        1,                      /* greedy */
   25.93 +        {
   25.94 +            44100,              /* freq */
   25.95 +            2,                  /* nchannels */
   25.96 +            AUD_FMT_S16         /* fmt */
   25.97 +        }
   25.98 +    },
   25.99 +
  25.100 +    { 0 },                      /* period */
  25.101 +    0,                          /* plive */
  25.102 +    0                           /* log_to_monitor */
  25.103 +};
  25.104 +
  25.105 +static AudioState glob_audio_state;
  25.106 +
  25.107 +volume_t nominal_volume = {
  25.108 +    0,
  25.109 +#ifdef FLOAT_MIXENG
  25.110 +    1.0,
  25.111 +    1.0
  25.112 +#else
  25.113 +    UINT_MAX,
  25.114 +    UINT_MAX
  25.115 +#endif
  25.116 +};
  25.117 +
  25.118 +/* http://www.df.lth.se/~john_e/gems/gem002d.html */
  25.119 +/* http://www.multi-platforms.com/Tips/PopCount.htm */
  25.120 +uint32_t popcount (uint32_t u)
  25.121 +{
  25.122 +    u = ((u&0x55555555) + ((u>>1)&0x55555555));
  25.123 +    u = ((u&0x33333333) + ((u>>2)&0x33333333));
  25.124 +    u = ((u&0x0f0f0f0f) + ((u>>4)&0x0f0f0f0f));
  25.125 +    u = ((u&0x00ff00ff) + ((u>>8)&0x00ff00ff));
  25.126 +    u = ( u&0x0000ffff) + (u>>16);
  25.127 +    return u;
  25.128 +}
  25.129 +
  25.130 +inline uint32_t lsbindex (uint32_t u)
  25.131 +{
  25.132 +    return popcount ((u&-u)-1);
  25.133 +}
  25.134 +
  25.135 +#ifdef AUDIO_IS_FLAWLESS_AND_NO_CHECKS_ARE_REQURIED
  25.136 +#error No its not
  25.137 +#else
  25.138 +int audio_bug (const char *funcname, int cond)
  25.139 +{
  25.140 +    if (cond) {
  25.141 +        static int shown;
  25.142 +
  25.143 +        AUD_log (NULL, "Error a bug that was just triggered in %s\n", funcname);
  25.144 +        if (!shown) {
  25.145 +            shown = 1;
  25.146 +            AUD_log (NULL, "Save all your work and restart without audio\n");
  25.147 +            AUD_log (NULL, "Please send bug report to malc@pulsesoft.com\n");
  25.148 +            AUD_log (NULL, "I am sorry\n");
  25.149 +        }
  25.150 +        AUD_log (NULL, "Context:\n");
  25.151 +
  25.152 +#if defined AUDIO_BREAKPOINT_ON_BUG
  25.153 +#  if defined HOST_I386
  25.154 +#    if defined __GNUC__
  25.155 +        __asm__ ("int3");
  25.156 +#    elif defined _MSC_VER
  25.157 +        _asm _emit 0xcc;
  25.158 +#    else
  25.159 +        abort ();
  25.160 +#    endif
  25.161 +#  else
  25.162 +        abort ();
  25.163 +#  endif
  25.164 +#endif
  25.165 +    }
  25.166 +
  25.167 +    return cond;
  25.168 +}
  25.169 +#endif
  25.170 +
  25.171 +void *audio_calloc (const char *funcname, int nmemb, size_t size)
  25.172 +{
  25.173 +    int cond;
  25.174 +    size_t len;
  25.175 +
  25.176 +    len = nmemb * size;
  25.177 +    cond = !nmemb || !size;
  25.178 +    cond |= nmemb < 0;
  25.179 +    cond |= len < size;
  25.180 +
  25.181 +    if (audio_bug ("audio_calloc", cond)) {
  25.182 +        AUD_log (NULL, "%s passed invalid arguments to audio_calloc\n",
  25.183 +                 funcname);
  25.184 +        AUD_log (NULL, "nmemb=%d size=%zu (len=%zu)\n", nmemb, size, len);
  25.185 +        return NULL;
  25.186 +    }
  25.187 +
  25.188 +    return qemu_mallocz (len);
  25.189 +}
  25.190 +
  25.191 +static char *audio_alloc_prefix (const char *s)
  25.192 +{
  25.193 +    const char qemu_prefix[] = "QEMU_";
  25.194 +    size_t len;
  25.195 +    char *r;
  25.196 +
  25.197 +    if (!s) {
  25.198 +        return NULL;
  25.199 +    }
  25.200 +
  25.201 +    len = strlen (s);
  25.202 +    r = qemu_malloc (len + sizeof (qemu_prefix));
  25.203 +
  25.204 +    if (r) {
  25.205 +        size_t i;
  25.206 +        char *u = r + sizeof (qemu_prefix) - 1;
  25.207 +
  25.208 +        strcpy (r, qemu_prefix);
  25.209 +        strcat (r, s);
  25.210 +
  25.211 +        for (i = 0; i < len; ++i) {
  25.212 +            u[i] = toupper (u[i]);
  25.213 +        }
  25.214 +    }
  25.215 +    return r;
  25.216 +}
  25.217 +
  25.218 +const char *audio_audfmt_to_string (audfmt_e fmt)
  25.219 +{
  25.220 +    switch (fmt) {
  25.221 +    case AUD_FMT_U8:
  25.222 +        return "U8";
  25.223 +
  25.224 +    case AUD_FMT_U16:
  25.225 +        return "U16";
  25.226 +
  25.227 +    case AUD_FMT_S8:
  25.228 +        return "S8";
  25.229 +
  25.230 +    case AUD_FMT_S16:
  25.231 +        return "S16";
  25.232 +    }
  25.233 +
  25.234 +    dolog ("Bogus audfmt %d returning S16\n", fmt);
  25.235 +    return "S16";
  25.236 +}
  25.237 +
  25.238 +audfmt_e audio_string_to_audfmt (const char *s, audfmt_e defval, int *defaultp)
  25.239 +{
  25.240 +    if (!strcasecmp (s, "u8")) {
  25.241 +        *defaultp = 0;
  25.242 +        return AUD_FMT_U8;
  25.243 +    }
  25.244 +    else if (!strcasecmp (s, "u16")) {
  25.245 +        *defaultp = 0;
  25.246 +        return AUD_FMT_U16;
  25.247 +    }
  25.248 +    else if (!strcasecmp (s, "s8")) {
  25.249 +        *defaultp = 0;
  25.250 +        return AUD_FMT_S8;
  25.251 +    }
  25.252 +    else if (!strcasecmp (s, "s16")) {
  25.253 +        *defaultp = 0;
  25.254 +        return AUD_FMT_S16;
  25.255 +    }
  25.256 +    else {
  25.257 +        dolog ("Bogus audio format `%s' using %s\n",
  25.258 +               s, audio_audfmt_to_string (defval));
  25.259 +        *defaultp = 1;
  25.260 +        return defval;
  25.261 +    }
  25.262 +}
  25.263 +
  25.264 +static audfmt_e audio_get_conf_fmt (const char *envname,
  25.265 +                                    audfmt_e defval,
  25.266 +                                    int *defaultp)
  25.267 +{
  25.268 +    const char *var = getenv (envname);
  25.269 +    if (!var) {
  25.270 +        *defaultp = 1;
  25.271 +        return defval;
  25.272 +    }
  25.273 +    return audio_string_to_audfmt (var, defval, defaultp);
  25.274 +}
  25.275 +
  25.276 +static int audio_get_conf_int (const char *key, int defval, int *defaultp)
  25.277 +{
  25.278 +    int val;
  25.279 +    char *strval;
  25.280 +
  25.281 +    strval = getenv (key);
  25.282 +    if (strval) {
  25.283 +        *defaultp = 0;
  25.284 +        val = atoi (strval);
  25.285 +        return val;
  25.286 +    }
  25.287 +    else {
  25.288 +        *defaultp = 1;
  25.289 +        return defval;
  25.290 +    }
  25.291 +}
  25.292 +
  25.293 +static const char *audio_get_conf_str (const char *key,
  25.294 +                                       const char *defval,
  25.295 +                                       int *defaultp)
  25.296 +{
  25.297 +    const char *val = getenv (key);
  25.298 +    if (!val) {
  25.299 +        *defaultp = 1;
  25.300 +        return defval;
  25.301 +    }
  25.302 +    else {
  25.303 +        *defaultp = 0;
  25.304 +        return val;
  25.305 +    }
  25.306 +}
  25.307 +
  25.308 +void AUD_vlog (const char *cap, const char *fmt, va_list ap)
  25.309 +{
  25.310 +    if (conf.log_to_monitor) {
  25.311 +        if (cap) {
  25.312 +            term_printf ("%s: ", cap);
  25.313 +        }
  25.314 +
  25.315 +        term_vprintf (fmt, ap);
  25.316 +    }
  25.317 +    else {
  25.318 +        if (cap) {
  25.319 +            fprintf (stderr, "%s: ", cap);
  25.320 +        }
  25.321 +
  25.322 +        vfprintf (stderr, fmt, ap);
  25.323 +    }
  25.324 +}
  25.325 +
  25.326 +void AUD_log (const char *cap, const char *fmt, ...)
  25.327 +{
  25.328 +    va_list ap;
  25.329 +
  25.330 +    va_start (ap, fmt);
  25.331 +    AUD_vlog (cap, fmt, ap);
  25.332 +    va_end (ap);
  25.333 +}
  25.334 +
  25.335 +static void audio_print_options (const char *prefix,
  25.336 +                                 struct audio_option *opt)
  25.337 +{
  25.338 +    char *uprefix;
  25.339 +
  25.340 +    if (!prefix) {
  25.341 +        dolog ("No prefix specified\n");
  25.342 +        return;
  25.343 +    }
  25.344 +
  25.345 +    if (!opt) {
  25.346 +        dolog ("No options\n");
  25.347 +        return;
  25.348 +    }
  25.349 +
  25.350 +    uprefix = audio_alloc_prefix (prefix);
  25.351 +
  25.352 +    for (; opt->name; opt++) {
  25.353 +        const char *state = "default";
  25.354 +        printf ("  %s_%s: ", uprefix, opt->name);
  25.355 +
  25.356 +        if (opt->overridenp && *opt->overridenp) {
  25.357 +            state = "current";
  25.358 +        }
  25.359 +
  25.360 +        switch (opt->tag) {
  25.361 +        case AUD_OPT_BOOL:
  25.362 +            {
  25.363 +                int *intp = opt->valp;
  25.364 +                printf ("boolean, %s = %d\n", state, *intp ? 1 : 0);
  25.365 +            }
  25.366 +            break;
  25.367 +
  25.368 +        case AUD_OPT_INT:
  25.369 +            {
  25.370 +                int *intp = opt->valp;
  25.371 +                printf ("integer, %s = %d\n", state, *intp);
  25.372 +            }
  25.373 +            break;
  25.374 +
  25.375 +        case AUD_OPT_FMT:
  25.376 +            {
  25.377 +                audfmt_e *fmtp = opt->valp;
  25.378 +                printf (
  25.379 +                    "format, %s = %s, (one of: U8 S8 U16 S16)\n",
  25.380 +                    state,
  25.381 +                    audio_audfmt_to_string (*fmtp)
  25.382 +                    );
  25.383 +            }
  25.384 +            break;
  25.385 +
  25.386 +        case AUD_OPT_STR:
  25.387 +            {
  25.388 +                const char **strp = opt->valp;
  25.389 +                printf ("string, %s = %s\n",
  25.390 +                        state,
  25.391 +                        *strp ? *strp : "(not set)");
  25.392 +            }
  25.393 +            break;
  25.394 +
  25.395 +        default:
  25.396 +            printf ("???\n");
  25.397 +            dolog ("Bad value tag for option %s_%s %d\n",
  25.398 +                   uprefix, opt->name, opt->tag);
  25.399 +            break;
  25.400 +        }
  25.401 +        printf ("    %s\n", opt->descr);
  25.402 +    }
  25.403 +
  25.404 +    qemu_free (uprefix);
  25.405 +}
  25.406 +
  25.407 +static void audio_process_options (const char *prefix,
  25.408 +                                   struct audio_option *opt)
  25.409 +{
  25.410 +    char *optname;
  25.411 +    const char qemu_prefix[] = "QEMU_";
  25.412 +    size_t preflen;
  25.413 +
  25.414 +    if (audio_bug (AUDIO_FUNC, !prefix)) {
  25.415 +        dolog ("prefix = NULL\n");
  25.416 +        return;
  25.417 +    }
  25.418 +
  25.419 +    if (audio_bug (AUDIO_FUNC, !opt)) {
  25.420 +        dolog ("opt = NULL\n");
  25.421 +        return;
  25.422 +    }
  25.423 +
  25.424 +    preflen = strlen (prefix);
  25.425 +
  25.426 +    for (; opt->name; opt++) {
  25.427 +        size_t len, i;
  25.428 +        int def;
  25.429 +
  25.430 +        if (!opt->valp) {
  25.431 +            dolog ("Option value pointer for `%s' is not set\n",
  25.432 +                   opt->name);
  25.433 +            continue;
  25.434 +        }
  25.435 +
  25.436 +        len = strlen (opt->name);
  25.437 +        /* len of opt->name + len of prefix + size of qemu_prefix
  25.438 +         * (includes trailing zero) + zero + underscore (on behalf of
  25.439 +         * sizeof) */
  25.440 +        optname = qemu_malloc (len + preflen + sizeof (qemu_prefix) + 1);
  25.441 +        if (!optname) {
  25.442 +            dolog ("Could not allocate memory for option name `%s'\n",
  25.443 +                   opt->name);
  25.444 +            continue;
  25.445 +        }
  25.446 +
  25.447 +        strcpy (optname, qemu_prefix);
  25.448 +
  25.449 +        /* copy while upper-casing, including trailing zero */
  25.450 +        for (i = 0; i <= preflen; ++i) {
  25.451 +            optname[i + sizeof (qemu_prefix) - 1] = toupper (prefix[i]);
  25.452 +        }
  25.453 +        strcat (optname, "_");
  25.454 +        strcat (optname, opt->name);
  25.455 +
  25.456 +        def = 1;
  25.457 +        switch (opt->tag) {
  25.458 +        case AUD_OPT_BOOL:
  25.459 +        case AUD_OPT_INT:
  25.460 +            {
  25.461 +                int *intp = opt->valp;
  25.462 +                *intp = audio_get_conf_int (optname, *intp, &def);
  25.463 +            }
  25.464 +            break;
  25.465 +
  25.466 +        case AUD_OPT_FMT:
  25.467 +            {
  25.468 +                audfmt_e *fmtp = opt->valp;
  25.469 +                *fmtp = audio_get_conf_fmt (optname, *fmtp, &def);
  25.470 +            }
  25.471 +            break;
  25.472 +
  25.473 +        case AUD_OPT_STR:
  25.474 +            {
  25.475 +                const char **strp = opt->valp;
  25.476 +                *strp = audio_get_conf_str (optname, *strp, &def);
  25.477 +            }
  25.478 +            break;
  25.479 +
  25.480 +        default:
  25.481 +            dolog ("Bad value tag for option `%s' - %d\n",
  25.482 +                   optname, opt->tag);
  25.483 +            break;
  25.484 +        }
  25.485 +
  25.486 +        if (!opt->overridenp) {
  25.487 +            opt->overridenp = &opt->overriden;
  25.488 +        }
  25.489 +        *opt->overridenp = !def;
  25.490 +        qemu_free (optname);
  25.491 +    }
  25.492 +}
  25.493 +
  25.494 +static void audio_print_settings (audsettings_t *as)
  25.495 +{
  25.496 +    dolog ("frequency=%d nchannels=%d fmt=", as->freq, as->nchannels);
  25.497 +
  25.498 +    switch (as->fmt) {
  25.499 +    case AUD_FMT_S8:
  25.500 +        AUD_log (NULL, "S8");
  25.501 +        break;
  25.502 +    case AUD_FMT_U8:
  25.503 +        AUD_log (NULL, "U8");
  25.504 +        break;
  25.505 +    case AUD_FMT_S16:
  25.506 +        AUD_log (NULL, "S16");
  25.507 +        break;
  25.508 +    case AUD_FMT_U16:
  25.509 +        AUD_log (NULL, "U16");
  25.510 +        break;
  25.511 +    default:
  25.512 +        AUD_log (NULL, "invalid(%d)", as->fmt);
  25.513 +        break;
  25.514 +    }
  25.515 +    AUD_log (NULL, "\n");
  25.516 +}
  25.517 +
  25.518 +static int audio_validate_settigs (audsettings_t *as)
  25.519 +{
  25.520 +    int invalid;
  25.521 +
  25.522 +    invalid = as->nchannels != 1 && as->nchannels != 2;
  25.523 +
  25.524 +    switch (as->fmt) {
  25.525 +    case AUD_FMT_S8:
  25.526 +    case AUD_FMT_U8:
  25.527 +    case AUD_FMT_S16:
  25.528 +    case AUD_FMT_U16:
  25.529 +        break;
  25.530 +    default:
  25.531 +        invalid = 1;
  25.532 +        break;
  25.533 +    }
  25.534 +
  25.535 +    invalid |= as->freq <= 0;
  25.536 +
  25.537 +    if (invalid) {
  25.538 +        return -1;
  25.539 +    }
  25.540 +    return 0;
  25.541 +}
  25.542 +
  25.543 +static int audio_pcm_info_eq (struct audio_pcm_info *info, audsettings_t *as)
  25.544 +{
  25.545 +    int bits = 8, sign = 0;
  25.546 +
  25.547 +    switch (as->fmt) {
  25.548 +    case AUD_FMT_S8:
  25.549 +        sign = 1;
  25.550 +    case AUD_FMT_U8:
  25.551 +        break;
  25.552 +
  25.553 +    case AUD_FMT_S16:
  25.554 +        sign = 1;
  25.555 +    case AUD_FMT_U16:
  25.556 +        bits = 16;
  25.557 +        break;
  25.558 +    }
  25.559 +    return info->freq == as->freq
  25.560 +        && info->nchannels == as->nchannels
  25.561 +        && info->sign == sign
  25.562 +        && info->bits == bits;
  25.563 +}
  25.564 +
  25.565 +void audio_pcm_init_info (
  25.566 +    struct audio_pcm_info *info,
  25.567 +    audsettings_t *as,
  25.568 +    int swap_endian
  25.569 +    )
  25.570 +{
  25.571 +    int bits = 8, sign = 0;
  25.572 +
  25.573 +    switch (as->fmt) {
  25.574 +    case AUD_FMT_S8:
  25.575 +        sign = 1;
  25.576 +    case AUD_FMT_U8:
  25.577 +        break;
  25.578 +
  25.579 +    case AUD_FMT_S16:
  25.580 +        sign = 1;
  25.581 +    case AUD_FMT_U16:
  25.582 +        bits = 16;
  25.583 +        break;
  25.584 +    }
  25.585 +
  25.586 +    info->freq = as->freq;
  25.587 +    info->bits = bits;
  25.588 +    info->sign = sign;
  25.589 +    info->nchannels = as->nchannels;
  25.590 +    info->shift = (as->nchannels == 2) + (bits == 16);
  25.591 +    info->align = (1 << info->shift) - 1;
  25.592 +    info->bytes_per_second = info->freq << info->shift;
  25.593 +    info->swap_endian = swap_endian;
  25.594 +}
  25.595 +
  25.596 +void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len)
  25.597 +{
  25.598 +    if (!len) {
  25.599 +        return;
  25.600 +    }
  25.601 +
  25.602 +    if (info->sign) {
  25.603 +        memset (buf, len << info->shift, 0x00);
  25.604 +    }
  25.605 +    else {
  25.606 +        if (info->bits == 8) {
  25.607 +            memset (buf, len << info->shift, 0x80);
  25.608 +        }
  25.609 +        else {
  25.610 +            int i;
  25.611 +            uint16_t *p = buf;
  25.612 +            int shift = info->nchannels - 1;
  25.613 +            short s = INT16_MAX;
  25.614 +
  25.615 +            if (info->swap_endian) {
  25.616 +                s = bswap16 (s);
  25.617 +            }
  25.618 +
  25.619 +            for (i = 0; i < len << shift; i++) {
  25.620 +                p[i] = s;
  25.621 +            }
  25.622 +        }
  25.623 +    }
  25.624 +}
  25.625 +
  25.626 +/*
  25.627 + * Hard voice (capture)
  25.628 + */
  25.629 +static int audio_pcm_hw_find_min_in (HWVoiceIn *hw)
  25.630 +{
  25.631 +    SWVoiceIn *sw;
  25.632 +    int m = hw->total_samples_captured;
  25.633 +
  25.634 +    for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
  25.635 +        if (sw->active) {
  25.636 +            m = audio_MIN (m, sw->total_hw_samples_acquired);
  25.637 +        }
  25.638 +    }
  25.639 +    return m;
  25.640 +}
  25.641 +
  25.642 +int audio_pcm_hw_get_live_in (HWVoiceIn *hw)
  25.643 +{
  25.644 +    int live = hw->total_samples_captured - audio_pcm_hw_find_min_in (hw);
  25.645 +    if (audio_bug (AUDIO_FUNC, live < 0 || live > hw->samples)) {
  25.646 +        dolog ("live=%d hw->samples=%d\n", live, hw->samples);
  25.647 +        return 0;
  25.648 +    }
  25.649 +    return live;
  25.650 +}
  25.651 +
  25.652 +/*
  25.653 + * Soft voice (capture)
  25.654 + */
  25.655 +static int audio_pcm_sw_get_rpos_in (SWVoiceIn *sw)
  25.656 +{
  25.657 +    HWVoiceIn *hw = sw->hw;
  25.658 +    int live = hw->total_samples_captured - sw->total_hw_samples_acquired;
  25.659 +    int rpos;
  25.660 +
  25.661 +    if (audio_bug (AUDIO_FUNC, live < 0 || live > hw->samples)) {
  25.662 +        dolog ("live=%d hw->samples=%d\n", live, hw->samples);
  25.663 +        return 0;
  25.664 +    }
  25.665 +
  25.666 +    rpos = hw->wpos - live;
  25.667 +    if (rpos >= 0) {
  25.668 +        return rpos;
  25.669 +    }
  25.670 +    else {
  25.671 +        return hw->samples + rpos;
  25.672 +    }
  25.673 +}
  25.674 +
  25.675 +int audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int size)
  25.676 +{
  25.677 +    HWVoiceIn *hw = sw->hw;
  25.678 +    int samples, live, ret = 0, swlim, isamp, osamp, rpos, total = 0;
  25.679 +    st_sample_t *src, *dst = sw->buf;
  25.680 +
  25.681 +    rpos = audio_pcm_sw_get_rpos_in (sw) % hw->samples;
  25.682 +
  25.683 +    live = hw->total_samples_captured - sw->total_hw_samples_acquired;
  25.684 +    if (audio_bug (AUDIO_FUNC, live < 0 || live > hw->samples)) {
  25.685 +        dolog ("live_in=%d hw->samples=%d\n", live, hw->samples);
  25.686 +        return 0;
  25.687 +    }
  25.688 +
  25.689 +    samples = size >> sw->info.shift;
  25.690 +    if (!live) {
  25.691 +        return 0;
  25.692 +    }
  25.693 +
  25.694 +    swlim = (live * sw->ratio) >> 32;
  25.695 +    swlim = audio_MIN (swlim, samples);
  25.696 +
  25.697 +    while (swlim) {
  25.698 +        src = hw->conv_buf + rpos;
  25.699 +        isamp = hw->wpos - rpos;
  25.700 +        /* XXX: <= ? */
  25.701 +        if (isamp <= 0) {
  25.702 +            isamp = hw->samples - rpos;
  25.703 +        }
  25.704 +
  25.705 +        if (!isamp) {
  25.706 +            break;
  25.707 +        }
  25.708 +        osamp = swlim;
  25.709 +
  25.710 +        if (audio_bug (AUDIO_FUNC, osamp < 0)) {
  25.711 +            dolog ("osamp=%d\n", osamp);
  25.712 +            return 0;
  25.713 +        }
  25.714 +
  25.715 +        st_rate_flow (sw->rate, src, dst, &isamp, &osamp);
  25.716 +        swlim -= osamp;
  25.717 +        rpos = (rpos + isamp) % hw->samples;
  25.718 +        dst += osamp;
  25.719 +        ret += osamp;
  25.720 +        total += isamp;
  25.721 +    }
  25.722 +
  25.723 +    sw->clip (buf, sw->buf, ret);
  25.724 +    sw->total_hw_samples_acquired += total;
  25.725 +    return ret << sw->info.shift;
  25.726 +}
  25.727 +
  25.728 +/*
  25.729 + * Hard voice (playback)
  25.730 + */
  25.731 +static int audio_pcm_hw_find_min_out (HWVoiceOut *hw, int *nb_livep)
  25.732 +{
  25.733 +    SWVoiceOut *sw;
  25.734 +    int m = INT_MAX;
  25.735 +    int nb_live = 0;
  25.736 +
  25.737 +    for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
  25.738 +        if (sw->active || !sw->empty) {
  25.739 +            m = audio_MIN (m, sw->total_hw_samples_mixed);
  25.740 +            nb_live += 1;
  25.741 +        }
  25.742 +    }
  25.743 +
  25.744 +    *nb_livep = nb_live;
  25.745 +    return m;
  25.746 +}
  25.747 +
  25.748 +int audio_pcm_hw_get_live_out2 (HWVoiceOut *hw, int *nb_live)
  25.749 +{
  25.750 +    int smin;
  25.751 +
  25.752 +    smin = audio_pcm_hw_find_min_out (hw, nb_live);
  25.753 +
  25.754 +    if (!*nb_live) {
  25.755 +        return 0;
  25.756 +    }
  25.757 +    else {
  25.758 +        int live = smin;
  25.759 +
  25.760 +        if (audio_bug (AUDIO_FUNC, live < 0 || live > hw->samples)) {
  25.761 +            dolog ("live=%d hw->samples=%d\n", live, hw->samples);
  25.762 +            return 0;
  25.763 +        }
  25.764 +        return live;
  25.765 +    }
  25.766 +}
  25.767 +
  25.768 +int audio_pcm_hw_get_live_out (HWVoiceOut *hw)
  25.769 +{
  25.770 +    int nb_live;
  25.771 +    int live;
  25.772 +
  25.773 +    live = audio_pcm_hw_get_live_out2 (hw, &nb_live);
  25.774 +    if (audio_bug (AUDIO_FUNC, live < 0 || live > hw->samples)) {
  25.775 +        dolog ("live=%d hw->samples=%d\n", live, hw->samples);
  25.776 +        return 0;
  25.777 +    }
  25.778 +    return live;
  25.779 +}
  25.780 +
  25.781 +/*
  25.782 + * Soft voice (playback)
  25.783 + */
  25.784 +int audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int size)
  25.785 +{
  25.786 +    int hwsamples, samples, isamp, osamp, wpos, live, dead, left, swlim, blck;
  25.787 +    int ret = 0, pos = 0, total = 0;
  25.788 +
  25.789 +    if (!sw) {
  25.790 +        return size;
  25.791 +    }
  25.792 +
  25.793 +    hwsamples = sw->hw->samples;
  25.794 +
  25.795 +    live = sw->total_hw_samples_mixed;
  25.796 +    if (audio_bug (AUDIO_FUNC, live < 0 || live > hwsamples)){
  25.797 +        dolog ("live=%d hw->samples=%d\n", live, hwsamples);
  25.798 +        return 0;
  25.799 +    }
  25.800 +
  25.801 +    if (live == hwsamples) {
  25.802 +        return 0;
  25.803 +    }
  25.804 +
  25.805 +    wpos = (sw->hw->rpos + live) % hwsamples;
  25.806 +    samples = size >> sw->info.shift;
  25.807 +
  25.808 +    dead = hwsamples - live;
  25.809 +    swlim = ((int64_t) dead << 32) / sw->ratio;
  25.810 +    swlim = audio_MIN (swlim, samples);
  25.811 +    if (swlim) {
  25.812 +        sw->conv (sw->buf, buf, swlim, &sw->vol);
  25.813 +    }
  25.814 +
  25.815 +    while (swlim) {
  25.816 +        dead = hwsamples - live;
  25.817 +        left = hwsamples - wpos;
  25.818 +        blck = audio_MIN (dead, left);
  25.819 +        if (!blck) {
  25.820 +            break;
  25.821 +        }
  25.822 +        isamp = swlim;
  25.823 +        osamp = blck;
  25.824 +        st_rate_flow_mix (
  25.825 +            sw->rate,
  25.826 +            sw->buf + pos,
  25.827 +            sw->hw->mix_buf + wpos,
  25.828 +            &isamp,
  25.829 +            &osamp
  25.830 +            );
  25.831 +        ret += isamp;
  25.832 +        swlim -= isamp;
  25.833 +        pos += isamp;
  25.834 +        live += osamp;
  25.835 +        wpos = (wpos + osamp) % hwsamples;
  25.836 +        total += osamp;
  25.837 +    }
  25.838 +
  25.839 +    sw->total_hw_samples_mixed += total;
  25.840 +    sw->empty = sw->total_hw_samples_mixed == 0;
  25.841 +
  25.842 +#ifdef DEBUG_OUT
  25.843 +    dolog (
  25.844 +        "%s: write size %d ret %d total sw %d\n",
  25.845 +        SW_NAME (sw),
  25.846 +        size >> sw->info.shift,
  25.847 +        ret,
  25.848 +        sw->total_hw_samples_mixed
  25.849 +        );
  25.850 +#endif
  25.851 +
  25.852 +    return ret << sw->info.shift;
  25.853 +}
  25.854 +
  25.855 +#ifdef DEBUG_AUDIO
  25.856 +static void audio_pcm_print_info (const char *cap, struct audio_pcm_info *info)
  25.857 +{
  25.858 +    dolog ("%s: bits %d, sign %d, freq %d, nchan %d\n",
  25.859 +           cap, info->bits, info->sign, info->freq, info->nchannels);
  25.860 +}
  25.861 +#endif
  25.862 +
  25.863 +#define DAC
  25.864 +#include "audio_template.h"
  25.865 +#undef DAC
  25.866 +#include "audio_template.h"
  25.867 +
  25.868 +int AUD_write (SWVoiceOut *sw, void *buf, int size)
  25.869 +{
  25.870 +    int bytes;
  25.871 +
  25.872 +    if (!sw) {
  25.873 +        /* XXX: Consider options */
  25.874 +        return size;
  25.875 +    }
  25.876 +
  25.877 +    if (!sw->hw->enabled) {
  25.878 +        dolog ("Writing to disabled voice %s\n", SW_NAME (sw));
  25.879 +        return 0;
  25.880 +    }
  25.881 +
  25.882 +    bytes = sw->hw->pcm_ops->write (sw, buf, size);
  25.883 +    return bytes;
  25.884 +}
  25.885 +
  25.886 +int AUD_read (SWVoiceIn *sw, void *buf, int size)
  25.887 +{
  25.888 +    int bytes;
  25.889 +
  25.890 +    if (!sw) {
  25.891 +        /* XXX: Consider options */
  25.892 +        return size;
  25.893 +    }
  25.894 +
  25.895 +    if (!sw->hw->enabled) {
  25.896 +        dolog ("Reading from disabled voice %s\n", SW_NAME (sw));
  25.897 +        return 0;
  25.898 +    }
  25.899 +
  25.900 +    bytes = sw->hw->pcm_ops->read (sw, buf, size);
  25.901 +    return bytes;
  25.902 +}
  25.903 +
  25.904 +int AUD_get_buffer_size_out (SWVoiceOut *sw)
  25.905 +{
  25.906 +    return sw->hw->samples << sw->hw->info.shift;
  25.907 +}
  25.908 +
  25.909 +void AUD_set_active_out (SWVoiceOut *sw, int on)
  25.910 +{
  25.911 +    HWVoiceOut *hw;
  25.912 +
  25.913 +    if (!sw) {
  25.914 +        return;
  25.915 +    }
  25.916 +
  25.917 +    hw = sw->hw;
  25.918 +    if (sw->active != on) {
  25.919 +        SWVoiceOut *temp_sw;
  25.920 +
  25.921 +        if (on) {
  25.922 +            int total;
  25.923 +
  25.924 +            hw->pending_disable = 0;
  25.925 +            if (!hw->enabled) {
  25.926 +                hw->enabled = 1;
  25.927 +                hw->pcm_ops->ctl_out (hw, VOICE_ENABLE);
  25.928 +            }
  25.929 +
  25.930 +            if (sw->empty) {
  25.931 +                total = 0;
  25.932 +            }
  25.933 +        }
  25.934 +        else {
  25.935 +            if (hw->enabled) {
  25.936 +                int nb_active = 0;
  25.937 +
  25.938 +                for (temp_sw = hw->sw_head.lh_first; temp_sw;
  25.939 +                     temp_sw = temp_sw->entries.le_next) {
  25.940 +                    nb_active += temp_sw->active != 0;
  25.941 +                }
  25.942 +
  25.943 +                hw->pending_disable = nb_active == 1;
  25.944 +            }
  25.945 +        }
  25.946 +        sw->active = on;
  25.947 +    }
  25.948 +}
  25.949 +
  25.950 +void AUD_set_active_in (SWVoiceIn *sw, int on)
  25.951 +{
  25.952 +    HWVoiceIn *hw;
  25.953 +
  25.954 +    if (!sw) {
  25.955 +        return;
  25.956 +    }
  25.957 +
  25.958 +    hw = sw->hw;
  25.959 +    if (sw->active != on) {
  25.960 +        SWVoiceIn *temp_sw;
  25.961 +
  25.962 +        if (on) {
  25.963 +            if (!hw->enabled) {
  25.964 +                hw->enabled = 1;
  25.965 +                hw->pcm_ops->ctl_in (hw, VOICE_ENABLE);
  25.966 +            }
  25.967 +            sw->total_hw_samples_acquired = hw->total_samples_captured;
  25.968 +        }
  25.969 +        else {
  25.970 +            if (hw->enabled) {
  25.971 +                int nb_active = 0;
  25.972 +
  25.973 +                for (temp_sw = hw->sw_head.lh_first; temp_sw;
  25.974 +                     temp_sw = temp_sw->entries.le_next) {
  25.975 +                    nb_active += temp_sw->active != 0;
  25.976 +                }
  25.977 +
  25.978 +                if (nb_active == 1) {
  25.979 +                    hw->enabled = 0;
  25.980 +                    hw->pcm_ops->ctl_in (hw, VOICE_DISABLE);
  25.981 +                }
  25.982 +            }
  25.983 +        }
  25.984 +        sw->active = on;
  25.985 +    }
  25.986 +}
  25.987 +
  25.988 +static int audio_get_avail (SWVoiceIn *sw)
  25.989 +{
  25.990 +    int live;
  25.991 +
  25.992 +    if (!sw) {
  25.993 +        return 0;
  25.994 +    }
  25.995 +
  25.996 +    live = sw->hw->total_samples_captured - sw->total_hw_samples_acquired;
  25.997 +    if (audio_bug (AUDIO_FUNC, live < 0 || live > sw->hw->samples)) {
  25.998 +        dolog ("live=%d sw->hw->samples=%d\n", live, sw->hw->samples);
  25.999 +        return 0;
 25.1000 +    }
 25.1001 +
 25.1002 +    ldebug (
 25.1003 +        "%s: get_avail live %d ret %lld\n",
 25.1004 +        SW_NAME (sw),
 25.1005 +        live, (((int64_t) live << 32) / sw->ratio) << sw->info.shift
 25.1006 +        );
 25.1007 +
 25.1008 +    return (((int64_t) live << 32) / sw->ratio) << sw->info.shift;
 25.1009 +}
 25.1010 +
 25.1011 +static int audio_get_free (SWVoiceOut *sw)
 25.1012 +{
 25.1013 +    int live, dead;
 25.1014 +
 25.1015 +    if (!sw) {
 25.1016 +        return 0;
 25.1017 +    }
 25.1018 +
 25.1019 +    live = sw->total_hw_samples_mixed;
 25.1020 +
 25.1021 +    if (audio_bug (AUDIO_FUNC, live < 0 || live > sw->hw->samples)) {
 25.1022 +        dolog ("live=%d sw->hw->samples=%d\n", live, sw->hw->samples);
 25.1023 +        return 0;
 25.1024 +    }
 25.1025 +
 25.1026 +    dead = sw->hw->samples - live;
 25.1027 +
 25.1028 +#ifdef DEBUG_OUT
 25.1029 +    dolog ("%s: get_free live %d dead %d ret %lld\n",
 25.1030 +           SW_NAME (sw),
 25.1031 +           live, dead, (((int64_t) dead << 32) / sw->ratio) << sw->info.shift);
 25.1032 +#endif
 25.1033 +
 25.1034 +    return (((int64_t) dead << 32) / sw->ratio) << sw->info.shift;
 25.1035 +}
 25.1036 +
 25.1037 +static void audio_run_out (AudioState *s)
 25.1038 +{
 25.1039 +    HWVoiceOut *hw = NULL;
 25.1040 +    SWVoiceOut *sw;
 25.1041 +
 25.1042 +    while ((hw = audio_pcm_hw_find_any_enabled_out (s, hw))) {
 25.1043 +        int played;
 25.1044 +        int live, free, nb_live, cleanup_required;
 25.1045 +
 25.1046 +        live = audio_pcm_hw_get_live_out2 (hw, &nb_live);
 25.1047 +        if (!nb_live) {
 25.1048 +            live = 0;
 25.1049 +        }
 25.1050 +
 25.1051 +        if (audio_bug (AUDIO_FUNC, live < 0 || live > hw->samples)) {
 25.1052 +            dolog ("live=%d hw->samples=%d\n", live, hw->samples);
 25.1053 +            continue;
 25.1054 +        }
 25.1055 +
 25.1056 +        if (hw->pending_disable && !nb_live) {
 25.1057 +#ifdef DEBUG_OUT
 25.1058 +            dolog ("Disabling voice\n");
 25.1059 +#endif
 25.1060 +            hw->enabled = 0;
 25.1061 +            hw->pending_disable = 0;
 25.1062 +            hw->pcm_ops->ctl_out (hw, VOICE_DISABLE);
 25.1063 +            continue;
 25.1064 +        }
 25.1065 +
 25.1066 +        if (!live) {
 25.1067 +            for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
 25.1068 +                if (sw->active) {
 25.1069 +                    free = audio_get_free (sw);
 25.1070 +                    if (free > 0) {
 25.1071 +                        sw->callback.fn (sw->callback.opaque, free);
 25.1072 +                    }
 25.1073 +                }
 25.1074 +            }
 25.1075 +            continue;
 25.1076 +        }
 25.1077 +
 25.1078 +        played = hw->pcm_ops->run_out (hw);
 25.1079 +        if (audio_bug (AUDIO_FUNC, hw->rpos >= hw->samples)) {
 25.1080 +            dolog ("hw->rpos=%d hw->samples=%d played=%d\n",
 25.1081 +                   hw->rpos, hw->samples, played);
 25.1082 +            hw->rpos = 0;
 25.1083 +        }
 25.1084 +
 25.1085 +#ifdef DEBUG_OUT
 25.1086 +        dolog ("played=%d\n", played);
 25.1087 +#endif
 25.1088 +
 25.1089 +        if (played) {
 25.1090 +            hw->ts_helper += played;
 25.1091 +        }
 25.1092 +
 25.1093 +        cleanup_required = 0;
 25.1094 +        for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
 25.1095 +            if (!sw->active && sw->empty) {
 25.1096 +                continue;
 25.1097 +            }
 25.1098 +
 25.1099 +            if (audio_bug (AUDIO_FUNC, played > sw->total_hw_samples_mixed)) {
 25.1100 +                dolog ("played=%d sw->total_hw_samples_mixed=%d\n",
 25.1101 +                       played, sw->total_hw_samples_mixed);
 25.1102 +                played = sw->total_hw_samples_mixed;
 25.1103 +            }
 25.1104 +
 25.1105 +            sw->total_hw_samples_mixed -= played;
 25.1106 +
 25.1107 +            if (!sw->total_hw_samples_mixed) {
 25.1108 +                sw->empty = 1;
 25.1109 +                cleanup_required |= !sw->active && !sw->callback.fn;
 25.1110 +            }
 25.1111 +
 25.1112 +            if (sw->active) {
 25.1113 +                free = audio_get_free (sw);
 25.1114 +                if (free > 0) {
 25.1115 +                    sw->callback.fn (sw->callback.opaque, free);
 25.1116 +                }
 25.1117 +            }
 25.1118 +        }
 25.1119 +
 25.1120 +        if (cleanup_required) {
 25.1121 +        restart:
 25.1122 +            for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
 25.1123 +                if (!sw->active && !sw->callback.fn) {
 25.1124 +#ifdef DEBUG_PLIVE
 25.1125 +                    dolog ("Finishing with old voice\n");
 25.1126 +#endif
 25.1127 +                    audio_close_out (s, sw);
 25.1128 +                    goto restart; /* play it safe */
 25.1129 +                }
 25.1130 +            }
 25.1131 +        }
 25.1132 +    }
 25.1133 +}
 25.1134 +
 25.1135 +static void audio_run_in (AudioState *s)
 25.1136 +{
 25.1137 +    HWVoiceIn *hw = NULL;
 25.1138 +
 25.1139 +    while ((hw = audio_pcm_hw_find_any_enabled_in (s, hw))) {
 25.1140 +        SWVoiceIn *sw;
 25.1141 +        int captured, min;
 25.1142 +
 25.1143 +        captured = hw->pcm_ops->run_in (hw);
 25.1144 +
 25.1145 +        min = audio_pcm_hw_find_min_in (hw);
 25.1146 +        hw->total_samples_captured += captured - min;
 25.1147 +        hw->ts_helper += captured;
 25.1148 +
 25.1149 +        for (sw = hw->sw_head.lh_first; sw; sw = sw->entries.le_next) {
 25.1150 +            sw->total_hw_samples_acquired -= min;
 25.1151 +
 25.1152 +            if (sw->active) {
 25.1153 +                int avail;
 25.1154 +
 25.1155 +                avail = audio_get_avail (sw);
 25.1156 +                if (avail > 0) {
 25.1157 +                    sw->callback.fn (sw->callback.opaque, avail);
 25.1158 +                }
 25.1159 +            }
 25.1160 +        }
 25.1161 +    }
 25.1162 +}
 25.1163 +
 25.1164 +static void audio_timer (void *opaque)
 25.1165 +{
 25.1166 +    AudioState *s = opaque;
 25.1167 +
 25.1168 +    audio_run_out (s);
 25.1169 +    audio_run_in (s);
 25.1170 +
 25.1171 +    qemu_mod_timer (s->ts, qemu_get_clock (vm_clock) + conf.period.ticks);
 25.1172 +}
 25.1173 +
 25.1174 +static struct audio_option audio_options[] = {
 25.1175 +    /* DAC */
 25.1176 +    {"DAC_FIXED_SETTINGS", AUD_OPT_BOOL, &conf.fixed_out.enabled,
 25.1177 +     "Use fixed settings for host DAC", NULL, 0},
 25.1178 +
 25.1179 +    {"DAC_FIXED_FREQ", AUD_OPT_INT, &conf.fixed_out.settings.freq,
 25.1180 +     "Frequency for fixed host DAC", NULL, 0},
 25.1181 +
 25.1182 +    {"DAC_FIXED_FMT", AUD_OPT_FMT, &conf.fixed_out.settings.fmt,
 25.1183 +     "Format for fixed host DAC", NULL, 0},
 25.1184 +
 25.1185 +    {"DAC_FIXED_CHANNELS", AUD_OPT_INT, &conf.fixed_out.settings.nchannels,
 25.1186 +     "Number of channels for fixed DAC (1 - mono, 2 - stereo)", NULL, 0},
 25.1187 +
 25.1188 +    {"DAC_VOICES", AUD_OPT_INT, &conf.fixed_out.nb_voices,
 25.1189 +     "Number of voices for DAC", NULL, 0},
 25.1190 +
 25.1191 +    /* ADC */
 25.1192 +    {"ADC_FIXED_SETTINGS", AUD_OPT_BOOL, &conf.fixed_in.enabled,
 25.1193 +     "Use fixed settings for host ADC", NULL, 0},
 25.1194 +
 25.1195 +    {"ADC_FIXED_FREQ", AUD_OPT_INT, &conf.fixed_in.settings.freq,
 25.1196 +     "Frequency for fixed host ADC", NULL, 0},
 25.1197 +
 25.1198 +    {"ADC_FIXED_FMT", AUD_OPT_FMT, &conf.fixed_in.settings.fmt,
 25.1199 +     "Format for fixed host ADC", NULL, 0},
 25.1200 +
 25.1201 +    {"ADC_FIXED_CHANNELS", AUD_OPT_INT, &conf.fixed_in.settings.nchannels,
 25.1202 +     "Number of channels for fixed ADC (1 - mono, 2 - stereo)", NULL, 0},
 25.1203 +
 25.1204 +    {"ADC_VOICES", AUD_OPT_INT, &conf.fixed_in.nb_voices,
 25.1205 +     "Number of voices for ADC", NULL, 0},
 25.1206 +
 25.1207 +    /* Misc */
 25.1208 +    {"TIMER_PERIOD", AUD_OPT_INT, &conf.period.hz,
 25.1209 +     "Timer period in HZ (0 - use lowest possible)", NULL, 0},
 25.1210 +
 25.1211 +    {"PLIVE", AUD_OPT_BOOL, &conf.plive,
 25.1212 +     "(undocumented)", NULL, 0},
 25.1213 +
 25.1214 +    {"LOG_TO_MONITOR", AUD_OPT_BOOL, &conf.log_to_monitor,
 25.1215 +     "print logging messages to montior instead of stderr", NULL, 0},
 25.1216 +
 25.1217 +    {NULL, 0, NULL, NULL, NULL, 0}
 25.1218 +};
 25.1219 +
 25.1220 +static void audio_pp_nb_voices (const char *typ, int nb)
 25.1221 +{
 25.1222 +    switch (nb) {
 25.1223 +    case 0:
 25.1224 +        printf ("Does not support %s\n", typ);
 25.1225 +        break;
 25.1226 +    case 1:
 25.1227 +        printf ("One %s voice\n", typ);
 25.1228 +        break;
 25.1229 +    case INT_MAX:
 25.1230 +        printf ("Theoretically supports many %s voices\n", typ);
 25.1231 +        break;
 25.1232 +    default:
 25.1233 +        printf ("Theoretically supports upto %d %s voices\n", nb, typ);
 25.1234 +        break;
 25.1235 +    }
 25.1236 +
 25.1237 +}
 25.1238 +
 25.1239 +void AUD_help (void)
 25.1240 +{
 25.1241 +    size_t i;
 25.1242 +
 25.1243 +    audio_process_options ("AUDIO", audio_options);
 25.1244 +    for (i = 0; i < sizeof (drvtab) / sizeof (drvtab[0]); i++) {
 25.1245 +        struct audio_driver *d = drvtab[i];
 25.1246 +        if (d->options) {
 25.1247 +            audio_process_options (d->name, d->options);
 25.1248 +        }
 25.1249 +    }
 25.1250 +
 25.1251 +    printf ("Audio options:\n");
 25.1252 +    audio_print_options ("AUDIO", audio_options);
 25.1253 +    printf ("\n");
 25.1254 +
 25.1255 +    printf ("Available drivers:\n");
 25.1256 +
 25.1257 +    for (i = 0; i < sizeof (drvtab) / sizeof (drvtab[0]); i++) {
 25.1258 +        struct audio_driver *d = drvtab[i];
 25.1259 +
 25.1260 +        printf ("Name: %s\n", d->name);
 25.1261 +        printf ("Description: %s\n", d->descr);
 25.1262 +
 25.1263 +        audio_pp_nb_voices ("playback", d->max_voices_out);
 25.1264 +        audio_pp_nb_voices ("capture", d->max_voices_in);
 25.1265 +
 25.1266 +        if (d->options) {
 25.1267 +            printf ("Options:\n");
 25.1268 +            audio_print_options (d->name, d->options);
 25.1269 +        }
 25.1270 +        else {
 25.1271 +            printf ("No options\n");
 25.1272 +        }
 25.1273 +        printf ("\n");
 25.1274 +    }
 25.1275 +
 25.1276 +    printf (
 25.1277 +        "Options are settable through environment variables.\n"
 25.1278 +        "Example:\n"
 25.1279 +#ifdef _WIN32
 25.1280 +        "  set QEMU_AUDIO_DRV=wav\n"
 25.1281 +        "  set QEMU_WAV_PATH=c:\\tune.wav\n"
 25.1282 +#else
 25.1283 +        "  export QEMU_AUDIO_DRV=wav\n"
 25.1284 +        "  export QEMU_WAV_PATH=$HOME/tune.wav\n"
 25.1285 +        "(for csh replace export with setenv in the above)\n"
 25.1286 +#endif
 25.1287 +        "  qemu ...\n\n"
 25.1288 +        );
 25.1289 +}
 25.1290 +
 25.1291 +static int audio_driver_init (AudioState *s, struct audio_driver *drv)
 25.1292 +{
 25.1293 +    if (drv->options) {
 25.1294 +        audio_process_options (drv->name, drv->options);
 25.1295 +    }
 25.1296 +    s->drv_opaque = drv->init ();
 25.1297 +
 25.1298 +    if (s->drv_opaque) {
 25.1299 +        audio_init_nb_voices_out (s, drv);
 25.1300 +        audio_init_nb_voices_in (s, drv);
 25.1301 +        s->drv = drv;
 25.1302 +        return 0;
 25.1303 +    }
 25.1304 +    else {
 25.1305 +        dolog ("Could not init `%s' audio driver\n", drv->name);
 25.1306 +        return -1;
 25.1307 +    }
 25.1308 +}
 25.1309 +
 25.1310 +static void audio_vm_change_state_handler (void *opaque, int running)
 25.1311 +{
 25.1312 +    AudioState *s = opaque;
 25.1313 +    HWVoiceOut *hwo = NULL;
 25.1314 +    HWVoiceIn *hwi = NULL;
 25.1315 +    int op = running ? VOICE_ENABLE : VOICE_DISABLE;
 25.1316 +
 25.1317 +    while ((hwo = audio_pcm_hw_find_any_enabled_out (s, hwo))) {
 25.1318 +        hwo->pcm_ops->ctl_out (hwo, op);
 25.1319 +    }
 25.1320 +
 25.1321 +    while ((hwi = audio_pcm_hw_find_any_enabled_in (s, hwi))) {
 25.1322 +        hwi->pcm_ops->ctl_in (hwi, op);
 25.1323 +    }
 25.1324 +}
 25.1325 +
 25.1326 +static void audio_atexit (void)
 25.1327 +{
 25.1328 +    AudioState *s = &glob_audio_state;
 25.1329 +    HWVoiceOut *hwo = NULL;
 25.1330 +    HWVoiceIn *hwi = NULL;
 25.1331 +
 25.1332 +    while ((hwo = audio_pcm_hw_find_any_enabled_out (s, hwo))) {
 25.1333 +        hwo->pcm_ops->ctl_out (hwo, VOICE_DISABLE);
 25.1334 +        hwo->pcm_ops->fini_out (hwo);
 25.1335 +    }
 25.1336 +
 25.1337 +    while ((hwi = audio_pcm_hw_find_any_enabled_in (s, hwi))) {
 25.1338 +        hwi->pcm_ops->ctl_in (hwi, VOICE_DISABLE);
 25.1339 +        hwi->pcm_ops->fini_in (hwi);
 25.1340 +    }
 25.1341 +
 25.1342 +    if (s->drv) {
 25.1343 +        s->drv->fini (s->drv_opaque);
 25.1344 +    }
 25.1345 +}
 25.1346 +
 25.1347 +static void audio_save (QEMUFile *f, void *opaque)
 25.1348 +{
 25.1349 +    (void) f;
 25.1350 +    (void) opaque;
 25.1351 +}
 25.1352 +
 25.1353 +static int audio_load (QEMUFile *f, void *opaque, int version_id)
 25.1354 +{
 25.1355 +    (void) f;
 25.1356 +    (void) opaque;
 25.1357 +
 25.1358 +    if (version_id != 1) {
 25.1359 +        return -EINVAL;
 25.1360 +    }
 25.1361 +
 25.1362 +    return 0;
 25.1363 +}
 25.1364 +
 25.1365 +void AUD_register_card (AudioState *s, const char *name, QEMUSoundCard *card)
 25.1366 +{
 25.1367 +    card->audio = s;
 25.1368 +    card->name = qemu_strdup (name);
 25.1369 +    memset (&card->entries, 0, sizeof (card->entries));
 25.1370 +    LIST_INSERT_HEAD (&s->card_head, card, entries);
 25.1371 +}
 25.1372 +
 25.1373 +void AUD_remove_card (QEMUSoundCard *card)
 25.1374 +{
 25.1375 +    LIST_REMOVE (card, entries);
 25.1376 +    card->audio = NULL;
 25.1377 +    qemu_free (card->name);
 25.1378 +}
 25.1379 +
 25.1380 +AudioState *AUD_init (void)
 25.1381 +{
 25.1382 +    size_t i;
 25.1383 +    int done = 0;
 25.1384 +    const char *drvname;
 25.1385 +    AudioState *s = &glob_audio_state;
 25.1386 +
 25.1387 +    LIST_INIT (&s->hw_head_out);
 25.1388 +    LIST_INIT (&s->hw_head_in);
 25.1389 +    atexit (audio_atexit);
 25.1390 +
 25.1391 +    s->ts = qemu_new_timer (vm_clock, audio_timer, s);
 25.1392 +    if (!s->ts) {
 25.1393 +        dolog ("Could not create audio timer\n");
 25.1394 +        return NULL;
 25.1395 +    }
 25.1396 +
 25.1397 +    audio_process_options ("AUDIO", audio_options);
 25.1398 +
 25.1399 +    s->nb_hw_voices_out = conf.fixed_out.nb_voices;
 25.1400 +    s->nb_hw_voices_in = conf.fixed_in.nb_voices;
 25.1401 +
 25.1402 +    if (s->nb_hw_voices_out <= 0) {
 25.1403 +        dolog ("Bogus number of playback voices %d, setting to 1\n",
 25.1404 +               s->nb_hw_voices_out);
 25.1405 +        s->nb_hw_voices_out = 1;
 25.1406 +    }
 25.1407 +
 25.1408 +    if (s->nb_hw_voices_in <= 0) {
 25.1409 +        dolog ("Bogus number of capture voices %d, setting to 0\n",
 25.1410 +               s->nb_hw_voices_in);
 25.1411 +        s->nb_hw_voices_in = 0;
 25.1412 +    }
 25.1413 +
 25.1414 +    {
 25.1415 +        int def;
 25.1416 +        drvname = audio_get_conf_str ("QEMU_AUDIO_DRV", NULL, &def);
 25.1417 +    }
 25.1418 +
 25.1419 +    if (drvname) {
 25.1420 +        int found = 0;
 25.1421 +
 25.1422 +        for (i = 0; i < sizeof (drvtab) / sizeof (drvtab[0]); i++) {
 25.1423 +            if (!strcmp (drvname, drvtab[i]->name)) {
 25.1424 +                done = !audio_driver_init (s, drvtab[i]);
 25.1425 +                found = 1;
 25.1426 +                break;
 25.1427 +            }
 25.1428 +        }
 25.1429 +
 25.1430 +        if (!found) {
 25.1431 +            dolog ("Unknown audio driver `%s'\n", drvname);
 25.1432 +            dolog ("Run with -audio-help to list available drivers\n");
 25.1433 +        }
 25.1434 +    }
 25.1435 +
 25.1436 +    if (!done) {
 25.1437 +        for (i = 0; !done && i < sizeof (drvtab) / sizeof (drvtab[0]); i++) {
 25.1438 +            if (drvtab[i]->can_be_default) {
 25.1439 +                done = !audio_driver_init (s, drvtab[i]);
 25.1440 +            }
 25.1441 +        }
 25.1442 +    }
 25.1443 +
 25.1444 +    if (!done) {
 25.1445 +        done = !audio_driver_init (s, &no_audio_driver);
 25.1446 +        if (!done) {
 25.1447 +            dolog ("Could not initialize audio subsystem\n");
 25.1448 +        }
 25.1449 +        else {
 25.1450 +            dolog ("warning: Using timer based audio emulation\n");
 25.1451 +        }
 25.1452 +    }
 25.1453 +
 25.1454 +    if (done) {
 25.1455 +        VMChangeStateEntry *e;
 25.1456 +
 25.1457 +        if (conf.period.hz <= 0) {
 25.1458 +            if (conf.period.hz < 0) {
 25.1459 +                dolog ("warning: Timer period is negative - %d "
 25.1460 +                       "treating as zero\n",
 25.1461 +                       conf.period.hz);
 25.1462 +            }
 25.1463 +            conf.period.ticks = 1;
 25.1464 +        }
 25.1465 +        else {
 25.1466 +            conf.period.ticks = ticks_per_sec / conf.period.hz;
 25.1467 +        }
 25.1468 +
 25.1469 +        e = qemu_add_vm_change_state_handler (audio_vm_change_state_handler, s);
 25.1470 +        if (!e) {
 25.1471 +            dolog ("warning: Could not register change state handler\n"
 25.1472 +                   "(Audio can continue looping even after stopping the VM)\n");
 25.1473 +        }
 25.1474 +    }
 25.1475 +    else {
 25.1476 +        qemu_del_timer (s->ts);
 25.1477 +        return NULL;
 25.1478 +    }
 25.1479 +
 25.1480 +    LIST_INIT (&s->card_head);
 25.1481 +    register_savevm ("audio", 0, 1, audio_save, audio_load, s);
 25.1482 +    qemu_mod_timer (s->ts, qemu_get_clock (vm_clock) + conf.period.ticks);
 25.1483 +    return s;
 25.1484 +}
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/tools/ioemu/audio/audio.h	Wed Jul 12 19:16:10 2006 +0100
    26.3 @@ -0,0 +1,133 @@
    26.4 +/*
    26.5 + * QEMU Audio subsystem header
    26.6 + *
    26.7 + * Copyright (c) 2003-2005 Vassili Karpov (malc)
    26.8 + *
    26.9 + * Permission is hereby granted, free of charge, to any person obtaining a copy
   26.10 + * of this software and associated documentation files (the "Software"), to deal
   26.11 + * in the Software without restriction, including without limitation the rights
   26.12 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   26.13 + * copies of the Software, and to permit persons to whom the Software is
   26.14 + * furnished to do so, subject to the following conditions:
   26.15 + *
   26.16 + * The above copyright notice and this permission notice shall be included in
   26.17 + * all copies or substantial portions of the Software.
   26.18 + *
   26.19 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   26.20 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   26.21 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
   26.22 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   26.23 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   26.24 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   26.25 + * THE SOFTWARE.
   26.26 + */
   26.27 +#ifndef QEMU_AUDIO_H
   26.28 +#define QEMU_AUDIO_H
   26.29 +
   26.30 +#include "sys-queue.h"
   26.31 +
   26.32 +typedef void (*audio_callback_fn_t) (void *opaque, int avail);
   26.33 +
   26.34 +typedef enum {
   26.35 +    AUD_FMT_U8,
   26.36 +    AUD_FMT_S8,
   26.37 +    AUD_FMT_U16,
   26.38 +    AUD_FMT_S16
   26.39 +} audfmt_e;
   26.40 +
   26.41 +typedef struct {
   26.42 +    int freq;
   26.43 +    int nchannels;
   26.44 +    audfmt_e fmt;
   26.45 +} audsettings_t;
   26.46 +
   26.47 +typedef struct AudioState AudioState;
   26.48 +typedef struct SWVoiceOut SWVoiceOut;
   26.49 +typedef struct SWVoiceIn SWVoiceIn;
   26.50 +
   26.51 +typedef struct QEMUSoundCard {
   26.52 +    AudioState *audio;
   26.53 +    char *name;
   26.54 +    LIST_ENTRY (QEMUSoundCard) entries;
   26.55 +} QEMUSoundCard;
   26.56 +
   26.57 +typedef struct QEMUAudioTimeStamp {
   26.58 +    uint64_t old_ts;
   26.59 +} QEMUAudioTimeStamp;
   26.60 +
   26.61 +void AUD_vlog (const char *cap, const char *fmt, va_list ap);
   26.62 +void AUD_log (const char *cap, const char *fmt, ...)
   26.63 +#ifdef __GNUC__
   26.64 +    __attribute__ ((__format__ (__printf__, 2, 3)))
   26.65 +#endif
   26.66 +    ;
   26.67 +
   26.68 +AudioState *AUD_init (void);
   26.69 +void AUD_help (void);
   26.70 +void AUD_register_card (AudioState *s, const char *name, QEMUSoundCard *card);
   26.71 +void AUD_remove_card (QEMUSoundCard *card);
   26.72 +
   26.73 +SWVoiceOut *AUD_open_out (
   26.74 +    QEMUSoundCard *card,
   26.75 +    SWVoiceOut *sw,
   26.76 +    const char *name,
   26.77 +    void *callback_opaque,
   26.78 +    audio_callback_fn_t callback_fn,
   26.79 +    audsettings_t *settings,
   26.80 +    int sw_endian
   26.81 +    );
   26.82 +
   26.83 +void AUD_close_out (QEMUSoundCard *card, SWVoiceOut *sw);
   26.84 +int  AUD_write (SWVoiceOut *sw, void *pcm_buf, int size);
   26.85 +int  AUD_get_buffer_size_out (SWVoiceOut *sw);
   26.86 +void AUD_set_active_out (SWVoiceOut *sw, int on);
   26.87 +int  AUD_is_active_out (SWVoiceOut *sw);
   26.88 +
   26.89 +void     AUD_init_time_stamp_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
   26.90 +uint64_t AUD_get_elapsed_usec_out (SWVoiceOut *sw, QEMUAudioTimeStamp *ts);
   26.91 +
   26.92 +SWVoiceIn *AUD_open_in (
   26.93 +    QEMUSoundCard *card,
   26.94 +    SWVoiceIn *sw,
   26.95 +    const char *name,
   26.96 +    void *callback_opaque,
   26.97 +    audio_callback_fn_t callback_fn,
   26.98 +    audsettings_t *settings,
   26.99 +    int sw_endian
  26.100 +    );
  26.101 +
  26.102 +void AUD_close_in (QEMUSoundCard *card, SWVoiceIn *sw);
  26.103 +int  AUD_read (SWVoiceIn *sw, void *pcm_buf, int size);
  26.104 +void AUD_set_active_in (SWVoiceIn *sw, int on);
  26.105 +int  AUD_is_active_in (SWVoiceIn *sw);
  26.106 +
  26.107 +void     AUD_init_time_stamp_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
  26.108 +uint64_t AUD_get_elapsed_usec_in (SWVoiceIn *sw, QEMUAudioTimeStamp *ts);
  26.109 +
  26.110 +static inline void *advance (void *p, int incr)
  26.111 +{
  26.112 +    uint8_t *d = p;
  26.113 +    return (d + incr);
  26.114 +}
  26.115 +
  26.116 +uint32_t popcount (uint32_t u);
  26.117 +inline uint32_t lsbindex (uint32_t u);
  26.118 +
  26.119 +#ifdef __GNUC__
  26.120 +#define audio_MIN(a, b) ( __extension__ ({      \
  26.121 +    __typeof (a) ta = a;                        \
  26.122 +    __typeof (b) tb = b;                        \
  26.123 +    ((ta)>(tb)?(tb):(ta));                      \
  26.124 +}))
  26.125 +
  26.126 +#define audio_MAX(a, b) ( __extension__ ({      \
  26.127 +    __typeof (a) ta = a;                        \
  26.128 +    __typeof (b) tb = b;                        \
  26.129 +    ((ta)<(tb)?(tb):(ta));                      \
  26.130 +}))
  26.131 +#else
  26.132 +#define audio_MIN(a, b) ((a)>(b)?(b):(a))
  26.133 +#define audio_MAX(a, b) ((a)<(b)?(b):(a))
  26.134 +#endif
  26.135 +
  26.136 +#endif  /* audio.h */
    27.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    27.2 +++ b/tools/ioemu/audio/audio_int.h	Wed Jul 12 19:16:10 2006 +0100
    27.3 @@ -0,0 +1,268 @@
    27.4 +/*
    27.5 + * QEMU Audio subsystem header
    27.6 + *
    27.7 + * Copyright (c) 2003-2005 Vassili Karpov (malc)
    27.8 + *
    27.9 + * Permission is hereby granted, free of charge, to any person obtaining a copy
   27.10 + * of this software and associated documentation files (the "Software"), to deal
   27.11 + * in the Software without restriction, including without limitation the rights
   27.12 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   27.13 + * copies of the Software, and to permit persons to whom the Software is
   27.14 + * furnished to do so, subject to the following conditions:
   27.15 + *
   27.16 + * The above copyright notice and this permission notice shall be included in
   27.17 + * all copies or substantial portions of the Software.
   27.18 + *
   27.19 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   27.20 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   27.21 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
   27.22 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   27.23 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   27.24 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   27.25 + * THE SOFTWARE.
   27.26 + */
   27.27 +#ifndef QEMU_AUDIO_INT_H
   27.28 +#define QEMU_AUDIO_INT_H
   27.29 +
   27.30 +#ifdef CONFIG_COREAUDIO
   27.31 +#define FLOAT_MIXENG
   27.32 +/* #define RECIPROCAL */
   27.33 +#endif
   27.34 +#include "mixeng.h"
   27.35 +
   27.36 +struct audio_pcm_ops;
   27.37 +
   27.38 +typedef enum {
   27.39 +    AUD_OPT_INT,
   27.40 +    AUD_OPT_FMT,
   27.41 +    AUD_OPT_STR,
   27.42 +    AUD_OPT_BOOL
   27.43 +} audio_option_tag_e;
   27.44 +
   27.45 +struct audio_option {
   27.46 +    const char *name;
   27.47 +    audio_option_tag_e tag;
   27.48 +    void *valp;
   27.49 +    const char *descr;
   27.50 +    int *overridenp;
   27.51 +    int overriden;
   27.52 +};
   27.53 +
   27.54 +struct audio_callback {
   27.55 +    void *opaque;
   27.56 +    audio_callback_fn_t fn;
   27.57 +};
   27.58 +
   27.59 +struct audio_pcm_info {
   27.60 +    int bits;
   27.61 +    int sign;
   27.62 +    int freq;
   27.63 +    int nchannels;
   27.64 +    int align;
   27.65 +    int shift;
   27.66 +    int bytes_per_second;
   27.67 +    int swap_endian;
   27.68 +};
   27.69 +
   27.70 +typedef struct HWVoiceOut {
   27.71 +    int enabled;
   27.72 +    int pending_disable;
   27.73 +    int valid;
   27.74 +    struct audio_pcm_info info;
   27.75 +
   27.76 +    f_sample *clip;
   27.77 +
   27.78 +    int rpos;
   27.79 +    uint64_t ts_helper;
   27.80 +
   27.81 +    st_sample_t *mix_buf;
   27.82 +
   27.83 +    int samples;
   27.84 +    LIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head;
   27.85 +    struct audio_pcm_ops *pcm_ops;
   27.86 +    LIST_ENTRY (HWVoiceOut) entries;
   27.87 +} HWVoiceOut;
   27.88 +
   27.89 +typedef struct HWVoiceIn {
   27.90 +    int enabled;
   27.91 +    struct audio_pcm_info info;
   27.92 +
   27.93 +    t_sample *conv;
   27.94 +
   27.95 +    int wpos;
   27.96 +    int total_samples_captured;
   27.97 +    uint64_t ts_helper;
   27.98 +
   27.99 +    st_sample_t *conv_buf;
  27.100 +
  27.101 +    int samples;
  27.102 +    LIST_HEAD (sw_in_listhead, SWVoiceIn) sw_head;
  27.103 +    struct audio_pcm_ops *pcm_ops;
  27.104 +    LIST_ENTRY (HWVoiceIn) entries;
  27.105 +} HWVoiceIn;
  27.106 +
  27.107 +struct SWVoiceOut {
  27.108 +    struct audio_pcm_info info;
  27.109 +    t_sample *conv;
  27.110 +    int64_t ratio;
  27.111 +    st_sample_t *buf;
  27.112 +    void *rate;
  27.113 +    int total_hw_samples_mixed;
  27.114 +    int active;
  27.115 +    int empty;
  27.116 +    HWVoiceOut *hw;
  27.117 +    char *name;
  27.118 +    volume_t vol;
  27.119 +    struct audio_callback callback;
  27.120 +    LIST_ENTRY (SWVoiceOut) entries;
  27.121 +};
  27.122 +
  27.123 +struct SWVoiceIn {
  27.124 +    int active;
  27.125 +    struct audio_pcm_info info;
  27.126 +    int64_t ratio;
  27.127 +    void *rate;
  27.128 +    int total_hw_samples_acquired;
  27.129 +    st_sample_t *buf;
  27.130 +    f_sample *clip;
  27.131 +    HWVoiceIn *hw;
  27.132 +    char *name;
  27.133 +    volume_t vol;
  27.134 +    struct audio_callback callback;
  27.135 +    LIST_ENTRY (SWVoiceIn) entries;
  27.136 +};
  27.137 +
  27.138 +struct audio_driver {
  27.139 +    const char *name;
  27.140 +    const char *descr;
  27.141 +    struct audio_option *options;
  27.142 +    void *(*init) (void);
  27.143 +    void (*fini) (void *);
  27.144 +    struct audio_pcm_ops *pcm_ops;
  27.145 +    int can_be_default;
  27.146 +    int max_voices_out;
  27.147 +    int max_voices_in;
  27.148 +    int voice_size_out;
  27.149 +    int voice_size_in;
  27.150 +};
  27.151 +
  27.152 +struct audio_pcm_ops {
  27.153 +    int  (*init_out)(HWVoiceOut *hw, audsettings_t *as);
  27.154 +    void (*fini_out)(HWVoiceOut *hw);
  27.155 +    int  (*run_out) (HWVoiceOut *hw);
  27.156 +    int  (*write)   (SWVoiceOut *sw, void *buf, int size);
  27.157 +    int  (*ctl_out) (HWVoiceOut *hw, int cmd, ...);
  27.158 +
  27.159 +    int  (*init_in) (HWVoiceIn *hw, audsettings_t *as);
  27.160 +    void (*fini_in) (HWVoiceIn *hw);
  27.161 +    int  (*run_in)  (HWVoiceIn *hw);
  27.162 +    int  (*read)    (SWVoiceIn *sw, void *buf, int size);
  27.163 +    int  (*ctl_in)  (HWVoiceIn *hw, int cmd, ...);
  27.164 +};
  27.165 +
  27.166 +struct AudioState {
  27.167 +    struct audio_driver *drv;
  27.168 +    void *drv_opaque;
  27.169 +
  27.170 +    QEMUTimer *ts;
  27.171 +    LIST_HEAD (card_head, QEMUSoundCard) card_head;
  27.172 +    LIST_HEAD (hw_in_listhead, HWVoiceIn) hw_head_in;
  27.173 +    LIST_HEAD (hw_out_listhead, HWVoiceOut) hw_head_out;
  27.174 +    int nb_hw_voices_out;
  27.175 +    int nb_hw_voices_in;
  27.176 +};
  27.177 +
  27.178 +extern struct audio_driver no_audio_driver;
  27.179 +extern struct audio_driver oss_audio_driver;
  27.180 +extern struct audio_driver sdl_audio_driver;
  27.181 +extern struct audio_driver wav_audio_driver;
  27.182 +extern struct audio_driver fmod_audio_driver;
  27.183 +extern struct audio_driver alsa_audio_driver;
  27.184 +extern struct audio_driver coreaudio_audio_driver;
  27.185 +extern struct audio_driver dsound_audio_driver;
  27.186 +extern volume_t nominal_volume;
  27.187 +
  27.188 +void audio_pcm_init_info (struct audio_pcm_info *info, audsettings_t *as,
  27.189 +                          int swap_endian);
  27.190 +void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len);
  27.191 +
  27.192 +int  audio_pcm_sw_write (SWVoiceOut *sw, void *buf, int len);
  27.193 +int  audio_pcm_hw_get_live_in (HWVoiceIn *hw);
  27.194 +
  27.195 +int  audio_pcm_sw_read (SWVoiceIn *sw, void *buf, int len);
  27.196 +int  audio_pcm_hw_get_live_out (HWVoiceOut *hw);
  27.197 +int  audio_pcm_hw_get_live_out2 (HWVoiceOut *hw, int *nb_live);
  27.198 +
  27.199 +int audio_bug (const char *funcname, int cond);
  27.200 +void *audio_calloc (const char *funcname, int nmemb, size_t size);
  27.201 +
  27.202 +#define VOICE_ENABLE 1
  27.203 +#define VOICE_DISABLE 2
  27.204 +
  27.205 +static inline int audio_ring_dist (int dst, int src, int len)
  27.206 +{
  27.207 +    return (dst >= src) ? (dst - src) : (len - src + dst);
  27.208 +}
  27.209 +
  27.210 +static inline int audio_need_to_swap_endian (int endianness)
  27.211 +{
  27.212 +#ifdef WORDS_BIGENDIAN
  27.213 +    return endianness != 1;
  27.214 +#else
  27.215 +    return endianness != 0;
  27.216 +#endif
  27.217 +}
  27.218 +
  27.219 +#if defined __GNUC__
  27.220 +#define GCC_ATTR __attribute__ ((__unused__, __format__ (__printf__, 1, 2)))
  27.221 +#define INIT_FIELD(f) . f
  27.222 +#define GCC_FMT_ATTR(n, m) __attribute__ ((__format__ (__printf__, n, m)))
  27.223 +#else
  27.224 +#define GCC_ATTR /**/
  27.225 +#define INIT_FIELD(f) /**/
  27.226 +#define GCC_FMT_ATTR(n, m)
  27.227 +#endif
  27.228 +
  27.229 +static void GCC_ATTR dolog (const char *fmt, ...)
  27.230 +{
  27.231 +    va_list ap;
  27.232 +
  27.233 +    va_start (ap, fmt);
  27.234 +    AUD_vlog (AUDIO_CAP, fmt, ap);
  27.235 +    va_end (ap);
  27.236 +}
  27.237 +
  27.238 +#ifdef DEBUG
  27.239 +static void GCC_ATTR ldebug (const char *fmt, ...)
  27.240 +{
  27.241 +    va_list ap;
  27.242 +
  27.243 +    va_start (ap, fmt);
  27.244 +    AUD_vlog (AUDIO_CAP, fmt, ap);
  27.245 +    va_end (ap);
  27.246 +}
  27.247 +#else
  27.248 +#if defined NDEBUG && defined __GNUC__
  27.249 +#define ldebug(...)
  27.250 +#elif defined NDEBUG && defined _MSC_VER
  27.251 +#define ldebug __noop
  27.252 +#else
  27.253 +static void GCC_ATTR ldebug (const char *fmt, ...)
  27.254 +{
  27.255 +    (void) fmt;
  27.256 +}
  27.257 +#endif
  27.258 +#endif
  27.259 +
  27.260 +#undef GCC_ATTR
  27.261 +
  27.262 +#define AUDIO_STRINGIFY_(n) #n
  27.263 +#define AUDIO_STRINGIFY(n) AUDIO_STRINGIFY_(n)
  27.264 +
  27.265 +#if defined _MSC_VER || defined __GNUC__
  27.266 +#define AUDIO_FUNC __FUNCTION__
  27.267 +#else
  27.268 +#define AUDIO_FUNC __FILE__ ":" AUDIO_STRINGIFY (__LINE__)
  27.269 +#endif
  27.270 +
  27.271 +#endif /* audio_int.h */
    28.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.2 +++ b/tools/ioemu/audio/audio_template.h	Wed Jul 12 19:16:10 2006 +0100
    28.3 @@ -0,0 +1,565 @@
    28.4 +/*
    28.5 + * QEMU Audio subsystem header
    28.6 + *
    28.7 + * Copyright (c) 2005 Vassili Karpov (malc)
    28.8 + *
    28.9 + * Permission is hereby granted, free of charge, to any person obtaining a copy
   28.10 + * of this software and associated documentation files (the "Software"), to deal
   28.11 + * in the Software without restriction, including without limitation the rights
   28.12 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   28.13 + * copies of the Software, and to permit persons to whom the Software is
   28.14 + * furnished to do so, subject to the following conditions:
   28.15 + *
   28.16 + * The above copyright notice and this permission notice shall be included in
   28.17 + * all copies or substantial portions of the Software.
   28.18 + *
   28.19 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   28.20 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   28.21 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
   28.22 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   28.23 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   28.24 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   28.25 + * THE SOFTWARE.
   28.26 + */
   28.27 +
   28.28 +#ifdef DAC
   28.29 +#define NAME "playback"
   28.30 +#define HWBUF hw->mix_buf
   28.31 +#define TYPE out
   28.32 +#define HW HWVoiceOut
   28.33 +#define SW SWVoiceOut
   28.34 +#else
   28.35 +#define NAME "capture"
   28.36 +#define TYPE in
   28.37 +#define HW HWVoiceIn
   28.38 +#define SW SWVoiceIn
   28.39 +#define HWBUF hw->conv_buf
   28.40 +#endif
   28.41 +
   28.42 +static void glue (audio_init_nb_voices_, TYPE) (
   28.43 +    AudioState *s,
   28.44 +    struct audio_driver *drv
   28.45 +    )
   28.46 +{
   28.47 +    int max_voices = glue (drv->max_voices_, TYPE);
   28.48 +    int voice_size = glue (drv->voice_size_, TYPE);
   28.49 +
   28.50 +    if (glue (s->nb_hw_voices_, TYPE) > max_voices) {
   28.51 +        if (!max_voices) {
   28.52 +#ifdef DAC
   28.53 +            dolog ("Driver `%s' does not support " NAME "\n", drv->name);
   28.54 +#endif
   28.55 +        }
   28.56 +        else {
   28.57 +            dolog ("Driver `%s' does not support %d " NAME " voices, max %d\n",
   28.58 +                   drv->name,
   28.59 +                   glue (s->nb_hw_voices_, TYPE),
   28.60 +                   max_voices);
   28.61 +        }
   28.62 +        glue (s->nb_hw_voices_, TYPE) = max_voices;
   28.63 +    }
   28.64 +
   28.65 +    if (audio_bug (AUDIO_FUNC, !voice_size && max_voices)) {
   28.66 +        dolog ("drv=`%s' voice_size=0 max_voices=%d\n",
   28.67 +               drv->name, max_voices);
   28.68 +        glue (s->nb_hw_voices_, TYPE) = 0;
   28.69 +    }
   28.70 +
   28.71 +    if (audio_bug (AUDIO_FUNC, voice_size && !max_voices)) {
   28.72 +        dolog ("drv=`%s' voice_size=%d max_voices=0\n",
   28.73 +               drv->name, voice_size);
   28.74 +    }
   28.75 +}
   28.76 +
   28.77 +static void glue (audio_pcm_hw_free_resources_, TYPE) (HW *hw)
   28.78 +{
   28.79 +    if (HWBUF) {
   28.80 +        qemu_free (HWBUF);
   28.81 +    }
   28.82 +
   28.83 +    HWBUF = NULL;
   28.84 +}
   28.85 +
   28.86 +static int glue (audio_pcm_hw_alloc_resources_, TYPE) (HW *hw)
   28.87 +{
   28.88 +    HWBUF = audio_calloc (AUDIO_FUNC, hw->samples, sizeof (st_sample_t));
   28.89 +    if (!HWBUF) {
   28.90 +        dolog ("Could not allocate " NAME " buffer (%d samples)\n",
   28.91 +               hw->samples);
   28.92 +        return -1;
   28.93 +    }
   28.94 +
   28.95 +    return 0;
   28.96 +}
   28.97 +
   28.98 +static void glue (audio_pcm_sw_free_resources_, TYPE) (SW *sw)
   28.99 +{
  28.100 +    if (sw->buf) {
  28.101 +        qemu_free (sw->buf);
  28.102 +    }
  28.103 +
  28.104 +    if (sw->rate) {
  28.105 +        st_rate_stop (sw->rate);
  28.106 +    }
  28.107 +
  28.108 +    sw->buf = NULL;
  28.109 +    sw->rate = NULL;
  28.110 +}
  28.111 +
  28.112 +static int glue (audio_pcm_sw_alloc_resources_, TYPE) (SW *sw)
  28.113 +{
  28.114 +    int samples;
  28.115 +
  28.116 +#ifdef DAC
  28.117 +    samples = sw->hw->samples;
  28.118 +#else
  28.119 +    samples = ((int64_t) sw->hw->samples << 32) / sw->ratio;
  28.120 +#endif
  28.121 +
  28.122 +    sw->buf = audio_calloc (AUDIO_FUNC, samples, sizeof (st_sample_t));
  28.123 +    if (!sw->buf) {
  28.124 +        dolog ("Could not allocate buffer for `%s' (%d samples)\n",
  28.125 +               SW_NAME (sw), samples);
  28.126 +        return -1;
  28.127 +    }
  28.128 +
  28.129 +#ifdef DAC
  28.130 +    sw->rate = st_rate_start (sw->info.freq, sw->hw->info.freq);
  28.131 +#else
  28.132 +    sw->rate = st_rate_start (sw->hw->info.freq, sw->info.freq);
  28.133 +#endif
  28.134 +    if (!sw->rate) {
  28.135 +        qemu_free (sw->buf);
  28.136 +        sw->buf = NULL;
  28.137 +        return -1;
  28.138 +    }
  28.139 +    return 0;
  28.140 +}
  28.141 +
  28.142 +static int glue (audio_pcm_sw_init_, TYPE) (
  28.143 +    SW *sw,
  28.144 +    HW *hw,
  28.145 +    const char *name,
  28.146 +    audsettings_t *as,
  28.147 +    int endian
  28.148 +    )
  28.149 +{
  28.150 +    int err;
  28.151 +
  28.152 +    audio_pcm_init_info (&sw->info, as, audio_need_to_swap_endian (endian));
  28.153 +    sw->hw = hw;
  28.154 +    sw->active = 0;
  28.155 +#ifdef DAC
  28.156 +    sw->ratio = ((int64_t) sw->hw->info.freq << 32) / sw->info.freq;
  28.157 +    sw->total_hw_samples_mixed = 0;
  28.158 +    sw->empty = 1;
  28.159 +#else
  28.160 +    sw->ratio = ((int64_t) sw->info.freq << 32) / sw->hw->info.freq;
  28.161 +#endif
  28.162 +
  28.163 +#ifdef DAC
  28.164 +    sw->conv = mixeng_conv
  28.165 +#else
  28.166 +    sw->clip = mixeng_clip
  28.167 +#endif
  28.168 +        [sw->info.nchannels == 2]
  28.169 +        [sw->info.sign]
  28.170 +        [sw->info.swap_endian]
  28.171 +        [sw->info.bits == 16];
  28.172 +
  28.173 +    sw->name = qemu_strdup (name);
  28.174 +    err = glue (audio_pcm_sw_alloc_resources_, TYPE) (sw);
  28.175 +    if (err) {
  28.176 +        qemu_free (sw->name);
  28.177 +        sw->name = NULL;
  28.178 +    }
  28.179 +    return err;
  28.180 +}
  28.181 +
  28.182 +static void glue (audio_pcm_sw_fini_, TYPE) (SW *sw)
  28.183 +{
  28.184 +    glue (audio_pcm_sw_free_resources_, TYPE) (sw);
  28.185 +    if (sw->name) {
  28.186 +        qemu_free (sw->name);
  28.187 +        sw->name = NULL;
  28.188 +    }
  28.189 +}
  28.190 +
  28.191 +static void glue (audio_pcm_hw_add_sw_, TYPE) (HW *hw, SW *sw)
  28.192 +{
  28.193 +    LIST_INSERT_HEAD (&hw->sw_head, sw, entries);
  28.194 +}
  28.195 +
  28.196 +static void glue (audio_pcm_hw_del_sw_, TYPE) (SW *sw)
  28.197 +{
  28.198 +    LIST_REMOVE (sw, entries);
  28.199 +}
  28.200 +
  28.201 +static void glue (audio_pcm_hw_gc_, TYPE) (AudioState *s, HW **hwp)
  28.202 +{
  28.203 +    HW *hw = *hwp;
  28.204 +
  28.205 +    if (!hw->sw_head.lh_first) {
  28.206 +        LIST_REMOVE (hw, entries);
  28.207 +        glue (s->nb_hw_voices_, TYPE) += 1;
  28.208 +        glue (audio_pcm_hw_free_resources_ ,TYPE) (hw);
  28.209 +        glue (hw->pcm_ops->fini_, TYPE) (hw);
  28.210 +        qemu_free (hw);
  28.211 +        *hwp = NULL;
  28.212 +    }
  28.213 +}
  28.214 +
  28.215 +static HW *glue (audio_pcm_hw_find_any_, TYPE) (AudioState *s, HW *hw)
  28.216 +{
  28.217 +    return hw ? hw->entries.le_next : s->glue (hw_head_, TYPE).lh_first;
  28.218 +}
  28.219 +
  28.220 +static HW *glue (audio_pcm_hw_find_any_enabled_, TYPE) (AudioState *s, HW *hw)
  28.221 +{
  28.222 +    while ((hw = glue (audio_pcm_hw_find_any_, TYPE) (s, hw))) {
  28.223 +        if (hw->enabled) {
  28.224 +            return hw;
  28.225 +        }
  28.226 +    }
  28.227 +    return NULL;
  28.228 +}
  28.229 +
  28.230 +static HW *glue (audio_pcm_hw_find_specific_, TYPE) (
  28.231 +    AudioState *s,
  28.232 +    HW *hw,
  28.233 +    audsettings_t *as
  28.234 +    )
  28.235 +{
  28.236 +    while ((hw = glue (audio_pcm_hw_find_any_, TYPE) (s, hw))) {
  28.237 +        if (audio_pcm_info_eq (&hw->info, as)) {
  28.238 +            return hw;
  28.239 +        }
  28.240 +    }
  28.241 +    return NULL;
  28.242 +}
  28.243 +
  28.244 +static HW *glue (audio_pcm_hw_add_new_, TYPE) (AudioState *s, audsettings_t *as)
  28.245 +{
  28.246 +    HW *hw;
  28.247 +    struct audio_driver *drv = s->drv;
  28.248 +
  28.249 +    if (!glue (s->nb_hw_voices_, TYPE)) {
  28.250 +        return NULL;
  28.251 +    }
  28.252 +
  28.253 +    if (audio_bug (AUDIO_FUNC, !drv)) {
  28.254 +        dolog ("No host audio driver\n");
  28.255 +        return NULL;
  28.256 +    }
  28.257 +
  28.258 +    if (audio_bug (AUDIO_FUNC, !drv->pcm_ops)) {
  28.259 +        dolog ("Host audio driver without pcm_ops\n");
  28.260 +        return NULL;
  28.261 +    }
  28.262 +
  28.263 +    hw = audio_calloc (AUDIO_FUNC, 1, glue (drv->voice_size_, TYPE));
  28.264 +    if (!hw) {
  28.265 +        dolog ("Can not allocate voice `%s' size %d\n",
  28.266 +               drv->name, glue (drv->voice_size_, TYPE));
  28.267 +        return NULL;
  28.268 +    }
  28.269 +
  28.270 +    hw->pcm_ops = drv->pcm_ops;
  28.271 +    LIST_INIT (&hw->sw_head);
  28.272 +
  28.273 +    if (glue (hw->pcm_ops->init_, TYPE) (hw, as)) {
  28.274 +        goto err0;
  28.275 +    }
  28.276 +
  28.277 +    if (audio_bug (AUDIO_FUNC, hw->samples <= 0)) {
  28.278 +        dolog ("hw->samples=%d\n", hw->samples);
  28.279 +        goto err1;
  28.280 +    }
  28.281 +
  28.282 +#ifdef DAC
  28.283 +    hw->clip = mixeng_clip
  28.284 +#else
  28.285 +    hw->conv = mixeng_conv
  28.286 +#endif
  28.287 +        [hw->info.nchannels == 2]
  28.288 +        [hw->info.sign]
  28.289 +        [hw->info.swap_endian]
  28.290 +        [hw->info.bits == 16];
  28.291 +
  28.292 +    if (glue (audio_pcm_hw_alloc_resources_, TYPE) (hw)) {
  28.293 +        goto err1;
  28.294 +    }
  28.295 +
  28.296 +    LIST_INSERT_HEAD (&s->glue (hw_head_, TYPE), hw, entries);
  28.297 +    glue (s->nb_hw_voices_, TYPE) -= 1;
  28.298 +    return hw;
  28.299 +
  28.300 + err1:
  28.301 +    glue (hw->pcm_ops->fini_, TYPE) (hw);
  28.302 + err0:
  28.303 +    qemu_free (hw);
  28.304 +    return NULL;
  28.305 +}
  28.306 +
  28.307 +static HW *glue (audio_pcm_hw_add_, TYPE) (AudioState *s, audsettings_t *as)
  28.308 +{
  28.309 +    HW *hw;
  28.310 +
  28.311 +    if (glue (conf.fixed_, TYPE).enabled && glue (conf.fixed_, TYPE).greedy) {
  28.312 +        hw = glue (audio_pcm_hw_add_new_, TYPE) (s, as);
  28.313 +        if (hw) {
  28.314 +            return hw;
  28.315 +        }
  28.316 +    }
  28.317 +
  28.318 +    hw = glue (audio_pcm_hw_find_specific_, TYPE) (s, NULL, as);
  28.319 +    if (hw) {
  28.320 +        return hw;
  28.321 +    }
  28.322 +
  28.323 +    hw = glue (audio_pcm_hw_add_new_, TYPE) (s, as);
  28.324 +    if (hw) {
  28.325 +        return hw;
  28.326 +    }
  28.327 +
  28.328 +    return glue (audio_pcm_hw_find_any_, TYPE) (s, NULL);
  28.329 +}
  28.330 +
  28.331 +static SW *glue (audio_pcm_create_voice_pair_, TYPE) (
  28.332 +    AudioState *s,
  28.333 +    const char *sw_name,
  28.334 +    audsettings_t *as,
  28.335 +    int sw_endian
  28.336 +    )
  28.337 +{
  28.338 +    SW *sw;
  28.339 +    HW *hw;
  28.340 +    audsettings_t hw_as;
  28.341 +
  28.342 +    if (glue (conf.fixed_, TYPE).enabled) {
  28.343 +        hw_as = glue (conf.fixed_, TYPE).settings;
  28.344 +    }
  28.345 +    else {
  28.346 +        hw_as = *as;
  28.347 +    }
  28.348 +
  28.349 +    sw = audio_calloc (AUDIO_FUNC, 1, sizeof (*sw));
  28.350 +    if (!sw) {
  28.351 +        dolog ("Could not allocate soft voice `%s' (%zu bytes)\n",
  28.352 +               sw_name ? sw_name : "unknown", sizeof (*sw));
  28.353 +        goto err1;
  28.354 +    }
  28.355 +
  28.356 +    hw = glue (audio_pcm_hw_add_, TYPE) (s, &hw_as);
  28.357 +    if (!hw) {
  28.358 +        goto err2;
  28.359 +    }
  28.360 +
  28.361 +    glue (audio_pcm_hw_add_sw_, TYPE) (hw, sw);
  28.362 +
  28.363 +    if (glue (audio_pcm_sw_init_, TYPE) (sw, hw, sw_name, as, sw_endian)) {
  28.364 +        goto err3;
  28.365 +    }
  28.366 +
  28.367 +    return sw;
  28.368 +
  28.369 +err3:
  28.370 +    glue (audio_pcm_hw_del_sw_, TYPE) (sw);
  28.371 +    glue (audio_pcm_hw_gc_, TYPE) (s, &hw);
  28.372 +err2:
  28.373 +    qemu_free (sw);
  28.374 +err1:
  28.375 +    return NULL;
  28.376 +}
  28.377 +
  28.378 +static void glue (audio_close_, TYPE) (AudioState *s, SW *sw)
  28.379 +{
  28.380 +    glue (audio_pcm_sw_fini_, TYPE) (sw);
  28.381 +    glue (audio_pcm_hw_del_sw_, TYPE) (sw);
  28.382 +    glue (audio_pcm_hw_gc_, TYPE) (s, &sw->hw);
  28.383 +    qemu_free (sw);
  28.384 +}
  28.385 +
  28.386 +void glue (AUD_close_, TYPE) (QEMUSoundCard *card, SW *sw)
  28.387 +{
  28.388 +    if (sw) {
  28.389 +        if (audio_bug (AUDIO_FUNC, !card || !card->audio)) {
  28.390 +            dolog ("card=%p card->audio=%p\n",
  28.391 +                   card, card ? card->audio : NULL);
  28.392 +            return;
  28.393 +        }
  28.394 +
  28.395 +        glue (audio_close_, TYPE) (card->audio, sw);
  28.396 +    }
  28.397 +}
  28.398 +
  28.399 +SW *glue (AUD_open_, TYPE) (
  28.400 +    QEMUSoundCard *card,
  28.401 +    SW *sw,
  28.402 +    const char *name,
  28.403 +    void *callback_opaque ,
  28.404 +    audio_callback_fn_t callback_fn,
  28.405 +    audsettings_t *as,
  28.406 +    int sw_endian
  28.407 +    )
  28.408 +{
  28.409 +    AudioState *s;
  28.410 +#ifdef DAC
  28.411 +    int live = 0;
  28.412 +    SW *old_sw = NULL;
  28.413 +#endif
  28.414 +
  28.415 +    ldebug ("open %s, freq %d, nchannels %d, fmt %d\n",
  28.416 +            name, as->freq, as->nchannels, as->fmt);
  28.417 +
  28.418 +    if (audio_bug (AUDIO_FUNC,
  28.419 +                   !card || !card->audio || !name || !callback_fn || !as)) {
  28.420 +        dolog ("card=%p card->audio=%p name=%p callback_fn=%p as=%p\n",
  28.421 +               card, card ? card->audio : NULL, name, callback_fn, as);
  28.422 +        goto fail;
  28.423 +    }
  28.424 +
  28.425 +    s = card->audio;
  28.426 +
  28.427 +    if (audio_bug (AUDIO_FUNC, audio_validate_settigs (as))) {
  28.428 +        audio_print_settings (as);
  28.429 +        goto fail;
  28.430 +    }
  28.431 +
  28.432 +    if (audio_bug (AUDIO_FUNC, !s->drv)) {
  28.433 +        dolog ("Can not open `%s' (no host audio driver)\n", name);
  28.434 +        goto fail;
  28.435 +    }
  28.436 +
  28.437 +    if (sw && audio_pcm_info_eq (&sw->info, as)) {
  28.438 +        return sw;
  28.439 +    }
  28.440 +
  28.441 +#ifdef DAC
  28.442 +    if (conf.plive && sw && (!sw->active && !sw->empty)) {
  28.443 +        live = sw->total_hw_samples_mixed;
  28.444 +
  28.445 +#ifdef DEBUG_PLIVE
  28.446 +        dolog ("Replacing voice %s with %d live samples\n", SW_NAME (sw), live);
  28.447 +        dolog ("Old %s freq %d, bits %d, channels %d\n",
  28.448 +               SW_NAME (sw), sw->info.freq, sw->info.bits, sw->info.nchannels);
  28.449 +        dolog ("New %s freq %d, bits %d, channels %d\n",
  28.450 +               name,
  28.451 +               freq,
  28.452 +               (fmt == AUD_FMT_S16 || fmt == AUD_FMT_U16) ? 16 : 8,
  28.453 +               nchannels);
  28.454 +#endif
  28.455 +
  28.456 +        if (live) {
  28.457 +            old_sw = sw;
  28.458 +            old_sw->callback.fn = NULL;
  28.459 +            sw = NULL;
  28.460 +        }
  28.461 +    }
  28.462 +#endif
  28.463 +
  28.464 +    if (!glue (conf.fixed_, TYPE).enabled && sw) {
  28.465 +        glue (AUD_close_, TYPE) (card, sw);
  28.466 +        sw = NULL;
  28.467 +    }
  28.468 +
  28.469 +    if (sw) {
  28.470 +        HW *hw = sw->hw;
  28.471 +
  28.472 +        if (!hw) {
  28.473 +            dolog ("Internal logic error voice `%s' has no hardware store\n",
  28.474 +                   SW_NAME (sw));
  28.475 +            goto fail;
  28.476 +        }
  28.477 +
  28.478 +        glue (audio_pcm_sw_fini_, TYPE) (sw);
  28.479 +        if (glue (audio_pcm_sw_init_, TYPE) (sw, hw, name, as, sw_endian)) {
  28.480 +            goto fail;
  28.481 +        }
  28.482 +    }
  28.483 +    else {
  28.484 +        sw = glue (audio_pcm_create_voice_pair_, TYPE) (s, name, as, sw_endian);
  28.485 +        if (!sw) {
  28.486 +            dolog ("Failed to create voice `%s'\n", name);
  28.487 +            return NULL;
  28.488 +        }
  28.489 +    }
  28.490 +
  28.491 +    if (sw) {
  28.492 +        sw->vol = nominal_volume;
  28.493 +        sw->callback.fn = callback_fn;
  28.494 +        sw->callback.opaque = callback_opaque;
  28.495 +
  28.496 +#ifdef DAC
  28.497 +        if (live) {
  28.498 +            int mixed =
  28.499 +                (live << old_sw->info.shift)
  28.500 +                * old_sw->info.bytes_per_second
  28.501 +                / sw->info.bytes_per_second;
  28.502 +
  28.503 +#ifdef DEBUG_PLIVE
  28.504 +            dolog ("Silence will be mixed %d\n", mixed);
  28.505 +#endif
  28.506 +            sw->total_hw_samples_mixed += mixed;
  28.507 +        }
  28.508 +#endif
  28.509 +
  28.510 +#ifdef DEBUG_AUDIO
  28.511 +        dolog ("%s\n", name);
  28.512 +        audio_pcm_print_info ("hw", &sw->hw->info);
  28.513 +        audio_pcm_print_info ("sw", &sw->info);
  28.514 +#endif
  28.515 +    }
  28.516 +
  28.517 +    return sw;
  28.518 +
  28.519 + fail:
  28.520 +    glue (AUD_close_, TYPE) (card, sw);
  28.521 +    return NULL;
  28.522 +}
  28.523 +
  28.524 +int glue (AUD_is_active_, TYPE) (SW *sw)
  28.525 +{
  28.526 +    return sw ? sw->active : 0;
  28.527 +}
  28.528 +
  28.529 +void glue (AUD_init_time_stamp_, TYPE) (SW *sw, QEMUAudioTimeStamp *ts)
  28.530 +{
  28.531 +    if (!sw) {
  28.532 +        return;
  28.533 +    }
  28.534 +
  28.535 +    ts->old_ts = sw->hw->ts_helper;
  28.536 +}
  28.537 +
  28.538 +uint64_t glue (AUD_get_elapsed_usec_, TYPE) (SW *sw, QEMUAudioTimeStamp *ts)
  28.539 +{
  28.540 +    uint64_t delta, cur_ts, old_ts;
  28.541 +
  28.542 +    if (!sw) {
  28.543 +        return 0;
  28.544 +    }
  28.545 +
  28.546 +    cur_ts = sw->hw->ts_helper;
  28.547 +    old_ts = ts->old_ts;
  28.548 +    /* dolog ("cur %lld old %lld\n", cur_ts, old_ts); */
  28.549 +
  28.550 +    if (cur_ts >= old_ts) {
  28.551 +        delta = cur_ts - old_ts;
  28.552 +    }
  28.553 +    else {
  28.554 +        delta = UINT64_MAX - old_ts + cur_ts;
  28.555 +    }
  28.556 +
  28.557 +    if (!delta) {
  28.558 +        return 0;
  28.559 +    }
  28.560 +
  28.561 +    return (delta * sw->hw->info.freq) / 1000000;
  28.562 +}
  28.563 +
  28.564 +#undef TYPE
  28.565 +#undef HW
  28.566 +#undef SW
  28.567 +#undef HWBUF
  28.568 +#undef NAME
    29.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.2 +++ b/tools/ioemu/audio/coreaudio.c	Wed Jul 12 19:16:10 2006 +0100
    29.3 @@ -0,0 +1,564 @@
    29.4 +/*
    29.5 + * QEMU OS X CoreAudio audio driver
    29.6 + *
    29.7 + * Copyright (c) 2005 Mike Kronenberg
    29.8 + *
    29.9 + * Permission is hereby granted, free of charge, to any person obtaining a copy
   29.10 + * of this software and associated documentation files (the "Software"), to deal
   29.11 + * in the Software without restriction, including without limitation the rights
   29.12 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   29.13 + * copies of the Software, and to permit persons to whom the Software is
   29.14 + * furnished to do so, subject to the following conditions:
   29.15 + *
   29.16 + * The above copyright notice and this permission notice shall be included in
   29.17 + * all copies or substantial portions of the Software.
   29.18 + *
   29.19 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   29.20 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   29.21 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
   29.22 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   29.23 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   29.24 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   29.25 + * THE SOFTWARE.
   29.26 + */
   29.27 +
   29.28 +#include <CoreAudio/CoreAudio.h>
   29.29 +#include <string.h>             /* strerror */
   29.30 +#include <pthread.h>            /* pthread_X */
   29.31 +
   29.32 +#include "vl.h"
   29.33 +
   29.34 +#define AUDIO_CAP "coreaudio"
   29.35 +#include "audio_int.h"
   29.36 +
   29.37 +struct {
   29.38 +    int buffer_frames;
   29.39 +    int nbuffers;
   29.40 +    int isAtexit;
   29.41 +} conf = {
   29.42 +    .buffer_frames = 512,
   29.43 +    .nbuffers = 4,
   29.44 +    .isAtexit = 0
   29.45 +};
   29.46 +
   29.47 +typedef struct coreaudioVoiceOut {
   29.48 +    HWVoiceOut hw;
   29.49 +    pthread_mutex_t mutex;
   29.50 +    int isAtexit;
   29.51 +    AudioDeviceID outputDeviceID;
   29.52 +    UInt32 audioDevicePropertyBufferFrameSize;
   29.53 +    AudioStreamBasicDescription outputStreamBasicDescription;
   29.54 +    int live;
   29.55 +    int decr;
   29.56 +    int rpos;
   29.57 +} coreaudioVoiceOut;
   29.58 +
   29.59 +static void coreaudio_logstatus (OSStatus status)
   29.60 +{
   29.61 +    char *str = "BUG";
   29.62 +
   29.63 +    switch(status) {
   29.64 +    case kAudioHardwareNoError:
   29.65 +        str = "kAudioHardwareNoError";
   29.66 +        break;
   29.67 +
   29.68 +    case kAudioHardwareNotRunningError:
   29.69 +        str = "kAudioHardwareNotRunningError";
   29.70 +        break;
   29.71 +
   29.72 +    case kAudioHardwareUnspecifiedError:
   29.73 +        str = "kAudioHardwareUnspecifiedError";
   29.74 +        break;
   29.75 +
   29.76 +    case kAudioHardwareUnknownPropertyError:
   29.77 +        str = "kAudioHardwareUnknownPropertyError";
   29.78 +        break;
   29.79 +
   29.80 +    case kAudioHardwareBadPropertySizeError:
   29.81 +        str = "kAudioHardwareBadPropertySizeError";
   29.82 +        break;
   29.83 +
   29.84 +    case kAudioHardwareIllegalOperationError:
   29.85 +        str = "kAudioHardwareIllegalOperationError";
   29.86 +        break;
   29.87 +
   29.88 +    case kAudioHardwareBadDeviceError:
   29.89 +        str = "kAudioHardwareBadDeviceError";
   29.90 +        break;
   29.91 +
   29.92 +    case kAudioHardwareBadStreamError:
   29.93 +        str = "kAudioHardwareBadStreamError";
   29.94 +        break;
   29.95 +
   29.96 +    case kAudioHardwareUnsupportedOperationError:
   29.97 +        str = "kAudioHardwareUnsupportedOperationError";
   29.98 +        break;
   29.99 +
  29.100 +    case kAudioDeviceUnsupportedFormatError:
  29.101 +        str = "kAudioDeviceUnsupportedFormatError";
  29.102 +        break;
  29.103 +
  29.104 +    case kAudioDevicePermissionsError:
  29.105 +        str = "kAudioDevicePermissionsError";
  29.106 +        break;
  29.107 +
  29.108 +    default:
  29.109 +        AUD_log (AUDIO_CAP, "Reason: status code %ld\n", status);
  29.110 +        return;
  29.111 +    }
  29.112 +
  29.113 +    AUD_log (AUDIO_CAP, "Reason: %s\n", str);
  29.114 +}
  29.115 +
  29.116 +static void GCC_FMT_ATTR (2, 3) coreaudio_logerr (
  29.117 +    OSStatus status,
  29.118 +    const char *fmt,
  29.119 +    ...
  29.120 +    )
  29.121 +{
  29.122 +    va_list ap;
  29.123 +
  29.124 +    va_start (ap, fmt);
  29.125 +    AUD_log (AUDIO_CAP, fmt, ap);
  29.126 +    va_end (ap);
  29.127 +
  29.128 +    coreaudio_logstatus (status);
  29.129 +}
  29.130 +
  29.131 +static void GCC_FMT_ATTR (3, 4) coreaudio_logerr2 (
  29.132 +    OSStatus status,
  29.133 +    const char *typ,
  29.134 +    const char *fmt,
  29.135 +    ...
  29.136 +    )
  29.137 +{
  29.138 +    va_list ap;
  29.139 +
  29.140 +    AUD_log (AUDIO_CAP, "Could not initialize %s\n", typ);
  29.141 +
  29.142 +    va_start (ap, fmt);
  29.143 +    AUD_vlog (AUDIO_CAP, fmt, ap);
  29.144 +    va_end (ap);
  29.145 +
  29.146 +    coreaudio_logstatus (status);
  29.147 +}
  29.148 +
  29.149 +static inline UInt32 isPlaying (AudioDeviceID outputDeviceID)
  29.150 +{
  29.151 +    OSStatus status;
  29.152 +    UInt32 result = 0;
  29.153 +    UInt32 propertySize = sizeof(outputDeviceID);
  29.154 +    status = AudioDeviceGetProperty(
  29.155 +        outputDeviceID, 0, 0,
  29.156 +        kAudioDevicePropertyDeviceIsRunning, &propertySize, &result);
  29.157 +    if (status != kAudioHardwareNoError) {
  29.158 +        coreaudio_logerr(status,
  29.159 +                         "Could not determine whether Device is playing\n");
  29.160 +    }
  29.161 +    return result;
  29.162 +}
  29.163 +
  29.164 +static void coreaudio_atexit (void)
  29.165 +{
  29.166 +    conf.isAtexit = 1;
  29.167 +}
  29.168 +
  29.169 +static int coreaudio_lock (coreaudioVoiceOut *core, const char *fn_name)
  29.170 +{
  29.171 +    int err;
  29.172 +
  29.173 +    err = pthread_mutex_lock (&core->mutex);
  29.174 +    if (err) {
  29.175 +        dolog ("Could not lock voice for %s\nReason: %s\n",
  29.176 +               fn_name, strerror (err));
  29.177 +        return -1;
  29.178 +    }
  29.179 +    return 0;
  29.180 +}
  29.181 +
  29.182 +static int coreaudio_unlock (coreaudioVoiceOut *core, const char *fn_name)
  29.183 +{
  29.184 +    int err;
  29.185 +
  29.186 +    err = pthread_mutex_unlock (&core->mutex);
  29.187 +    if (err) {
  29.188 +        dolog ("Could not unlock voice for %s\nReason: %s\n",
  29.189 +               fn_name, strerror (err));
  29.190 +        return -1;
  29.191 +    }
  29.192 +    return 0;
  29.193 +}
  29.194 +
  29.195 +static int coreaudio_run_out (HWVoiceOut *hw)
  29.196 +{
  29.197 +    int live, decr;
  29.198 +    coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw;
  29.199 +
  29.200 +    if (coreaudio_lock (core, "coreaudio_run_out")) {
  29.201 +        return 0;
  29.202 +    }
  29.203 +
  29.204 +    live = audio_pcm_hw_get_live_out (hw);
  29.205 +
  29.206 +    if (core->decr > live) {
  29.207 +        ldebug ("core->decr %d live %d core->live %d\n",
  29.208 +                core->decr,
  29.209 +                live,
  29.210 +                core->live);
  29.211 +    }
  29.212 +
  29.213 +    decr = audio_MIN (core->decr, live);
  29.214 +    core->decr -= decr;
  29.215 +
  29.216 +    core->live = live - decr;
  29.217 +    hw->rpos = core->rpos;
  29.218 +
  29.219 +    coreaudio_unlock (core, "coreaudio_run_out");
  29.220 +    return decr;
  29.221 +}
  29.222 +
  29.223 +/* callback to feed audiooutput buffer */
  29.224 +static OSStatus audioDeviceIOProc(
  29.225 +    AudioDeviceID inDevice,
  29.226 +    const AudioTimeStamp* inNow,
  29.227 +    const AudioBufferList* inInputData,
  29.228 +    const AudioTimeStamp* inInputTime,
  29.229 +    AudioBufferList* outOutputData,
  29.230 +    const AudioTimeStamp* inOutputTime,
  29.231 +    void* hwptr)
  29.232 +{
  29.233 +    UInt32 frame, frameCount;
  29.234 +    float *out = outOutputData->mBuffers[0].mData;
  29.235 +    HWVoiceOut *hw = hwptr;
  29.236 +    coreaudioVoiceOut *core = (coreaudioVoiceOut *) hwptr;
  29.237 +    int rpos, live;
  29.238 +    st_sample_t *src;
  29.239 +#ifndef FLOAT_MIXENG
  29.240 +#ifdef RECIPROCAL
  29.241 +    const float scale = 1.f / UINT_MAX;
  29.242 +#else
  29.243 +    const float scale = UINT_MAX;
  29.244 +#endif
  29.245 +#endif
  29.246 +
  29.247 +    if (coreaudio_lock (core, "audioDeviceIOProc")) {
  29.248 +        inInputTime = 0;
  29.249 +        return 0;
  29.250 +    }
  29.251 +
  29.252 +    frameCount = core->audioDevicePropertyBufferFrameSize;
  29.253 +    live = core->live;
  29.254 +
  29.255 +    /* if there are not enough samples, set signal and return */
  29.256 +    if (live < frameCount) {
  29.257 +        inInputTime = 0;
  29.258 +        coreaudio_unlock (core, "audioDeviceIOProc(empty)");
  29.259 +        return 0;
  29.260 +    }
  29.261 +
  29.262 +    rpos = core->rpos;
  29.263 +    src = hw->mix_buf + rpos;
  29.264 +
  29.265 +    /* fill buffer */
  29.266 +    for (frame = 0; frame < frameCount; frame++) {
  29.267 +#ifdef FLOAT_MIXENG
  29.268 +        *out++ = src[frame].l; /* left channel */
  29.269 +        *out++ = src[frame].r; /* right channel */
  29.270 +#else
  29.271 +#ifdef RECIPROCAL
  29.272 +        *out++ = src[frame].l * scale; /* left channel */
  29.273 +        *out++ = src[frame].r * scale; /* right channel */
  29.274 +#else
  29.275 +        *out++ = src[frame].l / scale; /* left channel */
  29.276 +        *out++ = src[frame].r / scale; /* right channel */
  29.277 +#endif
  29.278 +#endif
  29.279 +    }
  29.280 +
  29.281 +    /* cleanup */
  29.282 +    mixeng_clear (src, frameCount);
  29.283 +    rpos = (rpos + frameCount) % hw->samples;
  29.284 +    core->decr += frameCount;
  29.285 +    core->rpos = rpos;
  29.286 +
  29.287 +    coreaudio_unlock (core, "audioDeviceIOProc");
  29.288 +    return 0;
  29.289 +}
  29.290 +
  29.291 +static int coreaudio_write (SWVoiceOut *sw, void *buf, int len)
  29.292 +{
  29.293 +    return audio_pcm_sw_write (sw, buf, len);
  29.294 +}
  29.295 +
  29.296 +static int coreaudio_init_out (HWVoiceOut *hw, audsettings_t *as)
  29.297 +{
  29.298 +    OSStatus status;
  29.299 +    coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw;
  29.300 +    UInt32 propertySize;
  29.301 +    int err;
  29.302 +    int bits = 8;
  29.303 +    int endianess = 0;
  29.304 +    const char *typ = "playback";
  29.305 +    AudioValueRange frameRange;
  29.306 +
  29.307 +    /* create mutex */
  29.308 +    err = pthread_mutex_init(&core->mutex, NULL);
  29.309 +    if (err) {
  29.310 +        dolog("Could not create mutex\nReason: %s\n", strerror (err));
  29.311 +        return -1;
  29.312 +    }
  29.313 +
  29.314 +    if (as->fmt == AUD_FMT_S16 || as->fmt == AUD_FMT_U16) {
  29.315 +        bits = 16;
  29.316 +        endianess = 1;
  29.317 +    }
  29.318 +
  29.319 +    audio_pcm_init_info (
  29.320 +        &hw->info,
  29.321 +        as,
  29.322 +        /* Following is irrelevant actually since we do not use
  29.323 +           mixengs clipping routines */
  29.324 +        audio_need_to_swap_endian (endianess)
  29.325 +        );
  29.326 +
  29.327 +    /* open default output device */
  29.328 +    propertySize = sizeof(core->outputDeviceID);
  29.329 +    status = AudioHardwareGetProperty(
  29.330 +        kAudioHardwarePropertyDefaultOutputDevice,
  29.331 +        &propertySize,
  29.332 +        &core->outputDeviceID);
  29.333 +    if (status != kAudioHardwareNoError) {
  29.334 +        coreaudio_logerr2 (status, typ,
  29.335 +                           "Could not get default output Device\n");
  29.336 +        return -1;
  29.337 +    }
  29.338 +    if (core->outputDeviceID == kAudioDeviceUnknown) {
  29.339 +        dolog ("Could not initialize %s - Unknown Audiodevice\n", typ);
  29.340 +        return -1;
  29.341 +    }
  29.342 +
  29.343 +    /* get minimum and maximum buffer frame sizes */
  29.344 +    propertySize = sizeof(frameRange);
  29.345 +    status = AudioDeviceGetProperty(
  29.346 +        core->outputDeviceID,
  29.347 +        0,
  29.348 +        0,
  29.349 +        kAudioDevicePropertyBufferFrameSizeRange,
  29.350 +        &propertySize,
  29.351 +        &frameRange);
  29.352 +    if (status != kAudioHardwareNoError) {
  29.353 +        coreaudio_logerr2 (status, typ,
  29.354 +                           "Could not get device buffer frame range\n");
  29.355 +        return -1;
  29.356 +    }
  29.357 +
  29.358 +    if (frameRange.mMinimum > conf.buffer_frames) {
  29.359 +        core->audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMinimum;
  29.360 +        dolog ("warning: Upsizing Buffer Frames to %f\n", frameRange.mMinimum);
  29.361 +    }
  29.362 +    else if (frameRange.mMaximum < conf.buffer_frames) {
  29.363 +        core->audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMaximum;
  29.364 +        dolog ("warning: Downsizing Buffer Frames to %f\n", frameRange.mMaximum);
  29.365 +    }
  29.366 +    else {
  29.367 +        core->audioDevicePropertyBufferFrameSize = conf.buffer_frames;
  29.368 +    }
  29.369 +
  29.370 +    /* set Buffer Frame Size */
  29.371 +    propertySize = sizeof(core->audioDevicePropertyBufferFrameSize);
  29.372 +    status = AudioDeviceSetProperty(
  29.373 +        core->outputDeviceID,
  29.374 +        NULL,
  29.375 +        0,
  29.376 +        false,
  29.377 +        kAudioDevicePropertyBufferFrameSize,
  29.378 +        propertySize,
  29.379 +        &core->audioDevicePropertyBufferFrameSize);
  29.380 +    if (status != kAudioHardwareNoError) {
  29.381 +        coreaudio_logerr2 (status, typ,
  29.382 +                           "Could not set device buffer frame size %ld\n",
  29.383 +                           core->audioDevicePropertyBufferFrameSize);
  29.384 +        return -1;
  29.385 +    }
  29.386 +
  29.387 +    /* get Buffer Frame Size */
  29.388 +    propertySize = sizeof(core->audioDevicePropertyBufferFrameSize);
  29.389 +    status = AudioDeviceGetProperty(
  29.390 +        core->outputDeviceID,
  29.391 +        0,
  29.392 +        false,
  29.393 +        kAudioDevicePropertyBufferFrameSize,
  29.394 +        &propertySize,
  29.395 +        &core->audioDevicePropertyBufferFrameSize);
  29.396 +    if (status != kAudioHardwareNoError) {
  29.397 +        coreaudio_logerr2 (status, typ,
  29.398 +                           "Could not get device buffer frame size\n");
  29.399 +        return -1;
  29.400 +    }
  29.401 +    hw->samples = conf.nbuffers * core->audioDevicePropertyBufferFrameSize;
  29.402 +
  29.403 +    /* get StreamFormat */
  29.404 +    propertySize = sizeof(core->outputStreamBasicDescription);
  29.405 +    status = AudioDeviceGetProperty(
  29.406 +        core->outputDeviceID,
  29.407 +        0,
  29.408 +        false,
  29.409 +        kAudioDevicePropertyStreamFormat,
  29.410 +        &propertySize,
  29.411 +        &core->outputStreamBasicDescription);
  29.412 +    if (status != kAudioHardwareNoError) {
  29.413 +        coreaudio_logerr2 (status, typ,
  29.414 +                           "Could not get Device Stream properties\n");
  29.415 +        core->outputDeviceID = kAudioDeviceUnknown;
  29.416 +        return -1;
  29.417 +    }
  29.418 +
  29.419 +    /* set Samplerate */
  29.420 +    core->outputStreamBasicDescription.mSampleRate = (Float64) as->freq;
  29.421 +    propertySize = sizeof(core->outputStreamBasicDescription);
  29.422 +    status = AudioDeviceSetProperty(
  29.423 +        core->outputDeviceID,
  29.424 +        0,
  29.425 +        0,
  29.426 +        0,
  29.427 +        kAudioDevicePropertyStreamFormat,
  29.428 +        propertySize,
  29.429 +        &core->outputStreamBasicDescription);
  29.430 +    if (status != kAudioHardwareNoError) {
  29.431 +        coreaudio_logerr2 (status, typ, "Could not set samplerate %d\n",
  29.432 +                           as->freq);
  29.433 +        core->outputDeviceID = kAudioDeviceUnknown;
  29.434 +        return -1;
  29.435 +    }
  29.436 +
  29.437 +    /* set Callback */
  29.438 +    status = AudioDeviceAddIOProc(core->outputDeviceID, audioDeviceIOProc, hw);
  29.439 +    if (status != kAudioHardwareNoError) {
  29.440 +        coreaudio_logerr2 (status, typ, "Could not set IOProc\n");
  29.441 +        core->outputDeviceID = kAudioDeviceUnknown;
  29.442 +        return -1;
  29.443 +    }
  29.444 +
  29.445 +    /* start Playback */
  29.446 +    if (!isPlaying(core->outputDeviceID)) {
  29.447 +        status = AudioDeviceStart(core->outputDeviceID, audioDeviceIOProc);
  29.448 +        if (status != kAudioHardwareNoError) {
  29.449 +            coreaudio_logerr2 (status, typ, "Could not start playback\n");
  29.450 +            AudioDeviceRemoveIOProc(core->outputDeviceID, audioDeviceIOProc);
  29.451 +            core->outputDeviceID = kAudioDeviceUnknown;
  29.452 +            return -1;
  29.453 +        }
  29.454 +    }
  29.455 +
  29.456 +    return 0;
  29.457 +}
  29.458 +
  29.459 +static void coreaudio_fini_out (HWVoiceOut *hw)
  29.460 +{
  29.461 +    OSStatus status;
  29.462 +    int err;
  29.463 +    coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw;
  29.464 +
  29.465 +    if (!conf.isAtexit) {
  29.466 +        /* stop playback */
  29.467 +        if (isPlaying(core->outputDeviceID)) {
  29.468 +            status = AudioDeviceStop(core->outputDeviceID, audioDeviceIOProc);
  29.469 +            if (status != kAudioHardwareNoError) {
  29.470 +                coreaudio_logerr (status, "Could not stop playback\n");
  29.471 +            }
  29.472 +        }
  29.473 +
  29.474 +        /* remove callback */
  29.475 +        status = AudioDeviceRemoveIOProc(core->outputDeviceID,
  29.476 +                                         audioDeviceIOProc);
  29.477 +        if (status != kAudioHardwareNoError) {
  29.478 +            coreaudio_logerr (status, "Could not remove IOProc\n");
  29.479 +        }
  29.480 +    }
  29.481 +    core->outputDeviceID = kAudioDeviceUnknown;
  29.482 +
  29.483 +    /* destroy mutex */
  29.484 +    err = pthread_mutex_destroy(&core->mutex);
  29.485 +    if (err) {
  29.486 +        dolog("Could not destroy mutex\nReason: %s\n", strerror (err));
  29.487 +    }
  29.488 +}
  29.489 +
  29.490 +static int coreaudio_ctl_out (HWVoiceOut *hw, int cmd, ...)
  29.491 +{
  29.492 +    OSStatus status;
  29.493 +    coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw;
  29.494 +
  29.495 +    switch (cmd) {
  29.496 +    case VOICE_ENABLE:
  29.497 +        /* start playback */
  29.498 +        if (!isPlaying(core->outputDeviceID)) {
  29.499 +            status = AudioDeviceStart(core->outputDeviceID, audioDeviceIOProc);
  29.500 +            if (status != kAudioHardwareNoError) {
  29.501 +                coreaudio_logerr (status, "Could not resume playback\n");
  29.502 +            }
  29.503 +        }
  29.504 +        break;
  29.505 +
  29.506 +    case VOICE_DISABLE:
  29.507 +        /* stop playback */
  29.508 +        if (!conf.isAtexit) {
  29.509 +            if (isPlaying(core->outputDeviceID)) {
  29.510 +                status = AudioDeviceStop(core->outputDeviceID, audioDeviceIOProc);
  29.511 +                if (status != kAudioHardwareNoError) {
  29.512 +                    coreaudio_logerr (status, "Could not pause playback\n");
  29.513 +                }
  29.514 +            }
  29.515 +        }
  29.516 +        break;
  29.517 +    }
  29.518 +    return 0;
  29.519 +}
  29.520 +
  29.521 +static void *coreaudio_audio_init (void)
  29.522 +{
  29.523 +    atexit(coreaudio_atexit);
  29.524 +    return &coreaudio_audio_init;
  29.525 +}
  29.526 +
  29.527 +static void coreaudio_audio_fini (void *opaque)
  29.528 +{
  29.529 +    (void) opaque;
  29.530 +}
  29.531 +
  29.532 +static struct audio_option coreaudio_options[] = {
  29.533 +    {"BUFFER_SIZE", AUD_OPT_INT, &conf.buffer_frames,
  29.534 +     "Size of the buffer in frames", NULL, 0},
  29.535 +    {"BUFFER_COUNT", AUD_OPT_INT, &conf.nbuffers,
  29.536 +     "Number of buffers", NULL, 0},
  29.537 +    {NULL, 0, NULL, NULL, NULL, 0}
  29.538 +};
  29.539 +
  29.540 +static struct audio_pcm_ops coreaudio_pcm_ops = {
  29.541 +    coreaudio_init_out,
  29.542 +    coreaudio_fini_out,
  29.543 +    coreaudio_run_out,
  29.544 +    coreaudio_write,
  29.545 +    coreaudio_ctl_out,
  29.546 +
  29.547 +    NULL,
  29.548 +    NULL,
  29.549 +    NULL,
  29.550 +    NULL,
  29.551 +    NULL
  29.552 +};
  29.553 +
  29.554 +struct audio_driver coreaudio_audio_driver = {
  29.555 +    INIT_FIELD (name           = ) "coreaudio",
  29.556 +    INIT_FIELD (descr          = )
  29.557 +    "CoreAudio http://developer.apple.com/audio/coreaudio.html",
  29.558 +    INIT_FIELD (options        = ) coreaudio_options,
  29.559 +    INIT_FIELD (init           = ) coreaudio_audio_init,
  29.560 +    INIT_FIELD (fini           = ) coreaudio_audio_fini,
  29.561 +    INIT_FIELD (pcm_ops        = ) &coreaudio_pcm_ops,
  29.562 +    INIT_FIELD (can_be_default = ) 1,
  29.563 +    INIT_FIELD (max_voices_out = ) 1,
  29.564 +    INIT_FIELD (max_voices_in  = ) 0,
  29.565 +    INIT_FIELD (voice_size_out = ) sizeof (coreaudioVoiceOut),
  29.566 +    INIT_FIELD (voice_size_in  = ) 0
  29.567 +};
    30.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    30.2 +++ b/tools/ioemu/audio/dsound_template.h	Wed Jul 12 19:16:10 2006 +0100
    30.3 @@ -0,0 +1,282 @@
    30.4 +/*
    30.5 + * QEMU DirectSound audio driver header
    30.6 + *
    30.7 + * Copyright (c) 2005 Vassili Karpov (malc)
    30.8 + *
    30.9 + * Permission is hereby granted, free of charge, to any person obtaining a copy
   30.10 + * of this software and associated documentation files (the "Software"), to deal
   30.11 + * in the Software without restriction, including without limitation the rights
   30.12 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   30.13 + * copies of the Software, and to permit persons to whom the Software is
   30.14 + * furnished to do so, subject to the following conditions:
   30.15 + *
   30.16 + * The above copyright notice and this permission notice shall be included in
   30.17 + * all copies or substantial portions of the Software.
   30.18 + *
   30.19 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   30.20 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   30.21 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
   30.22 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   30.23 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   30.24 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   30.25 + * THE SOFTWARE.
   30.26 + */
   30.27 +#ifdef DSBTYPE_IN
   30.28 +#define NAME "capture buffer"
   30.29 +#define TYPE in
   30.30 +#define IFACE IDirectSoundCaptureBuffer
   30.31 +#define BUFPTR LPDIRECTSOUNDCAPTUREBUFFER
   30.32 +#define FIELD dsound_capture_buffer
   30.33 +#else
   30.34 +#define NAME "playback buffer"
   30.35 +#define TYPE out
   30.36 +#define IFACE IDirectSoundBuffer
   30.37 +#define BUFPTR LPDIRECTSOUNDBUFFER
   30.38 +#define FIELD dsound_buffer
   30.39 +#endif
   30.40 +
   30.41 +static int glue (dsound_unlock_, TYPE) (
   30.42 +    BUFPTR buf,
   30.43 +    LPVOID p1,
   30.44 +    LPVOID p2,
   30.45 +    DWORD blen1,
   30.46 +    DWORD blen2
   30.47 +    )
   30.48 +{
   30.49 +    HRESULT hr;
   30.50 +
   30.51 +    hr = glue (IFACE, _Unlock) (buf, p1, blen1, p2, blen2);
   30.52 +    if (FAILED (hr)) {
   30.53 +        dsound_logerr (hr, "Could not unlock " NAME "\n");
   30.54 +        return -1;
   30.55 +    }
   30.56 +
   30.57 +    return 0;
   30.58 +}
   30.59 +
   30.60 +static int glue (dsound_lock_, TYPE) (
   30.61 +    BUFPTR buf,
   30.62 +    struct audio_pcm_info *info,
   30.63 +    DWORD pos,
   30.64 +    DWORD len,
   30.65 +    LPVOID *p1p,
   30.66 +    LPVOID *p2p,
   30.67 +    DWORD *blen1p,
   30.68 +    DWORD *blen2p,
   30.69 +    int entire
   30.70 +    )
   30.71 +{
   30.72 +    HRESULT hr;
   30.73 +    int i;
   30.74 +    LPVOID p1 = NULL, p2 = NULL;
   30.75 +    DWORD blen1 = 0, blen2 = 0;
   30.76 +
   30.77 +    for (i = 0; i < conf.lock_retries; ++i) {
   30.78 +        hr = glue (IFACE, _Lock) (
   30.79 +            buf,
   30.80 +            pos,
   30.81 +            len,
   30.82 +            &p1,
   30.83 +            &blen1,
   30.84 +            &p2,
   30.85 +            &blen2,
   30.86 +            (entire
   30.87 +#ifdef DSBTYPE_IN
   30.88 +             ? DSCBLOCK_ENTIREBUFFER
   30.89 +#else
   30.90 +             ? DSBLOCK_ENTIREBUFFER
   30.91 +#endif
   30.92 +             : 0)
   30.93 +            );
   30.94 +
   30.95 +        if (FAILED (hr)) {
   30.96 +#ifndef DSBTYPE_IN
   30.97 +            if (hr == DSERR_BUFFERLOST) {
   30.98 +                if (glue (dsound_restore_, TYPE) (buf)) {
   30.99 +                    dsound_logerr (hr, "Could not lock " NAME "\n");
  30.100 +                    goto fail;
  30.101 +                }
  30.102 +                continue;
  30.103 +            }
  30.104 +#endif
  30.105 +            dsound_logerr (hr, "Could not lock " NAME "\n");
  30.106 +            goto fail;
  30.107 +        }
  30.108 +
  30.109 +        break;
  30.110 +    }
  30.111 +
  30.112 +    if (i == conf.lock_retries) {
  30.113 +        dolog ("%d attempts to lock " NAME " failed\n", i);
  30.114 +        goto fail;
  30.115 +    }
  30.116 +
  30.117 +    if ((p1 && (blen1 & info->align)) || (p2 && (blen2 & info->align))) {
  30.118 +        dolog ("DirectSound returned misaligned buffer %ld %ld\n",
  30.119 +               blen1, blen2);
  30.120 +        glue (dsound_unlock_, TYPE) (buf, p1, p2, blen1, blen2);
  30.121 +        goto fail;
  30.122 +    }
  30.123 +
  30.124 +    if (!p1 && blen1) {
  30.125 +        dolog ("warning: !p1 && blen1=%ld\n", blen1);
  30.126 +        blen1 = 0;
  30.127 +    }
  30.128 +
  30.129 +    if (!p2 && blen2) {
  30.130 +        dolog ("warning: !p2 && blen2=%ld\n", blen2);
  30.131 +        blen2 = 0;
  30.132 +    }
  30.133 +
  30.134 +    *p1p = p1;
  30.135 +    *p2p = p2;
  30.136 +    *blen1p = blen1;
  30.137 +    *blen2p = blen2;
  30.138 +    return 0;
  30.139 +
  30.140 + fail:
  30.141 +    *p1p = NULL - 1;
  30.142 +    *p2p = NULL - 1;
  30.143 +    *blen1p = -1;
  30.144 +    *blen2p = -1;
  30.145 +    return -1;
  30.146 +}
  30.147 +
  30.148 +#ifdef DSBTYPE_IN
  30.149 +static void dsound_fini_in (HWVoiceIn *hw)
  30.150 +#else
  30.151 +static void dsound_fini_out (HWVoiceOut *hw)
  30.152 +#endif
  30.153 +{
  30.154 +    HRESULT hr;
  30.155 +#ifdef DSBTYPE_IN
  30.156 +    DSoundVoiceIn *ds = (DSoundVoiceIn *) hw;
  30.157 +#else
  30.158 +    DSoundVoiceOut *ds = (DSoundVoiceOut *) hw;
  30.159 +#endif
  30.160 +
  30.161 +    if (ds->FIELD) {
  30.162 +        hr = glue (IFACE, _Stop) (ds->FIELD);
  30.163 +        if (FAILED (hr)) {
  30.164 +            dsound_logerr (hr, "Could not stop " NAME "\n");
  30.165 +        }
  30.166 +
  30.167 +        hr = glue (IFACE, _Release) (ds->FIELD);
  30.168 +        if (FAILED (hr)) {
  30.169 +            dsound_logerr (hr, "Could not release " NAME "\n");
  30.170 +        }
  30.171 +        ds->FIELD = NULL;
  30.172 +    }
  30.173 +}
  30.174 +
  30.175 +#ifdef DSBTYPE_IN
  30.176 +static int dsound_init_in (HWVoiceIn *hw, audsettings_t *as)
  30.177 +#else
  30.178 +static int dsound_init_out (HWVoiceOut *hw, audsettings_t *as)
  30.179 +#endif
  30.180 +{
  30.181 +    int err;
  30.182 +    HRESULT hr;
  30.183 +    dsound *s = &glob_dsound;
  30.184 +    WAVEFORMATEX wfx;
  30.185 +    audsettings_t obt_as;
  30.186 +#ifdef DSBTYPE_IN
  30.187 +    const char *typ = "ADC";
  30.188 +    DSoundVoiceIn *ds = (DSoundVoiceIn *) hw;
  30.189 +    DSCBUFFERDESC bd;
  30.190 +    DSCBCAPS bc;
  30.191 +#else
  30.192 +    const char *typ = "DAC";
  30.193 +    DSoundVoiceOut *ds = (DSoundVoiceOut *) hw;
  30.194 +    DSBUFFERDESC bd;
  30.195 +    DSBCAPS bc;
  30.196 +#endif
  30.197 +
  30.198 +    err = waveformat_from_audio_settings (&wfx, as);
  30.199 +    if (err) {
  30.200 +        return -1;
  30.201 +    }
  30.202 +
  30.203 +    memset (&bd, 0, sizeof (bd));
  30.204 +    bd.dwSize = sizeof (bd);
  30.205 +    bd.lpwfxFormat = &wfx;
  30.206 +#ifdef DSBTYPE_IN
  30.207 +    bd.dwBufferBytes = conf.bufsize_in;
  30.208 +    hr = IDirectSoundCapture_CreateCaptureBuffer (
  30.209 +        s->dsound_capture,
  30.210 +        &bd,
  30.211 +        &ds->dsound_capture_buffer,
  30.212 +        NULL
  30.213 +        );
  30.214 +#else
  30.215 +    bd.dwFlags = DSBCAPS_STICKYFOCUS | DSBCAPS_GETCURRENTPOSITION2;
  30.216 +    bd.dwBufferBytes = conf.bufsize_out;
  30.217 +    hr = IDirectSound_CreateSoundBuffer (
  30.218 +        s->dsound,
  30.219 +        &bd,
  30.220 +        &ds->dsound_buffer,
  30.221 +        NULL
  30.222 +        );
  30.223 +#endif
  30.224 +
  30.225 +    if (FAILED (hr)) {
  30.226 +        dsound_logerr2 (hr, typ, "Could not create " NAME "\n");
  30.227 +        return -1;
  30.228 +    }
  30.229 +
  30.230 +    hr = glue (IFACE, _GetFormat) (ds->FIELD, &wfx, sizeof (wfx), NULL);
  30.231 +    if (FAILED (hr)) {
  30.232 +        dsound_logerr2 (hr, typ, "Could not get " NAME " format\n");
  30.233 +        goto fail0;
  30.234 +    }
  30.235 +
  30.236 +#ifdef DEBUG_DSOUND
  30.237 +    dolog (NAME "\n");
  30.238 +    print_wave_format (&wfx);
  30.239 +#endif
  30.240 +
  30.241 +    memset (&bc, 0, sizeof (bc));
  30.242 +    bc.dwSize = sizeof (bc);
  30.243 +
  30.244 +    hr = glue (IFACE, _GetCaps) (ds->FIELD, &bc);
  30.245 +    if (FAILED (hr)) {
  30.246 +        dsound_logerr2 (hr, typ, "Could not get " NAME " format\n");
  30.247 +        goto fail0;
  30.248 +    }
  30.249 +
  30.250 +    err = waveformat_to_audio_settings (&wfx, &obt_as);
  30.251 +    if (err) {
  30.252 +        goto fail0;
  30.253 +    }
  30.254 +
  30.255 +    ds->first_time = 1;
  30.256 +
  30.257 +    audio_pcm_init_info (&hw->info, &obt_as, audio_need_to_swap_endian (0));
  30.258 +
  30.259 +    if (bc.dwBufferBytes & hw->info.align) {
  30.260 +        dolog (
  30.261 +            "GetCaps returned misaligned buffer size %ld, alignment %d\n",
  30.262 +            bc.dwBufferBytes, hw->info.align + 1
  30.263 +            );
  30.264 +    }
  30.265 +    hw->samples = bc.dwBufferBytes >> hw->info.shift;
  30.266 +
  30.267 +#ifdef DEBUG_DSOUND
  30.268 +    dolog ("caps %ld, desc %ld\n",
  30.269 +           bc.dwBufferBytes, bd.dwBufferBytes);
  30.270 +
  30.271 +    dolog ("bufsize %d, freq %d, chan %d, fmt %d\n",
  30.272 +           hw->bufsize, settings.freq, settings.nchannels, settings.fmt);
  30.273 +#endif
  30.274 +    return 0;
  30.275 +
  30.276 + fail0:
  30.277 +    glue (dsound_fini_, TYPE) (hw);
  30.278 +    return -1;
  30.279 +}
  30.280 +
  30.281 +#undef NAME
  30.282 +#undef TYPE
  30.283 +#undef IFACE
  30.284 +#undef BUFPTR
  30.285 +#undef FIELD
    31.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.2 +++ b/tools/ioemu/audio/dsoundaudio.c	Wed Jul 12 19:16:10 2006 +0100
    31.3 @@ -0,0 +1,1076 @@
    31.4 +/*
    31.5 + * QEMU DirectSound audio driver
    31.6 + *
    31.7 + * Copyright (c) 2005 Vassili Karpov (malc)
    31.8 + *
    31.9 + * Permission is hereby granted, free of charge, to any person obtaining a copy
   31.10 + * of this software and associated documentation files (the "Software"), to deal
   31.11 + * in the Software without restriction, including without limitation the rights
   31.12 + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
   31.13 + * copies of the Software, and to permit persons to whom the Software is
   31.14 + * furnished to do so, subject to the following conditions:
   31.15 + *
   31.16 + * The above copyright notice and this permission notice shall be included in
   31.17 + * all copies or substantial portions of the Software.
   31.18 + *
   31.19 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   31.20 + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   31.21 + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
   31.22 + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
   31.23 + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
   31.24 + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   31.25 + * THE SOFTWARE.
   31.26 + */
   31.27 +
   31.28 +/*
   31.29 + * SEAL 1.07 by Carlos 'pel' Hasan was used as documentation
   31.30 + */
   31.31 +
   31.32 +#include "vl.h"
   31.33 +
   31.34 +#define AUDIO_CAP "dsound"
   31.35 +#include "audio_int.h"
   31.36 +
   31.37 +#include <windows.h>
   31.38 +#include <objbase.h>
   31.39 +#include <dsound.h>
   31.40 +
   31.41 +/* #define DEBUG_DSOUND */
   31.42 +
   31.43 +static struct {
   31.44 +    int lock_retries;
   31.45 +    int restore_retries;
   31.46 +    int getstatus_retries;
   31.47 +    int set_primary;
   31.48 +    int bufsize_in;
   31.49 +    int bufsize_out;
   31.50 +    audsettings_t settings;
   31.51 +    int latency_millis;
   31.52 +} conf = {
   31.53 +    1,
   31.54 +    1,
   31.55 +    1,
   31.56 +    0,
   31.57 +    16384,
   31.58 +    16384,
   31.59 +    {
   31.60 +        44100,
   31.61 +        2,
   31.62 +        AUD_FMT_S16
   31.63 +    },
   31.64 +    10
   31.65 +};
   31.66 +
   31.67 +typedef struct {
   31.68 +    LPDIRECTSOUND dsound;
   31.69 +    LPDIRECTSOUNDCAPTURE dsound_capture;
   31.70 +    LPDIRECTSOUNDBUFFER dsound_primary_buffer;
   31.71 +    audsettings_t settings;
   31.72 +} dsound;
   31.73 +
   31.74 +static dsound glob_dsound;
   31.75 +
   31.76 +typedef struct {
   31.77 +    HWVoiceOut hw;
   31.78 +    LPDIRECTSOUNDBUFFER dsound_buffer;
   31.79 +    DWORD old_pos;
   31.80 +    int first_time;
   31.81 +#ifdef DEBUG_DSOUND
   31.82 +    DWORD old_ppos;
   31.83 +    DWORD played;
   31.84 +    DWORD mixed;
   31.85 +#endif
   31.86 +} DSoundVoiceOut;
   31.87 +
   31.88 +typedef struct {
   31.89 +    HWVoiceIn hw;
   31.90 +    int first_time;
   31.91 +    LPDIRECTSOUNDCAPTUREBUFFER dsound_capture_buffer;
   31.92 +} DSoundVoiceIn;
   31.93 +
   31.94 +static void dsound_log_hresult (HRESULT hr)
   31.95 +{
   31.96 +    const char *str = "BUG";
   31.97 +
   31.98 +    switch (hr) {
   31.99 +    case DS_OK:
  31.100 +        str = "The method succeeded";
  31.101 +        break;
  31.102 +#ifdef DS_NO_VIRTUALIZATION
  31.103 +    case DS_NO_VIRTUALIZATION:
  31.104 +        str = "The buffer was created, but another 3D algorithm was substituted";
  31.105 +        break;
  31.106 +#endif
  31.107 +#ifdef DS_INCOMPLETE
  31.108 +    case DS_INCOMPLETE:
  31.109 +        str = "The method succeeded, but not all the optional effects were obtained";
  31.110 +        break;
  31.111 +#endif
  31.112 +#ifdef DSERR_ACCESSDENIED
  31.113 +    case DSERR_ACCESSDENIED:
  31.114 +        str = "The request failed because access was denied";
  31.115 +        break;
  31.116 +#endif
  31.117 +#ifdef DSERR_ALLOCATED
  31.118 +    case DSERR_ALLOCATED:
  31.119 +        str = "The request failed because resources, such as a priority level, were already in use by another caller";
  31.120 +        break;
  31.121 +#endif
  31.122 +#ifdef DSERR_ALREADYINITIALIZED
  31.123 +    case DSERR_ALREADYINITIALIZED:
  31.124 +        str = "The object is already initialized";
  31.125 +        break;
  31.126 +#endif
  31.127 +#ifdef DSERR_BADFORMAT
  31.128 +    case DSERR_BADFORMAT:
  31.129 +        str = "The specified wave format is not supported";
  31.130 +        break;
  31.131 +#endif
  31.132 +#ifdef DSERR_BADSENDBUFFERGUID
  31.133 +    case DSERR_BADSENDBUFFERGUID:
  31.134 +        str = "The GUID specified in an audiopath file does not match a valid mix-in buffer";
  31.135 +        break;
  31.136 +#endif
  31.137 +#ifdef DSERR_BUFFERLOST
  31.138 +    case DSERR_BUFFERLOST:
  31.139 +        str = "The buffer memory has been lost and must be restored";
  31.140 +        break;
  31.141 +#endif
  31.142 +#ifdef DSERR_BUFFERTOOSMALL
  31.143 +    case DSERR_BUFFERTOOSMALL:
  31.144 +        str = "The buffer size is not great enough to enable effects processing";
  31.145 +        break;
  31.146 +#endif
  31.147 +#ifdef DSERR_CONTROLUNAVAIL
  31.148 +    case DSERR_CONTROLUNAVAIL:
  31.149 +        str = "The buffer control (volume, pan, and so on) requested by the caller is not available. Controls must be specified when the buffer is created, using the dwFlags member of DSBUFFERDESC";
  31.150 +        break;
  31.151 +#endif
  31.152 +#ifdef DSERR_DS8_REQUIRED
  31.153 +    case DSERR_DS8_REQUIRED:
  31.154 +        str = "A DirectSound object of class CLSID_DirectSound8 or later is required for the requested functionality. For more information, see IDirectSound8 Interface";
  31.155 +        break;
  31.156 +#endif
  31.157 +#ifdef DSERR_FXUNAVAILABLE
  31.158 +    case DSERR_FXUNAVAILABLE:
  31.159 +        str = "The effects requested could not be found on the system, or they are in the wrong order or in the wrong location; for example, an effect expected in hardware was found in software";
  31.160 +        break;
  31.161 +#endif
  31.162 +#ifdef DSERR_GENERIC
  31.163 +    case DSERR_GENERIC :
  31.164 +        str = "An undetermined error occurred inside the DirectSound subsystem";
  31.165 +        break;
  31.166 +#endif
  31.167 +#ifdef DSERR_INVALIDCALL
  31.168 +    case DSERR_INVALIDCALL:
  31.169 +        str = "This function is not valid for the current state of this object";
  31.170 +        break;
  31.171 +#endif
  31.172 +#ifdef DSERR_INVALIDPARAM
  31.173 +    case DSERR_INVALIDPARAM:
  31.174 +        str = "An invalid parameter was passed to the returning function";
  31.175 +        break;
  31.176 +#endif
  31.177 +#ifdef DSERR_NOAGGREGATION
  31.178 +    case DSERR_NOAGGREGATION:
  31.179 +        str = "The object does not support aggregation";
  31.180 +        break;
  31.181 +#endif
  31.182 +#ifdef DSERR_NODRIVER
  31.183 +    case DSERR_NODRIVER:
  31.184 +        str = "No sound driver is available for use, or the given GUID is not a valid DirectSound device ID";
  31.185 +        break;
  31.186 +#endif
  31.187 +#ifdef DSERR_NOINTERFACE
  31.188 +    case DSERR_NOINTERFACE:
  31.189 +        str = "The requested COM interface is not available";
  31.190 +        break;
  31.191 +#endif
  31.192 +#ifdef DSERR_OBJECTNOTFOUND
  31.193 +    case DSERR_OBJECTNOTFOUND:
  31.194 +        str = "The requested object was not found";
  31.195 +        break;
  31.196 +#endif
  31.197 +#ifdef DSERR_OTHERAPPHASPRIO
  31.198 +    case DSERR_OTHERAPPHASPRIO:
  31.199 +        str = "Another application has a higher priority level, preventing this call from succeeding";
  31.200 +        break;
  31.201 +#endif
  31.202 +#ifdef DSERR_OUTOFMEMORY
  31.203 +    case DSERR_OUTOFMEMORY:
  31.204 +        str = "The DirectSound subsystem could not allocate sufficient memory to complete the caller's request";
  31.205 +        break;
  31.206 +#endif
  31.207 +#ifdef DSERR_PRIOLEVELNEEDED
  31.208 +    case DSERR_PRIOLEVELNEEDED:
  31.209 +        str = "A cooperative level of DSSCL_PRIORITY or higher is required";
  31.210 +        break;
  31.211 +#endif
  31.212 +#ifdef DSERR_SENDLOOP
  31.213 +    case DSERR_SENDLOOP:
  31.214 +        str = "A circular loop of send effects was detected";
  31.215 +        break;
  31.216 +#endif
  31.217 +#ifdef DSERR_UNINITIALIZED
  31.218 +    case DSERR_UNINITIALIZED:
  31.219 +        str = "The Initialize method has not been called or has not been called successfully before other methods were called";
  31.220 +        break;
  31.221 +#endif
  31.222 +#ifdef DSERR_UNSUPPORTED
  31.223 +    case DSERR_UNSUPPORTED:
  31.224 +        str = "The function called is not supported at this time";
  31.225 +        break;
  31.226 +#endif
  31.227 +    default:
  31.228 +        AUD_log (AUDIO_CAP, "Reason: Unknown (HRESULT %#lx)\n", hr);
  31.229 +        return;
  31.230 +    }
  31.231 +
  31.232 +    AUD_log (AUDIO_CAP, "Reason: %s\n", str);
  31.233 +}
  31.234 +
  31.235 +static void GCC_FMT_ATTR (2, 3) dsound_logerr (
  31.236 +    HRESULT hr,
  31.237 +    const char *fmt,
  31.238 +    ...
  31.239 +    )
  31.240 +{
  31.241 +    va_list ap;
  31.242 +
  31.243 +    va_start (ap, fmt);
  31.244 +    AUD_vlog (AUDIO_CAP, fmt, ap);
  31.245 +    va_end (ap);
  31.246 +
  31.247 +    dsound_log_hresult (hr);
  31.248 +}
  31.249 +
  31.250 +static void GCC_FMT_ATTR (3, 4) dsound_logerr2 (
  31.251 +    HRESULT hr,
  31.252 +    const char *typ,
  31.253 +    const char *fmt,
  31.254 +    ...
  31.255 +    )
  31.256 +{
  31.257 +    va_list ap;
  31.258 +
  31.259 +    AUD_log (AUDIO_CAP, "Could not initialize %s\n", typ);
  31.260 +    va_start (ap, fmt);
  31.261 +    AUD_vlog (AUDIO_CAP, fmt, ap);
  31.262 +    va_end (ap);
  31.263 +
  31.264 +    dsound_log_hresult (hr);
  31.265 +}
  31.266 +
  31.267 +static DWORD millis_to_bytes (struct audio_pcm_info *info, DWORD millis)
  31.268 +{
  31.269 +    return (millis * info->bytes_per_second) / 1000;
  31.270 +}
  31.271 +
  31.272 +#ifdef DEBUG_DSOUND
  31.273 +static void print_wave_format (WAVEFORMATEX *wfx)
  31.274 +{
  31.275 +    dolog ("tag             = %d\n", wfx->wFormatTag);
  31.276 +    dolog ("nChannels       = %d\n", wfx->nChannels);
  31.277 +    dolog ("nSamplesPerSec  = %ld\n", wfx->nSamplesPerSec);
  31.278 +    dolog ("nAvgBytesPerSec = %ld\n", wfx->nAvgBytesPerSec);
  31.279 +    dolog ("nBlockAlign     = %d\n", wfx->nBlockAlign);
  31.280 +    dolog ("wBitsPerSample  = %d\n", wfx->wBitsPerSample);
  31.281 +    dolog ("cbSize          = %d\n", wfx->cbSize);
  31.282 +}
  31.283 +#endif
  31.284 +
  31.285 +static int dsound_restore_out (LPDIRECTSOUNDBUFFER dsb)
  31.286 +{
  31.287 +    HRESULT hr;
  31.288 +    int i;
  31.289 +
  31.290 +    for (i = 0; i < conf.restore_retries; ++i) {
  31.291 +        hr = IDirectSoundBuffer_Restore (dsb);
  31.292 +
  31.293 +        switch (hr) {
  31.294 +        case DS_OK:
  31.295 +            return 0;
  31.296 +
  31.297 +        case DSERR_BUFFERLOST:
  31.298 +            continue;
  31.299 +
  31.300 +        default:
  31.301 +            dsound_logerr (hr, "Could not restore playback buffer\n");
  31.302 +            return -1;
  31.303 +        }
  31.304 +    }
  31.305 +
  31.306 +    dolog ("%d attempts to restore playback buffer failed\n", i);
  31.307 +    return -1;
  31.308 +}
  31.309 +
  31.310 +static int waveformat_from_audio_settings (WAVEFORMATEX *wfx, audsettings_t *as)
  31.311 +{
  31.312 +    memset (wfx, 0, sizeof (*wfx));
  31.313 +
  31.314 +    wfx->wFormatTag = WAVE_FORMAT_PCM;
  31.315 +    wfx->nChannels = as->nchannels;
  31.316 +    wfx->nSamplesPerSec = as->freq;
  31.317 +    wfx->nAvgBytesPerSec = as->freq << (as->nchannels == 2);
  31.318 +    wfx->nBlockAlign = 1 << (as->nchannels == 2);
  31.319 +    wfx->cbSize = 0;
  31.320 +
  31.321 +    switch (as->fmt) {
  31.322 +    case AUD_FMT_S8:
  31.323 +        wfx->wBitsPerSample = 8;
  31.324 +        break;
  31.325 +
  31.326 +    case AUD_FMT_U8:
  31.327 +        wfx->wBitsPerSample = 8;
  31.328 +        break;
  31.329 +
  31.330 +    case AUD_FMT_S16:
  31.331 +        wfx->wBitsPerSample = 16;
  31.332 +        wfx->nAvgBytesPerSec <<= 1;
  31.333 +        wfx->nBlockAlign <<= 1;
  31.334 +        break;
  31.335 +
  31.336 +    case AUD_FMT_U16:
  31.337 +        wfx->wBitsPerSample = 16;
  31.338 +        wfx->nAvgBytesPerSec <<= 1;
  31.339 +        wfx->nBlockAlign <<= 1;
  31.340 +        break;
  31.341 +
  31.342 +    default:
  31.343 +        dolog ("Internal logic error: Bad audio format %d\n", as->freq);
  31.344 +        return -1;
  31.345 +    }
  31.346 +
  31.347 +    return 0;
  31.348 +}
  31.349 +
  31.350 +static int waveformat_to_audio_settings (WAVEFORMATEX *wfx, audsettings_t *as)
  31.351 +{
  31.352 +    if (wfx->wFormatTag != WAVE_FORMAT_PCM) {
  31.353 +        dolog ("Invalid wave format, tag is not PCM, but %d\n",
  31.354 +               wfx->wFormatTag);
  31.355 +        return -1;
  31.356 +    }
  31.357 +
  31.358 +    if (!wfx->nSamplesPerSec) {
  31.359 +        dolog ("Invalid wave format, frequency is zero\n");
  31.360 +        return -1;
  31.361 +    }
  31.362 +    as->freq = wfx->nSamplesPerSec;
  31.363 +
  31.364 +    switch (wfx->nChannels) {
  31.365 +    case 1:
  31.366 +        as->nchannels = 1;
  31.367 +        break;
  31.368 +
  31.369 +    case 2:
  31.370 +        as->nchannels = 2;
  31.371 +        break;
  31.372 +
  31.373 +    default:
  31.374 +        dolog (
  31.375 +            "Invalid wave format, number of channels is not 1 or 2, but %d\n",
  31.376 +            wfx->nChannels
  31.377 +            );
  31.378 +        return -1;
  31.379 +    }
  31.380 +
  31.381 +    switch (wfx->wBitsPerSample) {
  31.382 +    case 8:
  31.383 +        as->fmt = AUD_FMT_U8;
  31.384 +        break;
  31.385 +
  31.386 +    case 16:
  31.387 +        as->fmt = AUD_FMT_S16;
  31.388 +        break;
  31.389 +
  31.390 +    default:
  31.391 +        dolog ("Invalid wave format, bits per sample is not 8 or 16, but %d\n",
  31.392 +               wfx->wBitsPerSample);
  31.393 +        return -1;
  31.394 +    }
  31.395 +
  31.396 +    return 0;
  31.397 +}
  31.398 +
  31.399 +#include "dsound_template.h"
  31.400 +#define DSBTYPE_IN
  31.401 +#include "dsound_template.h"
  31.402 +#undef DSBTYPE_IN
  31.403 +
  31.404 +static int dsound_get_status_out (LPDIRECTSOUNDBUFFER dsb, DWORD *statusp)
  31.405 +{
  31.406 +    HRESULT hr;
  31.407 +    int i;
  31.408 +
  31.409 +    for (i = 0; i < conf.getstatus_retries; ++i) {
  31.410 +        hr = IDirectSoundBuffer_GetStatus (dsb, statusp);
  31.411 +        if (FAILED (hr)) {
  31.412 +            dsound_logerr (hr, "Could not get playback buffer status\n");
  31.413 +            return -1;
  31.414 +        }
  31.415 +
  31.416 +        if (*statusp & DSERR_BUFFERLOST) {
  31.417 +            if (dsound_restore_out (dsb)) {
  31.418 +                return -1;
  31.419 +            }
  31.420 +            continue;
  31.421 +        }
  31.422 +        break;
  31.423 +    }
  31.424 +
  31.425 +    return 0;
  31.426 +}
  31.427 +
  31.428 +static int dsound_get_status_in (LPDIRECTSOUNDCAPTUREBUFFER dscb,
  31.429 +                                 DWORD *statusp)
  31.430 +{
  31.431 +    HRESULT hr;
  31.432 +
  31.433 +    hr = IDirectSoundCaptureBuffer_GetStatus (dscb, statusp);
  31.434 +    if (FAILED (hr)) {
  31.435 +        dsound_logerr (hr, "Could not get capture buffer status\n");
  31.436 +        return -1;
  31.437 +    }
  31.438 +
  31.439 +    return 0;
  31.440 +}
  31.441 +
  31.442 +static void dsound_write_sample (HWVoiceOut *hw, uint8_t *dst, int dst_len)
  31.443 +{
  31.444 +    int src_len1 = dst_len;
  31.445 +    int src_len2 = 0;
  31.446 +    int pos = hw->rpos + dst_len;
  31.447 +    st_sample_t *src1 = hw->mix_buf + hw->rpos;
  31.448 +    st_sample_t *src2 = NULL;
  31.449 +
  31.450 +    if (pos > hw->samples) {
  31.451 +        src_len1 = hw->samples - hw->rpos;
  31.452 +        src2 = hw->mix_buf;
  31.453 +        src_len2 = dst_len - src_len1;
  31.454 +        pos = src_len2;
  31.455 +    }
  31.456 +
  31.457 +    if (src_len1) {
  31.458 +        hw->clip (dst, src1, src_len1);
  31.459 +        mixeng_clear (src1, src_len1);
  31.460 +    }
  31.461 +
  31.462 +    if (src_len2) {
  31.463 +        dst = advance (dst, src_len1 << hw->info.shift);
  31.464 +        hw->clip (dst, src2, src_len2);
  31.465 +        mixeng_clear (src2, src_len2);
  31.466 +    }
  31.467 +
  31.468 +    hw->rpos = pos % hw->samples;
  31.469 +}
  31.470 +
  31.471 +static void dsound_clear_sample (HWVoiceOut *hw, LPDIRECTSOUNDBUFFER dsb)
  31.472 +{
  31.473 +    int err;
  31.474 +    LPVOID p1, p2;
  31.475 +    DWORD blen1, blen2, len1, len2;
  31.476 +
  31.477 +    err = dsound_lock_out (
  31.478 +        dsb,
  31.479 +        &hw->info,
  31.480 +        0,
  31.481 +        hw->samples << hw->info.shift,
  31.482 +        &p1, &p2,
  31.483 +        &blen1, &blen2,
  31.484 +        1
  31.485 +        );
  31.486 +    if (err) {
  31.487 +        return;
  31.488 +    }
  31.489 +
  31.490 +    len1 = blen1 >> hw->info.shift;
  31.491 +    len2 = blen2 >> hw->info.shift;
  31.492 +
  31.493 +#ifdef DEBUG_DSOUND
  31.494 +    dolog ("clear %p,%ld,%ld %p,%ld,%ld\n",
  31.495 +           p1, blen1, len1,
  31.496 +           p2, blen2, len2);
  31.497 +#endif
  31.498 +
  31.499 +    if (p1 && len1) {
  31.500 +        audio_pcm_info_clear_buf (&hw->info, p1, len1);
  31.501 +    }
  31.502 +
  31.503 +    if (p2 && len2) {
  31.504 +        audio_pcm_info_clear_buf (&hw->info, p2, len2);
  31.505 +    }
  31.506 +
  31.507 +    dsound_unlock_out (dsb, p1, p2, blen1, blen2);
  31.508 +}
  31.509 +
  31.510 +static void dsound_close (dsound *s)
  31.511 +{
  31.512 +    HRESULT hr;
  31.513 +
  31.514 +    if (s->dsound_primary_buffer) {
  31.515 +        hr = IDirectSoundBuffer_Release (s->dsound_primary_buffer);
  31.516 +        if (FAILED (hr)) {
  31.517 +            dsound_logerr (hr, "Could not release primary buffer\n");
  31.518 +        }
  31.519 +        s->dsound_primary_buffer = NULL;
  31.520 +    }
  31.521 +}
  31.522 +
  31.523 +static int dsound_open (dsound *s)
  31.524 +{
  31.525 +    int err;
  31.526 +    HRESULT hr;
  31.527 +    WAVEFORMATEX wfx;
  31.528 +    DSBUFFERDESC dsbd;
  31.529 +    HWND hwnd;
  31.530 +
  31.531 +    hwnd = GetForegroundWindow ();
  31.532 +    hr = IDirectSound_SetCooperativeLevel (
  31.533 +        s->dsound,
  31.534 +        hwnd,
  31.535 +        DSSCL_PRIORITY
  31.536 +        );
  31.537 +
  31.538 +    if (FAILED (hr)) {
  31.539 +        dsound_logerr (hr, "Could not set cooperative level for window %p\n",
  31.540 +                       hwnd);
  31.541 +        return -1;
  31.542 +    }
  31.543 +
  31.544 +    if (!conf.set_primary) {
  31.545 +        return 0;
  31.546 +    }
  31.547 +
  31.548 +    err = waveformat_from_audio_settings (&wfx, &conf.settings);
  31.549 +    if (err) {
  31.550 +        return -1;
  31.551 +    }
  31.552 +
  31.553 +    memset (&dsbd, 0, sizeof (dsbd));
  31.554 +    dsbd.dwSize = sizeof (dsbd);
  31.555 +    dsbd.dwFlags = DSBCAPS_PRIMARYBUFFER;
  31.556 +    dsbd.dwBufferBytes = 0;
  31.557 +    dsbd.lpwfxFormat = NULL;
  31.558 +
  31.559 +    hr = IDirectSound_CreateSoundBuffer (
  31.560 +        s->dsound,
  31.561 +        &dsbd,
  31.562 +        &s->dsound_primary_buffer,
  31.563 +        NULL
  31.564 +        );
  31.565 +    if (FAILED (hr)) {
  31.566 +        dsound_logerr (hr, "Could not create primary playback buffer\n");
  31.567 +        return -1;
  31.568 +    }
  31.569 +
  31.570 +    hr = IDirectSoundBuffer_SetFormat (s->dsound_primary_buffer, &wfx);
  31.571 +    if (FAILED (hr)) {
  31.572 +        dsound_logerr (hr, "Could not set primary playback buffer format\n");
  31.573 +    }
  31.574 +
  31.575 +    hr = IDirectSoundBuffer_GetFormat (
  31.576 +        s->dsound_primary_buffer,
  31.577 +        &wfx,
  31.578 +        sizeof (wfx),
  31.579 +        NULL
  31.580 +        );
  31.581 +    if (FAILED (hr)) {
  31.582 +        dsound_logerr (hr, "Could not get primary playback buffer format\n");
  31.583 +        goto fail0;
  31.584 +    }
  31.585 +
  31.586 +#ifdef DEBUG_DSOUND
  31.587 +    dolog ("Primary\n");
  31.588 +    print_wave_format (&wfx);
  31.589 +#endif
  31.590 +
  31.591 +    err = waveformat_to_audio_settings (&wfx, &s->settings);
  31.592 +    if (err) {
  31.593 +        goto fail0;
  31.594 +    }
  31.595 +
  31.596 +    return 0;
  31.597 +
  31.598 + fail0:
  31.599 +    dsound_close (s);
  31.600 +    return -1;
  31.601 +}
  31.602 +
  31.603 +static int dsound_ctl_out (HWVoiceOut *hw, int cmd, ...)
  31.604 +{
  31.605 +    HRESULT hr;
  31.606 +    DWORD status;
  31.607 +    DSoundVoiceOut *ds = (DSoundVoiceOut *) hw;
  31.608 +    LPDIRECTSOUNDBUFFER dsb = ds->dsound_buffer;
  31.609 +
  31.610 +    if (!dsb) {
  31.611 +        dolog ("Attempt to control voice without a buffer\n");
  31.612 +        return 0;
  31.613 +    }
  31.614 +
  31.615 +    switch (cmd) {
  31.616 +    case VOICE_ENABLE:
  31.617 +        if (dsound_get_status_out (dsb, &status)) {
  31.618 +            return -1;
  31.619 +        }
  31.620 +
  31.621 +        if (status & DSBSTATUS_PLAYING) {
  31.622 +            dolog ("warning: Voice is already playing\n");
  31.623 +            return 0;
  31.624 +        }
  31.625 +
  31.626 +        dsound_clear_sample (hw, dsb);
  31.627 +
  31.628 +        hr = IDirectSoundBuffer_Play (dsb, 0, 0, DSBPLAY_LOOPING);
  31.629 +        if (FAILED (hr)) {
  31.630 +            dsound_logerr (hr, "Could not start playing buffer\n");
  31.631 +            return -1;
  31.632 +        }
  31.633 +        break;
  31.634 +
  31.635 +    case VOICE_DISABLE:
  31.636 +        if (dsound_get_status_out (dsb, &status)) {
  31.637 +            return -1;
  31.638 +        }
  31.639 +
  31.640 +        if (status & DSBSTATUS_PLAYING) {
  31.641 +            hr = IDirectSoundBuffer_Stop (dsb);
  31.642 +            if (FAILED (hr)) {
  31.643 +                dsound_logerr (hr, "Could not stop playing buffer\n");
  31.644 +                return -1;
  31.645 +            }
  31.646 +        }
  31.647 +        else {
  31.648 +            dolog ("warning: Voice is not playing\n");
  31.649 +        }
  31.650 +        break;
  31.651 +    }
  31.652 +    return 0;
  31.653 +}
  31.654 +
  31.655 +static int dsound_write (SWVoiceOut *sw, void *buf, int len)
  31.656 +{
  31.657 +    return audio_pcm_sw_write (sw, buf, len);
  31.658 +}
  31.659 +
  31.660 +static int dsound_run_out (HWVoiceOut *hw)
  31.661 +{
  31.662 +    int err;
  31.663 +    HRESULT hr;
  31.664 +    DSoundVoiceOut *ds = (DSoundVoiceOut *) hw;
  31.665 +    LPDIRECTSOUNDBUFFER dsb = ds->dsound_buffer;
  31.666 +    int live, len, hwshift;
  31.667 +    DWORD blen1, blen2;
  31.668 +    DWORD len1, len2;
  31.669 +    DWORD decr;
  31.670 +    DWORD wpos, ppos, old_pos;
  31.671 +    LPVOID p1, p2;
  31.672 +    int bufsize;
  31.673 +
  31.674 +    if (!dsb) {
  31.675 +        dolog ("Attempt to run empty with playback buffer\n");
  31.676 +        return 0;
  31.677 +    }
  31.678 +
  31.679 +    hwshift = hw->info.shift;
  31.680 +    bufsize = hw->samples << hwshift;
  31.681 +
  31.682 +    live = audio_pcm_hw_get_live_out (hw);
  31.683 +
  31.684 +    hr = IDirectSoundBuffer_GetCurrentPosition (
  31.685 +        dsb,
  31.686 +        &ppos,
  31.687 +        ds->first_time ? &wpos : NULL
  31.688 +        );
  31.689 +    if (FAILED (hr)) {
  31.690 +        dsound_logerr (hr, "Could not get playback buffer position\n");
  31.691 +        return 0;
  31.692 +    }
  31.693 +
  31.694 +    len = live << hwshift;
  31.695 +
  31.696 +    if (ds->first_time) {
  31.697 +        if (conf.latency_millis) {
  31.698 +            DWORD cur_blat;
  31.699 +
  31.700 +            cur_blat = audio_ring_dist (wpos, ppos, bufsize);
  31.701 +            ds->first_time = 0;
  31.702 +            old_pos = wpos;
  31.703 +            old_pos +=
  31.704 +                millis_to_bytes (&hw->info, conf.latency_millis) - cur_blat;
  31.705 +            old_pos %= bufsize;
  31.706 +            old_pos &= ~hw->info.align;
  31.707 +        }
  31.708 +        else {
  31.709 +            old_pos = wpos;
  31.710 +        }
  31.711 +#ifdef DEBUG_DSOUND
  31.712 +        ds->played = 0;
  31.713 +        ds->mixed = 0;
  31.714 +#endif
  31.715 +    }
  31.716 +    else {
  31.717 +        if (ds->old_pos == ppos) {
  31.718 +#ifdef DEBUG_DSOUND
  31.719 +            dolog ("old_pos == ppos\n");
  31.720 +#endif
  31.721 +            return 0;
  31.722 +        }
  31.723 +
  31.724 +#ifdef DEBUG_DSOUND
  31.725 +        ds->played += audio_ring_dist (ds->old_pos, ppos, hw->bufsize);
  31.726 +#endif
  31.727 +        old_pos = ds->old_pos;
  31.728 +    }
  31.729 +
  31.730 +    if ((old_pos < ppos) && ((old_pos + len) > ppos)) {
  31.731 +        len = ppos - old_pos;
  31.732 +    }
  31.733 +    else {
  31.734 +        if ((old_pos > ppos) && ((old_pos + len) > (ppos + bufsize))) {
  31.735 +            len = bufsize - old_pos + ppos;
  31.736 +        }
  31.737 +    }
  31.738 +
  31.739 +    if (audio_bug (AUDIO_FUNC, len < 0 || len > bufsize)) {
  31.740 +        dolog ("len=%d bufsize=%d old_pos=%ld ppos=%ld\n",
  31.741 +               len, bufsize, old_pos, ppos);
  31.742 +        return 0;
  31.743 +    }
  31.744 +
  31.745 +    len &= ~hw->info.align;
  31.746 +    if (!len) {
  31.747 +        return 0;
  31.748 +    }
  31.749 +
  31.750 +#ifdef DEBUG_DSOUND
  31.751 +    ds->old_ppos = ppos;
  31.752 +#endif
  31.753 +    err = dsound_lock_out (
  31.754 +        dsb,
  31.755 +        &hw->info,
  31.756 +        old_pos,
  31.757 +        len,
  31.758 +        &p1, &p2,
  31.759 +        &blen1, &blen2,
  31.760 +        0
  31.761 +        );
  31.762 +    if (err) {
  31.763 +        return 0;
  31.764 +    }
  31.765 +
  31.766 +    len1 = blen1 >> hwshift;
  31.767 +    len2 = blen2 >> hwshift;
  31.768 +    decr = len1 + len2;
  31.769 +
  31.770 +    if (p1 && len1) {
  31.771 +        dsound_write_sample (hw, p1, len1);
  31.772 +    }
  31.773 +
  31.774 +    if (p2 && len2) {
  31.775 +        dsound_write_sample (hw, p2, len2);
  31.776 +    }
  31.777 +
  31.778 +    dsound_unlock_out (dsb, p1, p2, blen1, blen2);
  31.779 +    ds->old_pos = (old_pos + (decr << hwshift)) % bufsize;
  31.780 +
  31.781 +#ifdef DEBUG_DSOUND
  31.782 +    ds->mixed += decr << hwshift;
  31.783 +
  31.784 +    dolog ("played %lu mixed %lu diff %ld sec %f\n",
  31.785 +           ds->played,
  31.786 +           ds->mixed,
  31.787 +           ds->mixed - ds->played,
  31.788 +           abs (ds->mixed - ds->played) / (double) hw->info.bytes_per_second);
  31.789 +#endif
  31.790 +    return decr;
  31.791 +}
  31.792 +
  31.793 +static int dsound_ctl_in (HWVoiceIn *hw, int cmd, ...)
  31.794 +{
  31.795 +    HRESULT hr;
  31.796 +    DWORD status;
  31.797 +    DSoundVoiceIn *ds = (DSoundVoiceIn *) hw;
  31.798 +    LPDIRECTSOUNDCAPTUREBUFFER dscb = ds->dsound_capture_buffer;
  31.799 +
  31.800 +    if (!dscb) {
  31.801 +        dolog ("Attempt to control capture voice without a buffer\n");
  31.802 +        return -1;
  31.803 +    }
  31.804 +
  31.805 +    switch (cmd) {
  31.806 +    case VOICE_ENABLE:
  31.807 +        if (dsound_get_status_in (dscb, &status)) {
  31.808 +            return -1;
  31.809 +        }
  31.810 +
  31.811 +        if (status & DSCBSTATUS_CAPTURING) {
  31.812 +            dolog ("warning: Voice is already capturing\n");
  31.813 +            return 0;
  31.814 +        }
  31.815 +
  31.816 +        /* clear ?? */
  31.817 +
  31.818 +        hr = IDirectSoundCaptureBuffer_Start (dscb, DSCBSTART_LOOPING);
  31.819 +        if (FAILED (hr)) {
  31.820 +            dsound_logerr (hr, "Could not start capturing\n");
  31.821 +            return -1;
  31.822 +        }
  31.823 +        break;
  31.824 +
  31.825 +    case VOICE_DISABLE:
  31.826 +        if (dsound_get_status_in (dscb, &status)) {
  31.827 +            return -1;
  31.828 +        }
  31.829 +
  31.830 +        if (status & DSCBSTATUS_CAPTURING) {
  31.831 +            hr = IDirectSoundCaptureBuffer_Stop (dscb);
  31.832 +            if (FAILED (hr)) {
  31.833 +                dsound_logerr (hr, "Could not stop capturing\n");
  31.834 +                return -1;
  31.835 +            }
  31.836 +        }
  31.837 +        else {
  31.838 +            dolog ("warning: Voice is not capturing\n");
  31.839 +        }
  31.840 +        break;
  31.841 +    }
  31.842 +    return 0;
  31.843 +}
  31.844 +
  31.845 +static int dsound_read (SWVoiceIn *sw, void *buf, int len)
  31.846 +{
  31.847 +    return audio_pcm_sw_read (sw, buf, len);
  31.848 +}
  31.849 +
  31.850 +static int dsound_run_in (HWVoiceIn *hw)
  31.851 +{
  31.852 +    int err;
  31.853 +    HRESULT hr;
  31.854 +    DSoundVoiceIn *ds = (DSoundVoiceIn *) hw;
  31.855 +    LPDIRECTSOUNDCAPTUREBUFFER dscb = ds->dsound_capture_buffer;
  31.856 +    int live, len, dead;
  31.857 +    DWORD blen1, blen2;
  31.858 +    DWORD len1, len2;
  31.859 +    DWORD decr;
  31.860 +    DWORD cpos, rpos;
  31.861 +    LPVOID p1, p2;
  31.862 +    int hwshift;
  31.863 +
  31.864 +    if (!dscb) {
  31.865 +        dolog ("Attempt to run without capture buffer\n");
  31.866 +        return 0;
  31.867 +    }
  31.868 +
  31.869 +    hwshift = hw->info.shift;
  31.870 +
  31.871 +    live = audio_pcm_hw_get_live_in (hw);
  31.872 +    dead = hw->samples - live;
  31.873 +    if (!dead) {
  31.874 +        return 0;
  31.875 +    }
  31.876 +
  31.877 +    hr = IDirectSoundCaptureBuffer_GetCurrentPosition (
  31.878 +        dscb,
  31.879 +        &cpos,
  31.880 +        ds->first_time ? &rpos : NULL
  31.881 +        );
  31.882 +    if (FAILED (hr)) {
  31.883 +        dsound_logerr (hr, "Could not get capture buffer position\n");
  31.884 +        return 0;
  31.885 +    }
  31.886 +
  31.887 +    if (ds->first_time) {
  31.888 +        ds->first_time = 0;
  31.889 +        if (rpos & hw->info.align) {
  31.890 +            ldebug ("warning: Misaligned capture read position %ld(%d)\n",
  31.891 +                    rpos, hw->info.align);
  31.892 +        }
  31.893 +        hw->wpos = rpos >> hwshift;
  31.894 +    }
  31.895 +
  31.896 +    if (cpos & hw->info.align) {
  31.897 +        ldebug ("warning: Misaligned capture position %ld(%d)\n",
  31.898 +                cpos, hw->info.align);
  31.899 +    }
  31.900 +    cpos >>= hwshift;
  31.901 +
  31.902 +    len = audio_ring_dist (cpos, hw->wpos, hw->samples);
  31.903 +    if (!len) {
  31.904 +        return 0;
  31.905 +    }
  31.906 +    len = audio_MIN (len, dead);
  31.907 +
  31.908 +    err = dsound_lock_in (
  31.909 +        dscb,
  31.910 +        &hw->info,
  31.911 +        hw->wpos << hwshift,
  31.912 +        len << hwshift,
  31.913 +        &p1,
  31.914 +        &p2,
  31.915 +        &blen1,
  31.916 +        &blen2,
  31.917 +        0
  31.918 +        );
  31.919 +    if (err) {
  31.920 +        return 0;
  31.921 +    }
  31.922 +
  31.923 +    len1 = blen1 >> hwshift;
  31.924 +    len2 = blen2 >> hwshift;
  31.925 +    decr = len1 + len2;
  31.926 +
  31.927 +    if (p1 && len1) {
  31.928 +        hw->conv (hw->conv_buf + hw->wpos, p1, len1, &nominal_volume);
  31.929 +    }
  31.930 +
  31.931 +    if (p2 && len2) {
  31.932 +        hw->conv (hw->conv_buf, p2, len2, &nominal_volume);
  31.933 +    }
  31.934 +
  31.935 +    dsound_unlock_in (dscb, p1, p2, blen1, blen2);
  31.936 +    hw->wpos = (hw->wpos + decr) % hw->samples;
  31.937 +    return decr;
  31.938 +}