Compare commits
	
		
			46 Commits
		
	
	
		
			v4.1.0-rc4
			...
			v0.15.1-qe
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					36f5bc4fdb | ||
| 
						 | 
					82b2b32a32 | ||
| 
						 | 
					4a81ab81e4 | ||
| 
						 | 
					68e3508eaf | ||
| 
						 | 
					fb524042db | ||
| 
						 | 
					336398391a | ||
| 
						 | 
					672aefeb5e | ||
| 
						 | 
					6a10ccca80 | ||
| 
						 | 
					7095e71576 | ||
| 
						 | 
					91b31d6158 | ||
| 
						 | 
					b89f4a7d2a | ||
| 
						 | 
					fbdd7c8bd5 | ||
| 
						 | 
					e19a4e89ae | ||
| 
						 | 
					ff5acedd8f | ||
| 
						 | 
					2af86a2ff7 | ||
| 
						 | 
					e62ad8314a | ||
| 
						 | 
					76e4e1d237 | ||
| 
						 | 
					4fbe5233fd | ||
| 
						 | 
					4bea41dbaa | ||
| 
						 | 
					e2f775205a | ||
| 
						 | 
					51dd7a94c7 | ||
| 
						 | 
					9096de69ff | ||
| 
						 | 
					09afeef1ab | ||
| 
						 | 
					01825a8ddf | ||
| 
						 | 
					ae2dd33693 | ||
| 
						 | 
					a80f53aee3 | ||
| 
						 | 
					88ca9f047b | ||
| 
						 | 
					898517b0bc | ||
| 
						 | 
					9dc9f2b820 | ||
| 
						 | 
					ef942b795a | ||
| 
						 | 
					868aa386b8 | ||
| 
						 | 
					7e10be8c74 | ||
| 
						 | 
					9843621e3b | ||
| 
						 | 
					ab640dbfc0 | ||
| 
						 | 
					eaa8b2778c | ||
| 
						 | 
					7ec7f28019 | ||
| 
						 | 
					31b1308046 | ||
| 
						 | 
					4ec648dd6e | ||
| 
						 | 
					e961d129e1 | ||
| 
						 | 
					8959459386 | ||
| 
						 | 
					e2b40e003a | ||
| 
						 | 
					1a39b0fcff | ||
| 
						 | 
					4a97e18b87 | ||
| 
						 | 
					f1ee0a0ebd | ||
| 
						 | 
					3583bc031e | ||
| 
						 | 
					2798b5e174 | 
							
								
								
									
										27
									
								
								.cirrus.yml
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								.cirrus.yml
									
									
									
									
									
								
							@@ -1,27 +0,0 @@
 | 
			
		||||
env:
 | 
			
		||||
  CIRRUS_CLONE_DEPTH: 1
 | 
			
		||||
 | 
			
		||||
freebsd_12_task:
 | 
			
		||||
  freebsd_instance:
 | 
			
		||||
    image: freebsd-12-0-release-amd64
 | 
			
		||||
    cpu: 8
 | 
			
		||||
    memory: 8G
 | 
			
		||||
  install_script: pkg install -y
 | 
			
		||||
    bash bison curl cyrus-sasl git glib gmake gnutls gsed
 | 
			
		||||
    nettle perl5 pixman pkgconf png usbredir
 | 
			
		||||
  script:
 | 
			
		||||
    - mkdir build
 | 
			
		||||
    - cd build
 | 
			
		||||
    - ../configure || { cat config.log; exit 1; }
 | 
			
		||||
    - gmake -j8
 | 
			
		||||
    - gmake -j8 V=1 check
 | 
			
		||||
 | 
			
		||||
macos_task:
 | 
			
		||||
  osx_instance:
 | 
			
		||||
    image: mojave-base
 | 
			
		||||
  install_script:
 | 
			
		||||
    - brew install pkg-config python gnu-sed glib pixman make sdl2
 | 
			
		||||
  script:
 | 
			
		||||
    - ./configure --python=/usr/local/bin/python3 || { cat config.log; exit 1; }
 | 
			
		||||
    - gmake -j$(sysctl -n hw.ncpu)
 | 
			
		||||
    - gmake check -j$(sysctl -n hw.ncpu)
 | 
			
		||||
@@ -1,2 +0,0 @@
 | 
			
		||||
((c-mode . ((c-file-style . "stroustrup")
 | 
			
		||||
	    (indent-tabs-mode . nil))))
 | 
			
		||||
@@ -1,43 +0,0 @@
 | 
			
		||||
# EditorConfig is a file format and collection of text editor plugins
 | 
			
		||||
# for maintaining consistent coding styles between different editors
 | 
			
		||||
# and IDEs. Most popular editors support this either natively or via
 | 
			
		||||
# plugin.
 | 
			
		||||
#
 | 
			
		||||
# Check https://editorconfig.org for details.
 | 
			
		||||
 | 
			
		||||
root = true
 | 
			
		||||
 | 
			
		||||
[*]
 | 
			
		||||
end_of_line = lf
 | 
			
		||||
insert_final_newline = true
 | 
			
		||||
charset = utf-8
 | 
			
		||||
 | 
			
		||||
[*.mak]
 | 
			
		||||
indent_style = tab
 | 
			
		||||
indent_size = 8
 | 
			
		||||
file_type_emacs = makefile
 | 
			
		||||
 | 
			
		||||
[Makefile*]
 | 
			
		||||
indent_style = tab
 | 
			
		||||
indent_size = 8
 | 
			
		||||
file_type_emacs = makefile
 | 
			
		||||
 | 
			
		||||
[*.{c,h}]
 | 
			
		||||
indent_style = space
 | 
			
		||||
indent_size = 4
 | 
			
		||||
 | 
			
		||||
[*.sh]
 | 
			
		||||
indent_style = space
 | 
			
		||||
indent_size = 4
 | 
			
		||||
 | 
			
		||||
[*.{s,S}]
 | 
			
		||||
indent_style = tab
 | 
			
		||||
indent_size = 8
 | 
			
		||||
file_type_emacs = asm
 | 
			
		||||
 | 
			
		||||
[*.{vert,frag}]
 | 
			
		||||
file_type_emacs = glsl
 | 
			
		||||
 | 
			
		||||
[*.json]
 | 
			
		||||
indent_style = space
 | 
			
		||||
file_type_emacs = python
 | 
			
		||||
							
								
								
									
										7
									
								
								.exrc
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								.exrc
									
									
									
									
									
								
							@@ -1,7 +0,0 @@
 | 
			
		||||
"VIM settings to match QEMU coding style.  They are activated by adding the
 | 
			
		||||
"following settings (without the " symbol) as last two lines in $HOME/.vimrc:
 | 
			
		||||
"set secure
 | 
			
		||||
"set exrc
 | 
			
		||||
set expandtab
 | 
			
		||||
set shiftwidth=4
 | 
			
		||||
set smarttab
 | 
			
		||||
							
								
								
									
										8
									
								
								.gdbinit
									
									
									
									
									
								
							
							
						
						
									
										8
									
								
								.gdbinit
									
									
									
									
									
								
							@@ -1,8 +0,0 @@
 | 
			
		||||
# GDB may have ./.gdbinit loading disabled by default.  In that case you can
 | 
			
		||||
# follow the instructions it prints.  They boil down to adding the following to
 | 
			
		||||
# your home directory's ~/.gdbinit file:
 | 
			
		||||
#
 | 
			
		||||
#   add-auto-load-safe-path /path/to/qemu/.gdbinit
 | 
			
		||||
 | 
			
		||||
# Load QEMU-specific sub-commands and settings
 | 
			
		||||
source scripts/qemu-gdb.py
 | 
			
		||||
							
								
								
									
										186
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										186
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -1,86 +1,51 @@
 | 
			
		||||
/.doctrees
 | 
			
		||||
/config-devices.*
 | 
			
		||||
/config-all-devices.*
 | 
			
		||||
/config-all-disas.*
 | 
			
		||||
/config-host.*
 | 
			
		||||
/config-target.*
 | 
			
		||||
/config.status
 | 
			
		||||
/config-temp
 | 
			
		||||
/elf2dmp
 | 
			
		||||
/trace-events-all
 | 
			
		||||
/trace/generated-events.h
 | 
			
		||||
/trace/generated-events.c
 | 
			
		||||
/trace/generated-helpers-wrappers.h
 | 
			
		||||
/trace/generated-helpers.h
 | 
			
		||||
/trace/generated-helpers.c
 | 
			
		||||
/trace/generated-tcg-tracers.h
 | 
			
		||||
/ui/shader/texture-blit-frag.h
 | 
			
		||||
/ui/shader/texture-blit-vert.h
 | 
			
		||||
/ui/shader/texture-blit-flip-vert.h
 | 
			
		||||
/ui/input-keymap-*.c
 | 
			
		||||
config-devices.*
 | 
			
		||||
config-all-devices.*
 | 
			
		||||
config-host.*
 | 
			
		||||
config-target.*
 | 
			
		||||
trace.h
 | 
			
		||||
trace.c
 | 
			
		||||
trace-dtrace.h
 | 
			
		||||
trace-dtrace.dtrace
 | 
			
		||||
*-timestamp
 | 
			
		||||
/*-softmmu
 | 
			
		||||
/*-darwin-user
 | 
			
		||||
/*-linux-user
 | 
			
		||||
/*-bsd-user
 | 
			
		||||
/ivshmem-client
 | 
			
		||||
/ivshmem-server
 | 
			
		||||
/libdis*
 | 
			
		||||
/libuser
 | 
			
		||||
/linux-headers/asm
 | 
			
		||||
/qga/qapi-generated
 | 
			
		||||
/qapi-gen-timestamp
 | 
			
		||||
/qapi/qapi-builtin-types.[ch]
 | 
			
		||||
/qapi/qapi-builtin-visit.[ch]
 | 
			
		||||
/qapi/qapi-commands-*.[ch]
 | 
			
		||||
/qapi/qapi-commands.[ch]
 | 
			
		||||
/qapi/qapi-emit-events.[ch]
 | 
			
		||||
/qapi/qapi-events-*.[ch]
 | 
			
		||||
/qapi/qapi-events.[ch]
 | 
			
		||||
/qapi/qapi-introspect.[ch]
 | 
			
		||||
/qapi/qapi-types-*.[ch]
 | 
			
		||||
/qapi/qapi-types.[ch]
 | 
			
		||||
/qapi/qapi-visit-*.[ch]
 | 
			
		||||
/qapi/qapi-visit.[ch]
 | 
			
		||||
/qapi/qapi-doc.texi
 | 
			
		||||
/qemu-doc.html
 | 
			
		||||
/qemu-doc.info
 | 
			
		||||
/qemu-doc.txt
 | 
			
		||||
/qemu-edid
 | 
			
		||||
/qemu-img
 | 
			
		||||
/qemu-nbd
 | 
			
		||||
/qemu-options.def
 | 
			
		||||
/qemu-options.texi
 | 
			
		||||
/qemu-img-cmds.texi
 | 
			
		||||
/qemu-img-cmds.h
 | 
			
		||||
/qemu-io
 | 
			
		||||
/qemu-ga
 | 
			
		||||
/qemu-bridge-helper
 | 
			
		||||
/qemu-keymap
 | 
			
		||||
/qemu-monitor.texi
 | 
			
		||||
/qemu-monitor-info.texi
 | 
			
		||||
/qemu-version.h
 | 
			
		||||
/qemu-version.h.tmp
 | 
			
		||||
/module_block.h
 | 
			
		||||
/scsi/qemu-pr-helper
 | 
			
		||||
/vhost-user-scsi
 | 
			
		||||
/vhost-user-blk
 | 
			
		||||
/fsdev/virtfs-proxy-helper
 | 
			
		||||
*.tmp
 | 
			
		||||
*.[1-9]
 | 
			
		||||
*-softmmu
 | 
			
		||||
*-darwin-user
 | 
			
		||||
*-linux-user
 | 
			
		||||
*-bsd-user
 | 
			
		||||
libdis*
 | 
			
		||||
libhw32
 | 
			
		||||
libhw64
 | 
			
		||||
libuser
 | 
			
		||||
qapi-generated
 | 
			
		||||
qemu-doc.html
 | 
			
		||||
qemu-tech.html
 | 
			
		||||
qemu-doc.info
 | 
			
		||||
qemu-tech.info
 | 
			
		||||
qemu.1
 | 
			
		||||
qemu.pod
 | 
			
		||||
qemu-img.1
 | 
			
		||||
qemu-img.pod
 | 
			
		||||
qemu-img
 | 
			
		||||
qemu-nbd
 | 
			
		||||
qemu-nbd.8
 | 
			
		||||
qemu-nbd.pod
 | 
			
		||||
qemu-options.def
 | 
			
		||||
qemu-options.texi
 | 
			
		||||
qemu-img-cmds.texi
 | 
			
		||||
qemu-img-cmds.h
 | 
			
		||||
qemu-io
 | 
			
		||||
qemu-ga
 | 
			
		||||
qemu-monitor.texi
 | 
			
		||||
QMP/qmp-commands.txt
 | 
			
		||||
.gdbinit
 | 
			
		||||
*.a
 | 
			
		||||
*.aux
 | 
			
		||||
*.cp
 | 
			
		||||
*.dvi
 | 
			
		||||
*.exe
 | 
			
		||||
*.msi
 | 
			
		||||
*.dll
 | 
			
		||||
*.so
 | 
			
		||||
*.mo
 | 
			
		||||
*.fn
 | 
			
		||||
*.ky
 | 
			
		||||
*.log
 | 
			
		||||
*.pdf
 | 
			
		||||
*.pod
 | 
			
		||||
*.cps
 | 
			
		||||
*.fns
 | 
			
		||||
*.kys
 | 
			
		||||
@@ -90,71 +55,20 @@
 | 
			
		||||
*.tp
 | 
			
		||||
*.vr
 | 
			
		||||
*.d
 | 
			
		||||
!/scripts/qemu-guest-agent/fsfreeze-hook.d
 | 
			
		||||
*.o
 | 
			
		||||
.sdk
 | 
			
		||||
*.gcda
 | 
			
		||||
*.gcno
 | 
			
		||||
*.gcov
 | 
			
		||||
/pc-bios/bios-pq/status
 | 
			
		||||
/pc-bios/edk2-*.fd
 | 
			
		||||
/pc-bios/vgabios-pq/status
 | 
			
		||||
/pc-bios/optionrom/linuxboot.asm
 | 
			
		||||
/pc-bios/optionrom/linuxboot.bin
 | 
			
		||||
/pc-bios/optionrom/linuxboot.raw
 | 
			
		||||
/pc-bios/optionrom/linuxboot.img
 | 
			
		||||
/pc-bios/optionrom/linuxboot_dma.asm
 | 
			
		||||
/pc-bios/optionrom/linuxboot_dma.bin
 | 
			
		||||
/pc-bios/optionrom/linuxboot_dma.raw
 | 
			
		||||
/pc-bios/optionrom/linuxboot_dma.img
 | 
			
		||||
/pc-bios/optionrom/pvh.asm
 | 
			
		||||
/pc-bios/optionrom/pvh.bin
 | 
			
		||||
/pc-bios/optionrom/pvh.raw
 | 
			
		||||
/pc-bios/optionrom/pvh.img
 | 
			
		||||
/pc-bios/optionrom/multiboot.asm
 | 
			
		||||
/pc-bios/optionrom/multiboot.bin
 | 
			
		||||
/pc-bios/optionrom/multiboot.raw
 | 
			
		||||
/pc-bios/optionrom/multiboot.img
 | 
			
		||||
/pc-bios/optionrom/kvmvapic.asm
 | 
			
		||||
/pc-bios/optionrom/kvmvapic.bin
 | 
			
		||||
/pc-bios/optionrom/kvmvapic.raw
 | 
			
		||||
/pc-bios/optionrom/kvmvapic.img
 | 
			
		||||
/pc-bios/s390-ccw/s390-ccw.elf
 | 
			
		||||
/pc-bios/s390-ccw/s390-ccw.img
 | 
			
		||||
/docs/built
 | 
			
		||||
/docs/interop/qemu-ga-qapi.texi
 | 
			
		||||
/docs/interop/qemu-ga-ref.html
 | 
			
		||||
/docs/interop/qemu-ga-ref.info*
 | 
			
		||||
/docs/interop/qemu-ga-ref.txt
 | 
			
		||||
/docs/interop/qemu-qmp-qapi.texi
 | 
			
		||||
/docs/interop/qemu-qmp-ref.html
 | 
			
		||||
/docs/interop/qemu-qmp-ref.info*
 | 
			
		||||
/docs/interop/qemu-qmp-ref.txt
 | 
			
		||||
/docs/version.texi
 | 
			
		||||
*.tps
 | 
			
		||||
*.swp
 | 
			
		||||
*.orig
 | 
			
		||||
.pc
 | 
			
		||||
patches
 | 
			
		||||
pc-bios/bios-pq/status
 | 
			
		||||
pc-bios/vgabios-pq/status
 | 
			
		||||
pc-bios/optionrom/linuxboot.bin
 | 
			
		||||
pc-bios/optionrom/multiboot.bin
 | 
			
		||||
pc-bios/optionrom/multiboot.raw
 | 
			
		||||
pc-bios/optionrom/extboot.bin
 | 
			
		||||
pc-bios/optionrom/vapic.bin
 | 
			
		||||
.stgit-*
 | 
			
		||||
.git-submodule-status
 | 
			
		||||
cscope.*
 | 
			
		||||
tags
 | 
			
		||||
TAGS
 | 
			
		||||
docker-src.*
 | 
			
		||||
*~
 | 
			
		||||
*.ast_raw
 | 
			
		||||
*.depend_raw
 | 
			
		||||
trace.h
 | 
			
		||||
trace.c
 | 
			
		||||
trace-ust.h
 | 
			
		||||
trace-ust.h
 | 
			
		||||
trace-dtrace.h
 | 
			
		||||
trace-dtrace.dtrace
 | 
			
		||||
trace-root.h
 | 
			
		||||
trace-root.c
 | 
			
		||||
trace-ust-root.h
 | 
			
		||||
trace-ust-root.h
 | 
			
		||||
trace-ust-all.h
 | 
			
		||||
trace-ust-all.c
 | 
			
		||||
trace-dtrace-root.h
 | 
			
		||||
trace-dtrace-root.dtrace
 | 
			
		||||
trace-ust-all.h
 | 
			
		||||
trace-ust-all.c
 | 
			
		||||
/target/arm/decode-sve.inc.c
 | 
			
		||||
 
 | 
			
		||||
@@ -1,88 +0,0 @@
 | 
			
		||||
before_script:
 | 
			
		||||
 - apt-get update -qq
 | 
			
		||||
 - apt-get install -y -qq flex bison libglib2.0-dev libpixman-1-dev genisoimage
 | 
			
		||||
 | 
			
		||||
build-system1:
 | 
			
		||||
 script:
 | 
			
		||||
 - apt-get install -y -qq libgtk-3-dev libvte-dev nettle-dev libcacard-dev
 | 
			
		||||
      libusb-dev libvde-dev libspice-protocol-dev libgl1-mesa-dev
 | 
			
		||||
 - ./configure --enable-werror --target-list="aarch64-softmmu alpha-softmmu
 | 
			
		||||
      cris-softmmu hppa-softmmu lm32-softmmu moxie-softmmu microblazeel-softmmu
 | 
			
		||||
      mips64el-softmmu m68k-softmmu ppc-softmmu riscv64-softmmu sparc-softmmu"
 | 
			
		||||
 - make -j2
 | 
			
		||||
 - make -j2 check
 | 
			
		||||
 | 
			
		||||
build-system2:
 | 
			
		||||
 script:
 | 
			
		||||
 - apt-get install -y -qq libsdl2-dev libgcrypt-dev libbrlapi-dev libaio-dev
 | 
			
		||||
      libfdt-dev liblzo2-dev librdmacm-dev libibverbs-dev libibumad-dev
 | 
			
		||||
 - ./configure --enable-werror --target-list="tricore-softmmu unicore32-softmmu
 | 
			
		||||
      microblaze-softmmu mips-softmmu riscv32-softmmu s390x-softmmu sh4-softmmu
 | 
			
		||||
      sparc64-softmmu x86_64-softmmu xtensa-softmmu nios2-softmmu or1k-softmmu"
 | 
			
		||||
 - make -j2
 | 
			
		||||
 - make -j2 check
 | 
			
		||||
 | 
			
		||||
build-disabled:
 | 
			
		||||
 script:
 | 
			
		||||
 - ./configure --enable-werror --disable-rdma --disable-slirp --disable-curl
 | 
			
		||||
      --disable-capstone --disable-live-block-migration --disable-glusterfs
 | 
			
		||||
      --disable-replication --disable-coroutine-pool --disable-smartcard
 | 
			
		||||
      --disable-guest-agent --disable-curses --disable-libxml2 --disable-tpm
 | 
			
		||||
      --disable-qom-cast-debug --disable-spice --disable-vhost-vsock
 | 
			
		||||
      --disable-vhost-net --disable-vhost-crypto --disable-vhost-user
 | 
			
		||||
      --target-list="i386-softmmu ppc64-softmmu mips64-softmmu i386-linux-user"
 | 
			
		||||
 - make -j2
 | 
			
		||||
 - make -j2 check-qtest SPEED=slow
 | 
			
		||||
 | 
			
		||||
build-tcg-disabled:
 | 
			
		||||
 script:
 | 
			
		||||
 - apt-get install -y -qq clang libgtk-3-dev libbluetooth-dev libusb-dev
 | 
			
		||||
 - ./configure --cc=clang --enable-werror --disable-tcg --audio-drv-list=""
 | 
			
		||||
 - make -j2
 | 
			
		||||
 - make check-unit
 | 
			
		||||
 - make check-qapi-schema
 | 
			
		||||
 - cd tests/qemu-iotests/
 | 
			
		||||
 - ./check -raw 001 002 003 004 005 008 009 010 011 012 021 025 032 033 048
 | 
			
		||||
            052 063 077 086 101 104 106 113 147 148 150 151 152 157 159 160
 | 
			
		||||
            163 170 171 183 184 192 194 197 205 208 215 221 222 226 227 236
 | 
			
		||||
 - ./check -qcow2 001 002 003 004 005 007 008 009 010 011 012 013 017 018 019
 | 
			
		||||
            020 021 022 024 025 027 028 029 031 032 033 034 035 036 037 038
 | 
			
		||||
            039 040 042 043 046 047 048 049 050 051 052 053 054 056 057 058
 | 
			
		||||
            060 061 062 063 065 066 067 068 069 071 072 073 074 079 080 082
 | 
			
		||||
            085 086 089 090 091 095 096 097 098 099 102 103 104 105 107 108
 | 
			
		||||
            110 111 114 117 120 122 124 126 127 129 130 132 133 134 137 138
 | 
			
		||||
            139 140 141 142 143 144 145 147 150 151 152 154 155 156 157 158
 | 
			
		||||
            161 165 170 172 174 176 177 179 184 186 187 190 192 194 195 196
 | 
			
		||||
            197 200 202 203 205 208 209 214 215 216 217 218 222 226 227 229 234
 | 
			
		||||
 | 
			
		||||
build-user:
 | 
			
		||||
 script:
 | 
			
		||||
 - ./configure --enable-werror --disable-system --disable-guest-agent
 | 
			
		||||
               --disable-capstone --disable-slirp --disable-fdt
 | 
			
		||||
 - make -j2
 | 
			
		||||
 - make run-tcg-tests-i386-linux-user run-tcg-tests-x86_64-linux-user
 | 
			
		||||
 | 
			
		||||
build-clang:
 | 
			
		||||
 script:
 | 
			
		||||
 - apt-get install -y -qq clang libsdl2-dev
 | 
			
		||||
      xfslibs-dev libiscsi-dev libnfs-dev libseccomp-dev gnutls-dev librbd-dev
 | 
			
		||||
 - ./configure --cc=clang --cxx=clang++ --enable-werror
 | 
			
		||||
      --target-list="alpha-softmmu arm-softmmu m68k-softmmu mips64-softmmu
 | 
			
		||||
                     ppc-softmmu s390x-softmmu x86_64-softmmu arm-linux-user"
 | 
			
		||||
 - make -j2
 | 
			
		||||
 - make -j2 check
 | 
			
		||||
 | 
			
		||||
build-tci:
 | 
			
		||||
 script:
 | 
			
		||||
 - TARGETS="aarch64 alpha arm hppa m68k microblaze moxie ppc64 s390x x86_64"
 | 
			
		||||
 - ./configure --enable-tcg-interpreter
 | 
			
		||||
      --target-list="$(for tg in $TARGETS; do echo -n ${tg}'-softmmu '; done)"
 | 
			
		||||
 - make -j2
 | 
			
		||||
 - make tests/boot-serial-test tests/cdrom-test tests/pxe-test
 | 
			
		||||
 - for tg in $TARGETS ; do
 | 
			
		||||
     export QTEST_QEMU_BINARY="${tg}-softmmu/qemu-system-${tg}" ;
 | 
			
		||||
     ./tests/boot-serial-test || exit 1 ;
 | 
			
		||||
     ./tests/cdrom-test || exit 1 ;
 | 
			
		||||
   done
 | 
			
		||||
 - QTEST_QEMU_BINARY="x86_64-softmmu/qemu-system-x86_64" ./tests/pxe-test
 | 
			
		||||
 - QTEST_QEMU_BINARY="s390x-softmmu/qemu-system-s390x" ./tests/pxe-test -m slow
 | 
			
		||||
							
								
								
									
										60
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										60
									
								
								.gitmodules
									
									
									
									
										vendored
									
									
								
							@@ -1,60 +1,12 @@
 | 
			
		||||
[submodule "roms/vgabios"]
 | 
			
		||||
	path = roms/vgabios
 | 
			
		||||
	url = git://git.kernel.org/pub/scm/virt/kvm/vgabios.git/
 | 
			
		||||
[submodule "roms/seabios"]
 | 
			
		||||
	path = roms/seabios
 | 
			
		||||
	url = https://git.qemu.org/git/seabios.git/
 | 
			
		||||
	url = git://git.qemu.org/seabios.git/
 | 
			
		||||
[submodule "roms/SLOF"]
 | 
			
		||||
	path = roms/SLOF
 | 
			
		||||
	url = https://git.qemu.org/git/SLOF.git
 | 
			
		||||
	url = git://git.qemu.org/SLOF.git
 | 
			
		||||
[submodule "roms/ipxe"]
 | 
			
		||||
	path = roms/ipxe
 | 
			
		||||
	url = https://git.qemu.org/git/ipxe.git
 | 
			
		||||
[submodule "roms/openbios"]
 | 
			
		||||
	path = roms/openbios
 | 
			
		||||
	url = https://git.qemu.org/git/openbios.git
 | 
			
		||||
[submodule "roms/openhackware"]
 | 
			
		||||
	path = roms/openhackware
 | 
			
		||||
	url = https://git.qemu.org/git/openhackware.git
 | 
			
		||||
[submodule "roms/qemu-palcode"]
 | 
			
		||||
	path = roms/qemu-palcode
 | 
			
		||||
	url = https://git.qemu.org/git/qemu-palcode.git
 | 
			
		||||
[submodule "roms/sgabios"]
 | 
			
		||||
	path = roms/sgabios
 | 
			
		||||
	url = https://git.qemu.org/git/sgabios.git
 | 
			
		||||
[submodule "dtc"]
 | 
			
		||||
	path = dtc
 | 
			
		||||
	url = https://git.qemu.org/git/dtc.git
 | 
			
		||||
[submodule "roms/u-boot"]
 | 
			
		||||
	path = roms/u-boot
 | 
			
		||||
	url = https://git.qemu.org/git/u-boot.git
 | 
			
		||||
[submodule "roms/skiboot"]
 | 
			
		||||
	path = roms/skiboot
 | 
			
		||||
	url = https://git.qemu.org/git/skiboot.git
 | 
			
		||||
[submodule "roms/QemuMacDrivers"]
 | 
			
		||||
	path = roms/QemuMacDrivers
 | 
			
		||||
	url = https://git.qemu.org/git/QemuMacDrivers.git
 | 
			
		||||
[submodule "ui/keycodemapdb"]
 | 
			
		||||
	path = ui/keycodemapdb
 | 
			
		||||
	url = https://git.qemu.org/git/keycodemapdb.git
 | 
			
		||||
[submodule "capstone"]
 | 
			
		||||
	path = capstone
 | 
			
		||||
	url = https://git.qemu.org/git/capstone.git
 | 
			
		||||
[submodule "roms/seabios-hppa"]
 | 
			
		||||
	path = roms/seabios-hppa
 | 
			
		||||
	url = https://git.qemu.org/git/seabios-hppa.git
 | 
			
		||||
[submodule "roms/u-boot-sam460ex"]
 | 
			
		||||
	path = roms/u-boot-sam460ex
 | 
			
		||||
	url = https://git.qemu.org/git/u-boot-sam460ex.git
 | 
			
		||||
[submodule "tests/fp/berkeley-testfloat-3"]
 | 
			
		||||
	path = tests/fp/berkeley-testfloat-3
 | 
			
		||||
	url = https://git.qemu.org/git/berkeley-testfloat-3.git
 | 
			
		||||
[submodule "tests/fp/berkeley-softfloat-3"]
 | 
			
		||||
	path = tests/fp/berkeley-softfloat-3
 | 
			
		||||
	url = https://git.qemu.org/git/berkeley-softfloat-3.git
 | 
			
		||||
[submodule "roms/edk2"]
 | 
			
		||||
	path = roms/edk2
 | 
			
		||||
	url = https://git.qemu.org/git/edk2.git
 | 
			
		||||
[submodule "slirp"]
 | 
			
		||||
	path = slirp
 | 
			
		||||
	url = https://git.qemu.org/git/libslirp.git
 | 
			
		||||
[submodule "roms/opensbi"]
 | 
			
		||||
	path = roms/opensbi
 | 
			
		||||
	url = 	https://git.qemu.org/git/opensbi.git
 | 
			
		||||
	url = git://git.qemu.org/ipxe.git
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										51
									
								
								.gitpublish
									
									
									
									
									
								
							
							
						
						
									
										51
									
								
								.gitpublish
									
									
									
									
									
								
							@@ -1,51 +0,0 @@
 | 
			
		||||
#
 | 
			
		||||
# Common git-publish profiles that can be used to send patches to QEMU upstream.
 | 
			
		||||
#
 | 
			
		||||
# See https://github.com/stefanha/git-publish for more information
 | 
			
		||||
#
 | 
			
		||||
[gitpublishprofile "default"]
 | 
			
		||||
base = master
 | 
			
		||||
to = qemu-devel@nongnu.org
 | 
			
		||||
cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null
 | 
			
		||||
 | 
			
		||||
[gitpublishprofile "rfc"]
 | 
			
		||||
base = master
 | 
			
		||||
prefix = RFC PATCH
 | 
			
		||||
to = qemu-devel@nongnu.org
 | 
			
		||||
cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null
 | 
			
		||||
 | 
			
		||||
[gitpublishprofile "stable"]
 | 
			
		||||
base = master
 | 
			
		||||
to = qemu-devel@nongnu.org
 | 
			
		||||
cc = qemu-stable@nongnu.org
 | 
			
		||||
cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null
 | 
			
		||||
 | 
			
		||||
[gitpublishprofile "trivial"]
 | 
			
		||||
base = master
 | 
			
		||||
to = qemu-devel@nongnu.org
 | 
			
		||||
cc = qemu-trivial@nongnu.org
 | 
			
		||||
cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null
 | 
			
		||||
 | 
			
		||||
[gitpublishprofile "block"]
 | 
			
		||||
base = master
 | 
			
		||||
to = qemu-devel@nongnu.org
 | 
			
		||||
cc = qemu-block@nongnu.org
 | 
			
		||||
cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null
 | 
			
		||||
 | 
			
		||||
[gitpublishprofile "arm"]
 | 
			
		||||
base = master
 | 
			
		||||
to = qemu-devel@nongnu.org
 | 
			
		||||
cc = qemu-arm@nongnu.org
 | 
			
		||||
cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null
 | 
			
		||||
 | 
			
		||||
[gitpublishprofile "s390"]
 | 
			
		||||
base = master
 | 
			
		||||
to = qemu-devel@nongnu.org
 | 
			
		||||
cc = qemu-s390@nongnu.org
 | 
			
		||||
cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null
 | 
			
		||||
 | 
			
		||||
[gitpublishprofile "ppc"]
 | 
			
		||||
base = master
 | 
			
		||||
to = qemu-devel@nongnu.org
 | 
			
		||||
cc = qemu-ppc@nongnu.org
 | 
			
		||||
cccmd = scripts/get_maintainer.pl --noroles --norolestats --nogit --nogit-fallback 2>/dev/null
 | 
			
		||||
							
								
								
									
										39
									
								
								.mailmap
									
									
									
									
									
								
							
							
						
						
									
										39
									
								
								.mailmap
									
									
									
									
									
								
							@@ -1,39 +0,0 @@
 | 
			
		||||
# This mailmap fixes up author names/addresses.
 | 
			
		||||
 | 
			
		||||
# The first section translates weird addresses from the original git import
 | 
			
		||||
# into proper addresses so that they are counted properly by git shortlog.
 | 
			
		||||
Andrzej Zaborowski <balrogg@gmail.com> balrog <balrog@c046a42c-6fe2-441c-8c8c-71466251a162>
 | 
			
		||||
Anthony Liguori <anthony@codemonkey.ws> aliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>
 | 
			
		||||
Anthony Liguori <anthony@codemonkey.ws> Anthony Liguori <aliguori@us.ibm.com>
 | 
			
		||||
Aurelien Jarno <aurelien@aurel32.net> aurel32 <aurel32@c046a42c-6fe2-441c-8c8c-71466251a162>
 | 
			
		||||
Blue Swirl <blauwirbel@gmail.com> blueswir1 <blueswir1@c046a42c-6fe2-441c-8c8c-71466251a162>
 | 
			
		||||
Edgar E. Iglesias <edgar.iglesias@gmail.com> edgar_igl <edgar_igl@c046a42c-6fe2-441c-8c8c-71466251a162>
 | 
			
		||||
Fabrice Bellard <fabrice@bellard.org> bellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162>
 | 
			
		||||
James Hogan <jhogan@kernel.org> <james.hogan@imgtec.com>
 | 
			
		||||
Jocelyn Mayer <l_indien@magic.fr> j_mayer <j_mayer@c046a42c-6fe2-441c-8c8c-71466251a162>
 | 
			
		||||
Paul Brook <paul@codesourcery.com> pbrook <pbrook@c046a42c-6fe2-441c-8c8c-71466251a162>
 | 
			
		||||
Yongbok Kim <yongbok.kim@mips.com> <yongbok.kim@imgtec.com>
 | 
			
		||||
Aleksandar Markovic <amarkovic@wavecomp.com> <aleksandar.markovic@mips.com>
 | 
			
		||||
Aleksandar Markovic <amarkovic@wavecomp.com> <aleksandar.markovic@imgtec.com>
 | 
			
		||||
Paul Burton <pburton@wavecomp.com> <paul.burton@mips.com>
 | 
			
		||||
Paul Burton <pburton@wavecomp.com> <paul.burton@imgtec.com>
 | 
			
		||||
Paul Burton <pburton@wavecomp.com> <paul@archlinuxmips.org>
 | 
			
		||||
Thiemo Seufer <ths@networkno.de> ths <ths@c046a42c-6fe2-441c-8c8c-71466251a162>
 | 
			
		||||
malc <av1474@comtv.ru> malc <malc@c046a42c-6fe2-441c-8c8c-71466251a162>
 | 
			
		||||
 | 
			
		||||
# There is also a:
 | 
			
		||||
#    (no author) <(no author)@c046a42c-6fe2-441c-8c8c-71466251a162>
 | 
			
		||||
# for the cvs2svn initialization commit e63c3dc74bf.
 | 
			
		||||
 | 
			
		||||
# Next, translate a few commits where mailman rewrote the From: line due
 | 
			
		||||
# to strict SPF, although we prefer to avoid adding more entries like that.
 | 
			
		||||
Ed Swierk <eswierk@skyportsystems.com> Ed Swierk via Qemu-devel <qemu-devel@nongnu.org>
 | 
			
		||||
Ian McKellar <ianloic@google.com> Ian McKellar via Qemu-devel <qemu-devel@nongnu.org>
 | 
			
		||||
Julia Suvorova <jusual@mail.ru> Julia Suvorova via Qemu-devel <qemu-devel@nongnu.org>
 | 
			
		||||
Justin Terry (VM) <juterry@microsoft.com> Justin Terry (VM) via Qemu-devel <qemu-devel@nongnu.org>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# Also list preferred name forms where people have changed their
 | 
			
		||||
# git author config, or had utf8/latin1 encoding issues.
 | 
			
		||||
Daniel P. Berrangé <berrange@redhat.com>
 | 
			
		||||
Reimar Döffinger <Reimar.Doeffinger@gmx.de>
 | 
			
		||||
							
								
								
									
										302
									
								
								.patchew.yml
									
									
									
									
									
								
							
							
						
						
									
										302
									
								
								.patchew.yml
									
									
									
									
									
								
							@@ -1,302 +0,0 @@
 | 
			
		||||
---
 | 
			
		||||
# Note: this file is still unused.  It serves as a documentation for the
 | 
			
		||||
# Patchew configuration in case patchew.org disappears or has to be
 | 
			
		||||
# reinstalled.
 | 
			
		||||
#
 | 
			
		||||
# Patchew configuration is available to project administrators at
 | 
			
		||||
# https://patchew.org/api/v1/projects/1/config/ and can be configured
 | 
			
		||||
# to YAML using the following Python script:
 | 
			
		||||
#
 | 
			
		||||
#     import json
 | 
			
		||||
#     import sys
 | 
			
		||||
#     import ruamel.yaml
 | 
			
		||||
#
 | 
			
		||||
#     json_str = sys.stdin.read()
 | 
			
		||||
#     yaml = ruamel.yaml.YAML()
 | 
			
		||||
#     yaml.explicit_start = True
 | 
			
		||||
#     data = json.loads(json_str, object_pairs_hook=ruamel.yaml.comments.CommentedMap)
 | 
			
		||||
#     ruamel.yaml.scalarstring.walk_tree(data)
 | 
			
		||||
#     yaml.dump(data, sys.stdout)
 | 
			
		||||
 | 
			
		||||
email:
 | 
			
		||||
  notifications:
 | 
			
		||||
    timeouts:
 | 
			
		||||
      event: TestingReport
 | 
			
		||||
      enabled: true
 | 
			
		||||
      to_user: false
 | 
			
		||||
      reply_subject: true
 | 
			
		||||
      set_reply_to: true
 | 
			
		||||
      in_reply_to: true
 | 
			
		||||
      reply_to_all: false
 | 
			
		||||
      subject_template: none
 | 
			
		||||
      to: fam@euphon.net
 | 
			
		||||
      cc: ''
 | 
			
		||||
      body_template: |
 | 
			
		||||
        {% if not is_timeout %} {{ cancel }} {% endif %}
 | 
			
		||||
 | 
			
		||||
        Test '{{ test }}' timeout, log:
 | 
			
		||||
 | 
			
		||||
        {{ log }}
 | 
			
		||||
    ENOSPC:
 | 
			
		||||
      event: TestingReport
 | 
			
		||||
      enabled: true
 | 
			
		||||
      to_user: false
 | 
			
		||||
      reply_subject: false
 | 
			
		||||
      set_reply_to: false
 | 
			
		||||
      in_reply_to: true
 | 
			
		||||
      reply_to_all: false
 | 
			
		||||
      subject_template: Out of space error
 | 
			
		||||
      to: fam@euphon.net
 | 
			
		||||
      cc: ''
 | 
			
		||||
      body_template: |
 | 
			
		||||
        {% if passed %}
 | 
			
		||||
          {{ cancel }}
 | 
			
		||||
        {% endif %}
 | 
			
		||||
 | 
			
		||||
        {% if 'No space left on device' in log %}
 | 
			
		||||
        Tester {{ tester }} out of space when running {{ test }}
 | 
			
		||||
 | 
			
		||||
          {{ log }}
 | 
			
		||||
        {% else %}
 | 
			
		||||
          {{ cancel }}
 | 
			
		||||
        {% endif %}
 | 
			
		||||
    FailureShort:
 | 
			
		||||
      event: TestingReport
 | 
			
		||||
      enabled: true
 | 
			
		||||
      to_user: false
 | 
			
		||||
      reply_subject: true
 | 
			
		||||
      set_reply_to: true
 | 
			
		||||
      in_reply_to: true
 | 
			
		||||
      reply_to_all: true
 | 
			
		||||
      subject_template: Testing failed
 | 
			
		||||
      to: ''
 | 
			
		||||
      cc: ''
 | 
			
		||||
      body_template: |
 | 
			
		||||
        {% if passed or not obj.message_id or is_timeout %}
 | 
			
		||||
          {{ cancel }}
 | 
			
		||||
        {% endif %}
 | 
			
		||||
        {% if 'No space left on device' in log %}
 | 
			
		||||
          {{ cancel }}
 | 
			
		||||
        {% endif %}
 | 
			
		||||
        Patchew URL: https://patchew.org/QEMU/{{ obj.message_id }}/
 | 
			
		||||
 | 
			
		||||
        {% ansi2text log as logtext %}
 | 
			
		||||
        {% if test == "checkpatch" %}
 | 
			
		||||
        Hi,
 | 
			
		||||
 | 
			
		||||
        This series seems to have some coding style problems. See output below for
 | 
			
		||||
        more information:
 | 
			
		||||
 | 
			
		||||
        {{ logtext }}
 | 
			
		||||
        {% elif test == "docker-mingw@fedora" or test == "docker-quick@centos7" or test == "asan" %}
 | 
			
		||||
        Hi,
 | 
			
		||||
 | 
			
		||||
        This series failed the {{ test }} build test. Please find the testing commands and
 | 
			
		||||
        their output below. If you have Docker installed, you can probably reproduce it
 | 
			
		||||
        locally.
 | 
			
		||||
 | 
			
		||||
        {% lines_between logtext start="^=== TEST SCRIPT BEGIN ===$" stop="^=== TEST SCRIPT END ===$" %}
 | 
			
		||||
        {% lines_between logtext start="^=== OUTPUT BEGIN ===$" stop="=== OUTPUT END ===$" as output %}
 | 
			
		||||
        {% grep_C output regex="\b(FAIL|XPASS|ERROR|WARN|error:|warning:)" n=3 %}
 | 
			
		||||
        {% elif test == "s390x" or test == "FreeBSD" or test == "ppcle" or test == "ppcbe" %}
 | 
			
		||||
        Hi,
 | 
			
		||||
 | 
			
		||||
        This series failed build test on {{test}} host. Please find the details below.
 | 
			
		||||
 | 
			
		||||
        {% lines_between logtext start="^=== TEST SCRIPT BEGIN ===$" stop="^=== TEST SCRIPT END ===$" %}
 | 
			
		||||
        {% lines_between logtext start="^=== OUTPUT BEGIN ===$" stop="=== OUTPUT END ===$" as output %}
 | 
			
		||||
        {% grep_C output regex="\b(FAIL|XPASS|ERROR|WARN|error:|warning:)" n=3 %}
 | 
			
		||||
        {% else %}
 | 
			
		||||
        {{ cancel }}
 | 
			
		||||
        {% endif %}
 | 
			
		||||
 | 
			
		||||
        The full log is available at
 | 
			
		||||
        {{ log_url }}.
 | 
			
		||||
        ---
 | 
			
		||||
        Email generated automatically by Patchew [https://patchew.org/].
 | 
			
		||||
        Please send your feedback to patchew-devel@redhat.com
 | 
			
		||||
testing:
 | 
			
		||||
  tests:
 | 
			
		||||
    asan:
 | 
			
		||||
      enabled: true
 | 
			
		||||
      requirements: docker
 | 
			
		||||
      timeout: 3600
 | 
			
		||||
      script: |
 | 
			
		||||
        #!/bin/bash
 | 
			
		||||
        time make docker-test-debug@fedora TARGET_LIST=x86_64-softmmu J=14 NETWORK=1
 | 
			
		||||
    docker-quick@centos7:
 | 
			
		||||
      enabled: false
 | 
			
		||||
      requirements: docker,x86_64
 | 
			
		||||
      timeout: 3600
 | 
			
		||||
      script: |
 | 
			
		||||
        #!/bin/bash
 | 
			
		||||
        time make docker-test-quick@centos7 SHOW_ENV=1 J=14 NETWORK=1
 | 
			
		||||
    checkpatch:
 | 
			
		||||
      enabled: true
 | 
			
		||||
      requirements: ''
 | 
			
		||||
      timeout: 600
 | 
			
		||||
      script: |
 | 
			
		||||
        #!/bin/bash
 | 
			
		||||
        git rev-parse base > /dev/null || exit 0
 | 
			
		||||
        git config --local diff.renamelimit 0
 | 
			
		||||
        git config --local diff.renames True
 | 
			
		||||
        git config --local diff.algorithm histogram
 | 
			
		||||
        ./scripts/checkpatch.pl --mailback base..
 | 
			
		||||
    docker-mingw@fedora:
 | 
			
		||||
      enabled: true
 | 
			
		||||
      requirements: docker,x86_64
 | 
			
		||||
      timeout: 3600
 | 
			
		||||
      script: |
 | 
			
		||||
        #! /bin/bash
 | 
			
		||||
        test "$(uname -m)" = "x86_64"
 | 
			
		||||
    ppcle:
 | 
			
		||||
      enabled: false
 | 
			
		||||
      requirements: ppcle
 | 
			
		||||
      timeout: 3600
 | 
			
		||||
      script: |
 | 
			
		||||
        #!/bin/bash
 | 
			
		||||
        # Testing script will be invoked under the git checkout with
 | 
			
		||||
        # HEAD pointing to a commit that has the patches applied on top of "base"
 | 
			
		||||
        # branch
 | 
			
		||||
        set -e
 | 
			
		||||
        CC=$HOME/bin/cc
 | 
			
		||||
        INSTALL=$PWD/install
 | 
			
		||||
        BUILD=$PWD/build
 | 
			
		||||
        mkdir -p $BUILD $INSTALL
 | 
			
		||||
        SRC=$PWD
 | 
			
		||||
        cd $BUILD
 | 
			
		||||
        $SRC/configure --cc=$CC --prefix=$INSTALL
 | 
			
		||||
        make -j4
 | 
			
		||||
        # XXX: we need reliable clean up
 | 
			
		||||
        # make check -j4 V=1
 | 
			
		||||
        make install
 | 
			
		||||
 | 
			
		||||
        echo
 | 
			
		||||
        echo "=== ENV ==="
 | 
			
		||||
        env
 | 
			
		||||
 | 
			
		||||
        echo
 | 
			
		||||
        echo "=== PACKAGES ==="
 | 
			
		||||
        rpm -qa
 | 
			
		||||
    ppcbe:
 | 
			
		||||
      enabled: false
 | 
			
		||||
      requirements: ppcbe
 | 
			
		||||
      timeout: 3600
 | 
			
		||||
      script: |
 | 
			
		||||
        #!/bin/bash
 | 
			
		||||
        # Testing script will be invoked under the git checkout with
 | 
			
		||||
        # HEAD pointing to a commit that has the patches applied on top of "base"
 | 
			
		||||
        # branch
 | 
			
		||||
        set -e
 | 
			
		||||
        CC=$HOME/bin/cc
 | 
			
		||||
        INSTALL=$PWD/install
 | 
			
		||||
        BUILD=$PWD/build
 | 
			
		||||
        mkdir -p $BUILD $INSTALL
 | 
			
		||||
        SRC=$PWD
 | 
			
		||||
        cd $BUILD
 | 
			
		||||
        $SRC/configure --cc=$CC --prefix=$INSTALL
 | 
			
		||||
        make -j4
 | 
			
		||||
        # XXX: we need reliable clean up
 | 
			
		||||
        # make check -j4 V=1
 | 
			
		||||
        make install
 | 
			
		||||
 | 
			
		||||
        echo
 | 
			
		||||
        echo "=== ENV ==="
 | 
			
		||||
        env
 | 
			
		||||
 | 
			
		||||
        echo
 | 
			
		||||
        echo "=== PACKAGES ==="
 | 
			
		||||
        rpm -qa
 | 
			
		||||
    FreeBSD:
 | 
			
		||||
      enabled: true
 | 
			
		||||
      requirements: qemu-x86,x86_64,git
 | 
			
		||||
      timeout: 3600
 | 
			
		||||
      script: |
 | 
			
		||||
        #!/bin/bash
 | 
			
		||||
        # Testing script will be invoked under the git checkout with
 | 
			
		||||
        # HEAD pointing to a commit that has the patches applied on top of "base"
 | 
			
		||||
        # branch
 | 
			
		||||
        if qemu-system-x86_64 --help >/dev/null 2>&1; then
 | 
			
		||||
          QEMU=qemu-system-x86_64
 | 
			
		||||
        elif /usr/libexec/qemu-kvm --help >/dev/null 2>&1; then
 | 
			
		||||
          QEMU=/usr/libexec/qemu-kvm
 | 
			
		||||
        else
 | 
			
		||||
          exit 1
 | 
			
		||||
        fi
 | 
			
		||||
        make vm-build-freebsd J=21 QEMU=$QEMU
 | 
			
		||||
        exit 0
 | 
			
		||||
    docker-clang@ubuntu:
 | 
			
		||||
      enabled: true
 | 
			
		||||
      requirements: docker,x86_64
 | 
			
		||||
      timeout: 3600
 | 
			
		||||
      script: |
 | 
			
		||||
        #!/bin/bash
 | 
			
		||||
        time make docker-test-clang@ubuntu SHOW_ENV=1 J=14 NETWORK=1
 | 
			
		||||
    s390x:
 | 
			
		||||
      enabled: true
 | 
			
		||||
      requirements: s390x
 | 
			
		||||
      timeout: 3600
 | 
			
		||||
      script: |
 | 
			
		||||
        #!/bin/bash
 | 
			
		||||
        # Testing script will be invoked under the git checkout with
 | 
			
		||||
        # HEAD pointing to a commit that has the patches applied on top of "base"
 | 
			
		||||
        # branch
 | 
			
		||||
        set -e
 | 
			
		||||
        CC=$HOME/bin/cc
 | 
			
		||||
        INSTALL=$PWD/install
 | 
			
		||||
        BUILD=$PWD/build
 | 
			
		||||
        mkdir -p $BUILD $INSTALL
 | 
			
		||||
        SRC=$PWD
 | 
			
		||||
        cd $BUILD
 | 
			
		||||
        $SRC/configure --cc=$CC --prefix=$INSTALL
 | 
			
		||||
        make -j4
 | 
			
		||||
        # XXX: we need reliable clean up
 | 
			
		||||
        # make check -j4 V=1
 | 
			
		||||
        make install
 | 
			
		||||
 | 
			
		||||
        echo
 | 
			
		||||
        echo "=== ENV ==="
 | 
			
		||||
        env
 | 
			
		||||
 | 
			
		||||
        echo
 | 
			
		||||
        echo "=== PACKAGES ==="
 | 
			
		||||
        rpm -qa
 | 
			
		||||
  requirements:
 | 
			
		||||
    x86_64:
 | 
			
		||||
      script: |
 | 
			
		||||
        #! /bin/bash
 | 
			
		||||
        test "$(uname -m)" = "x86_64"
 | 
			
		||||
    qemu-x86:
 | 
			
		||||
      script: |
 | 
			
		||||
        #!/bin/bash
 | 
			
		||||
        if qemu-system-x86_64 --help >/dev/null 2>&1; then
 | 
			
		||||
          :
 | 
			
		||||
        elif /usr/libexec/qemu-kvm --help >/dev/null 2>&1; then
 | 
			
		||||
          :
 | 
			
		||||
        else
 | 
			
		||||
          exit 1
 | 
			
		||||
        fi
 | 
			
		||||
    ppcle:
 | 
			
		||||
      script: |
 | 
			
		||||
        #!/bin/bash
 | 
			
		||||
        test "$(uname -m)" = "ppc64le"
 | 
			
		||||
    ppcbe:
 | 
			
		||||
      script: |
 | 
			
		||||
        #!/bin/bash
 | 
			
		||||
        test "$(uname -m)" = "ppc64"
 | 
			
		||||
    git:
 | 
			
		||||
      script: |
 | 
			
		||||
        #! /bin/bash
 | 
			
		||||
        git config user.name > /dev/null 2>&1
 | 
			
		||||
    docker:
 | 
			
		||||
      script: |
 | 
			
		||||
        #!/bin/bash
 | 
			
		||||
        docker ps || sudo -n docker ps
 | 
			
		||||
    s390x:
 | 
			
		||||
      script: |
 | 
			
		||||
        #!/bin/bash
 | 
			
		||||
        test "$(uname -m)" = "s390x"
 | 
			
		||||
git:
 | 
			
		||||
  push_to: git@github.com:patchew-project/qemu
 | 
			
		||||
  public_repo: https://github.com/patchew-project/qemu
 | 
			
		||||
  url_template: https://github.com/patchew-project/qemu/tree/%t
 | 
			
		||||
@@ -1,39 +0,0 @@
 | 
			
		||||
language: c
 | 
			
		||||
git:
 | 
			
		||||
   submodules: false
 | 
			
		||||
env:
 | 
			
		||||
  global:
 | 
			
		||||
    - LC_ALL=C
 | 
			
		||||
  matrix:
 | 
			
		||||
    - IMAGE=debian-amd64
 | 
			
		||||
      TARGET_LIST=x86_64-softmmu,x86_64-linux-user
 | 
			
		||||
    - IMAGE=debian-win32-cross
 | 
			
		||||
      TARGET_LIST=arm-softmmu,i386-softmmu,lm32-softmmu
 | 
			
		||||
    - IMAGE=debian-win64-cross
 | 
			
		||||
      TARGET_LIST=aarch64-softmmu,sparc64-softmmu,x86_64-softmmu
 | 
			
		||||
    - IMAGE=debian-armel-cross
 | 
			
		||||
      TARGET_LIST=arm-softmmu,arm-linux-user,armeb-linux-user
 | 
			
		||||
    - IMAGE=debian-armhf-cross
 | 
			
		||||
      TARGET_LIST=arm-softmmu,arm-linux-user,armeb-linux-user
 | 
			
		||||
    - IMAGE=debian-arm64-cross
 | 
			
		||||
      TARGET_LIST=aarch64-softmmu,aarch64-linux-user
 | 
			
		||||
    - IMAGE=debian-s390x-cross
 | 
			
		||||
      TARGET_LIST=s390x-softmmu,s390x-linux-user
 | 
			
		||||
    - IMAGE=debian-mips-cross
 | 
			
		||||
      TARGET_LIST=mips-softmmu,mipsel-linux-user
 | 
			
		||||
    - IMAGE=debian-mips64el-cross
 | 
			
		||||
      TARGET_LIST=mips64el-softmmu,mips64el-linux-user
 | 
			
		||||
    - IMAGE=debian-ppc64el-cross
 | 
			
		||||
      TARGET_LIST=ppc64-softmmu,ppc64-linux-user,ppc64abi32-linux-user
 | 
			
		||||
build:
 | 
			
		||||
  pre_ci:
 | 
			
		||||
    - make docker-image-${IMAGE} V=1
 | 
			
		||||
  pre_ci_boot:
 | 
			
		||||
    image_name: qemu
 | 
			
		||||
    image_tag: ${IMAGE}
 | 
			
		||||
    pull: false
 | 
			
		||||
    options: "-e HOME=/root"
 | 
			
		||||
  ci:
 | 
			
		||||
    - unset CC
 | 
			
		||||
    - ./configure ${QEMU_CONFIGURE_OPTS} --target-list=${TARGET_LIST}
 | 
			
		||||
    - make -j$(($(getconf _NPROCESSORS_ONLN) + 1))
 | 
			
		||||
							
								
								
									
										298
									
								
								.travis.yml
									
									
									
									
									
								
							
							
						
						
									
										298
									
								
								.travis.yml
									
									
									
									
									
								
							@@ -1,298 +0,0 @@
 | 
			
		||||
# The current Travis default is a VM based 16.04 Xenial on GCE
 | 
			
		||||
# Additional builds with specific requirements for a full VM need to
 | 
			
		||||
# be added as additional matrix: entries later on
 | 
			
		||||
dist: xenial
 | 
			
		||||
language: c
 | 
			
		||||
compiler:
 | 
			
		||||
  - gcc
 | 
			
		||||
cache: ccache
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
addons:
 | 
			
		||||
  apt:
 | 
			
		||||
    packages:
 | 
			
		||||
      # Build dependencies
 | 
			
		||||
      - libaio-dev
 | 
			
		||||
      - libattr1-dev
 | 
			
		||||
      - libbrlapi-dev
 | 
			
		||||
      - libcap-ng-dev
 | 
			
		||||
      - libgcc-4.8-dev
 | 
			
		||||
      - libgnutls-dev
 | 
			
		||||
      - libgtk-3-dev
 | 
			
		||||
      - libiscsi-dev
 | 
			
		||||
      - liblttng-ust-dev
 | 
			
		||||
      - libncurses5-dev
 | 
			
		||||
      - libnfs-dev
 | 
			
		||||
      - libnss3-dev
 | 
			
		||||
      - libpixman-1-dev
 | 
			
		||||
      - libpng12-dev
 | 
			
		||||
      - librados-dev
 | 
			
		||||
      - libsdl1.2-dev
 | 
			
		||||
      - libseccomp-dev
 | 
			
		||||
      - libspice-protocol-dev
 | 
			
		||||
      - libspice-server-dev
 | 
			
		||||
      - libssh-dev
 | 
			
		||||
      - liburcu-dev
 | 
			
		||||
      - libusb-1.0-0-dev
 | 
			
		||||
      - libvte-2.91-dev
 | 
			
		||||
      - sparse
 | 
			
		||||
      - uuid-dev
 | 
			
		||||
      - gcovr
 | 
			
		||||
  homebrew:
 | 
			
		||||
    packages:
 | 
			
		||||
      - glib
 | 
			
		||||
      - pixman
 | 
			
		||||
      - gnu-sed
 | 
			
		||||
    update: true
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# The channel name "irc.oftc.net#qemu" is encrypted against qemu/qemu
 | 
			
		||||
# to prevent IRC notifications from forks. This was created using:
 | 
			
		||||
# $ travis encrypt -r "qemu/qemu" "irc.oftc.net#qemu"
 | 
			
		||||
notifications:
 | 
			
		||||
  irc:
 | 
			
		||||
    channels:
 | 
			
		||||
      - secure: "F7GDRgjuOo5IUyRLqSkmDL7kvdU4UcH3Lm/W2db2JnDHTGCqgEdaYEYKciyCLZ57vOTsTsOgesN8iUT7hNHBd1KWKjZe9KDTZWppWRYVwAwQMzVeSOsbbU4tRoJ6Pp+3qhH1Z0eGYR9ZgKYAoTumDFgSAYRp4IscKS8jkoedOqM="
 | 
			
		||||
    on_success: change
 | 
			
		||||
    on_failure: always
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
env:
 | 
			
		||||
  global:
 | 
			
		||||
    - SRC_DIR="."
 | 
			
		||||
    - BUILD_DIR="."
 | 
			
		||||
    - BASE_CONFIG="--disable-docs --disable-tools"
 | 
			
		||||
    - TEST_CMD="make check -j3 V=1"
 | 
			
		||||
    # This is broadly a list of "mainline" softmmu targets which have support across the major distros
 | 
			
		||||
    - MAIN_SOFTMMU_TARGETS="aarch64-softmmu,arm-softmmu,i386-softmmu,mips-softmmu,mips64-softmmu,ppc64-softmmu,riscv64-softmmu,s390x-softmmu,x86_64-softmmu"
 | 
			
		||||
 | 
			
		||||
git:
 | 
			
		||||
  # we want to do this ourselves
 | 
			
		||||
  submodules: false
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
before_script:
 | 
			
		||||
  - mkdir -p ${BUILD_DIR} && cd ${BUILD_DIR}
 | 
			
		||||
  - ${SRC_DIR}/configure ${BASE_CONFIG} ${CONFIG} || { cat config.log && exit 1; }
 | 
			
		||||
script:
 | 
			
		||||
  - make -j3 && travis_retry ${TEST_CMD}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
matrix:
 | 
			
		||||
  include:
 | 
			
		||||
    - env:
 | 
			
		||||
        - CONFIG="--disable-system --static"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    # we split the system builds as it takes a while to build them all
 | 
			
		||||
    - env:
 | 
			
		||||
        - CONFIG="--disable-user --target-list=${MAIN_SOFTMMU_TARGETS}"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    - env:
 | 
			
		||||
        - CONFIG="--disable-user --target-list-exclude=${MAIN_SOFTMMU_TARGETS}"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    # Just build tools and run minimal unit and softfloat checks
 | 
			
		||||
    - env:
 | 
			
		||||
        - BASE_CONFIG="--enable-tools"
 | 
			
		||||
        - CONFIG="--disable-user --disable-system"
 | 
			
		||||
        - TEST_CMD="make check-unit check-softfloat -j3"
 | 
			
		||||
 | 
			
		||||
    - env:
 | 
			
		||||
        - CONFIG="--enable-debug --enable-debug-tcg --disable-user"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    # TCG debug can be run just on it's own and is mostly agnostic to user/softmmu distinctions
 | 
			
		||||
    - env:
 | 
			
		||||
        - CONFIG="--enable-debug-tcg --disable-system"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    - env:
 | 
			
		||||
        - CONFIG="--disable-linux-aio --disable-cap-ng --disable-attr --disable-brlapi --disable-libusb --disable-replication --target-list=${MAIN_SOFTMMU_TARGETS}"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    # Module builds are mostly of interest to major distros
 | 
			
		||||
    - env:
 | 
			
		||||
        - CONFIG="--enable-modules --target-list=${MAIN_SOFTMMU_TARGETS}"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    # Alternate coroutines implementations are only really of interest to KVM users
 | 
			
		||||
    # However we can't test against KVM on Travis so we can only run unit tests
 | 
			
		||||
    - env:
 | 
			
		||||
        - CONFIG="--with-coroutine=ucontext --disable-tcg"
 | 
			
		||||
        - TEST_CMD="make check-unit -j3 V=1"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    - env:
 | 
			
		||||
        - CONFIG="--with-coroutine=sigaltstack --disable-tcg"
 | 
			
		||||
        - TEST_CMD="make check-unit -j3 V=1"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    # Check we can build docs and tools (out of tree)
 | 
			
		||||
    - env:
 | 
			
		||||
        - BUILD_DIR="out-of-tree/build/dir" SRC_DIR="../../.."
 | 
			
		||||
        - BASE_CONFIG="--enable-tools --enable-docs"
 | 
			
		||||
        - CONFIG="--target-list=x86_64-softmmu,aarch64-linux-user"
 | 
			
		||||
      addons:
 | 
			
		||||
        apt:
 | 
			
		||||
          packages:
 | 
			
		||||
            - python-sphinx
 | 
			
		||||
            - texinfo
 | 
			
		||||
            - perl
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    # Test with Clang for compile portability (Travis uses clang-5.0)
 | 
			
		||||
    - env:
 | 
			
		||||
        - CONFIG="--disable-system"
 | 
			
		||||
      compiler: clang
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    - env:
 | 
			
		||||
        - CONFIG="--disable-user --target-list=${MAIN_SOFTMMU_TARGETS}"
 | 
			
		||||
      compiler: clang
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    - env:
 | 
			
		||||
        - CONFIG="--target-list=${MAIN_SOFTMMU_TARGETS} "
 | 
			
		||||
      compiler: clang
 | 
			
		||||
      before_script:
 | 
			
		||||
        - ./configure ${CONFIG} --extra-cflags="-fsanitize=undefined -Werror" || { cat config.log && exit 1; }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    - env:
 | 
			
		||||
        - CONFIG="--disable-user --target-list-exclude=${MAIN_SOFTMMU_TARGETS}"
 | 
			
		||||
      compiler: clang
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    # gprof/gcov are GCC features
 | 
			
		||||
    - env:
 | 
			
		||||
        - CONFIG="--enable-gprof --enable-gcov --disable-pie --target-list=${MAIN_SOFTMMU_TARGETS}"
 | 
			
		||||
      after_success:
 | 
			
		||||
        - ${SRC_DIR}/scripts/travis/coverage-summary.sh
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    # We manually include builds which we disable "make check" for
 | 
			
		||||
    - env:
 | 
			
		||||
        - CONFIG="--without-default-devices --disable-user"
 | 
			
		||||
        - TEST_CMD=""
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    # We manually include builds which we disable "make check" for
 | 
			
		||||
    - env:
 | 
			
		||||
        - CONFIG="--enable-debug --enable-tcg-interpreter"
 | 
			
		||||
        - TEST_CMD=""
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    # We don't need to exercise every backend with every front-end
 | 
			
		||||
    - env:
 | 
			
		||||
        - CONFIG="--enable-trace-backends=log,simple,syslog --disable-system"
 | 
			
		||||
        - TEST_CMD=""
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    - env:
 | 
			
		||||
        - CONFIG="--enable-trace-backends=ftrace --target-list=x86_64-softmmu"
 | 
			
		||||
        - TEST_CMD=""
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    - env:
 | 
			
		||||
        - CONFIG="--enable-trace-backends=ust --target-list=x86_64-softmmu"
 | 
			
		||||
        - TEST_CMD=""
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    # MacOSX builds
 | 
			
		||||
    - env:
 | 
			
		||||
        - CONFIG="--target-list=${MAIN_SOFTMMU_TARGETS}"
 | 
			
		||||
      os: osx
 | 
			
		||||
      osx_image: xcode9.4
 | 
			
		||||
      compiler: clang
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    - env:
 | 
			
		||||
        - CONFIG="--target-list=i386-softmmu,ppc-softmmu,ppc64-softmmu,m68k-softmmu,x86_64-softmmu"
 | 
			
		||||
      os: osx
 | 
			
		||||
      osx_image: xcode10.2
 | 
			
		||||
      compiler: clang
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    # Python builds
 | 
			
		||||
    - env:
 | 
			
		||||
        - CONFIG="--target-list=x86_64-softmmu"
 | 
			
		||||
      language: python
 | 
			
		||||
      python:
 | 
			
		||||
        - "3.4"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    - env:
 | 
			
		||||
        - CONFIG="--target-list=x86_64-softmmu"
 | 
			
		||||
      language: python
 | 
			
		||||
      python:
 | 
			
		||||
        - "3.6"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    # Acceptance (Functional) tests
 | 
			
		||||
    - env:
 | 
			
		||||
        - CONFIG="--python=/usr/bin/python3 --target-list=x86_64-softmmu,mips-softmmu,mips64el-softmmu,aarch64-softmmu,arm-softmmu,s390x-softmmu,alpha-softmmu"
 | 
			
		||||
        - TEST_CMD="make check-acceptance"
 | 
			
		||||
      after_failure:
 | 
			
		||||
        - cat tests/results/latest/job.log
 | 
			
		||||
      addons:
 | 
			
		||||
        apt:
 | 
			
		||||
          packages:
 | 
			
		||||
            - python3-pip
 | 
			
		||||
            - python3.5-venv
 | 
			
		||||
    # Using newer GCC with sanitizers
 | 
			
		||||
    - addons:
 | 
			
		||||
        apt:
 | 
			
		||||
          update: true
 | 
			
		||||
          sources:
 | 
			
		||||
            # PPAs for newer toolchains
 | 
			
		||||
            - ubuntu-toolchain-r-test
 | 
			
		||||
          packages:
 | 
			
		||||
            # Extra toolchains
 | 
			
		||||
            - gcc-9
 | 
			
		||||
            - g++-9
 | 
			
		||||
            # Build dependencies
 | 
			
		||||
            - libaio-dev
 | 
			
		||||
            - libattr1-dev
 | 
			
		||||
            - libbrlapi-dev
 | 
			
		||||
            - libcap-ng-dev
 | 
			
		||||
            - libgnutls-dev
 | 
			
		||||
            - libgtk-3-dev
 | 
			
		||||
            - libiscsi-dev
 | 
			
		||||
            - liblttng-ust-dev
 | 
			
		||||
            - libnfs-dev
 | 
			
		||||
            - libncurses5-dev
 | 
			
		||||
            - libnss3-dev
 | 
			
		||||
            - libpixman-1-dev
 | 
			
		||||
            - libpng12-dev
 | 
			
		||||
            - librados-dev
 | 
			
		||||
            - libsdl1.2-dev
 | 
			
		||||
            - libseccomp-dev
 | 
			
		||||
            - libspice-protocol-dev
 | 
			
		||||
            - libspice-server-dev
 | 
			
		||||
            - libssh-dev
 | 
			
		||||
            - liburcu-dev
 | 
			
		||||
            - libusb-1.0-0-dev
 | 
			
		||||
            - libvte-2.91-dev
 | 
			
		||||
            - sparse
 | 
			
		||||
            - uuid-dev
 | 
			
		||||
      language: generic
 | 
			
		||||
      compiler: none
 | 
			
		||||
      env:
 | 
			
		||||
        - COMPILER_NAME=gcc CXX=g++-9 CC=gcc-9
 | 
			
		||||
        - CONFIG="--cc=gcc-9 --cxx=g++-9 --disable-pie --disable-linux-user"
 | 
			
		||||
        - TEST_CMD=""
 | 
			
		||||
      before_script:
 | 
			
		||||
        - ./configure ${CONFIG} --extra-cflags="-g3 -O0 -Wno-error=stringop-truncation -fsanitize=thread -fuse-ld=gold" || { cat config.log && exit 1; }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    # Run check-tcg against linux-user
 | 
			
		||||
    - env:
 | 
			
		||||
        - CONFIG="--disable-system"
 | 
			
		||||
        - TEST_CMD="make -j3 check-tcg V=1"
 | 
			
		||||
 | 
			
		||||
    # Run check-tcg against softmmu targets
 | 
			
		||||
    - env:
 | 
			
		||||
        - CONFIG="--target-list=xtensa-softmmu,arm-softmmu,aarch64-softmmu,alpha-softmmu"
 | 
			
		||||
        - TEST_CMD="make -j3 check-tcg V=1"
 | 
			
		||||
							
								
								
									
										143
									
								
								CODING_STYLE
									
									
									
									
									
								
							
							
						
						
									
										143
									
								
								CODING_STYLE
									
									
									
									
									
								
							@@ -1,4 +1,4 @@
 | 
			
		||||
QEMU Coding Style
 | 
			
		||||
Qemu Coding Style
 | 
			
		||||
=================
 | 
			
		||||
 | 
			
		||||
Please use the script checkpatch.pl in the scripts directory to check
 | 
			
		||||
@@ -9,7 +9,7 @@ patches before submitting.
 | 
			
		||||
Of course, the most important aspect in any coding style is whitespace.
 | 
			
		||||
Crusty old coders who have trouble spotting the glasses on their noses
 | 
			
		||||
can tell the difference between a tab and eight spaces from a distance
 | 
			
		||||
of approximately fifteen parsecs.  Many a flamewar has been fought and
 | 
			
		||||
of approximately fifteen parsecs.  Many a flamewar have been fought and
 | 
			
		||||
lost on this issue.
 | 
			
		||||
 | 
			
		||||
QEMU indents are four spaces.  Tabs are never used, except in Makefiles
 | 
			
		||||
@@ -29,52 +29,9 @@ Spaces of course are superior to tabs because:
 | 
			
		||||
 | 
			
		||||
Do not leave whitespace dangling off the ends of lines.
 | 
			
		||||
 | 
			
		||||
1.1 Multiline Indent
 | 
			
		||||
 | 
			
		||||
There are several places where indent is necessary:
 | 
			
		||||
 | 
			
		||||
 - if/else
 | 
			
		||||
 - while/for
 | 
			
		||||
 - function definition & call
 | 
			
		||||
 | 
			
		||||
When breaking up a long line to fit within line width, we need a proper indent
 | 
			
		||||
for the following lines.
 | 
			
		||||
 | 
			
		||||
In case of if/else, while/for, align the secondary lines just after the
 | 
			
		||||
opening parenthesis of the first.
 | 
			
		||||
 | 
			
		||||
For example:
 | 
			
		||||
 | 
			
		||||
    if (a == 1 &&
 | 
			
		||||
        b == 2) {
 | 
			
		||||
 | 
			
		||||
    while (a == 1 &&
 | 
			
		||||
           b == 2) {
 | 
			
		||||
 | 
			
		||||
In case of function, there are several variants:
 | 
			
		||||
 | 
			
		||||
    * 4 spaces indent from the beginning
 | 
			
		||||
    * align the secondary lines just after the opening parenthesis of the
 | 
			
		||||
      first
 | 
			
		||||
 | 
			
		||||
For example:
 | 
			
		||||
 | 
			
		||||
    do_something(x, y,
 | 
			
		||||
        z);
 | 
			
		||||
 | 
			
		||||
    do_something(x, y,
 | 
			
		||||
                 z);
 | 
			
		||||
 | 
			
		||||
    do_something(x, do_another(y,
 | 
			
		||||
                               z));
 | 
			
		||||
 | 
			
		||||
2. Line width
 | 
			
		||||
 | 
			
		||||
Lines should be 80 characters; try not to make them longer.
 | 
			
		||||
 | 
			
		||||
Sometimes it is hard to do, especially when dealing with QEMU subsystems
 | 
			
		||||
that use long function or symbol names.  Even in that case, do not make
 | 
			
		||||
lines much longer than 80 characters.
 | 
			
		||||
Lines are 80 characters; not longer.
 | 
			
		||||
 | 
			
		||||
Rationale:
 | 
			
		||||
 - Some people like to tile their 24" screens with a 6x4 matrix of 80x24
 | 
			
		||||
@@ -82,15 +39,12 @@ Rationale:
 | 
			
		||||
   let them keep doing it.
 | 
			
		||||
 - Code and especially patches is much more readable if limited to a sane
 | 
			
		||||
   line length.  Eighty is traditional.
 | 
			
		||||
 - The four-space indentation makes the most common excuse ("But look
 | 
			
		||||
   at all that white space on the left!") moot.
 | 
			
		||||
 - It is the QEMU coding style.
 | 
			
		||||
 | 
			
		||||
3. Naming
 | 
			
		||||
 | 
			
		||||
Variables are lower_case_with_underscores; easy to type and read.  Structured
 | 
			
		||||
type names are in CamelCase; harder to type but standing out.  Enum type
 | 
			
		||||
names and function type names should also be in CamelCase.  Scalar type
 | 
			
		||||
type names are in CamelCase; harder to type but standing out.  Scalar type
 | 
			
		||||
names are lower_case_with_underscores_ending_with_a_t, like the POSIX
 | 
			
		||||
uint64_t and family.  Note that this last convention contradicts POSIX
 | 
			
		||||
and is therefore likely to be changed.
 | 
			
		||||
@@ -114,10 +68,6 @@ keyword.  Example:
 | 
			
		||||
        printf("a was something else entirely.\n");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
Note that 'else if' is considered a single statement; otherwise a long if/
 | 
			
		||||
else if/else if/.../else sequence would need an indent for every else
 | 
			
		||||
statement.
 | 
			
		||||
 | 
			
		||||
An exception is the opening brace for a function; for reasons of tradition
 | 
			
		||||
and clarity it comes on a line by itself:
 | 
			
		||||
 | 
			
		||||
@@ -129,88 +79,3 @@ and clarity it comes on a line by itself:
 | 
			
		||||
Rationale: a consistent (except for functions...) bracing style reduces
 | 
			
		||||
ambiguity and avoids needless churn when lines are added or removed.
 | 
			
		||||
Furthermore, it is the QEMU coding style.
 | 
			
		||||
 | 
			
		||||
5. Declarations
 | 
			
		||||
 | 
			
		||||
Mixed declarations (interleaving statements and declarations within
 | 
			
		||||
blocks) are generally not allowed; declarations should be at the beginning
 | 
			
		||||
of blocks.
 | 
			
		||||
 | 
			
		||||
Every now and then, an exception is made for declarations inside a
 | 
			
		||||
#ifdef or #ifndef block: if the code looks nicer, such declarations can
 | 
			
		||||
be placed at the top of the block even if there are statements above.
 | 
			
		||||
On the other hand, however, it's often best to move that #ifdef/#ifndef
 | 
			
		||||
block to a separate function altogether.
 | 
			
		||||
 | 
			
		||||
6. Conditional statements
 | 
			
		||||
 | 
			
		||||
When comparing a variable for (in)equality with a constant, list the
 | 
			
		||||
constant on the right, as in:
 | 
			
		||||
 | 
			
		||||
    if (a == 1) {
 | 
			
		||||
        /* Reads like: "If a equals 1" */
 | 
			
		||||
        do_something();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
Rationale: Yoda conditions (as in 'if (1 == a)') are awkward to read.
 | 
			
		||||
Besides, good compilers already warn users when '==' is mis-typed as '=',
 | 
			
		||||
even when the constant is on the right.
 | 
			
		||||
 | 
			
		||||
7. Comment style
 | 
			
		||||
 | 
			
		||||
We use traditional C-style /* */ comments and avoid // comments.
 | 
			
		||||
 | 
			
		||||
Rationale: The // form is valid in C99, so this is purely a matter of
 | 
			
		||||
consistency of style. The checkpatch script will warn you about this.
 | 
			
		||||
 | 
			
		||||
Multiline comment blocks should have a row of stars on the left,
 | 
			
		||||
and the initial /* and terminating */ both on their own lines:
 | 
			
		||||
    /*
 | 
			
		||||
     * like
 | 
			
		||||
     * this
 | 
			
		||||
     */
 | 
			
		||||
This is the same format required by the Linux kernel coding style.
 | 
			
		||||
 | 
			
		||||
(Some of the existing comments in the codebase use the GNU Coding
 | 
			
		||||
Standards form which does not have stars on the left, or other
 | 
			
		||||
variations; avoid these when writing new comments, but don't worry
 | 
			
		||||
about converting to the preferred form unless you're editing that
 | 
			
		||||
comment anyway.)
 | 
			
		||||
 | 
			
		||||
Rationale: Consistency, and ease of visually picking out a multiline
 | 
			
		||||
comment from the surrounding code.
 | 
			
		||||
 | 
			
		||||
8. trace-events style
 | 
			
		||||
 | 
			
		||||
8.1 0x prefix
 | 
			
		||||
 | 
			
		||||
In trace-events files, use a '0x' prefix to specify hex numbers, as in:
 | 
			
		||||
 | 
			
		||||
some_trace(unsigned x, uint64_t y) "x 0x%x y 0x" PRIx64
 | 
			
		||||
 | 
			
		||||
An exception is made for groups of numbers that are hexadecimal by
 | 
			
		||||
convention and separated by the symbols '.', '/', ':', or ' ' (such as
 | 
			
		||||
PCI bus id):
 | 
			
		||||
 | 
			
		||||
another_trace(int cssid, int ssid, int dev_num) "bus id: %x.%x.%04x"
 | 
			
		||||
 | 
			
		||||
However, you can use '0x' for such groups if you want. Anyway, be sure that
 | 
			
		||||
it is obvious that numbers are in hex, ex.:
 | 
			
		||||
 | 
			
		||||
data_dump(uint8_t c1, uint8_t c2, uint8_t c3) "bytes (in hex): %02x %02x %02x"
 | 
			
		||||
 | 
			
		||||
Rationale: hex numbers are hard to read in logs when there is no 0x prefix,
 | 
			
		||||
especially when (occasionally) the representation doesn't contain any letters
 | 
			
		||||
and especially in one line with other decimal numbers. Number groups are allowed
 | 
			
		||||
to not use '0x' because for some things notations like %x.%x.%x are used not
 | 
			
		||||
only in Qemu. Also dumping raw data bytes with '0x' is less readable.
 | 
			
		||||
 | 
			
		||||
8.2 '#' printf flag
 | 
			
		||||
 | 
			
		||||
Do not use printf flag '#', like '%#x'.
 | 
			
		||||
 | 
			
		||||
Rationale: there are two ways to add a '0x' prefix to printed number: '0x%...'
 | 
			
		||||
and '%#...'. For consistency the only one way should be used. Arguments for
 | 
			
		||||
'0x%' are:
 | 
			
		||||
 - it is more popular
 | 
			
		||||
 - '%#' omits the 0x for the value 0 which makes output inconsistent
 | 
			
		||||
 
 | 
			
		||||
@@ -2,7 +2,7 @@
 | 
			
		||||
		       Version 2.1, February 1999
 | 
			
		||||
 | 
			
		||||
 Copyright (C) 1991, 1999 Free Software Foundation, Inc.
 | 
			
		||||
 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 | 
			
		||||
	51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 | 
			
		||||
 Everyone is permitted to copy and distribute verbatim copies
 | 
			
		||||
 of this license document, but changing it is not allowed.
 | 
			
		||||
 | 
			
		||||
@@ -476,7 +476,7 @@ convey the exclusion of warranty; and each file should have at least the
 | 
			
		||||
    This library is free software; you can redistribute it and/or
 | 
			
		||||
    modify it under the terms of the GNU Lesser General Public
 | 
			
		||||
    License as published by the Free Software Foundation; either
 | 
			
		||||
    version 2.1 of the License, or (at your option) any later version.
 | 
			
		||||
    version 2 of the License, or (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
    This library is distributed in the hope that it will be useful,
 | 
			
		||||
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
@@ -485,7 +485,7 @@ convey the exclusion of warranty; and each file should have at least the
 | 
			
		||||
 | 
			
		||||
    You should have received a copy of the GNU Lesser General Public
 | 
			
		||||
    License along with this library; if not, write to the Free Software
 | 
			
		||||
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 | 
			
		||||
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 | 
			
		||||
 | 
			
		||||
Also add information on how to contact you by electronic and paper mail.
 | 
			
		||||
 | 
			
		||||
@@ -500,3 +500,5 @@ necessary.  Here is a sample; alter the names:
 | 
			
		||||
  Ty Coon, President of Vice
 | 
			
		||||
 | 
			
		||||
That's all there is to it!
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,6 @@
 | 
			
		||||
This file documents changes for QEMU releases 0.12 and earlier.
 | 
			
		||||
For changelog information for later releases, see
 | 
			
		||||
https://wiki.qemu.org/ChangeLog or look at the git history for
 | 
			
		||||
http://wiki.qemu.org/ChangeLog or look at the git history for
 | 
			
		||||
more detailed information.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -78,7 +78,7 @@ version 0.10.2:
 | 
			
		||||
 | 
			
		||||
  - fix savevm/loadvm (Anthony Liguori)
 | 
			
		||||
  - live migration: fix dirty tracking windows (Glauber Costa)
 | 
			
		||||
  - live migration: improve error propagation (Glauber Costa)
 | 
			
		||||
  - live migration: improve error propogation (Glauber Costa)
 | 
			
		||||
  - qcow2: fix image creation for > ~2TB images (Chris Wright)
 | 
			
		||||
  - hotplug: fix error handling for if= parameter (Eduardo Habkost)
 | 
			
		||||
  - qcow2: fix data corruption (Nolan Leake)
 | 
			
		||||
@@ -386,7 +386,7 @@ version 0.5.3:
 | 
			
		||||
  - support of CD-ROM change
 | 
			
		||||
  - multiple network interface support
 | 
			
		||||
  - initial x86-64 host support (Gwenole Beauchesne)
 | 
			
		||||
  - lret to outer privilege fix (OS/2 install fix)
 | 
			
		||||
  - lret to outer priviledge fix (OS/2 install fix)
 | 
			
		||||
  - task switch fixes (SkyOS boot)
 | 
			
		||||
  - VM save/restore commands
 | 
			
		||||
  - new timer API
 | 
			
		||||
@@ -447,7 +447,7 @@ version 0.5.0:
 | 
			
		||||
  - multi-target build
 | 
			
		||||
  - fixed: no error code in hardware interrupts
 | 
			
		||||
  - fixed: pop ss, mov ss, x and sti disable hardware irqs for the next insn
 | 
			
		||||
  - correct single stepping through string operations
 | 
			
		||||
  - correct single stepping thru string operations
 | 
			
		||||
  - preliminary SPARC target support (Thomas M. Ogrisegg)
 | 
			
		||||
  - tun-fd option (Rusty Russell)
 | 
			
		||||
  - automatic IDE geometry detection
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										153
									
								
								HACKING
									
									
									
									
									
								
							
							
						
						
									
										153
									
								
								HACKING
									
									
									
									
									
								
							@@ -1,28 +1,10 @@
 | 
			
		||||
1. Preprocessor
 | 
			
		||||
 | 
			
		||||
1.1. Variadic macros
 | 
			
		||||
 | 
			
		||||
For variadic macros, stick with this C99-like syntax:
 | 
			
		||||
 | 
			
		||||
#define DPRINTF(fmt, ...)                                       \
 | 
			
		||||
    do { printf("IRQ: " fmt, ## __VA_ARGS__); } while (0)
 | 
			
		||||
 | 
			
		||||
1.2. Include directives
 | 
			
		||||
 | 
			
		||||
Order include directives as follows:
 | 
			
		||||
 | 
			
		||||
#include "qemu/osdep.h"  /* Always first... */
 | 
			
		||||
#include <...>           /* then system headers... */
 | 
			
		||||
#include "..."           /* and finally QEMU headers. */
 | 
			
		||||
 | 
			
		||||
The "qemu/osdep.h" header contains preprocessor macros that affect the behavior
 | 
			
		||||
of core system headers like <stdint.h>.  It must be the first include so that
 | 
			
		||||
core system headers included by external libraries get the preprocessor macros
 | 
			
		||||
that QEMU depends on.
 | 
			
		||||
 | 
			
		||||
Do not include "qemu/osdep.h" from header files since the .c file will have
 | 
			
		||||
already included it.
 | 
			
		||||
 | 
			
		||||
2. C types
 | 
			
		||||
 | 
			
		||||
It should be common sense to use the right type, but we have collected
 | 
			
		||||
@@ -50,7 +32,7 @@ mandatory for VMState fields.
 | 
			
		||||
 | 
			
		||||
Don't use Linux kernel internal types like u32, __u32 or __le32.
 | 
			
		||||
 | 
			
		||||
Use hwaddr for guest physical addresses except pcibus_t
 | 
			
		||||
Use target_phys_addr_t for guest physical addresses except pcibus_t
 | 
			
		||||
for PCI addresses.  In addition, ram_addr_t is a QEMU internal address
 | 
			
		||||
space that maps guest RAM physical addresses into an intermediate
 | 
			
		||||
address space that can map to host virtual address spaces.  Generally
 | 
			
		||||
@@ -58,23 +40,8 @@ speaking, the size of guest memory can always fit into ram_addr_t but
 | 
			
		||||
it would not be correct to store an actual guest physical address in a
 | 
			
		||||
ram_addr_t.
 | 
			
		||||
 | 
			
		||||
For CPU virtual addresses there are several possible types.
 | 
			
		||||
vaddr is the best type to use to hold a CPU virtual address in
 | 
			
		||||
target-independent code. It is guaranteed to be large enough to hold a
 | 
			
		||||
virtual address for any target, and it does not change size from target
 | 
			
		||||
to target. It is always unsigned.
 | 
			
		||||
target_ulong is a type the size of a virtual address on the CPU; this means
 | 
			
		||||
it may be 32 or 64 bits depending on which target is being built. It should
 | 
			
		||||
therefore be used only in target-specific code, and in some
 | 
			
		||||
performance-critical built-per-target core code such as the TLB code.
 | 
			
		||||
There is also a signed version, target_long.
 | 
			
		||||
abi_ulong is for the *-user targets, and represents a type the size of
 | 
			
		||||
'void *' in that target's ABI. (This may not be the same as the size of a
 | 
			
		||||
full CPU virtual address in the case of target ABIs which use 32 bit pointers
 | 
			
		||||
on 64 bit CPUs, like sparc32plus.) Definitions of structures that must match
 | 
			
		||||
the target's ABI must use this type for anything that on the target is defined
 | 
			
		||||
to be an 'unsigned long' or a pointer type.
 | 
			
		||||
There is also a signed version, abi_long.
 | 
			
		||||
Use target_ulong (or abi_ulong) for CPU virtual addresses, however
 | 
			
		||||
devices should not need to use target_ulong.
 | 
			
		||||
 | 
			
		||||
Of course, take all of the above with a grain of salt.  If you're about
 | 
			
		||||
to use some system interface that requires a type like size_t, pid_t or
 | 
			
		||||
@@ -110,33 +77,22 @@ avoided.
 | 
			
		||||
 | 
			
		||||
Use of the malloc/free/realloc/calloc/valloc/memalign/posix_memalign
 | 
			
		||||
APIs is not allowed in the QEMU codebase. Instead of these routines,
 | 
			
		||||
use the GLib memory allocation routines g_malloc/g_malloc0/g_new/
 | 
			
		||||
g_new0/g_realloc/g_free or QEMU's qemu_memalign/qemu_blockalign/qemu_vfree
 | 
			
		||||
APIs.
 | 
			
		||||
use the replacement qemu_malloc/qemu_mallocz/qemu_realloc/qemu_free or
 | 
			
		||||
qemu_vmalloc/qemu_memalign/qemu_vfree APIs.
 | 
			
		||||
 | 
			
		||||
Please note that g_malloc will exit on allocation failure, so there
 | 
			
		||||
is no need to test for failure (as you would have to with malloc).
 | 
			
		||||
Calling g_malloc with a zero size is valid and will return NULL.
 | 
			
		||||
Please note that NULL check for the qemu_malloc result is redundant and
 | 
			
		||||
that qemu_malloc() call with zero size is not allowed.
 | 
			
		||||
 | 
			
		||||
Prefer g_new(T, n) instead of g_malloc(sizeof(T) * n) for the following
 | 
			
		||||
reasons:
 | 
			
		||||
 | 
			
		||||
  a. It catches multiplication overflowing size_t;
 | 
			
		||||
  b. It returns T * instead of void *, letting compiler catch more type
 | 
			
		||||
     errors.
 | 
			
		||||
 | 
			
		||||
Declarations like T *v = g_malloc(sizeof(*v)) are acceptable, though.
 | 
			
		||||
 | 
			
		||||
Memory allocated by qemu_memalign or qemu_blockalign must be freed with
 | 
			
		||||
qemu_vfree, since breaking this will cause problems on Win32.
 | 
			
		||||
Memory allocated by qemu_vmalloc or qemu_memalign must be freed with
 | 
			
		||||
qemu_vfree, since breaking this will cause problems on Win32 and user
 | 
			
		||||
emulators.
 | 
			
		||||
 | 
			
		||||
4. String manipulation
 | 
			
		||||
 | 
			
		||||
Do not use the strncpy function.  As mentioned in the man page, it does *not*
 | 
			
		||||
guarantee a NULL-terminated buffer, which makes it extremely dangerous to use.
 | 
			
		||||
It also zeros trailing destination bytes out to the specified length.  Instead,
 | 
			
		||||
use this similar function when possible, but note its different signature:
 | 
			
		||||
void pstrcpy(char *dest, int dest_buf_size, const char *src)
 | 
			
		||||
Do not use the strncpy function.  According to the man page, it does
 | 
			
		||||
*not* guarantee a NULL-terminated buffer, which makes it extremely dangerous
 | 
			
		||||
to use.  Instead, use functionally equivalent function:
 | 
			
		||||
void pstrcpy(char *buf, int buf_size, const char *str)
 | 
			
		||||
 | 
			
		||||
Don't use strcat because it can't check for buffer overflows, but:
 | 
			
		||||
char *pstrcat(char *buf, int buf_size, const char *s)
 | 
			
		||||
@@ -152,7 +108,7 @@ int qemu_strnlen(const char *s, int max_len)
 | 
			
		||||
There are also replacement character processing macros for isxyz and toxyz,
 | 
			
		||||
so instead of e.g. isalnum you should use qemu_isalnum.
 | 
			
		||||
 | 
			
		||||
Because of the memory management rules, you must use g_strdup/g_strndup
 | 
			
		||||
Because of the memory management rules, you must use qemu_strdup/qemu_strndup
 | 
			
		||||
instead of plain strdup/strndup.
 | 
			
		||||
 | 
			
		||||
5. Printf-style functions
 | 
			
		||||
@@ -164,82 +120,3 @@ gcc's printf attribute directive in the prototype.
 | 
			
		||||
This makes it so gcc's -Wformat and -Wformat-security options can do
 | 
			
		||||
their jobs and cross-check format strings with the number and types
 | 
			
		||||
of arguments.
 | 
			
		||||
 | 
			
		||||
6. C standard, implementation defined and undefined behaviors
 | 
			
		||||
 | 
			
		||||
C code in QEMU should be written to the C99 language specification. A copy
 | 
			
		||||
of the final version of the C99 standard with corrigenda TC1, TC2, and TC3
 | 
			
		||||
included, formatted as a draft, can be downloaded from:
 | 
			
		||||
 http://www.open-std.org/jtc1/sc22/WG14/www/docs/n1256.pdf
 | 
			
		||||
 | 
			
		||||
The C language specification defines regions of undefined behavior and
 | 
			
		||||
implementation defined behavior (to give compiler authors enough leeway to
 | 
			
		||||
produce better code).  In general, code in QEMU should follow the language
 | 
			
		||||
specification and avoid both undefined and implementation defined
 | 
			
		||||
constructs. ("It works fine on the gcc I tested it with" is not a valid
 | 
			
		||||
argument...) However there are a few areas where we allow ourselves to
 | 
			
		||||
assume certain behaviors because in practice all the platforms we care about
 | 
			
		||||
behave in the same way and writing strictly conformant code would be
 | 
			
		||||
painful. These are:
 | 
			
		||||
 * you may assume that integers are 2s complement representation
 | 
			
		||||
 * you may assume that right shift of a signed integer duplicates
 | 
			
		||||
   the sign bit (ie it is an arithmetic shift, not a logical shift)
 | 
			
		||||
 | 
			
		||||
In addition, QEMU assumes that the compiler does not use the latitude
 | 
			
		||||
given in C99 and C11 to treat aspects of signed '<<' as undefined, as
 | 
			
		||||
documented in the GNU Compiler Collection manual starting at version 4.0.
 | 
			
		||||
 | 
			
		||||
7. Error handling and reporting
 | 
			
		||||
 | 
			
		||||
7.1 Reporting errors to the human user
 | 
			
		||||
 | 
			
		||||
Do not use printf(), fprintf() or monitor_printf().  Instead, use
 | 
			
		||||
error_report() or error_vreport() from error-report.h.  This ensures the
 | 
			
		||||
error is reported in the right place (current monitor or stderr), and in
 | 
			
		||||
a uniform format.
 | 
			
		||||
 | 
			
		||||
Use error_printf() & friends to print additional information.
 | 
			
		||||
 | 
			
		||||
error_report() prints the current location.  In certain common cases
 | 
			
		||||
like command line parsing, the current location is tracked
 | 
			
		||||
automatically.  To manipulate it manually, use the loc_*() from
 | 
			
		||||
error-report.h.
 | 
			
		||||
 | 
			
		||||
7.2 Propagating errors
 | 
			
		||||
 | 
			
		||||
An error can't always be reported to the user right where it's detected,
 | 
			
		||||
but often needs to be propagated up the call chain to a place that can
 | 
			
		||||
handle it.  This can be done in various ways.
 | 
			
		||||
 | 
			
		||||
The most flexible one is Error objects.  See error.h for usage
 | 
			
		||||
information.
 | 
			
		||||
 | 
			
		||||
Use the simplest suitable method to communicate success / failure to
 | 
			
		||||
callers.  Stick to common methods: non-negative on success / -1 on
 | 
			
		||||
error, non-negative / -errno, non-null / null, or Error objects.
 | 
			
		||||
 | 
			
		||||
Example: when a function returns a non-null pointer on success, and it
 | 
			
		||||
can fail only in one way (as far as the caller is concerned), returning
 | 
			
		||||
null on failure is just fine, and certainly simpler and a lot easier on
 | 
			
		||||
the eyes than propagating an Error object through an Error ** parameter.
 | 
			
		||||
 | 
			
		||||
Example: when a function's callers need to report details on failure
 | 
			
		||||
only the function really knows, use Error **, and set suitable errors.
 | 
			
		||||
 | 
			
		||||
Do not report an error to the user when you're also returning an error
 | 
			
		||||
for somebody else to handle.  Leave the reporting to the place that
 | 
			
		||||
consumes the error returned.
 | 
			
		||||
 | 
			
		||||
7.3 Handling errors
 | 
			
		||||
 | 
			
		||||
Calling exit() is fine when handling configuration errors during
 | 
			
		||||
startup.  It's problematic during normal operation.  In particular,
 | 
			
		||||
monitor commands should never exit().
 | 
			
		||||
 | 
			
		||||
Do not call exit() or abort() to handle an error that can be triggered
 | 
			
		||||
by the guest (e.g., some unimplemented corner case in guest code
 | 
			
		||||
translation or device emulation).  Guests should not be able to
 | 
			
		||||
terminate QEMU.
 | 
			
		||||
 | 
			
		||||
Note that &error_fatal is just another way to exit(1), and &error_abort
 | 
			
		||||
is just another way to abort().
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										36
									
								
								Kconfig.host
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								Kconfig.host
									
									
									
									
									
								
							@@ -1,36 +0,0 @@
 | 
			
		||||
# These are "proxy" symbols used to pass config-host.mak values
 | 
			
		||||
# down to Kconfig.  See also MINIKCONF_ARGS in the Makefile:
 | 
			
		||||
# these two need to be kept in sync.
 | 
			
		||||
 | 
			
		||||
config KVM
 | 
			
		||||
    bool
 | 
			
		||||
 | 
			
		||||
config LINUX
 | 
			
		||||
    bool
 | 
			
		||||
 | 
			
		||||
config OPENGL
 | 
			
		||||
    bool
 | 
			
		||||
 | 
			
		||||
config X11
 | 
			
		||||
    bool
 | 
			
		||||
 | 
			
		||||
config SPICE
 | 
			
		||||
    bool
 | 
			
		||||
 | 
			
		||||
config IVSHMEM
 | 
			
		||||
    bool
 | 
			
		||||
 | 
			
		||||
config TPM
 | 
			
		||||
    bool
 | 
			
		||||
 | 
			
		||||
config VHOST_USER
 | 
			
		||||
    bool
 | 
			
		||||
 | 
			
		||||
config XEN
 | 
			
		||||
    bool
 | 
			
		||||
 | 
			
		||||
config VIRTFS
 | 
			
		||||
    bool
 | 
			
		||||
 | 
			
		||||
config PVRDMA
 | 
			
		||||
    bool
 | 
			
		||||
							
								
								
									
										26
									
								
								LICENSE
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								LICENSE
									
									
									
									
									
								
							@@ -1,26 +1,18 @@
 | 
			
		||||
The QEMU distribution includes both the QEMU emulator and
 | 
			
		||||
various firmware files.  These are separate programs that are
 | 
			
		||||
distributed together for our users' convenience, and they have
 | 
			
		||||
separate licenses.
 | 
			
		||||
The following points clarify the QEMU license:
 | 
			
		||||
 | 
			
		||||
The following points clarify the license of the QEMU emulator:
 | 
			
		||||
1) QEMU as a whole is released under the GNU General Public License
 | 
			
		||||
 | 
			
		||||
1) The QEMU emulator as a whole is released under the GNU General
 | 
			
		||||
Public License, version 2.
 | 
			
		||||
2) Parts of QEMU have specific licenses which are compatible with the
 | 
			
		||||
GNU General Public License. Hence each source file contains its own
 | 
			
		||||
licensing information.
 | 
			
		||||
 | 
			
		||||
2) Parts of the QEMU emulator have specific licenses which are compatible
 | 
			
		||||
with the GNU General Public License, version 2. Hence each source file
 | 
			
		||||
contains its own licensing information.  Source files with no licensing
 | 
			
		||||
information are released under the GNU General Public License, version
 | 
			
		||||
2 or (at your option) any later version.
 | 
			
		||||
 | 
			
		||||
As of July 2013, contributions under version 2 of the GNU General Public
 | 
			
		||||
License (and no later version) are only accepted for the following files
 | 
			
		||||
or directories: bsd-user/, linux-user/, hw/vfio/, hw/xen/xen_pt*.
 | 
			
		||||
In particular, the QEMU virtual CPU core library (libqemu.a) is
 | 
			
		||||
released under the GNU Lesser General Public License. Many hardware
 | 
			
		||||
device emulation sources are released under the BSD license.
 | 
			
		||||
 | 
			
		||||
3) The Tiny Code Generator (TCG) is released under the BSD license
 | 
			
		||||
   (see license headers in files).
 | 
			
		||||
 | 
			
		||||
4) QEMU is a trademark of Fabrice Bellard.
 | 
			
		||||
 | 
			
		||||
Fabrice Bellard and the QEMU team
 | 
			
		||||
Fabrice Bellard.
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										2577
									
								
								MAINTAINERS
									
									
									
									
									
								
							
							
						
						
									
										2577
									
								
								MAINTAINERS
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										23
									
								
								Makefile.dis
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								Makefile.dis
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
			
		||||
# Makefile for disassemblers.
 | 
			
		||||
 | 
			
		||||
include ../config-host.mak
 | 
			
		||||
include config.mak
 | 
			
		||||
include $(SRC_PATH)/rules.mak
 | 
			
		||||
 | 
			
		||||
.PHONY: all
 | 
			
		||||
 | 
			
		||||
$(call set-vpath, $(SRC_PATH))
 | 
			
		||||
 | 
			
		||||
QEMU_CFLAGS+=-I..
 | 
			
		||||
 | 
			
		||||
include $(SRC_PATH)/Makefile.objs
 | 
			
		||||
 | 
			
		||||
all: $(libdis-y)
 | 
			
		||||
# Dummy command so that make thinks it has done something
 | 
			
		||||
	@true
 | 
			
		||||
 | 
			
		||||
clean:
 | 
			
		||||
	rm -f *.o *.d *.a *~
 | 
			
		||||
 | 
			
		||||
# Include automatically generated dependency files
 | 
			
		||||
-include $(wildcard *.d */*.d)
 | 
			
		||||
							
								
								
									
										24
									
								
								Makefile.hw
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								Makefile.hw
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
			
		||||
# Makefile for qemu target independent devices.
 | 
			
		||||
 | 
			
		||||
include ../config-host.mak
 | 
			
		||||
include ../config-all-devices.mak
 | 
			
		||||
include config.mak
 | 
			
		||||
include $(SRC_PATH)/rules.mak
 | 
			
		||||
 | 
			
		||||
.PHONY: all
 | 
			
		||||
 | 
			
		||||
$(call set-vpath, $(SRC_PATH):$(SRC_PATH)/hw)
 | 
			
		||||
 | 
			
		||||
QEMU_CFLAGS+=-I.. -I$(SRC_PATH)/fpu
 | 
			
		||||
 | 
			
		||||
include $(SRC_PATH)/Makefile.objs
 | 
			
		||||
 | 
			
		||||
all: $(hw-obj-y)
 | 
			
		||||
# Dummy command so that make thinks it has done something
 | 
			
		||||
	@true
 | 
			
		||||
 | 
			
		||||
clean:
 | 
			
		||||
	rm -f *.o */*.o *.d */*.d *.a */*.a *~ */*~
 | 
			
		||||
 | 
			
		||||
# Include automatically generated dependency files
 | 
			
		||||
-include $(wildcard *.d */*.d)
 | 
			
		||||
							
								
								
									
										539
									
								
								Makefile.objs
									
									
									
									
									
								
							
							
						
						
									
										539
									
								
								Makefile.objs
									
									
									
									
									
								
							@@ -1,213 +1,390 @@
 | 
			
		||||
#######################################################################
 | 
			
		||||
# Common libraries for tools and emulators
 | 
			
		||||
stub-obj-y = stubs/ util/ crypto/
 | 
			
		||||
util-obj-y = util/ qobject/ qapi/
 | 
			
		||||
 | 
			
		||||
chardev-obj-y = chardev/
 | 
			
		||||
# QObject
 | 
			
		||||
qobject-obj-y = qint.o qstring.o qdict.o qlist.o qfloat.o qbool.o
 | 
			
		||||
qobject-obj-y += qjson.o json-lexer.o json-streamer.o json-parser.o
 | 
			
		||||
qobject-obj-y += qerror.o error.o
 | 
			
		||||
 | 
			
		||||
#######################################################################
 | 
			
		||||
# authz-obj-y is code used by both qemu system emulation and qemu-img
 | 
			
		||||
 | 
			
		||||
authz-obj-y = authz/
 | 
			
		||||
# oslib-obj-y is code depending on the OS (win32 vs posix)
 | 
			
		||||
oslib-obj-y = osdep.o
 | 
			
		||||
oslib-obj-$(CONFIG_WIN32) += oslib-win32.o qemu-thread-win32.o
 | 
			
		||||
oslib-obj-$(CONFIG_POSIX) += oslib-posix.o qemu-thread-posix.o
 | 
			
		||||
 | 
			
		||||
#######################################################################
 | 
			
		||||
# block-obj-y is code used by both qemu system emulation and qemu-img
 | 
			
		||||
 | 
			
		||||
block-obj-y = nbd/
 | 
			
		||||
block-obj-y += block.o blockjob.o job.o
 | 
			
		||||
block-obj-y += block/ scsi/
 | 
			
		||||
block-obj-y += qemu-io-cmds.o
 | 
			
		||||
block-obj-$(CONFIG_REPLICATION) += replication.o
 | 
			
		||||
block-obj-y = cutils.o cache-utils.o qemu-malloc.o qemu-option.o module.o async.o
 | 
			
		||||
block-obj-y += nbd.o block.o aio.o aes.o qemu-config.o qemu-progress.o qemu-sockets.o
 | 
			
		||||
block-obj-$(CONFIG_POSIX) += posix-aio-compat.o
 | 
			
		||||
block-obj-$(CONFIG_LINUX_AIO) += linux-aio.o
 | 
			
		||||
block-obj-$(CONFIG_POSIX) += compatfd.o
 | 
			
		||||
 | 
			
		||||
block-obj-m = block/
 | 
			
		||||
block-nested-y += raw.o cow.o qcow.o vdi.o vmdk.o cloop.o dmg.o bochs.o vpc.o vvfat.o
 | 
			
		||||
block-nested-y += qcow2.o qcow2-refcount.o qcow2-cluster.o qcow2-snapshot.o qcow2-cache.o
 | 
			
		||||
block-nested-y += qed.o qed-gencb.o qed-l2-cache.o qed-table.o qed-cluster.o
 | 
			
		||||
block-nested-y += qed-check.o
 | 
			
		||||
block-nested-y += parallels.o nbd.o blkdebug.o sheepdog.o blkverify.o
 | 
			
		||||
block-nested-$(CONFIG_WIN32) += raw-win32.o
 | 
			
		||||
block-nested-$(CONFIG_POSIX) += raw-posix.o
 | 
			
		||||
block-nested-$(CONFIG_CURL) += curl.o
 | 
			
		||||
block-nested-$(CONFIG_RBD) += rbd.o
 | 
			
		||||
 | 
			
		||||
#######################################################################
 | 
			
		||||
# crypto-obj-y is code used by both qemu system emulation and qemu-img
 | 
			
		||||
block-obj-y +=  $(addprefix block/, $(block-nested-y))
 | 
			
		||||
 | 
			
		||||
crypto-obj-y = crypto/
 | 
			
		||||
crypto-user-obj-y = crypto/
 | 
			
		||||
net-obj-y = net.o
 | 
			
		||||
net-nested-y = queue.o checksum.o util.o
 | 
			
		||||
net-nested-y += socket.o
 | 
			
		||||
net-nested-y += dump.o
 | 
			
		||||
net-nested-$(CONFIG_POSIX) += tap.o
 | 
			
		||||
net-nested-$(CONFIG_LINUX) += tap-linux.o
 | 
			
		||||
net-nested-$(CONFIG_WIN32) += tap-win32.o
 | 
			
		||||
net-nested-$(CONFIG_BSD) += tap-bsd.o
 | 
			
		||||
net-nested-$(CONFIG_SOLARIS) += tap-solaris.o
 | 
			
		||||
net-nested-$(CONFIG_AIX) += tap-aix.o
 | 
			
		||||
net-nested-$(CONFIG_HAIKU) += tap-haiku.o
 | 
			
		||||
net-nested-$(CONFIG_SLIRP) += slirp.o
 | 
			
		||||
net-nested-$(CONFIG_VDE) += vde.o
 | 
			
		||||
net-obj-y += $(addprefix net/, $(net-nested-y))
 | 
			
		||||
 | 
			
		||||
#######################################################################
 | 
			
		||||
# qom-obj-y is code used by both qemu system emulation and qemu-img
 | 
			
		||||
 | 
			
		||||
qom-obj-y = qom/
 | 
			
		||||
 | 
			
		||||
#######################################################################
 | 
			
		||||
# io-obj-y is code used by both qemu system emulation and qemu-img
 | 
			
		||||
 | 
			
		||||
io-obj-y = io/
 | 
			
		||||
ifeq ($(CONFIG_VIRTIO)$(CONFIG_VIRTFS)$(CONFIG_PCI),yyy)
 | 
			
		||||
# Lots of the fsdev/9pcode is pulled in by vl.c via qemu_fsdev_add.
 | 
			
		||||
# only pull in the actual virtio-9p device if we also enabled virtio.
 | 
			
		||||
CONFIG_REALLY_VIRTFS=y
 | 
			
		||||
fsdev-nested-y = qemu-fsdev.o
 | 
			
		||||
else
 | 
			
		||||
fsdev-nested-y = qemu-fsdev-dummy.o
 | 
			
		||||
endif
 | 
			
		||||
fsdev-obj-$(CONFIG_VIRTFS) += $(addprefix fsdev/, $(fsdev-nested-y))
 | 
			
		||||
 | 
			
		||||
######################################################################
 | 
			
		||||
# Target independent part of system emulation. The long term path is to
 | 
			
		||||
# suppress *all* target specific code in case of system emulation, i.e. a
 | 
			
		||||
# single QEMU executable should support all CPUs and machines.
 | 
			
		||||
# libqemu_common.a: Target independent part of system emulation. The
 | 
			
		||||
# long term path is to suppress *all* target specific code in case of
 | 
			
		||||
# system emulation, i.e. a single QEMU executable should support all
 | 
			
		||||
# CPUs and machines.
 | 
			
		||||
 | 
			
		||||
ifeq ($(CONFIG_SOFTMMU),y)
 | 
			
		||||
common-obj-y = blockdev.o blockdev-nbd.o block/
 | 
			
		||||
common-obj-y += bootdevice.o iothread.o
 | 
			
		||||
common-obj-y += dump/
 | 
			
		||||
common-obj-y += job-qmp.o
 | 
			
		||||
common-obj-y += monitor/
 | 
			
		||||
common-obj-y += net/
 | 
			
		||||
common-obj-y += qdev-monitor.o device-hotplug.o
 | 
			
		||||
common-obj-y = $(block-obj-y) blockdev.o
 | 
			
		||||
common-obj-y += $(net-obj-y)
 | 
			
		||||
common-obj-y += $(qobject-obj-y)
 | 
			
		||||
common-obj-$(CONFIG_LINUX) += $(fsdev-obj-$(CONFIG_LINUX))
 | 
			
		||||
common-obj-y += readline.o console.o cursor.o qemu-error.o
 | 
			
		||||
common-obj-y += $(oslib-obj-y)
 | 
			
		||||
common-obj-$(CONFIG_WIN32) += os-win32.o
 | 
			
		||||
common-obj-$(CONFIG_POSIX) += os-posix.o
 | 
			
		||||
 | 
			
		||||
common-obj-$(CONFIG_LINUX) += fsdev/
 | 
			
		||||
common-obj-y += tcg-runtime.o host-utils.o
 | 
			
		||||
common-obj-y += irq.o ioport.o input.o
 | 
			
		||||
common-obj-$(CONFIG_PTIMER) += ptimer.o
 | 
			
		||||
common-obj-$(CONFIG_MAX7310) += max7310.o
 | 
			
		||||
common-obj-$(CONFIG_WM8750) += wm8750.o
 | 
			
		||||
common-obj-$(CONFIG_TWL92230) += twl92230.o
 | 
			
		||||
common-obj-$(CONFIG_TSC2005) += tsc2005.o
 | 
			
		||||
common-obj-$(CONFIG_LM832X) += lm832x.o
 | 
			
		||||
common-obj-$(CONFIG_TMP105) += tmp105.o
 | 
			
		||||
common-obj-$(CONFIG_STELLARIS_INPUT) += stellaris_input.o
 | 
			
		||||
common-obj-$(CONFIG_SSD0303) += ssd0303.o
 | 
			
		||||
common-obj-$(CONFIG_SSD0323) += ssd0323.o
 | 
			
		||||
common-obj-$(CONFIG_ADS7846) += ads7846.o
 | 
			
		||||
common-obj-$(CONFIG_MAX111X) += max111x.o
 | 
			
		||||
common-obj-$(CONFIG_DS1338) += ds1338.o
 | 
			
		||||
common-obj-y += i2c.o smbus.o smbus_eeprom.o
 | 
			
		||||
common-obj-y += eeprom93xx.o
 | 
			
		||||
common-obj-y += scsi-disk.o cdrom.o
 | 
			
		||||
common-obj-y += scsi-generic.o scsi-bus.o
 | 
			
		||||
common-obj-y += usb.o usb-hub.o usb-$(HOST_USB).o usb-hid.o usb-msd.o usb-wacom.o
 | 
			
		||||
common-obj-y += usb-serial.o usb-net.o usb-bus.o usb-desc.o
 | 
			
		||||
common-obj-$(CONFIG_SSI) += ssi.o
 | 
			
		||||
common-obj-$(CONFIG_SSI_SD) += ssi-sd.o
 | 
			
		||||
common-obj-$(CONFIG_SD) += sd.o
 | 
			
		||||
common-obj-y += bt.o bt-host.o bt-vhci.o bt-l2cap.o bt-sdp.o bt-hci.o bt-hid.o usb-bt.o
 | 
			
		||||
common-obj-y += bt-hci-csr.o
 | 
			
		||||
common-obj-y += buffered_file.o migration.o migration-tcp.o
 | 
			
		||||
common-obj-y += qemu-char.o savevm.o #aio.o
 | 
			
		||||
common-obj-y += msmouse.o ps2.o
 | 
			
		||||
common-obj-y += qdev.o qdev-properties.o
 | 
			
		||||
common-obj-y += block-migration.o iohandler.o
 | 
			
		||||
common-obj-y += pflib.o
 | 
			
		||||
common-obj-y += bitmap.o bitops.o
 | 
			
		||||
 | 
			
		||||
common-obj-y += migration/
 | 
			
		||||
common-obj-$(CONFIG_BRLAPI) += baum.o
 | 
			
		||||
common-obj-$(CONFIG_POSIX) += migration-exec.o migration-unix.o migration-fd.o
 | 
			
		||||
common-obj-$(CONFIG_WIN32) += version.o
 | 
			
		||||
 | 
			
		||||
common-obj-y += audio/
 | 
			
		||||
common-obj-m += audio/
 | 
			
		||||
common-obj-y += hw/
 | 
			
		||||
common-obj-$(CONFIG_SPICE) += ui/spice-core.o ui/spice-input.o ui/spice-display.o spice-qemu-char.o
 | 
			
		||||
 | 
			
		||||
common-obj-y += replay/
 | 
			
		||||
audio-obj-y = audio.o noaudio.o wavaudio.o mixeng.o
 | 
			
		||||
audio-obj-$(CONFIG_SDL) += sdlaudio.o
 | 
			
		||||
audio-obj-$(CONFIG_OSS) += ossaudio.o
 | 
			
		||||
audio-obj-$(CONFIG_SPICE) += spiceaudio.o
 | 
			
		||||
audio-obj-$(CONFIG_COREAUDIO) += coreaudio.o
 | 
			
		||||
audio-obj-$(CONFIG_ALSA) += alsaaudio.o
 | 
			
		||||
audio-obj-$(CONFIG_DSOUND) += dsoundaudio.o
 | 
			
		||||
audio-obj-$(CONFIG_FMOD) += fmodaudio.o
 | 
			
		||||
audio-obj-$(CONFIG_ESD) += esdaudio.o
 | 
			
		||||
audio-obj-$(CONFIG_PA) += paaudio.o
 | 
			
		||||
audio-obj-$(CONFIG_WINWAVE) += winwaveaudio.o
 | 
			
		||||
audio-obj-$(CONFIG_AUDIO_PT_INT) += audio_pt_int.o
 | 
			
		||||
audio-obj-$(CONFIG_AUDIO_WIN_INT) += audio_win_int.o
 | 
			
		||||
audio-obj-y += wavcapture.o
 | 
			
		||||
common-obj-y += $(addprefix audio/, $(audio-obj-y))
 | 
			
		||||
 | 
			
		||||
common-obj-y += ui/
 | 
			
		||||
common-obj-m += ui/
 | 
			
		||||
common-obj-y += bt-host.o bt-vhci.o
 | 
			
		||||
bt-host.o-cflags := $(BLUEZ_CFLAGS)
 | 
			
		||||
ui-obj-y += keymaps.o
 | 
			
		||||
ui-obj-$(CONFIG_SDL) += sdl.o sdl_zoom.o x_keymap.o
 | 
			
		||||
ui-obj-$(CONFIG_COCOA) += cocoa.o
 | 
			
		||||
ui-obj-$(CONFIG_CURSES) += curses.o
 | 
			
		||||
vnc-obj-y += vnc.o d3des.o
 | 
			
		||||
vnc-obj-y += vnc-enc-zlib.o vnc-enc-hextile.o
 | 
			
		||||
vnc-obj-y += vnc-enc-tight.o vnc-palette.o
 | 
			
		||||
vnc-obj-y += vnc-enc-zrle.o
 | 
			
		||||
vnc-obj-$(CONFIG_VNC_TLS) += vnc-tls.o vnc-auth-vencrypt.o
 | 
			
		||||
vnc-obj-$(CONFIG_VNC_SASL) += vnc-auth-sasl.o
 | 
			
		||||
ifdef CONFIG_VNC_THREAD
 | 
			
		||||
vnc-obj-y += vnc-jobs-async.o
 | 
			
		||||
else
 | 
			
		||||
vnc-obj-y += vnc-jobs-sync.o
 | 
			
		||||
endif
 | 
			
		||||
common-obj-y += $(addprefix ui/, $(ui-obj-y))
 | 
			
		||||
common-obj-$(CONFIG_VNC) += $(addprefix ui/, $(vnc-obj-y))
 | 
			
		||||
 | 
			
		||||
common-obj-y += dma-helpers.o
 | 
			
		||||
common-obj-y += vl.o
 | 
			
		||||
vl.o-cflags := $(GPROF_CFLAGS) $(SDL_CFLAGS)
 | 
			
		||||
common-obj-$(CONFIG_TPM) += tpm.o
 | 
			
		||||
common-obj-y += iov.o acl.o
 | 
			
		||||
#common-obj-$(CONFIG_POSIX) += compatfd.o
 | 
			
		||||
common-obj-y += notify.o event_notifier.o
 | 
			
		||||
common-obj-y += qemu-timer.o qemu-timer-common.o
 | 
			
		||||
 | 
			
		||||
common-obj-y += backends/
 | 
			
		||||
common-obj-y += chardev/
 | 
			
		||||
slirp-obj-y = cksum.o if.o ip_icmp.o ip_input.o ip_output.o
 | 
			
		||||
slirp-obj-y += slirp.o mbuf.o misc.o sbuf.o socket.o tcp_input.o tcp_output.o
 | 
			
		||||
slirp-obj-y += tcp_subr.o tcp_timer.o udp.o bootp.o tftp.o
 | 
			
		||||
common-obj-$(CONFIG_SLIRP) += $(addprefix slirp/, $(slirp-obj-y))
 | 
			
		||||
 | 
			
		||||
common-obj-$(CONFIG_SECCOMP) += qemu-seccomp.o
 | 
			
		||||
qemu-seccomp.o-cflags := $(SECCOMP_CFLAGS)
 | 
			
		||||
qemu-seccomp.o-libs := $(SECCOMP_LIBS)
 | 
			
		||||
# xen backend driver support
 | 
			
		||||
common-obj-$(CONFIG_XEN_BACKEND) += xen_backend.o xen_devconfig.o
 | 
			
		||||
common-obj-$(CONFIG_XEN_BACKEND) += xen_console.o xenfb.o xen_disk.o xen_nic.o
 | 
			
		||||
 | 
			
		||||
common-obj-$(CONFIG_FDT) += device_tree.o
 | 
			
		||||
######################################################################
 | 
			
		||||
# libuser
 | 
			
		||||
 | 
			
		||||
user-obj-y =
 | 
			
		||||
user-obj-y += envlist.o path.o
 | 
			
		||||
user-obj-y += tcg-runtime.o host-utils.o
 | 
			
		||||
user-obj-y += cutils.o cache-utils.o
 | 
			
		||||
 | 
			
		||||
######################################################################
 | 
			
		||||
# libhw
 | 
			
		||||
 | 
			
		||||
hw-obj-y =
 | 
			
		||||
hw-obj-y += loader.o
 | 
			
		||||
hw-obj-$(CONFIG_VIRTIO) += virtio-console.o
 | 
			
		||||
hw-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
 | 
			
		||||
hw-obj-y += fw_cfg.o
 | 
			
		||||
hw-obj-$(CONFIG_PCI) += pci_bridge.o
 | 
			
		||||
hw-obj-$(CONFIG_PCI) += msix.o msi.o
 | 
			
		||||
hw-obj-$(CONFIG_PCI) += pci_host.o pcie_host.o
 | 
			
		||||
hw-obj-$(CONFIG_PCI) += ioh3420.o xio3130_upstream.o xio3130_downstream.o
 | 
			
		||||
hw-obj-y += watchdog.o
 | 
			
		||||
hw-obj-$(CONFIG_ISA_MMIO) += isa_mmio.o
 | 
			
		||||
hw-obj-$(CONFIG_ECC) += ecc.o
 | 
			
		||||
hw-obj-$(CONFIG_NAND) += nand.o
 | 
			
		||||
hw-obj-$(CONFIG_PFLASH_CFI01) += pflash_cfi01.o
 | 
			
		||||
hw-obj-$(CONFIG_PFLASH_CFI02) += pflash_cfi02.o
 | 
			
		||||
 | 
			
		||||
hw-obj-$(CONFIG_M48T59) += m48t59.o
 | 
			
		||||
hw-obj-$(CONFIG_ESCC) += escc.o
 | 
			
		||||
hw-obj-$(CONFIG_EMPTY_SLOT) += empty_slot.o
 | 
			
		||||
 | 
			
		||||
hw-obj-$(CONFIG_SERIAL) += serial.o
 | 
			
		||||
hw-obj-$(CONFIG_PARALLEL) += parallel.o
 | 
			
		||||
# Moved back to Makefile.target due to #include qemu-kvm.h:
 | 
			
		||||
#hw-obj-$(CONFIG_I8254) += i8254.o
 | 
			
		||||
#hw-obj-$(CONFIG_PCSPK) += pcspk.o
 | 
			
		||||
hw-obj-$(CONFIG_PCKBD) += pckbd.o
 | 
			
		||||
hw-obj-$(CONFIG_USB_UHCI) += usb-uhci.o
 | 
			
		||||
hw-obj-$(CONFIG_USB_OHCI) += usb-ohci.o
 | 
			
		||||
hw-obj-$(CONFIG_USB_EHCI) += usb-ehci.o
 | 
			
		||||
hw-obj-$(CONFIG_FDC) += fdc.o
 | 
			
		||||
# needs fixes for cpu hotplug, so moved to Makefile.target:
 | 
			
		||||
# hw-obj-$(CONFIG_ACPI) += acpi.o acpi_piix4.o
 | 
			
		||||
hw-obj-$(CONFIG_APM) += pm_smbus.o apm.o
 | 
			
		||||
hw-obj-$(CONFIG_DMA) += dma.o
 | 
			
		||||
hw-obj-$(CONFIG_HPET) += hpet.o
 | 
			
		||||
hw-obj-$(CONFIG_APPLESMC) += applesmc.o
 | 
			
		||||
hw-obj-$(CONFIG_SMARTCARD) += usb-ccid.o ccid-card-passthru.o
 | 
			
		||||
hw-obj-$(CONFIG_SMARTCARD_NSS) += ccid-card-emulated.o
 | 
			
		||||
hw-obj-$(CONFIG_USB_REDIR) += usb-redir.o
 | 
			
		||||
 | 
			
		||||
# PPC devices
 | 
			
		||||
hw-obj-$(CONFIG_OPENPIC) += openpic.o
 | 
			
		||||
hw-obj-$(CONFIG_PREP_PCI) += prep_pci.o
 | 
			
		||||
# Mac shared devices
 | 
			
		||||
hw-obj-$(CONFIG_MACIO) += macio.o
 | 
			
		||||
hw-obj-$(CONFIG_CUDA) += cuda.o
 | 
			
		||||
hw-obj-$(CONFIG_ADB) += adb.o
 | 
			
		||||
hw-obj-$(CONFIG_MAC_NVRAM) += mac_nvram.o
 | 
			
		||||
hw-obj-$(CONFIG_MAC_DBDMA) += mac_dbdma.o
 | 
			
		||||
# OldWorld PowerMac
 | 
			
		||||
hw-obj-$(CONFIG_HEATHROW_PIC) += heathrow_pic.o
 | 
			
		||||
hw-obj-$(CONFIG_GRACKLE_PCI) += grackle_pci.o
 | 
			
		||||
# NewWorld PowerMac
 | 
			
		||||
hw-obj-$(CONFIG_UNIN_PCI) += unin_pci.o
 | 
			
		||||
hw-obj-$(CONFIG_DEC_PCI) += dec_pci.o
 | 
			
		||||
# PowerPC E500 boards
 | 
			
		||||
hw-obj-$(CONFIG_PPCE500_PCI) += ppce500_pci.o
 | 
			
		||||
 | 
			
		||||
# MIPS devices
 | 
			
		||||
hw-obj-$(CONFIG_PIIX4) += piix4.o
 | 
			
		||||
 | 
			
		||||
# PCI watchdog devices
 | 
			
		||||
hw-obj-$(CONFIG_PCI) += wdt_i6300esb.o
 | 
			
		||||
 | 
			
		||||
hw-obj-$(CONFIG_PCI) += pcie.o pcie_aer.o pcie_port.o
 | 
			
		||||
 | 
			
		||||
# PCI network cards
 | 
			
		||||
hw-obj-$(CONFIG_NE2000_PCI) += ne2000.o
 | 
			
		||||
hw-obj-$(CONFIG_EEPRO100_PCI) += eepro100.o
 | 
			
		||||
hw-obj-$(CONFIG_PCNET_PCI) += pcnet-pci.o
 | 
			
		||||
hw-obj-$(CONFIG_PCNET_COMMON) += pcnet.o
 | 
			
		||||
hw-obj-$(CONFIG_E1000_PCI) += e1000.o
 | 
			
		||||
hw-obj-$(CONFIG_RTL8139_PCI) += rtl8139.o
 | 
			
		||||
 | 
			
		||||
hw-obj-$(CONFIG_SMC91C111) += smc91c111.o
 | 
			
		||||
hw-obj-$(CONFIG_LAN9118) += lan9118.o
 | 
			
		||||
hw-obj-$(CONFIG_NE2000_ISA) += ne2000-isa.o
 | 
			
		||||
 | 
			
		||||
# IDE
 | 
			
		||||
hw-obj-$(CONFIG_IDE_CORE) += ide/core.o ide/atapi.o
 | 
			
		||||
hw-obj-$(CONFIG_IDE_QDEV) += ide/qdev.o
 | 
			
		||||
hw-obj-$(CONFIG_IDE_PCI) += ide/pci.o
 | 
			
		||||
hw-obj-$(CONFIG_IDE_ISA) += ide/isa.o
 | 
			
		||||
hw-obj-$(CONFIG_IDE_PIIX) += ide/piix.o
 | 
			
		||||
hw-obj-$(CONFIG_IDE_CMD646) += ide/cmd646.o
 | 
			
		||||
hw-obj-$(CONFIG_IDE_MACIO) += ide/macio.o
 | 
			
		||||
hw-obj-$(CONFIG_IDE_VIA) += ide/via.o
 | 
			
		||||
hw-obj-$(CONFIG_AHCI) += ide/ahci.o
 | 
			
		||||
hw-obj-$(CONFIG_AHCI) += ide/ich.o
 | 
			
		||||
 | 
			
		||||
# SCSI layer
 | 
			
		||||
hw-obj-$(CONFIG_LSI_SCSI_PCI) += lsi53c895a.o
 | 
			
		||||
hw-obj-$(CONFIG_ESP) += esp.o
 | 
			
		||||
 | 
			
		||||
hw-obj-y += dma-helpers.o sysbus.o isa-bus.o
 | 
			
		||||
hw-obj-y += qdev-addr.o
 | 
			
		||||
 | 
			
		||||
# VGA
 | 
			
		||||
hw-obj-$(CONFIG_VGA_PCI) += vga-pci.o
 | 
			
		||||
hw-obj-$(CONFIG_VGA_ISA) += vga-isa.o
 | 
			
		||||
hw-obj-$(CONFIG_VGA_ISA_MM) += vga-isa-mm.o
 | 
			
		||||
hw-obj-$(CONFIG_VMWARE_VGA) += vmware_vga.o
 | 
			
		||||
hw-obj-$(CONFIG_VMMOUSE) += vmmouse.o
 | 
			
		||||
 | 
			
		||||
hw-obj-$(CONFIG_RC4030) += rc4030.o
 | 
			
		||||
hw-obj-$(CONFIG_DP8393X) += dp8393x.o
 | 
			
		||||
hw-obj-$(CONFIG_DS1225Y) += ds1225y.o
 | 
			
		||||
hw-obj-$(CONFIG_MIPSNET) += mipsnet.o
 | 
			
		||||
 | 
			
		||||
# Sound
 | 
			
		||||
sound-obj-y =
 | 
			
		||||
sound-obj-$(CONFIG_SB16) += sb16.o
 | 
			
		||||
sound-obj-$(CONFIG_ES1370) += es1370.o
 | 
			
		||||
sound-obj-$(CONFIG_AC97) += ac97.o
 | 
			
		||||
sound-obj-$(CONFIG_ADLIB) += fmopl.o adlib.o
 | 
			
		||||
sound-obj-$(CONFIG_GUS) += gus.o gusemu_hal.o gusemu_mixer.o
 | 
			
		||||
sound-obj-$(CONFIG_CS4231A) += cs4231a.o
 | 
			
		||||
sound-obj-$(CONFIG_HDA) += intel-hda.o hda-audio.o
 | 
			
		||||
 | 
			
		||||
adlib.o fmopl.o: QEMU_CFLAGS += -DBUILD_Y8950=0
 | 
			
		||||
hw-obj-$(CONFIG_SOUND) += $(sound-obj-y)
 | 
			
		||||
 | 
			
		||||
9pfs-nested-$(CONFIG_VIRTFS) = virtio-9p.o virtio-9p-debug.o
 | 
			
		||||
9pfs-nested-$(CONFIG_VIRTFS) +=  virtio-9p-local.o virtio-9p-xattr.o
 | 
			
		||||
9pfs-nested-$(CONFIG_VIRTFS) +=   virtio-9p-xattr-user.o virtio-9p-posix-acl.o
 | 
			
		||||
 | 
			
		||||
hw-obj-$(CONFIG_REALLY_VIRTFS) += $(addprefix 9pfs/, $(9pfs-nested-y))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
######################################################################
 | 
			
		||||
# libdis
 | 
			
		||||
# NOTE: the disassembler code is only needed for debugging
 | 
			
		||||
 | 
			
		||||
libdis-y =
 | 
			
		||||
libdis-$(CONFIG_ALPHA_DIS) += alpha-dis.o
 | 
			
		||||
libdis-$(CONFIG_ARM_DIS) += arm-dis.o
 | 
			
		||||
libdis-$(CONFIG_CRIS_DIS) += cris-dis.o
 | 
			
		||||
libdis-$(CONFIG_HPPA_DIS) += hppa-dis.o
 | 
			
		||||
libdis-$(CONFIG_I386_DIS) += i386-dis.o
 | 
			
		||||
libdis-$(CONFIG_IA64_DIS) += ia64-dis.o
 | 
			
		||||
libdis-$(CONFIG_M68K_DIS) += m68k-dis.o
 | 
			
		||||
libdis-$(CONFIG_MICROBLAZE_DIS) += microblaze-dis.o
 | 
			
		||||
libdis-$(CONFIG_MIPS_DIS) += mips-dis.o
 | 
			
		||||
libdis-$(CONFIG_PPC_DIS) += ppc-dis.o
 | 
			
		||||
libdis-$(CONFIG_S390_DIS) += s390-dis.o
 | 
			
		||||
libdis-$(CONFIG_SH4_DIS) += sh4-dis.o
 | 
			
		||||
libdis-$(CONFIG_SPARC_DIS) += sparc-dis.o
 | 
			
		||||
 | 
			
		||||
######################################################################
 | 
			
		||||
# trace
 | 
			
		||||
 | 
			
		||||
ifeq ($(TRACE_BACKEND),dtrace)
 | 
			
		||||
trace.h: trace.h-timestamp trace-dtrace.h
 | 
			
		||||
else
 | 
			
		||||
trace.h: trace.h-timestamp
 | 
			
		||||
endif
 | 
			
		||||
trace.h-timestamp: $(SRC_PATH)/trace-events config-host.mak
 | 
			
		||||
	$(call quiet-command,sh $(SRC_PATH)/scripts/tracetool --$(TRACE_BACKEND) -h < $< > $@,"  GEN   trace.h")
 | 
			
		||||
	@cmp -s $@ trace.h || cp $@ trace.h
 | 
			
		||||
 | 
			
		||||
trace.c: trace.c-timestamp
 | 
			
		||||
trace.c-timestamp: $(SRC_PATH)/trace-events config-host.mak
 | 
			
		||||
	$(call quiet-command,sh $(SRC_PATH)/scripts/tracetool --$(TRACE_BACKEND) -c < $< > $@,"  GEN   trace.c")
 | 
			
		||||
	@cmp -s $@ trace.c || cp $@ trace.c
 | 
			
		||||
 | 
			
		||||
trace.o: trace.c $(GENERATED_HEADERS)
 | 
			
		||||
 | 
			
		||||
trace-dtrace.h: trace-dtrace.dtrace
 | 
			
		||||
	$(call quiet-command,dtrace -o $@ -h -s $<, "  GEN   trace-dtrace.h")
 | 
			
		||||
 | 
			
		||||
# Normal practice is to name DTrace probe file with a '.d' extension
 | 
			
		||||
# but that gets picked up by QEMU's Makefile as an external dependency
 | 
			
		||||
# rule file. So we use '.dtrace' instead
 | 
			
		||||
trace-dtrace.dtrace: trace-dtrace.dtrace-timestamp
 | 
			
		||||
trace-dtrace.dtrace-timestamp: $(SRC_PATH)/trace-events config-host.mak
 | 
			
		||||
	$(call quiet-command,sh $(SRC_PATH)/scripts/tracetool --$(TRACE_BACKEND) -d < $< > $@,"  GEN   trace-dtrace.dtrace")
 | 
			
		||||
	@cmp -s $@ trace-dtrace.dtrace || cp $@ trace-dtrace.dtrace
 | 
			
		||||
 | 
			
		||||
trace-dtrace.o: trace-dtrace.dtrace $(GENERATED_HEADERS)
 | 
			
		||||
	$(call quiet-command,dtrace -o $@ -G -s $<, "  GEN trace-dtrace.o")
 | 
			
		||||
 | 
			
		||||
ifeq ($(LIBTOOL),)
 | 
			
		||||
trace-dtrace.lo: trace-dtrace.dtrace
 | 
			
		||||
	@echo "missing libtool. please install and rerun configure."; exit 1
 | 
			
		||||
else
 | 
			
		||||
trace-dtrace.lo: trace-dtrace.dtrace
 | 
			
		||||
	$(call quiet-command,libtool --mode=compile --tag=CC dtrace -o $@ -G -s $<, "  lt GEN trace-dtrace.o")
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
simpletrace.o: simpletrace.c $(GENERATED_HEADERS)
 | 
			
		||||
 | 
			
		||||
ifeq ($(TRACE_BACKEND),dtrace)
 | 
			
		||||
trace-obj-y = trace-dtrace.o
 | 
			
		||||
else
 | 
			
		||||
trace-obj-y = trace.o
 | 
			
		||||
ifeq ($(TRACE_BACKEND),simple)
 | 
			
		||||
trace-obj-y += simpletrace.o
 | 
			
		||||
user-obj-y += qemu-timer-common.o
 | 
			
		||||
endif
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
######################################################################
 | 
			
		||||
# smartcard
 | 
			
		||||
 | 
			
		||||
libcacard-y = cac.o event.o vcard.o vreader.o vcard_emul_nss.o vcard_emul_type.o card_7816.o
 | 
			
		||||
 | 
			
		||||
######################################################################
 | 
			
		||||
# qapi
 | 
			
		||||
 | 
			
		||||
common-obj-y += qapi/
 | 
			
		||||
endif
 | 
			
		||||
qapi-nested-y = qapi-visit-core.o qmp-input-visitor.o qmp-output-visitor.o qapi-dealloc-visitor.o
 | 
			
		||||
qapi-nested-y += qmp-registry.o qmp-dispatch.o
 | 
			
		||||
qapi-obj-y = $(addprefix qapi/, $(qapi-nested-y))
 | 
			
		||||
 | 
			
		||||
#######################################################################
 | 
			
		||||
# Target-independent parts used in system and user emulation
 | 
			
		||||
common-obj-y += cpus-common.o
 | 
			
		||||
common-obj-y += hw/
 | 
			
		||||
common-obj-y += qom/
 | 
			
		||||
common-obj-y += disas/
 | 
			
		||||
vl.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 | 
			
		||||
 | 
			
		||||
######################################################################
 | 
			
		||||
# Resource file for Windows executables
 | 
			
		||||
version-obj-$(CONFIG_WIN32) += $(BUILD_DIR)/version.o
 | 
			
		||||
vl.o: QEMU_CFLAGS+=$(SDL_CFLAGS)
 | 
			
		||||
 | 
			
		||||
######################################################################
 | 
			
		||||
# tracing
 | 
			
		||||
util-obj-y +=  trace/
 | 
			
		||||
 | 
			
		||||
######################################################################
 | 
			
		||||
# guest agent
 | 
			
		||||
 | 
			
		||||
# FIXME: a few definitions from qapi/qapi-types.o and
 | 
			
		||||
# qapi/qapi-visit.o are needed by libqemuutil.a.  These should be
 | 
			
		||||
# extracted into a QAPI schema module, or perhaps a separate schema.
 | 
			
		||||
qga-obj-y = qga/
 | 
			
		||||
qga-vss-dll-obj-y = qga/
 | 
			
		||||
 | 
			
		||||
######################################################################
 | 
			
		||||
# contrib
 | 
			
		||||
elf2dmp-obj-y = contrib/elf2dmp/
 | 
			
		||||
ivshmem-client-obj-$(CONFIG_IVSHMEM) = contrib/ivshmem-client/
 | 
			
		||||
ivshmem-server-obj-$(CONFIG_IVSHMEM) = contrib/ivshmem-server/
 | 
			
		||||
libvhost-user-obj-y = contrib/libvhost-user/
 | 
			
		||||
vhost-user-scsi.o-cflags := $(LIBISCSI_CFLAGS)
 | 
			
		||||
vhost-user-scsi.o-libs := $(LIBISCSI_LIBS)
 | 
			
		||||
vhost-user-scsi-obj-y = contrib/vhost-user-scsi/
 | 
			
		||||
vhost-user-blk-obj-y = contrib/vhost-user-blk/
 | 
			
		||||
rdmacm-mux-obj-y = contrib/rdmacm-mux/
 | 
			
		||||
vhost-user-input-obj-y = contrib/vhost-user-input/
 | 
			
		||||
vhost-user-gpu-obj-y = contrib/vhost-user-gpu/
 | 
			
		||||
 | 
			
		||||
######################################################################
 | 
			
		||||
trace-events-subdirs =
 | 
			
		||||
trace-events-subdirs += accel/kvm
 | 
			
		||||
trace-events-subdirs += accel/tcg
 | 
			
		||||
trace-events-subdirs += crypto
 | 
			
		||||
trace-events-subdirs += monitor
 | 
			
		||||
ifeq ($(CONFIG_USER_ONLY),y)
 | 
			
		||||
trace-events-subdirs += linux-user
 | 
			
		||||
endif
 | 
			
		||||
ifeq ($(CONFIG_BLOCK),y)
 | 
			
		||||
trace-events-subdirs += authz
 | 
			
		||||
trace-events-subdirs += block
 | 
			
		||||
trace-events-subdirs += io
 | 
			
		||||
trace-events-subdirs += nbd
 | 
			
		||||
trace-events-subdirs += scsi
 | 
			
		||||
endif
 | 
			
		||||
ifeq ($(CONFIG_SOFTMMU),y)
 | 
			
		||||
trace-events-subdirs += chardev
 | 
			
		||||
trace-events-subdirs += audio
 | 
			
		||||
trace-events-subdirs += hw/9pfs
 | 
			
		||||
trace-events-subdirs += hw/acpi
 | 
			
		||||
trace-events-subdirs += hw/alpha
 | 
			
		||||
trace-events-subdirs += hw/arm
 | 
			
		||||
trace-events-subdirs += hw/audio
 | 
			
		||||
trace-events-subdirs += hw/block
 | 
			
		||||
trace-events-subdirs += hw/block/dataplane
 | 
			
		||||
trace-events-subdirs += hw/char
 | 
			
		||||
trace-events-subdirs += hw/dma
 | 
			
		||||
trace-events-subdirs += hw/hppa
 | 
			
		||||
trace-events-subdirs += hw/i2c
 | 
			
		||||
trace-events-subdirs += hw/i386
 | 
			
		||||
trace-events-subdirs += hw/i386/xen
 | 
			
		||||
trace-events-subdirs += hw/ide
 | 
			
		||||
trace-events-subdirs += hw/input
 | 
			
		||||
trace-events-subdirs += hw/intc
 | 
			
		||||
trace-events-subdirs += hw/isa
 | 
			
		||||
trace-events-subdirs += hw/mem
 | 
			
		||||
trace-events-subdirs += hw/mips
 | 
			
		||||
trace-events-subdirs += hw/misc
 | 
			
		||||
trace-events-subdirs += hw/misc/macio
 | 
			
		||||
trace-events-subdirs += hw/net
 | 
			
		||||
trace-events-subdirs += hw/nvram
 | 
			
		||||
trace-events-subdirs += hw/pci
 | 
			
		||||
trace-events-subdirs += hw/pci-host
 | 
			
		||||
trace-events-subdirs += hw/ppc
 | 
			
		||||
trace-events-subdirs += hw/rdma
 | 
			
		||||
trace-events-subdirs += hw/rdma/vmw
 | 
			
		||||
trace-events-subdirs += hw/s390x
 | 
			
		||||
trace-events-subdirs += hw/scsi
 | 
			
		||||
trace-events-subdirs += hw/sd
 | 
			
		||||
trace-events-subdirs += hw/sparc
 | 
			
		||||
trace-events-subdirs += hw/sparc64
 | 
			
		||||
trace-events-subdirs += hw/timer
 | 
			
		||||
trace-events-subdirs += hw/tpm
 | 
			
		||||
trace-events-subdirs += hw/usb
 | 
			
		||||
trace-events-subdirs += hw/vfio
 | 
			
		||||
trace-events-subdirs += hw/virtio
 | 
			
		||||
trace-events-subdirs += hw/watchdog
 | 
			
		||||
trace-events-subdirs += hw/xen
 | 
			
		||||
trace-events-subdirs += hw/gpio
 | 
			
		||||
trace-events-subdirs += hw/riscv
 | 
			
		||||
trace-events-subdirs += migration
 | 
			
		||||
trace-events-subdirs += net
 | 
			
		||||
trace-events-subdirs += ui
 | 
			
		||||
endif
 | 
			
		||||
trace-events-subdirs += hw/display
 | 
			
		||||
trace-events-subdirs += qapi
 | 
			
		||||
trace-events-subdirs += qom
 | 
			
		||||
trace-events-subdirs += target/arm
 | 
			
		||||
trace-events-subdirs += target/hppa
 | 
			
		||||
trace-events-subdirs += target/i386
 | 
			
		||||
trace-events-subdirs += target/mips
 | 
			
		||||
trace-events-subdirs += target/ppc
 | 
			
		||||
trace-events-subdirs += target/riscv
 | 
			
		||||
trace-events-subdirs += target/s390x
 | 
			
		||||
trace-events-subdirs += target/sparc
 | 
			
		||||
trace-events-subdirs += util
 | 
			
		||||
 | 
			
		||||
trace-events-files = $(SRC_PATH)/trace-events $(trace-events-subdirs:%=$(SRC_PATH)/%/trace-events)
 | 
			
		||||
 | 
			
		||||
trace-obj-y = trace-root.o
 | 
			
		||||
trace-obj-y += $(trace-events-subdirs:%=%/trace.o)
 | 
			
		||||
trace-obj-$(CONFIG_TRACE_UST) += trace-ust-all.o
 | 
			
		||||
trace-obj-$(CONFIG_TRACE_DTRACE) += trace-dtrace-root.o
 | 
			
		||||
trace-obj-$(CONFIG_TRACE_DTRACE) += $(trace-events-subdirs:%=%/trace-dtrace.o)
 | 
			
		||||
vl.o: QEMU_CFLAGS+=$(GLIB_CFLAGS)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										537
									
								
								Makefile.target
									
									
									
									
									
								
							
							
						
						
									
										537
									
								
								Makefile.target
									
									
									
									
									
								
							@@ -1,55 +1,51 @@
 | 
			
		||||
# -*- Mode: makefile -*-
 | 
			
		||||
 | 
			
		||||
BUILD_DIR?=$(CURDIR)/..
 | 
			
		||||
GENERATED_HEADERS = config-target.h
 | 
			
		||||
CONFIG_NO_PCI = $(if $(subst n,,$(CONFIG_PCI)),n,y)
 | 
			
		||||
CONFIG_NO_KVM = $(if $(subst n,,$(CONFIG_KVM)),n,y)
 | 
			
		||||
CONFIG_NO_XEN = $(if $(subst n,,$(CONFIG_XEN)),n,y)
 | 
			
		||||
 | 
			
		||||
include ../config-host.mak
 | 
			
		||||
include config-devices.mak
 | 
			
		||||
include config-target.mak
 | 
			
		||||
include $(SRC_PATH)/rules.mak
 | 
			
		||||
 | 
			
		||||
ifdef CONFIG_SOFTMMU
 | 
			
		||||
include config-devices.mak
 | 
			
		||||
ifneq ($(HWDIR),)
 | 
			
		||||
include $(HWDIR)/config.mak
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
$(call set-vpath, $(SRC_PATH):$(BUILD_DIR))
 | 
			
		||||
TARGET_PATH=$(SRC_PATH)/target-$(TARGET_BASE_ARCH)
 | 
			
		||||
$(call set-vpath, $(SRC_PATH):$(TARGET_PATH):$(SRC_PATH)/hw)
 | 
			
		||||
ifdef CONFIG_LINUX
 | 
			
		||||
QEMU_CFLAGS += -I../linux-headers
 | 
			
		||||
endif
 | 
			
		||||
QEMU_CFLAGS += -iquote .. -iquote $(SRC_PATH)/target/$(TARGET_BASE_ARCH) -DNEED_CPU_H
 | 
			
		||||
QEMU_CFLAGS += -I.. -I$(TARGET_PATH) -DNEED_CPU_H
 | 
			
		||||
 | 
			
		||||
QEMU_CFLAGS+=-iquote $(SRC_PATH)/include
 | 
			
		||||
include $(SRC_PATH)/Makefile.objs
 | 
			
		||||
 | 
			
		||||
ifdef CONFIG_USER_ONLY
 | 
			
		||||
# user emulator name
 | 
			
		||||
QEMU_PROG=qemu-$(TARGET_NAME)
 | 
			
		||||
QEMU_PROG_BUILD = $(QEMU_PROG)
 | 
			
		||||
QEMU_PROG=qemu-$(TARGET_ARCH2)
 | 
			
		||||
else
 | 
			
		||||
# system emulator name
 | 
			
		||||
QEMU_PROG=qemu-system-$(TARGET_NAME)$(EXESUF)
 | 
			
		||||
ifneq (,$(findstring -mwindows,$(SDL_LIBS)))
 | 
			
		||||
# Terminate program name with a 'w' because the linker builds a windows executable.
 | 
			
		||||
QEMU_PROGW=qemu-system-$(TARGET_NAME)w$(EXESUF)
 | 
			
		||||
$(QEMU_PROG): $(QEMU_PROGW)
 | 
			
		||||
	$(call quiet-command,$(OBJCOPY) --subsystem console $(QEMU_PROGW) $(QEMU_PROG),"GEN","$(TARGET_DIR)$(QEMU_PROG)")
 | 
			
		||||
QEMU_PROG_BUILD = $(QEMU_PROGW)
 | 
			
		||||
ifeq ($(TARGET_ARCH), i386)
 | 
			
		||||
QEMU_PROG=qemu$(EXESUF)
 | 
			
		||||
else
 | 
			
		||||
QEMU_PROG_BUILD = $(QEMU_PROG)
 | 
			
		||||
QEMU_PROG=qemu-system-$(TARGET_ARCH2)$(EXESUF)
 | 
			
		||||
endif
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
PROGS=$(QEMU_PROG) $(QEMU_PROGW)
 | 
			
		||||
PROGS=$(QEMU_PROG)
 | 
			
		||||
STPFILES=
 | 
			
		||||
 | 
			
		||||
# Makefile Tests
 | 
			
		||||
include $(SRC_PATH)/tests/tcg/Makefile.include
 | 
			
		||||
ifndef CONFIG_HAIKU
 | 
			
		||||
LIBS+=-lm
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
config-target.h: config-target.h-timestamp
 | 
			
		||||
config-target.h-timestamp: config-target.mak
 | 
			
		||||
 | 
			
		||||
config-devices.h: config-devices.h-timestamp
 | 
			
		||||
config-devices.h-timestamp: config-devices.mak
 | 
			
		||||
 | 
			
		||||
ifdef CONFIG_TRACE_SYSTEMTAP
 | 
			
		||||
stap: $(QEMU_PROG).stp-installed $(QEMU_PROG).stp $(QEMU_PROG)-simpletrace.stp $(QEMU_PROG)-log.stp
 | 
			
		||||
ifdef CONFIG_SYSTEMTAP_TRACE
 | 
			
		||||
stap: $(QEMU_PROG).stp
 | 
			
		||||
 | 
			
		||||
ifdef CONFIG_USER_ONLY
 | 
			
		||||
TARGET_TYPE=user
 | 
			
		||||
@@ -57,205 +53,406 @@ else
 | 
			
		||||
TARGET_TYPE=system
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
tracetool-y = $(SRC_PATH)/scripts/tracetool.py
 | 
			
		||||
tracetool-y += $(shell find $(SRC_PATH)/scripts/tracetool -name "*.py")
 | 
			
		||||
 | 
			
		||||
$(QEMU_PROG).stp-installed: $(BUILD_DIR)/trace-events-all $(tracetool-y)
 | 
			
		||||
	$(call quiet-command,$(TRACETOOL) \
 | 
			
		||||
		--group=all \
 | 
			
		||||
		--format=stap \
 | 
			
		||||
		--backends=$(TRACE_BACKENDS) \
 | 
			
		||||
		--binary=$(bindir)/$(QEMU_PROG) \
 | 
			
		||||
		--target-name=$(TARGET_NAME) \
 | 
			
		||||
		--target-type=$(TARGET_TYPE) \
 | 
			
		||||
		$< > $@,"GEN","$(TARGET_DIR)$(QEMU_PROG).stp-installed")
 | 
			
		||||
 | 
			
		||||
$(QEMU_PROG).stp: $(BUILD_DIR)/trace-events-all $(tracetool-y)
 | 
			
		||||
	$(call quiet-command,$(TRACETOOL) \
 | 
			
		||||
		--group=all \
 | 
			
		||||
		--format=stap \
 | 
			
		||||
		--backends=$(TRACE_BACKENDS) \
 | 
			
		||||
		--binary=$(realpath .)/$(QEMU_PROG) \
 | 
			
		||||
		--target-name=$(TARGET_NAME) \
 | 
			
		||||
		--target-type=$(TARGET_TYPE) \
 | 
			
		||||
		$< > $@,"GEN","$(TARGET_DIR)$(QEMU_PROG).stp")
 | 
			
		||||
 | 
			
		||||
$(QEMU_PROG)-simpletrace.stp: $(BUILD_DIR)/trace-events-all $(tracetool-y)
 | 
			
		||||
	$(call quiet-command,$(TRACETOOL) \
 | 
			
		||||
		--group=all \
 | 
			
		||||
		--format=simpletrace-stap \
 | 
			
		||||
		--backends=$(TRACE_BACKENDS) \
 | 
			
		||||
		--probe-prefix=qemu.$(TARGET_TYPE).$(TARGET_NAME) \
 | 
			
		||||
		$< > $@,"GEN","$(TARGET_DIR)$(QEMU_PROG)-simpletrace.stp")
 | 
			
		||||
 | 
			
		||||
$(QEMU_PROG)-log.stp: $(BUILD_DIR)/trace-events-all $(tracetool-y)
 | 
			
		||||
	$(call quiet-command,$(TRACETOOL) \
 | 
			
		||||
		--group=all \
 | 
			
		||||
		--format=log-stap \
 | 
			
		||||
		--backends=$(TRACE_BACKENDS) \
 | 
			
		||||
		--probe-prefix=qemu.$(TARGET_TYPE).$(TARGET_NAME) \
 | 
			
		||||
		$< > $@,"GEN","$(TARGET_DIR)$(QEMU_PROG)-log.stp")
 | 
			
		||||
 | 
			
		||||
$(QEMU_PROG).stp:
 | 
			
		||||
	$(call quiet-command,sh $(SRC_PATH)/scripts/tracetool \
 | 
			
		||||
		--$(TRACE_BACKEND) \
 | 
			
		||||
		--binary $(bindir)/$(QEMU_PROG) \
 | 
			
		||||
		--target-arch $(TARGET_ARCH) \
 | 
			
		||||
		--target-type $(TARGET_TYPE) \
 | 
			
		||||
		--stap < $(SRC_PATH)/trace-events > $(QEMU_PROG).stp,"  GEN   $(QEMU_PROG).stp")
 | 
			
		||||
else
 | 
			
		||||
stap:
 | 
			
		||||
endif
 | 
			
		||||
.PHONY: stap
 | 
			
		||||
 | 
			
		||||
all: $(PROGS) stap
 | 
			
		||||
 | 
			
		||||
# Dummy command so that make thinks it has done something
 | 
			
		||||
	@true
 | 
			
		||||
 | 
			
		||||
obj-y += trace/
 | 
			
		||||
 | 
			
		||||
#########################################################
 | 
			
		||||
# cpu emulator library
 | 
			
		||||
obj-y += exec.o
 | 
			
		||||
obj-y += accel/
 | 
			
		||||
obj-$(CONFIG_TCG) += tcg/tcg.o tcg/tcg-op.o tcg/tcg-op-vec.o tcg/tcg-op-gvec.o
 | 
			
		||||
obj-$(CONFIG_TCG) += tcg/tcg-common.o tcg/optimize.o
 | 
			
		||||
obj-$(CONFIG_TCG_INTERPRETER) += tcg/tci.o
 | 
			
		||||
obj-$(CONFIG_TCG_INTERPRETER) += disas/tci.o
 | 
			
		||||
obj-$(CONFIG_TCG) += fpu/softfloat.o
 | 
			
		||||
obj-y += target/$(TARGET_BASE_ARCH)/
 | 
			
		||||
obj-y += disas.o
 | 
			
		||||
obj-$(call notempty,$(TARGET_XML_FILES)) += gdbstub-xml.o
 | 
			
		||||
LIBS := $(libs_cpu) $(LIBS)
 | 
			
		||||
libobj-y = exec.o cpu-exec.o
 | 
			
		||||
libobj-$(CONFIG_NO_CPU_EMULATION) += fake-exec.o
 | 
			
		||||
libobj-$(CONFIG_CPU_EMULATION) += translate-all.o translate.o
 | 
			
		||||
libobj-$(CONFIG_CPU_EMULATION) += tcg/tcg.o
 | 
			
		||||
libobj-y += fpu/softfloat.o
 | 
			
		||||
libobj-y += op_helper.o helper.o
 | 
			
		||||
ifeq ($(TARGET_BASE_ARCH), i386)
 | 
			
		||||
libobj-y += cpuid.o
 | 
			
		||||
endif
 | 
			
		||||
libobj-$(CONFIG_NEED_MMU) += mmu.o
 | 
			
		||||
 | 
			
		||||
libobj-$(CONFIG_KVM) += kvm-tpr-opt.o
 | 
			
		||||
 | 
			
		||||
libobj-$(TARGET_ARM) += neon_helper.o iwmmxt_helper.o
 | 
			
		||||
 | 
			
		||||
libobj-y += disas.o
 | 
			
		||||
 | 
			
		||||
$(libobj-y): $(GENERATED_HEADERS)
 | 
			
		||||
 | 
			
		||||
# libqemu
 | 
			
		||||
 | 
			
		||||
translate.o: translate.c cpu.h
 | 
			
		||||
 | 
			
		||||
translate-all.o: translate-all.c cpu.h
 | 
			
		||||
 | 
			
		||||
tcg/tcg.o: cpu.h
 | 
			
		||||
 | 
			
		||||
# HELPER_CFLAGS is used for all the code compiled with static register
 | 
			
		||||
# variables
 | 
			
		||||
op_helper.o user-exec.o: QEMU_CFLAGS += $(HELPER_CFLAGS)
 | 
			
		||||
 | 
			
		||||
# Note: this is a workaround. The real fix is to avoid compiling
 | 
			
		||||
# cpu_signal_handler() in user-exec.c.
 | 
			
		||||
signal.o: QEMU_CFLAGS += $(HELPER_CFLAGS)
 | 
			
		||||
 | 
			
		||||
#########################################################
 | 
			
		||||
# Linux user emulator target
 | 
			
		||||
 | 
			
		||||
ifdef CONFIG_LINUX_USER
 | 
			
		||||
 | 
			
		||||
QEMU_CFLAGS+=-I$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR) \
 | 
			
		||||
             -I$(SRC_PATH)/linux-user/host/$(ARCH) \
 | 
			
		||||
             -I$(SRC_PATH)/linux-user
 | 
			
		||||
$(call set-vpath, $(SRC_PATH)/linux-user:$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR))
 | 
			
		||||
 | 
			
		||||
obj-y += linux-user/
 | 
			
		||||
obj-y += gdbstub.o thunk.o
 | 
			
		||||
QEMU_CFLAGS+=-I$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR) -I$(SRC_PATH)/linux-user
 | 
			
		||||
obj-y = main.o syscall.o strace.o mmap.o signal.o thunk.o \
 | 
			
		||||
      elfload.o linuxload.o uaccess.o gdbstub.o cpu-uname.o \
 | 
			
		||||
      qemu-malloc.o user-exec.o $(oslib-obj-y)
 | 
			
		||||
 | 
			
		||||
obj-$(TARGET_HAS_BFLT) += flatload.o
 | 
			
		||||
 | 
			
		||||
obj-$(TARGET_I386) += vm86.o
 | 
			
		||||
 | 
			
		||||
obj-i386-y += ioport-user.o
 | 
			
		||||
 | 
			
		||||
nwfpe-obj-y = fpa11.o fpa11_cpdo.o fpa11_cpdt.o fpa11_cprt.o fpopcode.o
 | 
			
		||||
nwfpe-obj-y += single_cpdo.o double_cpdo.o extended_cpdo.o
 | 
			
		||||
obj-arm-y +=  $(addprefix nwfpe/, $(nwfpe-obj-y))
 | 
			
		||||
obj-arm-y += arm-semi.o
 | 
			
		||||
 | 
			
		||||
obj-m68k-y += m68k-sim.o m68k-semi.o
 | 
			
		||||
 | 
			
		||||
$(obj-y) $(obj-$(TARGET_BASE_ARCH)-y): $(GENERATED_HEADERS)
 | 
			
		||||
 | 
			
		||||
obj-y += $(addprefix ../libuser/, $(user-obj-y))
 | 
			
		||||
obj-y += $(addprefix ../libdis-user/, $(libdis-y))
 | 
			
		||||
obj-y += $(libobj-y)
 | 
			
		||||
 | 
			
		||||
endif #CONFIG_LINUX_USER
 | 
			
		||||
 | 
			
		||||
#########################################################
 | 
			
		||||
# Darwin user emulator target
 | 
			
		||||
 | 
			
		||||
ifdef CONFIG_DARWIN_USER
 | 
			
		||||
 | 
			
		||||
$(call set-vpath, $(SRC_PATH)/darwin-user)
 | 
			
		||||
 | 
			
		||||
QEMU_CFLAGS+=-I$(SRC_PATH)/darwin-user -I$(SRC_PATH)/darwin-user/$(TARGET_ARCH)
 | 
			
		||||
 | 
			
		||||
# Leave some space for the regular program loading zone
 | 
			
		||||
LDFLAGS+=-Wl,-segaddr,__STD_PROG_ZONE,0x1000 -image_base 0x0e000000
 | 
			
		||||
 | 
			
		||||
LIBS+=-lmx
 | 
			
		||||
 | 
			
		||||
obj-y = main.o commpage.o machload.o mmap.o signal.o syscall.o thunk.o \
 | 
			
		||||
        gdbstub.o user-exec.o
 | 
			
		||||
 | 
			
		||||
obj-i386-y += ioport-user.o
 | 
			
		||||
 | 
			
		||||
$(obj-y) $(obj-$(TARGET_BASE_ARCH)-y): $(GENERATED_HEADERS)
 | 
			
		||||
 | 
			
		||||
obj-y += $(addprefix ../libuser/, $(user-obj-y))
 | 
			
		||||
obj-y += $(addprefix ../libdis-user/, $(libdis-y))
 | 
			
		||||
obj-y += $(libobj-y)
 | 
			
		||||
 | 
			
		||||
endif #CONFIG_DARWIN_USER
 | 
			
		||||
 | 
			
		||||
#########################################################
 | 
			
		||||
# BSD user emulator target
 | 
			
		||||
 | 
			
		||||
ifdef CONFIG_BSD_USER
 | 
			
		||||
 | 
			
		||||
QEMU_CFLAGS+=-I$(SRC_PATH)/bsd-user -I$(SRC_PATH)/bsd-user/$(TARGET_ABI_DIR) \
 | 
			
		||||
			 -I$(SRC_PATH)/bsd-user/$(HOST_VARIANT_DIR)
 | 
			
		||||
$(call set-vpath, $(SRC_PATH)/bsd-user)
 | 
			
		||||
 | 
			
		||||
obj-y += bsd-user/
 | 
			
		||||
obj-y += gdbstub.o
 | 
			
		||||
QEMU_CFLAGS+=-I$(SRC_PATH)/bsd-user -I$(SRC_PATH)/bsd-user/$(TARGET_ARCH)
 | 
			
		||||
 | 
			
		||||
obj-y = main.o bsdload.o elfload.o mmap.o signal.o strace.o syscall.o \
 | 
			
		||||
        gdbstub.o uaccess.o user-exec.o
 | 
			
		||||
 | 
			
		||||
obj-i386-y += ioport-user.o
 | 
			
		||||
 | 
			
		||||
$(obj-y) $(obj-$(TARGET_BASE_ARCH)-y): $(GENERATED_HEADERS)
 | 
			
		||||
 | 
			
		||||
obj-y += $(addprefix ../libuser/, $(user-obj-y))
 | 
			
		||||
obj-y += $(addprefix ../libdis-user/, $(libdis-y))
 | 
			
		||||
obj-y += $(libobj-y)
 | 
			
		||||
 | 
			
		||||
endif #CONFIG_BSD_USER
 | 
			
		||||
 | 
			
		||||
#########################################################
 | 
			
		||||
# System emulator target
 | 
			
		||||
ifdef CONFIG_SOFTMMU
 | 
			
		||||
obj-y += arch_init.o cpus.o gdbstub.o balloon.o ioport.o
 | 
			
		||||
obj-y += qtest.o
 | 
			
		||||
obj-y += dump/
 | 
			
		||||
obj-y += hw/
 | 
			
		||||
obj-y += monitor/
 | 
			
		||||
obj-y += qapi/
 | 
			
		||||
obj-y += memory.o
 | 
			
		||||
obj-y += memory_mapping.o
 | 
			
		||||
obj-y += migration/ram.o
 | 
			
		||||
LIBS := $(libs_softmmu) $(LIBS)
 | 
			
		||||
 | 
			
		||||
obj-y = arch_init.o cpus.o monitor.o machine.o gdbstub.o vl.o balloon.o
 | 
			
		||||
# virtio has to be here due to weird dependency between PCI and virtio-net.
 | 
			
		||||
# need to fix this properly
 | 
			
		||||
obj-$(CONFIG_NO_PCI) += pci-stub.o
 | 
			
		||||
obj-$(CONFIG_PCI) += pci.o
 | 
			
		||||
obj-$(CONFIG_VIRTIO) += virtio.o virtio-blk.o virtio-balloon.o virtio-net.o virtio-serial-bus.o
 | 
			
		||||
obj-y += vhost_net.o
 | 
			
		||||
obj-$(CONFIG_VHOST_NET) += vhost.o
 | 
			
		||||
obj-$(CONFIG_REALLY_VIRTFS) += 9pfs/virtio-9p-device.o
 | 
			
		||||
obj-y += rwhandler.o
 | 
			
		||||
obj-$(CONFIG_KVM) += kvm.o kvm-all.o
 | 
			
		||||
obj-$(CONFIG_NO_KVM) += kvm-stub.o
 | 
			
		||||
LIBS+=-lz
 | 
			
		||||
 | 
			
		||||
QEMU_CFLAGS += $(VNC_TLS_CFLAGS)
 | 
			
		||||
QEMU_CFLAGS += $(VNC_SASL_CFLAGS)
 | 
			
		||||
QEMU_CFLAGS += $(VNC_JPEG_CFLAGS)
 | 
			
		||||
QEMU_CFLAGS += $(VNC_PNG_CFLAGS)
 | 
			
		||||
QEMU_CFLAGS += $(GLIB_CFLAGS)
 | 
			
		||||
 | 
			
		||||
# xen support
 | 
			
		||||
obj-$(CONFIG_XEN) += xen-all.o xen_machine_pv.o xen_domainbuild.o xen-mapcache.o
 | 
			
		||||
obj-$(CONFIG_NO_XEN) += xen-stub.o
 | 
			
		||||
 | 
			
		||||
obj-i386-$(CONFIG_XEN) += xen_platform.o
 | 
			
		||||
 | 
			
		||||
# Inter-VM PCI shared memory
 | 
			
		||||
CONFIG_IVSHMEM =
 | 
			
		||||
ifeq ($(CONFIG_KVM), y)
 | 
			
		||||
  ifeq ($(CONFIG_PCI), y)
 | 
			
		||||
    CONFIG_IVSHMEM = y
 | 
			
		||||
  endif
 | 
			
		||||
endif
 | 
			
		||||
obj-$(CONFIG_IVSHMEM) += ivshmem.o
 | 
			
		||||
 | 
			
		||||
# Hardware support
 | 
			
		||||
ifeq ($(TARGET_NAME), sparc64)
 | 
			
		||||
obj-y += hw/sparc64/
 | 
			
		||||
obj-i386-y += vga.o
 | 
			
		||||
obj-i386-y += mc146818rtc.o i8259.o pc.o
 | 
			
		||||
obj-i386-y += cirrus_vga.o sga.o apic.o ioapic.o piix_pci.o
 | 
			
		||||
obj-i386-y += vmport.o
 | 
			
		||||
obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o
 | 
			
		||||
obj-i386-y += extboot.o
 | 
			
		||||
obj-i386-y += debugcon.o multiboot.o
 | 
			
		||||
obj-i386-y += pc_piix.o
 | 
			
		||||
obj-i386-$(CONFIG_KVM) += kvmclock.o
 | 
			
		||||
obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o
 | 
			
		||||
obj-i386-y += testdev.o
 | 
			
		||||
obj-i386-y += acpi.o acpi_piix4.o
 | 
			
		||||
 | 
			
		||||
obj-i386-y += pcspk.o i8254.o
 | 
			
		||||
obj-i386-$(CONFIG_KVM_PIT) += i8254-kvm.o
 | 
			
		||||
obj-i386-$(CONFIG_KVM_DEVICE_ASSIGNMENT) += device-assignment.o
 | 
			
		||||
 | 
			
		||||
# Hardware support
 | 
			
		||||
obj-ia64-y += ide.o pckbd.o vga.o $(SOUND_HW) dma.o $(AUDIODRV)
 | 
			
		||||
obj-ia64-y += fdc.o mc146818rtc.o serial.o i8259.o ipf.o
 | 
			
		||||
obj-ia64-y += cirrus_vga.o parallel.o acpi.o piix_pci.o
 | 
			
		||||
obj-ia64-y += usb-uhci.o
 | 
			
		||||
obj-ia64-$(CONFIG_KVM_DEVICE_ASSIGNMENT) += device-assignment.o
 | 
			
		||||
 | 
			
		||||
# shared objects
 | 
			
		||||
obj-ppc-y = ppc.o
 | 
			
		||||
obj-ppc-y += vga.o
 | 
			
		||||
# PREP target
 | 
			
		||||
obj-ppc-y += i8259.o mc146818rtc.o
 | 
			
		||||
obj-ppc-y += ppc_prep.o
 | 
			
		||||
# OldWorld PowerMac
 | 
			
		||||
obj-ppc-y += ppc_oldworld.o
 | 
			
		||||
# NewWorld PowerMac
 | 
			
		||||
obj-ppc-y += ppc_newworld.o
 | 
			
		||||
# IBM pSeries (sPAPR)
 | 
			
		||||
ifeq ($(CONFIG_FDT)$(TARGET_PPC64),yy)
 | 
			
		||||
obj-ppc-y += spapr.o spapr_hcall.o spapr_rtas.o spapr_vio.o
 | 
			
		||||
obj-ppc-y += xics.o spapr_vty.o spapr_llan.o spapr_vscsi.o
 | 
			
		||||
endif
 | 
			
		||||
# PowerPC 4xx boards
 | 
			
		||||
obj-ppc-y += ppc4xx_devs.o ppc4xx_pci.o ppc405_uc.o ppc405_boards.o
 | 
			
		||||
obj-ppc-y += ppc440.o ppc440_bamboo.o
 | 
			
		||||
# PowerPC E500 boards
 | 
			
		||||
obj-ppc-y += ppce500_mpc8544ds.o mpc8544_guts.o
 | 
			
		||||
# PowerPC 440 Xilinx ML507 reference board.
 | 
			
		||||
obj-ppc-y += virtex_ml507.o
 | 
			
		||||
obj-ppc-$(CONFIG_KVM) += kvm_ppc.o
 | 
			
		||||
obj-ppc-$(CONFIG_FDT) += device_tree.o
 | 
			
		||||
 | 
			
		||||
# Xilinx PPC peripherals
 | 
			
		||||
obj-ppc-y += xilinx_intc.o
 | 
			
		||||
obj-ppc-y += xilinx_timer.o
 | 
			
		||||
obj-ppc-y += xilinx_uartlite.o
 | 
			
		||||
obj-ppc-y += xilinx_ethlite.o
 | 
			
		||||
 | 
			
		||||
# LM32 boards
 | 
			
		||||
obj-lm32-y += lm32_boards.o
 | 
			
		||||
obj-lm32-y += milkymist.o
 | 
			
		||||
 | 
			
		||||
# LM32 peripherals
 | 
			
		||||
obj-lm32-y += lm32_pic.o
 | 
			
		||||
obj-lm32-y += lm32_juart.o
 | 
			
		||||
obj-lm32-y += lm32_timer.o
 | 
			
		||||
obj-lm32-y += lm32_uart.o
 | 
			
		||||
obj-lm32-y += lm32_sys.o
 | 
			
		||||
obj-lm32-y += milkymist-ac97.o
 | 
			
		||||
obj-lm32-y += milkymist-hpdmc.o
 | 
			
		||||
obj-lm32-y += milkymist-memcard.o
 | 
			
		||||
obj-lm32-y += milkymist-minimac2.o
 | 
			
		||||
obj-lm32-y += milkymist-pfpu.o
 | 
			
		||||
obj-lm32-y += milkymist-softusb.o
 | 
			
		||||
obj-lm32-y += milkymist-sysctl.o
 | 
			
		||||
obj-lm32-$(CONFIG_OPENGL) += milkymist-tmu2.o
 | 
			
		||||
obj-lm32-y += milkymist-uart.o
 | 
			
		||||
obj-lm32-y += milkymist-vgafb.o
 | 
			
		||||
obj-lm32-y += framebuffer.o
 | 
			
		||||
 | 
			
		||||
obj-mips-y = mips_r4k.o mips_jazz.o mips_malta.o mips_mipssim.o
 | 
			
		||||
obj-mips-y += pcspk.o i8254.o
 | 
			
		||||
obj-mips-y += acpi.o acpi_piix4.o
 | 
			
		||||
obj-mips-y += mips_addr.o mips_timer.o mips_int.o
 | 
			
		||||
obj-mips-y += vga.o i8259.o
 | 
			
		||||
obj-mips-y += g364fb.o jazz_led.o
 | 
			
		||||
obj-mips-y += gt64xxx.o mc146818rtc.o
 | 
			
		||||
obj-mips-y += cirrus_vga.o
 | 
			
		||||
obj-mips-$(CONFIG_FULONG) += bonito.o vt82c686.o mips_fulong2e.o
 | 
			
		||||
 | 
			
		||||
obj-microblaze-y = petalogix_s3adsp1800_mmu.o
 | 
			
		||||
obj-microblaze-y += petalogix_ml605_mmu.o
 | 
			
		||||
 | 
			
		||||
obj-microblaze-y += microblaze_pic_cpu.o
 | 
			
		||||
obj-microblaze-y += xilinx_intc.o
 | 
			
		||||
obj-microblaze-y += xilinx_timer.o
 | 
			
		||||
obj-microblaze-y += xilinx_uartlite.o
 | 
			
		||||
obj-microblaze-y += xilinx_ethlite.o
 | 
			
		||||
obj-microblaze-y += xilinx_axidma.o
 | 
			
		||||
obj-microblaze-y += xilinx_axienet.o
 | 
			
		||||
 | 
			
		||||
obj-microblaze-$(CONFIG_FDT) += device_tree.o
 | 
			
		||||
 | 
			
		||||
# Boards
 | 
			
		||||
obj-cris-y = cris_pic_cpu.o
 | 
			
		||||
obj-cris-y += cris-boot.o
 | 
			
		||||
obj-cris-y += etraxfs.o axis_dev88.o
 | 
			
		||||
obj-cris-y += axis_dev88.o
 | 
			
		||||
 | 
			
		||||
# IO blocks
 | 
			
		||||
obj-cris-y += etraxfs_dma.o
 | 
			
		||||
obj-cris-y += etraxfs_pic.o
 | 
			
		||||
obj-cris-y += etraxfs_eth.o
 | 
			
		||||
obj-cris-y += etraxfs_timer.o
 | 
			
		||||
obj-cris-y += etraxfs_ser.o
 | 
			
		||||
 | 
			
		||||
ifeq ($(TARGET_ARCH), sparc64)
 | 
			
		||||
obj-sparc-y = sun4u.o apb_pci.o
 | 
			
		||||
obj-sparc-y += vga.o
 | 
			
		||||
obj-sparc-y += mc146818rtc.o
 | 
			
		||||
obj-sparc-y += cirrus_vga.o
 | 
			
		||||
else
 | 
			
		||||
obj-y += hw/$(TARGET_BASE_ARCH)/
 | 
			
		||||
obj-sparc-y = sun4m.o lance.o tcx.o sun4m_iommu.o slavio_intctl.o
 | 
			
		||||
obj-sparc-y += slavio_timer.o slavio_misc.o sparc32_dma.o
 | 
			
		||||
obj-sparc-y += cs4231.o eccmemctl.o sbi.o sun4c_intctl.o leon3.o
 | 
			
		||||
 | 
			
		||||
# GRLIB
 | 
			
		||||
obj-sparc-y += grlib_gptimer.o grlib_irqmp.o grlib_apbuart.o
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
generated-files-y += hmp-commands.h hmp-commands-info.h
 | 
			
		||||
generated-files-y += config-devices.h
 | 
			
		||||
obj-arm-y = integratorcp.o versatilepb.o arm_pic.o arm_timer.o
 | 
			
		||||
obj-arm-y += arm_boot.o pl011.o pl031.o pl050.o pl080.o pl110.o pl181.o pl190.o
 | 
			
		||||
obj-arm-y += versatile_pci.o
 | 
			
		||||
obj-arm-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o
 | 
			
		||||
obj-arm-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o
 | 
			
		||||
obj-arm-y += pl061.o
 | 
			
		||||
obj-arm-y += arm-semi.o
 | 
			
		||||
obj-arm-y += pxa2xx.o pxa2xx_pic.o pxa2xx_gpio.o pxa2xx_timer.o pxa2xx_dma.o
 | 
			
		||||
obj-arm-y += pxa2xx_lcd.o pxa2xx_mmci.o pxa2xx_pcmcia.o pxa2xx_keypad.o
 | 
			
		||||
obj-arm-y += gumstix.o
 | 
			
		||||
obj-arm-y += zaurus.o ide/microdrive.o spitz.o tosa.o tc6393xb.o
 | 
			
		||||
obj-arm-y += omap1.o omap_lcdc.o omap_dma.o omap_clk.o omap_mmc.o omap_i2c.o \
 | 
			
		||||
		omap_gpio.o omap_intc.o omap_uart.o
 | 
			
		||||
obj-arm-y += omap2.o omap_dss.o soc_dma.o omap_gptimer.o omap_synctimer.o \
 | 
			
		||||
		omap_gpmc.o omap_sdrc.o omap_spi.o omap_tap.o omap_l4.o
 | 
			
		||||
obj-arm-y += omap_sx1.o palm.o tsc210x.o
 | 
			
		||||
obj-arm-y += nseries.o blizzard.o onenand.o vga.o cbus.o tusb6010.o usb-musb.o
 | 
			
		||||
obj-arm-y += mst_fpga.o mainstone.o
 | 
			
		||||
obj-arm-y += musicpal.o bitbang_i2c.o marvell_88w8618_audio.o
 | 
			
		||||
obj-arm-y += framebuffer.o
 | 
			
		||||
obj-arm-y += syborg.o syborg_fb.o syborg_interrupt.o syborg_keyboard.o
 | 
			
		||||
obj-arm-y += syborg_serial.o syborg_timer.o syborg_pointer.o syborg_rtc.o
 | 
			
		||||
obj-arm-y += syborg_virtio.o
 | 
			
		||||
obj-arm-y += vexpress.o
 | 
			
		||||
obj-arm-y += strongarm.o
 | 
			
		||||
obj-arm-y += collie.o
 | 
			
		||||
 | 
			
		||||
obj-sh4-y = shix.o r2d.o sh7750.o sh7750_regnames.o tc58128.o
 | 
			
		||||
obj-sh4-y += sh_timer.o sh_serial.o sh_intc.o sh_pci.o sm501.o
 | 
			
		||||
obj-sh4-y += ide/mmio.o
 | 
			
		||||
 | 
			
		||||
obj-m68k-y = an5206.o mcf5206.o mcf_uart.o mcf_intc.o mcf5208.o mcf_fec.o
 | 
			
		||||
obj-m68k-y += m68k-semi.o dummy_m68k.o
 | 
			
		||||
 | 
			
		||||
obj-s390x-y = s390-virtio-bus.o s390-virtio.o
 | 
			
		||||
 | 
			
		||||
obj-alpha-y = i8259.o mc146818rtc.o
 | 
			
		||||
obj-alpha-y += vga.o cirrus_vga.o
 | 
			
		||||
 | 
			
		||||
ifeq ($(TARGET_ARCH), ia64)
 | 
			
		||||
firmware.o: firmware.c
 | 
			
		||||
	$(CC) $(HELPER_CFLAGS) $(CPPFLAGS) $(BASE_CFLAGS) -c -o $@ $<
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
main.o: QEMU_CFLAGS+=$(GPROF_CFLAGS)
 | 
			
		||||
 | 
			
		||||
monitor.o: hmp-commands.h qmp-commands.h
 | 
			
		||||
 | 
			
		||||
$(obj-y) $(obj-$(TARGET_BASE_ARCH)-y): $(GENERATED_HEADERS)
 | 
			
		||||
 | 
			
		||||
obj-y += $(addprefix ../, $(common-obj-y))
 | 
			
		||||
obj-y += $(addprefix ../libdis/, $(libdis-y))
 | 
			
		||||
obj-y += $(libobj-y)
 | 
			
		||||
obj-y += $(addprefix $(HWDIR)/, $(hw-obj-y))
 | 
			
		||||
 | 
			
		||||
endif # CONFIG_SOFTMMU
 | 
			
		||||
 | 
			
		||||
dummy := $(call unnest-vars,,obj-y)
 | 
			
		||||
all-obj-y := $(obj-y)
 | 
			
		||||
ifndef CONFIG_LINUX_USER
 | 
			
		||||
# libcacard needs qemu-thread support, and besides is only needed by devices
 | 
			
		||||
# so not requires with linux-user targets
 | 
			
		||||
obj-$(CONFIG_SMARTCARD_NSS) += $(addprefix ../libcacard/, $(libcacard-y))
 | 
			
		||||
endif # CONFIG_LINUX_USER
 | 
			
		||||
 | 
			
		||||
include $(SRC_PATH)/Makefile.objs
 | 
			
		||||
dummy := $(call unnest-vars,.., \
 | 
			
		||||
               authz-obj-y \
 | 
			
		||||
               block-obj-y \
 | 
			
		||||
               block-obj-m \
 | 
			
		||||
               chardev-obj-y \
 | 
			
		||||
               crypto-obj-y \
 | 
			
		||||
               crypto-user-obj-y \
 | 
			
		||||
               qom-obj-y \
 | 
			
		||||
               io-obj-y \
 | 
			
		||||
               common-obj-y \
 | 
			
		||||
               common-obj-m)
 | 
			
		||||
all-obj-y += $(common-obj-y)
 | 
			
		||||
all-obj-y += $(qom-obj-y)
 | 
			
		||||
all-obj-$(CONFIG_SOFTMMU) += $(authz-obj-y)
 | 
			
		||||
all-obj-$(CONFIG_SOFTMMU) += $(block-obj-y) $(chardev-obj-y)
 | 
			
		||||
all-obj-$(CONFIG_USER_ONLY) += $(crypto-user-obj-y)
 | 
			
		||||
all-obj-$(CONFIG_SOFTMMU) += $(crypto-obj-y)
 | 
			
		||||
all-obj-$(CONFIG_SOFTMMU) += $(io-obj-y)
 | 
			
		||||
obj-y += $(addprefix ../, $(trace-obj-y))
 | 
			
		||||
obj-$(CONFIG_GDBSTUB_XML) += gdbstub-xml.o
 | 
			
		||||
 | 
			
		||||
ifdef CONFIG_SOFTMMU
 | 
			
		||||
$(QEMU_PROG_BUILD): config-devices.mak
 | 
			
		||||
endif
 | 
			
		||||
$(QEMU_PROG): $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y)
 | 
			
		||||
	$(call LINK,$(obj-y) $(obj-$(TARGET_BASE_ARCH)-y))
 | 
			
		||||
 | 
			
		||||
COMMON_LDADDS = ../libqemuutil.a
 | 
			
		||||
 | 
			
		||||
# build either PROG or PROGW
 | 
			
		||||
$(QEMU_PROG_BUILD): $(all-obj-y) $(COMMON_LDADDS)
 | 
			
		||||
	$(call LINK, $(filter-out %.mak, $^))
 | 
			
		||||
ifdef CONFIG_DARWIN
 | 
			
		||||
	$(call quiet-command,Rez -append $(SRC_PATH)/pc-bios/qemu.rsrc -o $@,"REZ","$(TARGET_DIR)$@")
 | 
			
		||||
	$(call quiet-command,SetFile -a C $@,"SETFILE","$(TARGET_DIR)$@")
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
gdbstub-xml.c: $(TARGET_XML_FILES) $(SRC_PATH)/scripts/feature_to_c.sh
 | 
			
		||||
	$(call quiet-command,rm -f $@ && $(SHELL) $(SRC_PATH)/scripts/feature_to_c.sh $@ $(TARGET_XML_FILES),"GEN","$(TARGET_DIR)$@")
 | 
			
		||||
	$(call quiet-command,rm -f $@ && $(SHELL) $(SRC_PATH)/scripts/feature_to_c.sh $@ $(TARGET_XML_FILES),"  GEN   $(TARGET_DIR)$@")
 | 
			
		||||
 | 
			
		||||
hmp-commands.h: $(SRC_PATH)/hmp-commands.hx $(SRC_PATH)/scripts/hxtool
 | 
			
		||||
	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"GEN","$(TARGET_DIR)$@")
 | 
			
		||||
hmp-commands.h: $(SRC_PATH)/hmp-commands.hx
 | 
			
		||||
	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"  GEN   $(TARGET_DIR)$@")
 | 
			
		||||
 | 
			
		||||
hmp-commands-info.h: $(SRC_PATH)/hmp-commands-info.hx $(SRC_PATH)/scripts/hxtool
 | 
			
		||||
	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"GEN","$(TARGET_DIR)$@")
 | 
			
		||||
qmp-commands.h: $(SRC_PATH)/qmp-commands.hx
 | 
			
		||||
	$(call quiet-command,sh $(SRC_PATH)/scripts/hxtool -h < $< > $@,"  GEN   $(TARGET_DIR)$@")
 | 
			
		||||
 | 
			
		||||
clean: clean-target
 | 
			
		||||
	rm -f *.a *~ $(PROGS)
 | 
			
		||||
	rm -f $(shell find . -name '*.[od]')
 | 
			
		||||
	rm -f hmp-commands.h gdbstub-xml.c
 | 
			
		||||
	rm -f trace/generated-helpers.c trace/generated-helpers.c-timestamp
 | 
			
		||||
ifdef CONFIG_TRACE_SYSTEMTAP
 | 
			
		||||
clean:
 | 
			
		||||
	rm -f *.o *.a *~ $(PROGS) nwfpe/*.o fpu/*.o
 | 
			
		||||
	rm -f *.d */*.d tcg/*.o ide/*.o 9pfs/*.o
 | 
			
		||||
	rm -f hmp-commands.h qmp-commands.h gdbstub-xml.c
 | 
			
		||||
ifdef CONFIG_SYSTEMTAP_TRACE
 | 
			
		||||
	rm -f *.stp
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
install: all
 | 
			
		||||
ifneq ($(PROGS),)
 | 
			
		||||
	$(call install-prog,$(PROGS),$(DESTDIR)$(bindir))
 | 
			
		||||
	$(INSTALL) -m 755 $(PROGS) "$(DESTDIR)$(bindir)"
 | 
			
		||||
ifneq ($(STRIP),)
 | 
			
		||||
	$(STRIP) $(patsubst %,"$(DESTDIR)$(bindir)/%",$(PROGS))
 | 
			
		||||
endif
 | 
			
		||||
ifdef CONFIG_TRACE_SYSTEMTAP
 | 
			
		||||
	$(INSTALL_DIR) "$(DESTDIR)$(qemu_datadir)/../systemtap/tapset"
 | 
			
		||||
	$(INSTALL_DATA) $(QEMU_PROG).stp-installed "$(DESTDIR)$(qemu_datadir)/../systemtap/tapset/$(QEMU_PROG).stp"
 | 
			
		||||
	$(INSTALL_DATA) $(QEMU_PROG)-simpletrace.stp "$(DESTDIR)$(qemu_datadir)/../systemtap/tapset/$(QEMU_PROG)-simpletrace.stp"
 | 
			
		||||
	$(INSTALL_DATA) $(QEMU_PROG)-log.stp "$(DESTDIR)$(qemu_datadir)/../systemtap/tapset/$(QEMU_PROG)-log.stp"
 | 
			
		||||
endif
 | 
			
		||||
ifdef CONFIG_SYSTEMTAP_TRACE
 | 
			
		||||
	$(INSTALL_DIR) "$(DESTDIR)$(datadir)/../systemtap/tapset"
 | 
			
		||||
	$(INSTALL_DATA) $(QEMU_PROG).stp "$(DESTDIR)$(datadir)/../systemtap/tapset"
 | 
			
		||||
endif
 | 
			
		||||
 | 
			
		||||
generated-files-y += config-target.h
 | 
			
		||||
Makefile: $(generated-files-y)
 | 
			
		||||
 | 
			
		||||
# Reports/Analysis
 | 
			
		||||
#
 | 
			
		||||
# The target specific coverage report only cares about target specific
 | 
			
		||||
# blobs and not the shared code.
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
%/coverage-report.html:
 | 
			
		||||
	@mkdir -p $*
 | 
			
		||||
	$(call quiet-command,\
 | 
			
		||||
		gcovr -r $(SRC_PATH) --object-directory $(CURDIR) \
 | 
			
		||||
		-p --html --html-details -o $@, \
 | 
			
		||||
		"GEN", "coverage-report.html")
 | 
			
		||||
 | 
			
		||||
.PHONY: coverage-report
 | 
			
		||||
coverage-report: $(CURDIR)/reports/coverage/coverage-report.html
 | 
			
		||||
# Include automatically generated dependency files
 | 
			
		||||
-include $(wildcard *.d */*.d)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										23
									
								
								Makefile.user
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								Makefile.user
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,23 @@
 | 
			
		||||
# Makefile for qemu target independent user files.
 | 
			
		||||
 | 
			
		||||
include ../config-host.mak
 | 
			
		||||
include $(SRC_PATH)/rules.mak
 | 
			
		||||
-include config.mak
 | 
			
		||||
 | 
			
		||||
.PHONY: all
 | 
			
		||||
 | 
			
		||||
$(call set-vpath, $(SRC_PATH))
 | 
			
		||||
 | 
			
		||||
QEMU_CFLAGS+=-I..
 | 
			
		||||
 | 
			
		||||
include $(SRC_PATH)/Makefile.objs
 | 
			
		||||
 | 
			
		||||
all: $(user-obj-y)
 | 
			
		||||
# Dummy command so that make thinks it has done something
 | 
			
		||||
	@true
 | 
			
		||||
 | 
			
		||||
clean:
 | 
			
		||||
	rm -f *.o *.d *.a *~
 | 
			
		||||
 | 
			
		||||
# Include automatically generated dependency files
 | 
			
		||||
-include $(wildcard *.d */*.d)
 | 
			
		||||
							
								
								
									
										88
									
								
								QMP/README
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										88
									
								
								QMP/README
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,88 @@
 | 
			
		||||
                          QEMU Monitor Protocol
 | 
			
		||||
                          =====================
 | 
			
		||||
 | 
			
		||||
Introduction
 | 
			
		||||
-------------
 | 
			
		||||
 | 
			
		||||
The QEMU Monitor Protocol (QMP) allows applications to communicate with
 | 
			
		||||
QEMU's Monitor.
 | 
			
		||||
 | 
			
		||||
QMP is JSON[1] based and currently has the following features:
 | 
			
		||||
 | 
			
		||||
- Lightweight, text-based, easy to parse data format
 | 
			
		||||
- Asynchronous messages support (ie. events)
 | 
			
		||||
- Capabilities Negotiation
 | 
			
		||||
 | 
			
		||||
For detailed information on QMP's usage, please, refer to the following files:
 | 
			
		||||
 | 
			
		||||
o qmp-spec.txt      QEMU Monitor Protocol current specification
 | 
			
		||||
o qmp-commands.txt  QMP supported commands (auto-generated at build-time)
 | 
			
		||||
o qmp-events.txt    List of available asynchronous events
 | 
			
		||||
 | 
			
		||||
There is also a simple Python script called 'qmp-shell' available.
 | 
			
		||||
 | 
			
		||||
IMPORTANT: It's strongly recommended to read the 'Stability Considerations'
 | 
			
		||||
section in the qmp-commands.txt file before making any serious use of QMP.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
[1] http://www.json.org
 | 
			
		||||
 | 
			
		||||
Usage
 | 
			
		||||
-----
 | 
			
		||||
 | 
			
		||||
To enable QMP, you need a QEMU monitor instance in "control mode". There are
 | 
			
		||||
two ways of doing this.
 | 
			
		||||
 | 
			
		||||
The simplest one is using the '-qmp' command-line option. The following
 | 
			
		||||
example makes QMP available on localhost port 4444:
 | 
			
		||||
 | 
			
		||||
  $ qemu [...] -qmp tcp:localhost:4444,server
 | 
			
		||||
 | 
			
		||||
However, in order to have more complex combinations, like multiple monitors,
 | 
			
		||||
the '-mon' command-line option should be used along with the '-chardev' one.
 | 
			
		||||
For instance, the following example creates one user monitor on stdio and one
 | 
			
		||||
QMP monitor on localhost port 4444.
 | 
			
		||||
 | 
			
		||||
   $ qemu [...] -chardev stdio,id=mon0 -mon chardev=mon0,mode=readline \
 | 
			
		||||
                -chardev socket,id=mon1,host=localhost,port=4444,server \
 | 
			
		||||
                -mon chardev=mon1,mode=control
 | 
			
		||||
 | 
			
		||||
Please, refer to QEMU's manpage for more information.
 | 
			
		||||
 | 
			
		||||
Simple Testing
 | 
			
		||||
--------------
 | 
			
		||||
 | 
			
		||||
To manually test QMP one can connect with telnet and issue commands by hand:
 | 
			
		||||
 | 
			
		||||
$ telnet localhost 4444
 | 
			
		||||
Trying 127.0.0.1...
 | 
			
		||||
Connected to localhost.
 | 
			
		||||
Escape character is '^]'.
 | 
			
		||||
{"QMP": {"version": {"qemu": {"micro": 50, "minor": 13, "major": 0}, "package": ""}, "capabilities": []}}
 | 
			
		||||
{ "execute": "qmp_capabilities" }
 | 
			
		||||
{"return": {}}
 | 
			
		||||
{ "execute": "query-version" }
 | 
			
		||||
{"return": {"qemu": {"micro": 50, "minor": 13, "major": 0}, "package": ""}}
 | 
			
		||||
 | 
			
		||||
Development Process
 | 
			
		||||
-------------------
 | 
			
		||||
 | 
			
		||||
When changing QMP's interface (by adding new commands, events or modifying
 | 
			
		||||
existing ones) it's mandatory to update the relevant documentation, which is
 | 
			
		||||
one (or more) of the files listed in the 'Introduction' section*.
 | 
			
		||||
 | 
			
		||||
Also, it's strongly recommended to send the documentation patch first, before
 | 
			
		||||
doing any code change. This is so because:
 | 
			
		||||
 | 
			
		||||
  1. Avoids the code dictating the interface
 | 
			
		||||
 | 
			
		||||
  2. Review can improve your interface.  Letting that happen before
 | 
			
		||||
     you implement it can save you work.
 | 
			
		||||
 | 
			
		||||
* The qmp-commands.txt file is generated from the qmp-commands.hx one, which
 | 
			
		||||
  is the file that should be edited.
 | 
			
		||||
 | 
			
		||||
Homepage
 | 
			
		||||
--------
 | 
			
		||||
 | 
			
		||||
http://wiki.qemu.org/QMP
 | 
			
		||||
							
								
								
									
										266
									
								
								QMP/qmp-events.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										266
									
								
								QMP/qmp-events.txt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,266 @@
 | 
			
		||||
                   QEMU Monitor Protocol Events
 | 
			
		||||
                   ============================
 | 
			
		||||
 | 
			
		||||
BLOCK_IO_ERROR
 | 
			
		||||
--------------
 | 
			
		||||
 | 
			
		||||
Emitted when a disk I/O error occurs.
 | 
			
		||||
 | 
			
		||||
Data:
 | 
			
		||||
 | 
			
		||||
- "device": device name (json-string)
 | 
			
		||||
- "operation": I/O operation (json-string, "read" or "write")
 | 
			
		||||
- "action": action that has been taken, it's one of the following (json-string):
 | 
			
		||||
    "ignore": error has been ignored
 | 
			
		||||
    "report": error has been reported to the device
 | 
			
		||||
    "stop": error caused VM to be stopped
 | 
			
		||||
 | 
			
		||||
Example:
 | 
			
		||||
 | 
			
		||||
{ "event": "BLOCK_IO_ERROR",
 | 
			
		||||
    "data": { "device": "ide0-hd1",
 | 
			
		||||
              "operation": "write",
 | 
			
		||||
              "action": "stop" },
 | 
			
		||||
    "timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
 | 
			
		||||
 | 
			
		||||
Note: If action is "stop", a STOP event will eventually follow the
 | 
			
		||||
BLOCK_IO_ERROR event.
 | 
			
		||||
 | 
			
		||||
RESET
 | 
			
		||||
-----
 | 
			
		||||
 | 
			
		||||
Emitted when the Virtual Machine is reseted.
 | 
			
		||||
 | 
			
		||||
Data: None.
 | 
			
		||||
 | 
			
		||||
Example:
 | 
			
		||||
 | 
			
		||||
{ "event": "RESET",
 | 
			
		||||
    "timestamp": { "seconds": 1267041653, "microseconds": 9518 } }
 | 
			
		||||
 | 
			
		||||
RESUME
 | 
			
		||||
------
 | 
			
		||||
 | 
			
		||||
Emitted when the Virtual Machine resumes execution.
 | 
			
		||||
 | 
			
		||||
Data: None.
 | 
			
		||||
 | 
			
		||||
Example:
 | 
			
		||||
 | 
			
		||||
{ "event": "RESUME",
 | 
			
		||||
    "timestamp": { "seconds": 1271770767, "microseconds": 582542 } }
 | 
			
		||||
 | 
			
		||||
RTC_CHANGE
 | 
			
		||||
----------
 | 
			
		||||
 | 
			
		||||
Emitted when the guest changes the RTC time.
 | 
			
		||||
 | 
			
		||||
Data:
 | 
			
		||||
 | 
			
		||||
- "offset": delta against the host UTC in seconds (json-number)
 | 
			
		||||
 | 
			
		||||
Example:
 | 
			
		||||
 | 
			
		||||
{ "event": "RTC_CHANGE",
 | 
			
		||||
    "data": { "offset": 78 },
 | 
			
		||||
    "timestamp": { "seconds": 1267020223, "microseconds": 435656 } }
 | 
			
		||||
 | 
			
		||||
SHUTDOWN
 | 
			
		||||
--------
 | 
			
		||||
 | 
			
		||||
Emitted when the Virtual Machine is powered down.
 | 
			
		||||
 | 
			
		||||
Data: None.
 | 
			
		||||
 | 
			
		||||
Example:
 | 
			
		||||
 | 
			
		||||
{ "event": "SHUTDOWN",
 | 
			
		||||
    "timestamp": { "seconds": 1267040730, "microseconds": 682951 } }
 | 
			
		||||
 | 
			
		||||
Note: If the command-line option "-no-shutdown" has been specified, a STOP
 | 
			
		||||
event will eventually follow the SHUTDOWN event.
 | 
			
		||||
 | 
			
		||||
STOP
 | 
			
		||||
----
 | 
			
		||||
 | 
			
		||||
Emitted when the Virtual Machine is stopped.
 | 
			
		||||
 | 
			
		||||
Data: None.
 | 
			
		||||
 | 
			
		||||
Example:
 | 
			
		||||
 | 
			
		||||
{ "event": "STOP",
 | 
			
		||||
    "timestamp": { "seconds": 1267041730, "microseconds": 281295 } }
 | 
			
		||||
 | 
			
		||||
VNC_CONNECTED
 | 
			
		||||
-------------
 | 
			
		||||
 | 
			
		||||
Emitted when a VNC client establishes a connection.
 | 
			
		||||
 | 
			
		||||
Data:
 | 
			
		||||
 | 
			
		||||
- "server": Server information (json-object)
 | 
			
		||||
  - "host": IP address (json-string)
 | 
			
		||||
  - "service": port number (json-string)
 | 
			
		||||
  - "family": address family (json-string, "ipv4" or "ipv6")
 | 
			
		||||
  - "auth": authentication method (json-string, optional)
 | 
			
		||||
- "client": Client information (json-object)
 | 
			
		||||
  - "host": IP address (json-string)
 | 
			
		||||
  - "service": port number (json-string)
 | 
			
		||||
  - "family": address family (json-string, "ipv4" or "ipv6")
 | 
			
		||||
 | 
			
		||||
Example:
 | 
			
		||||
 | 
			
		||||
{ "event": "VNC_CONNECTED",
 | 
			
		||||
    "data": {
 | 
			
		||||
        "server": { "auth": "sasl", "family": "ipv4",
 | 
			
		||||
                    "service": "5901", "host": "0.0.0.0" },
 | 
			
		||||
        "client": { "family": "ipv4", "service": "58425",
 | 
			
		||||
                    "host": "127.0.0.1" } },
 | 
			
		||||
    "timestamp": { "seconds": 1262976601, "microseconds": 975795 } }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Note: This event is emitted before any authentication takes place, thus
 | 
			
		||||
the authentication ID is not provided.
 | 
			
		||||
 | 
			
		||||
VNC_DISCONNECTED
 | 
			
		||||
----------------
 | 
			
		||||
 | 
			
		||||
Emitted when the conection is closed.
 | 
			
		||||
 | 
			
		||||
Data:
 | 
			
		||||
 | 
			
		||||
- "server": Server information (json-object)
 | 
			
		||||
  - "host": IP address (json-string)
 | 
			
		||||
  - "service": port number (json-string)
 | 
			
		||||
  - "family": address family (json-string, "ipv4" or "ipv6")
 | 
			
		||||
  - "auth": authentication method (json-string, optional)
 | 
			
		||||
- "client": Client information (json-object)
 | 
			
		||||
  - "host": IP address (json-string)
 | 
			
		||||
  - "service": port number (json-string)
 | 
			
		||||
  - "family": address family (json-string, "ipv4" or "ipv6")
 | 
			
		||||
  - "x509_dname": TLS dname (json-string, optional)
 | 
			
		||||
  - "sasl_username": SASL username (json-string, optional)
 | 
			
		||||
 | 
			
		||||
Example:
 | 
			
		||||
 | 
			
		||||
{ "event": "VNC_DISCONNECTED",
 | 
			
		||||
    "data": {
 | 
			
		||||
        "server": { "auth": "sasl", "family": "ipv4",
 | 
			
		||||
                    "service": "5901", "host": "0.0.0.0" },
 | 
			
		||||
        "client": { "family": "ipv4", "service": "58425",
 | 
			
		||||
                    "host": "127.0.0.1", "sasl_username": "luiz" } },
 | 
			
		||||
    "timestamp": { "seconds": 1262976601, "microseconds": 975795 } }
 | 
			
		||||
 | 
			
		||||
VNC_INITIALIZED
 | 
			
		||||
---------------
 | 
			
		||||
 | 
			
		||||
Emitted after authentication takes place (if any) and the VNC session is
 | 
			
		||||
made active.
 | 
			
		||||
 | 
			
		||||
Data:
 | 
			
		||||
 | 
			
		||||
- "server": Server information (json-object)
 | 
			
		||||
  - "host": IP address (json-string)
 | 
			
		||||
  - "service": port number (json-string)
 | 
			
		||||
  - "family": address family (json-string, "ipv4" or "ipv6")
 | 
			
		||||
  - "auth": authentication method (json-string, optional)
 | 
			
		||||
- "client": Client information (json-object)
 | 
			
		||||
  - "host": IP address (json-string)
 | 
			
		||||
  - "service": port number (json-string)
 | 
			
		||||
  - "family": address family (json-string, "ipv4" or "ipv6")
 | 
			
		||||
  - "x509_dname": TLS dname (json-string, optional)
 | 
			
		||||
  - "sasl_username": SASL username (json-string, optional)
 | 
			
		||||
 | 
			
		||||
Example:
 | 
			
		||||
 | 
			
		||||
{ "event": "VNC_INITIALIZED",
 | 
			
		||||
    "data": {
 | 
			
		||||
        "server": { "auth": "sasl", "family": "ipv4",
 | 
			
		||||
                    "service": "5901", "host": "0.0.0.0"},
 | 
			
		||||
        "client": { "family": "ipv4", "service": "46089",
 | 
			
		||||
                    "host": "127.0.0.1", "sasl_username": "luiz" } },
 | 
			
		||||
        "timestamp": { "seconds": 1263475302, "microseconds": 150772 } }
 | 
			
		||||
 | 
			
		||||
SPICE_CONNECTED, SPICE_DISCONNECTED
 | 
			
		||||
-----------------------------------
 | 
			
		||||
 | 
			
		||||
Emitted when a SPICE client connects or disconnects.
 | 
			
		||||
 | 
			
		||||
Data:
 | 
			
		||||
 | 
			
		||||
- "server": Server information (json-object)
 | 
			
		||||
  - "host": IP address (json-string)
 | 
			
		||||
  - "port": port number (json-string)
 | 
			
		||||
  - "family": address family (json-string, "ipv4" or "ipv6")
 | 
			
		||||
- "client": Client information (json-object)
 | 
			
		||||
  - "host": IP address (json-string)
 | 
			
		||||
  - "port": port number (json-string)
 | 
			
		||||
  - "family": address family (json-string, "ipv4" or "ipv6")
 | 
			
		||||
 | 
			
		||||
Example:
 | 
			
		||||
 | 
			
		||||
{ "timestamp": {"seconds": 1290688046, "microseconds": 388707},
 | 
			
		||||
  "event": "SPICE_CONNECTED",
 | 
			
		||||
  "data": {
 | 
			
		||||
    "server": { "port": "5920", "family": "ipv4", "host": "127.0.0.1"},
 | 
			
		||||
    "client": {"port": "52873", "family": "ipv4", "host": "127.0.0.1"}
 | 
			
		||||
}}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
SPICE_INITIALIZED
 | 
			
		||||
-----------------
 | 
			
		||||
 | 
			
		||||
Emitted after initial handshake and authentication takes place (if any)
 | 
			
		||||
and the SPICE channel is up'n'running
 | 
			
		||||
 | 
			
		||||
Data:
 | 
			
		||||
 | 
			
		||||
- "server": Server information (json-object)
 | 
			
		||||
  - "host": IP address (json-string)
 | 
			
		||||
  - "port": port number (json-string)
 | 
			
		||||
  - "family": address family (json-string, "ipv4" or "ipv6")
 | 
			
		||||
  - "auth": authentication method (json-string, optional)
 | 
			
		||||
- "client": Client information (json-object)
 | 
			
		||||
  - "host": IP address (json-string)
 | 
			
		||||
  - "port": port number (json-string)
 | 
			
		||||
  - "family": address family (json-string, "ipv4" or "ipv6")
 | 
			
		||||
  - "connection-id": spice connection id.  All channels with the same id
 | 
			
		||||
                     belong to the same spice session (json-int)
 | 
			
		||||
  - "channel-type": channel type.  "1" is the main control channel, filter for
 | 
			
		||||
                    this one if you want track spice sessions only (json-int)
 | 
			
		||||
  - "channel-id": channel id.  Usually "0", might be different needed when
 | 
			
		||||
                  multiple channels of the same type exist, such as multiple
 | 
			
		||||
                  display channels in a multihead setup (json-int)
 | 
			
		||||
  - "tls": whevener the channel is encrypted (json-bool)
 | 
			
		||||
 | 
			
		||||
Example:
 | 
			
		||||
 | 
			
		||||
{ "timestamp": {"seconds": 1290688046, "microseconds": 417172},
 | 
			
		||||
  "event": "SPICE_INITIALIZED",
 | 
			
		||||
  "data": {"server": {"auth": "spice", "port": "5921",
 | 
			
		||||
                      "family": "ipv4", "host": "127.0.0.1"},
 | 
			
		||||
           "client": {"port": "49004", "family": "ipv4", "channel-type": 3,
 | 
			
		||||
                      "connection-id": 1804289383, "host": "127.0.0.1",
 | 
			
		||||
                      "channel-id": 0, "tls": true}
 | 
			
		||||
}}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
WATCHDOG
 | 
			
		||||
--------
 | 
			
		||||
 | 
			
		||||
Emitted when the watchdog device's timer is expired.
 | 
			
		||||
 | 
			
		||||
Data:
 | 
			
		||||
 | 
			
		||||
- "action": Action that has been taken, it's one of the following (json-string):
 | 
			
		||||
            "reset", "shutdown", "poweroff", "pause", "debug", or "none"
 | 
			
		||||
 | 
			
		||||
Example:
 | 
			
		||||
 | 
			
		||||
{ "event": "WATCHDOG",
 | 
			
		||||
     "data": { "action": "reset" },
 | 
			
		||||
     "timestamp": { "seconds": 1267061043, "microseconds": 959568 } }
 | 
			
		||||
 | 
			
		||||
Note: If action is "reset", "shutdown", or "pause" the WATCHDOG event is
 | 
			
		||||
followed respectively by the RESET, SHUTDOWN, or STOP events.
 | 
			
		||||
							
								
								
									
										259
									
								
								QMP/qmp-shell
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										259
									
								
								QMP/qmp-shell
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,259 @@
 | 
			
		||||
#!/usr/bin/python
 | 
			
		||||
#
 | 
			
		||||
# Low-level QEMU shell on top of QMP.
 | 
			
		||||
#
 | 
			
		||||
# Copyright (C) 2009, 2010 Red Hat Inc.
 | 
			
		||||
#
 | 
			
		||||
# Authors:
 | 
			
		||||
#  Luiz Capitulino <lcapitulino@redhat.com>
 | 
			
		||||
#
 | 
			
		||||
# This work is licensed under the terms of the GNU GPL, version 2.  See
 | 
			
		||||
# the COPYING file in the top-level directory.
 | 
			
		||||
#
 | 
			
		||||
# Usage:
 | 
			
		||||
#
 | 
			
		||||
# Start QEMU with:
 | 
			
		||||
#
 | 
			
		||||
# # qemu [...] -qmp unix:./qmp-sock,server
 | 
			
		||||
#
 | 
			
		||||
# Run the shell:
 | 
			
		||||
#
 | 
			
		||||
# $ qmp-shell ./qmp-sock
 | 
			
		||||
#
 | 
			
		||||
# Commands have the following format:
 | 
			
		||||
#
 | 
			
		||||
#    < command-name > [ arg-name1=arg1 ] ... [ arg-nameN=argN ]
 | 
			
		||||
#
 | 
			
		||||
# For example:
 | 
			
		||||
#
 | 
			
		||||
# (QEMU) device_add driver=e1000 id=net1
 | 
			
		||||
# {u'return': {}}
 | 
			
		||||
# (QEMU)
 | 
			
		||||
 | 
			
		||||
import qmp
 | 
			
		||||
import readline
 | 
			
		||||
import sys
 | 
			
		||||
 | 
			
		||||
class QMPCompleter(list):
 | 
			
		||||
    def complete(self, text, state):
 | 
			
		||||
        for cmd in self:
 | 
			
		||||
            if cmd.startswith(text):
 | 
			
		||||
                if not state:
 | 
			
		||||
                    return cmd
 | 
			
		||||
                else:
 | 
			
		||||
                    state -= 1
 | 
			
		||||
 | 
			
		||||
class QMPShellError(Exception):
 | 
			
		||||
    pass
 | 
			
		||||
 | 
			
		||||
class QMPShellBadPort(QMPShellError):
 | 
			
		||||
    pass
 | 
			
		||||
 | 
			
		||||
# TODO: QMPShell's interface is a bit ugly (eg. _fill_completion() and
 | 
			
		||||
#       _execute_cmd()). Let's design a better one.
 | 
			
		||||
class QMPShell(qmp.QEMUMonitorProtocol):
 | 
			
		||||
    def __init__(self, address):
 | 
			
		||||
        qmp.QEMUMonitorProtocol.__init__(self, self.__get_address(address))
 | 
			
		||||
        self._greeting = None
 | 
			
		||||
        self._completer = None
 | 
			
		||||
 | 
			
		||||
    def __get_address(self, arg):
 | 
			
		||||
        """
 | 
			
		||||
        Figure out if the argument is in the port:host form, if it's not it's
 | 
			
		||||
        probably a file path.
 | 
			
		||||
        """
 | 
			
		||||
        addr = arg.split(':')
 | 
			
		||||
        if len(addr) == 2:
 | 
			
		||||
            try:
 | 
			
		||||
                port = int(addr[1])
 | 
			
		||||
            except ValueError:
 | 
			
		||||
                raise QMPShellBadPort
 | 
			
		||||
            return ( addr[0], port )
 | 
			
		||||
        # socket path
 | 
			
		||||
        return arg
 | 
			
		||||
 | 
			
		||||
    def _fill_completion(self):
 | 
			
		||||
        for cmd in self.cmd('query-commands')['return']:
 | 
			
		||||
            self._completer.append(cmd['name'])
 | 
			
		||||
 | 
			
		||||
    def __completer_setup(self):
 | 
			
		||||
        self._completer = QMPCompleter()
 | 
			
		||||
        self._fill_completion()
 | 
			
		||||
        readline.set_completer(self._completer.complete)
 | 
			
		||||
        readline.parse_and_bind("tab: complete")
 | 
			
		||||
        # XXX: default delimiters conflict with some command names (eg. query-),
 | 
			
		||||
        # clearing everything as it doesn't seem to matter
 | 
			
		||||
        readline.set_completer_delims('')
 | 
			
		||||
 | 
			
		||||
    def __build_cmd(self, cmdline):
 | 
			
		||||
        """
 | 
			
		||||
        Build a QMP input object from a user provided command-line in the
 | 
			
		||||
        following format:
 | 
			
		||||
    
 | 
			
		||||
            < command-name > [ arg-name1=arg1 ] ... [ arg-nameN=argN ]
 | 
			
		||||
        """
 | 
			
		||||
        cmdargs = cmdline.split()
 | 
			
		||||
        qmpcmd = { 'execute': cmdargs[0], 'arguments': {} }
 | 
			
		||||
        for arg in cmdargs[1:]:
 | 
			
		||||
            opt = arg.split('=')
 | 
			
		||||
            try:
 | 
			
		||||
                value = int(opt[1])
 | 
			
		||||
            except ValueError:
 | 
			
		||||
                value = opt[1]
 | 
			
		||||
            qmpcmd['arguments'][opt[0]] = value
 | 
			
		||||
        return qmpcmd
 | 
			
		||||
 | 
			
		||||
    def _execute_cmd(self, cmdline):
 | 
			
		||||
        try:
 | 
			
		||||
            qmpcmd = self.__build_cmd(cmdline)
 | 
			
		||||
        except:
 | 
			
		||||
            print 'command format: <command-name> ',
 | 
			
		||||
            print '[arg-name1=arg1] ... [arg-nameN=argN]'
 | 
			
		||||
            return True
 | 
			
		||||
        resp = self.cmd_obj(qmpcmd)
 | 
			
		||||
        if resp is None:
 | 
			
		||||
            print 'Disconnected'
 | 
			
		||||
            return False
 | 
			
		||||
        print resp
 | 
			
		||||
        return True
 | 
			
		||||
 | 
			
		||||
    def connect(self):
 | 
			
		||||
        self._greeting = qmp.QEMUMonitorProtocol.connect(self)
 | 
			
		||||
        self.__completer_setup()
 | 
			
		||||
 | 
			
		||||
    def show_banner(self, msg='Welcome to the QMP low-level shell!'):
 | 
			
		||||
        print msg
 | 
			
		||||
        version = self._greeting['QMP']['version']['qemu']
 | 
			
		||||
        print 'Connected to QEMU %d.%d.%d\n' % (version['major'],version['minor'],version['micro'])
 | 
			
		||||
 | 
			
		||||
    def read_exec_command(self, prompt):
 | 
			
		||||
        """
 | 
			
		||||
        Read and execute a command.
 | 
			
		||||
 | 
			
		||||
        @return True if execution was ok, return False if disconnected.
 | 
			
		||||
        """
 | 
			
		||||
        try:
 | 
			
		||||
            cmdline = raw_input(prompt)
 | 
			
		||||
        except EOFError:
 | 
			
		||||
            print
 | 
			
		||||
            return False
 | 
			
		||||
        if cmdline == '':
 | 
			
		||||
            for ev in self.get_events():
 | 
			
		||||
                print ev
 | 
			
		||||
            self.clear_events()
 | 
			
		||||
            return True
 | 
			
		||||
        else:
 | 
			
		||||
            return self._execute_cmd(cmdline)
 | 
			
		||||
 | 
			
		||||
class HMPShell(QMPShell):
 | 
			
		||||
    def __init__(self, address):
 | 
			
		||||
        QMPShell.__init__(self, address)
 | 
			
		||||
        self.__cpu_index = 0
 | 
			
		||||
 | 
			
		||||
    def __cmd_completion(self):
 | 
			
		||||
        for cmd in self.__cmd_passthrough('help')['return'].split('\r\n'):
 | 
			
		||||
            if cmd and cmd[0] != '[' and cmd[0] != '\t':
 | 
			
		||||
                name = cmd.split()[0] # drop help text
 | 
			
		||||
                if name == 'info':
 | 
			
		||||
                    continue
 | 
			
		||||
                if name.find('|') != -1:
 | 
			
		||||
                    # Command in the form 'foobar|f' or 'f|foobar', take the
 | 
			
		||||
                    # full name
 | 
			
		||||
                    opt = name.split('|')
 | 
			
		||||
                    if len(opt[0]) == 1:
 | 
			
		||||
                        name = opt[1]
 | 
			
		||||
                    else:
 | 
			
		||||
                        name = opt[0]
 | 
			
		||||
                self._completer.append(name)
 | 
			
		||||
                self._completer.append('help ' + name) # help completion
 | 
			
		||||
 | 
			
		||||
    def __info_completion(self):
 | 
			
		||||
        for cmd in self.__cmd_passthrough('info')['return'].split('\r\n'):
 | 
			
		||||
            if cmd:
 | 
			
		||||
                self._completer.append('info ' + cmd.split()[1])
 | 
			
		||||
 | 
			
		||||
    def __other_completion(self):
 | 
			
		||||
        # special cases
 | 
			
		||||
        self._completer.append('help info')
 | 
			
		||||
 | 
			
		||||
    def _fill_completion(self):
 | 
			
		||||
        self.__cmd_completion()
 | 
			
		||||
        self.__info_completion()
 | 
			
		||||
        self.__other_completion()
 | 
			
		||||
 | 
			
		||||
    def __cmd_passthrough(self, cmdline, cpu_index = 0):
 | 
			
		||||
        return self.cmd_obj({ 'execute': 'human-monitor-command', 'arguments':
 | 
			
		||||
                              { 'command-line': cmdline,
 | 
			
		||||
                                'cpu-index': cpu_index } })
 | 
			
		||||
 | 
			
		||||
    def _execute_cmd(self, cmdline):
 | 
			
		||||
        if cmdline.split()[0] == "cpu":
 | 
			
		||||
            # trap the cpu command, it requires special setting
 | 
			
		||||
            try:
 | 
			
		||||
                idx = int(cmdline.split()[1])
 | 
			
		||||
                if not 'return' in self.__cmd_passthrough('info version', idx):
 | 
			
		||||
                    print 'bad CPU index'
 | 
			
		||||
                    return True
 | 
			
		||||
                self.__cpu_index = idx
 | 
			
		||||
            except ValueError:
 | 
			
		||||
                print 'cpu command takes an integer argument'
 | 
			
		||||
                return True
 | 
			
		||||
        resp = self.__cmd_passthrough(cmdline, self.__cpu_index)
 | 
			
		||||
        if resp is None:
 | 
			
		||||
            print 'Disconnected'
 | 
			
		||||
            return False
 | 
			
		||||
        assert 'return' in resp or 'error' in resp
 | 
			
		||||
        if 'return' in resp:
 | 
			
		||||
            # Success
 | 
			
		||||
            if len(resp['return']) > 0:
 | 
			
		||||
                print resp['return'],
 | 
			
		||||
        else:
 | 
			
		||||
            # Error
 | 
			
		||||
            print '%s: %s' % (resp['error']['class'], resp['error']['desc'])
 | 
			
		||||
        return True
 | 
			
		||||
 | 
			
		||||
    def show_banner(self):
 | 
			
		||||
        QMPShell.show_banner(self, msg='Welcome to the HMP shell!')
 | 
			
		||||
 | 
			
		||||
def die(msg):
 | 
			
		||||
    sys.stderr.write('ERROR: %s\n' % msg)
 | 
			
		||||
    sys.exit(1)
 | 
			
		||||
 | 
			
		||||
def fail_cmdline(option=None):
 | 
			
		||||
    if option:
 | 
			
		||||
        sys.stderr.write('ERROR: bad command-line option \'%s\'\n' % option)
 | 
			
		||||
    sys.stderr.write('qemu-shell [ -H ] < UNIX socket path> | < TCP address:port >\n')
 | 
			
		||||
    sys.exit(1)
 | 
			
		||||
 | 
			
		||||
def main():
 | 
			
		||||
    addr = ''
 | 
			
		||||
    try:
 | 
			
		||||
        if len(sys.argv) == 2:
 | 
			
		||||
            qemu = QMPShell(sys.argv[1])
 | 
			
		||||
            addr = sys.argv[1]
 | 
			
		||||
        elif len(sys.argv) == 3:
 | 
			
		||||
            if sys.argv[1] != '-H':
 | 
			
		||||
                fail_cmdline(sys.argv[1])
 | 
			
		||||
            qemu = HMPShell(sys.argv[2])
 | 
			
		||||
            addr = sys.argv[2]
 | 
			
		||||
        else:
 | 
			
		||||
                fail_cmdline()
 | 
			
		||||
    except QMPShellBadPort:
 | 
			
		||||
        die('bad port number in command-line')
 | 
			
		||||
 | 
			
		||||
    try:
 | 
			
		||||
        qemu.connect()
 | 
			
		||||
    except qmp.QMPConnectError:
 | 
			
		||||
        die('Didn\'t get QMP greeting message')
 | 
			
		||||
    except qmp.QMPCapabilitiesError:
 | 
			
		||||
        die('Could not negotiate capabilities')
 | 
			
		||||
    except qemu.error:
 | 
			
		||||
        die('Could not connect to %s' % addr)
 | 
			
		||||
 | 
			
		||||
    qemu.show_banner()
 | 
			
		||||
    while qemu.read_exec_command('(QEMU) '):
 | 
			
		||||
        pass
 | 
			
		||||
    qemu.close()
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    main()
 | 
			
		||||
							
								
								
									
										272
									
								
								QMP/qmp-spec.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										272
									
								
								QMP/qmp-spec.txt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,272 @@
 | 
			
		||||
           QEMU Monitor Protocol Specification - Version 0.1
 | 
			
		||||
 | 
			
		||||
1. Introduction
 | 
			
		||||
===============
 | 
			
		||||
 | 
			
		||||
This document specifies the QEMU Monitor Protocol (QMP), a JSON-based protocol
 | 
			
		||||
which is available for applications to control QEMU at the machine-level.
 | 
			
		||||
 | 
			
		||||
To enable QMP support, QEMU has to be run in "control mode". This is done by
 | 
			
		||||
starting QEMU with the appropriate command-line options. Please, refer to the
 | 
			
		||||
QEMU manual page for more information.
 | 
			
		||||
 | 
			
		||||
2. Protocol Specification
 | 
			
		||||
=========================
 | 
			
		||||
 | 
			
		||||
This section details the protocol format. For the purpose of this document
 | 
			
		||||
"Client" is any application which is communicating with QEMU in control mode,
 | 
			
		||||
and "Server" is QEMU itself.
 | 
			
		||||
 | 
			
		||||
JSON data structures, when mentioned in this document, are always in the
 | 
			
		||||
following format:
 | 
			
		||||
 | 
			
		||||
    json-DATA-STRUCTURE-NAME
 | 
			
		||||
 | 
			
		||||
Where DATA-STRUCTURE-NAME is any valid JSON data structure, as defined by
 | 
			
		||||
the JSON standard:
 | 
			
		||||
 | 
			
		||||
http://www.ietf.org/rfc/rfc4627.txt
 | 
			
		||||
 | 
			
		||||
For convenience, json-object members and json-array elements mentioned in
 | 
			
		||||
this document will be in a certain order. However, in real protocol usage
 | 
			
		||||
they can be in ANY order, thus no particular order should be assumed.
 | 
			
		||||
 | 
			
		||||
2.1 General Definitions
 | 
			
		||||
-----------------------
 | 
			
		||||
 | 
			
		||||
2.1.1 All interactions transmitted by the Server are json-objects, always
 | 
			
		||||
      terminating with CRLF
 | 
			
		||||
 | 
			
		||||
2.1.2 All json-objects members are mandatory when not specified otherwise
 | 
			
		||||
 | 
			
		||||
2.2 Server Greeting
 | 
			
		||||
-------------------
 | 
			
		||||
 | 
			
		||||
Right when connected the Server will issue a greeting message, which signals
 | 
			
		||||
that the connection has been successfully established and that the Server is
 | 
			
		||||
ready for capabilities negotiation (for more information refer to section
 | 
			
		||||
'4. Capabilities Negotiation').
 | 
			
		||||
 | 
			
		||||
The format is:
 | 
			
		||||
 | 
			
		||||
{ "QMP": { "version": json-object, "capabilities": json-array } }
 | 
			
		||||
 | 
			
		||||
 Where,
 | 
			
		||||
 | 
			
		||||
- The "version" member contains the Server's version information (the format
 | 
			
		||||
  is the same of the 'query-version' command)
 | 
			
		||||
- The "capabilities" member specify the availability of features beyond the
 | 
			
		||||
  baseline specification
 | 
			
		||||
 | 
			
		||||
2.3 Issuing Commands
 | 
			
		||||
--------------------
 | 
			
		||||
 | 
			
		||||
The format for command execution is:
 | 
			
		||||
 | 
			
		||||
{ "execute": json-string, "arguments": json-object, "id": json-value }
 | 
			
		||||
 | 
			
		||||
 Where,
 | 
			
		||||
 | 
			
		||||
- The "execute" member identifies the command to be executed by the Server
 | 
			
		||||
- The "arguments" member is used to pass any arguments required for the
 | 
			
		||||
  execution of the command, it is optional when no arguments are required
 | 
			
		||||
- The "id" member is a transaction identification associated with the
 | 
			
		||||
  command execution, it is optional and will be part of the response if
 | 
			
		||||
  provided
 | 
			
		||||
 | 
			
		||||
2.4 Commands Responses
 | 
			
		||||
----------------------
 | 
			
		||||
 | 
			
		||||
There are two possible responses which the Server will issue as the result
 | 
			
		||||
of a command execution: success or error.
 | 
			
		||||
 | 
			
		||||
2.4.1 success
 | 
			
		||||
-------------
 | 
			
		||||
 | 
			
		||||
The success response is issued when the command execution has finished
 | 
			
		||||
without errors.
 | 
			
		||||
 | 
			
		||||
The format is:
 | 
			
		||||
 | 
			
		||||
{ "return": json-object, "id": json-value }
 | 
			
		||||
 | 
			
		||||
 Where,
 | 
			
		||||
 | 
			
		||||
- The "return" member contains the command returned data, which is defined
 | 
			
		||||
  in a per-command basis or an empty json-object if the command does not
 | 
			
		||||
  return data
 | 
			
		||||
- The "id" member contains the transaction identification associated
 | 
			
		||||
  with the command execution (if issued by the Client)
 | 
			
		||||
 | 
			
		||||
2.4.2 error
 | 
			
		||||
-----------
 | 
			
		||||
 | 
			
		||||
The error response is issued when the command execution could not be
 | 
			
		||||
completed because of an error condition.
 | 
			
		||||
 | 
			
		||||
The format is:
 | 
			
		||||
 | 
			
		||||
{ "error": { "class": json-string, "data": json-object, "desc": json-string },
 | 
			
		||||
  "id": json-value }
 | 
			
		||||
 | 
			
		||||
 Where,
 | 
			
		||||
 | 
			
		||||
- The "class" member contains the error class name (eg. "ServiceUnavailable")
 | 
			
		||||
- The "data" member contains specific error data and is defined in a
 | 
			
		||||
  per-command basis, it will be an empty json-object if the error has no data
 | 
			
		||||
- The "desc" member is a human-readable error message. Clients should
 | 
			
		||||
  not attempt to parse this message.
 | 
			
		||||
- The "id" member contains the transaction identification associated with
 | 
			
		||||
  the command execution (if issued by the Client)
 | 
			
		||||
 | 
			
		||||
NOTE: Some errors can occur before the Server is able to read the "id" member,
 | 
			
		||||
in these cases the "id" member will not be part of the error response, even
 | 
			
		||||
if provided by the client.
 | 
			
		||||
 | 
			
		||||
2.5 Asynchronous events
 | 
			
		||||
-----------------------
 | 
			
		||||
 | 
			
		||||
As a result of state changes, the Server may send messages unilaterally
 | 
			
		||||
to the Client at any time. They are called 'asynchronous events'.
 | 
			
		||||
 | 
			
		||||
The format is:
 | 
			
		||||
 | 
			
		||||
{ "event": json-string, "data": json-object,
 | 
			
		||||
  "timestamp": { "seconds": json-number, "microseconds": json-number } }
 | 
			
		||||
 | 
			
		||||
 Where,
 | 
			
		||||
 | 
			
		||||
- The "event" member contains the event's name
 | 
			
		||||
- The "data" member contains event specific data, which is defined in a
 | 
			
		||||
  per-event basis, it is optional
 | 
			
		||||
- The "timestamp" member contains the exact time of when the event occurred
 | 
			
		||||
  in the Server. It is a fixed json-object with time in seconds and
 | 
			
		||||
  microseconds
 | 
			
		||||
 | 
			
		||||
For a listing of supported asynchronous events, please, refer to the
 | 
			
		||||
qmp-events.txt file.
 | 
			
		||||
 | 
			
		||||
3. QMP Examples
 | 
			
		||||
===============
 | 
			
		||||
 | 
			
		||||
This section provides some examples of real QMP usage, in all of them
 | 
			
		||||
'C' stands for 'Client' and 'S' stands for 'Server'.
 | 
			
		||||
 | 
			
		||||
3.1 Server greeting
 | 
			
		||||
-------------------
 | 
			
		||||
 | 
			
		||||
S: {"QMP": {"version": {"qemu": "0.12.50", "package": ""}, "capabilities": []}}
 | 
			
		||||
 | 
			
		||||
3.2 Simple 'stop' execution
 | 
			
		||||
---------------------------
 | 
			
		||||
 | 
			
		||||
C: { "execute": "stop" }
 | 
			
		||||
S: {"return": {}}
 | 
			
		||||
 | 
			
		||||
3.3 KVM information
 | 
			
		||||
-------------------
 | 
			
		||||
 | 
			
		||||
C: { "execute": "query-kvm", "id": "example" }
 | 
			
		||||
S: {"return": {"enabled": true, "present": true}, "id": "example"}
 | 
			
		||||
 | 
			
		||||
3.4 Parsing error
 | 
			
		||||
------------------
 | 
			
		||||
 | 
			
		||||
C: { "execute": }
 | 
			
		||||
S: {"error": {"class": "JSONParsing", "desc": "Invalid JSON syntax", "data":
 | 
			
		||||
{}}}
 | 
			
		||||
 | 
			
		||||
3.5 Powerdown event
 | 
			
		||||
-------------------
 | 
			
		||||
 | 
			
		||||
S: {"timestamp": {"seconds": 1258551470, "microseconds": 802384}, "event":
 | 
			
		||||
"POWERDOWN"}
 | 
			
		||||
 | 
			
		||||
4. Capabilities Negotiation
 | 
			
		||||
----------------------------
 | 
			
		||||
 | 
			
		||||
When a Client successfully establishes a connection, the Server is in
 | 
			
		||||
Capabilities Negotiation mode.
 | 
			
		||||
 | 
			
		||||
In this mode only the 'qmp_capabilities' command is allowed to run, all
 | 
			
		||||
other commands will return the CommandNotFound error. Asynchronous messages
 | 
			
		||||
are not delivered either.
 | 
			
		||||
 | 
			
		||||
Clients should use the 'qmp_capabilities' command to enable capabilities
 | 
			
		||||
advertised in the Server's greeting (section '2.2 Server Greeting') they
 | 
			
		||||
support.
 | 
			
		||||
 | 
			
		||||
When the 'qmp_capabilities' command is issued, and if it does not return an
 | 
			
		||||
error, the Server enters in Command mode where capabilities changes take
 | 
			
		||||
effect, all commands (except 'qmp_capabilities') are allowed and asynchronous
 | 
			
		||||
messages are delivered.
 | 
			
		||||
 | 
			
		||||
5 Compatibility Considerations
 | 
			
		||||
------------------------------
 | 
			
		||||
 | 
			
		||||
All protocol changes or new features which modify the protocol format in an
 | 
			
		||||
incompatible way are disabled by default and will be advertised by the
 | 
			
		||||
capabilities array (section '2.2 Server Greeting'). Thus, Clients can check
 | 
			
		||||
that array and enable the capabilities they support.
 | 
			
		||||
 | 
			
		||||
Additionally, Clients must not assume any particular:
 | 
			
		||||
 | 
			
		||||
- Size of json-objects or length of json-arrays
 | 
			
		||||
- Order of json-object members or json-array elements
 | 
			
		||||
- Amount of errors generated by a command, that is, new errors can be added
 | 
			
		||||
  to any existing command in newer versions of the Server
 | 
			
		||||
 | 
			
		||||
6. Downstream extension of QMP
 | 
			
		||||
------------------------------
 | 
			
		||||
 | 
			
		||||
We recommend that downstream consumers of QEMU do *not* modify QMP.
 | 
			
		||||
Management tools should be able to support both upstream and downstream
 | 
			
		||||
versions of QMP without special logic, and downstream extensions are
 | 
			
		||||
inherently at odds with that.
 | 
			
		||||
 | 
			
		||||
However, we recognize that it is sometimes impossible for downstreams to
 | 
			
		||||
avoid modifying QMP.  Both upstream and downstream need to take care to
 | 
			
		||||
preserve long-term compatibility and interoperability.
 | 
			
		||||
 | 
			
		||||
To help with that, QMP reserves JSON object member names beginning with
 | 
			
		||||
'__' (double underscore) for downstream use ("downstream names").  This
 | 
			
		||||
means upstream will never use any downstream names for its commands,
 | 
			
		||||
arguments, errors, asynchronous events, and so forth.
 | 
			
		||||
 | 
			
		||||
Any new names downstream wishes to add must begin with '__'.  To
 | 
			
		||||
ensure compatibility with other downstreams, it is strongly
 | 
			
		||||
recommended that you prefix your downstram names with '__RFQDN_' where
 | 
			
		||||
RFQDN is a valid, reverse fully qualified domain name which you
 | 
			
		||||
control.  For example, a qemu-kvm specific monitor command would be:
 | 
			
		||||
 | 
			
		||||
    (qemu) __org.linux-kvm_enable_irqchip
 | 
			
		||||
 | 
			
		||||
Downstream must not change the server greeting (section 2.2) other than
 | 
			
		||||
to offer additional capabilities.  But see below for why even that is
 | 
			
		||||
discouraged.
 | 
			
		||||
 | 
			
		||||
Section '5 Compatibility Considerations' applies to downstream as well
 | 
			
		||||
as to upstream, obviously.  It follows that downstream must behave
 | 
			
		||||
exactly like upstream for any input not containing members with
 | 
			
		||||
downstream names ("downstream members"), except it may add members
 | 
			
		||||
with downstream names to its output.
 | 
			
		||||
 | 
			
		||||
Thus, a client should not be able to distinguish downstream from
 | 
			
		||||
upstream as long as it doesn't send input with downstream members, and
 | 
			
		||||
properly ignores any downstream members in the output it receives.
 | 
			
		||||
 | 
			
		||||
Advice on downstream modifications:
 | 
			
		||||
 | 
			
		||||
1. Introducing new commands is okay.  If you want to extend an existing
 | 
			
		||||
   command, consider introducing a new one with the new behaviour
 | 
			
		||||
   instead.
 | 
			
		||||
 | 
			
		||||
2. Introducing new asynchronous messages is okay.  If you want to extend
 | 
			
		||||
   an existing message, consider adding a new one instead.
 | 
			
		||||
 | 
			
		||||
3. Introducing new errors for use in new commands is okay.  Adding new
 | 
			
		||||
   errors to existing commands counts as extension, so 1. applies.
 | 
			
		||||
 | 
			
		||||
4. New capabilities are strongly discouraged.  Capabilities are for
 | 
			
		||||
   evolving the basic protocol, and multiple diverging basic protocol
 | 
			
		||||
   dialects are most undesirable.
 | 
			
		||||
							
								
								
									
										157
									
								
								QMP/qmp.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										157
									
								
								QMP/qmp.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,157 @@
 | 
			
		||||
# QEMU Monitor Protocol Python class
 | 
			
		||||
# 
 | 
			
		||||
# Copyright (C) 2009, 2010 Red Hat Inc.
 | 
			
		||||
#
 | 
			
		||||
# Authors:
 | 
			
		||||
#  Luiz Capitulino <lcapitulino@redhat.com>
 | 
			
		||||
#
 | 
			
		||||
# This work is licensed under the terms of the GNU GPL, version 2.  See
 | 
			
		||||
# the COPYING file in the top-level directory.
 | 
			
		||||
 | 
			
		||||
import json
 | 
			
		||||
import errno
 | 
			
		||||
import socket
 | 
			
		||||
 | 
			
		||||
class QMPError(Exception):
 | 
			
		||||
    pass
 | 
			
		||||
 | 
			
		||||
class QMPConnectError(QMPError):
 | 
			
		||||
    pass
 | 
			
		||||
 | 
			
		||||
class QMPCapabilitiesError(QMPError):
 | 
			
		||||
    pass
 | 
			
		||||
 | 
			
		||||
class QEMUMonitorProtocol:
 | 
			
		||||
    def __init__(self, address, server=False):
 | 
			
		||||
        """
 | 
			
		||||
        Create a QEMUMonitorProtocol class.
 | 
			
		||||
 | 
			
		||||
        @param address: QEMU address, can be either a unix socket path (string)
 | 
			
		||||
                        or a tuple in the form ( address, port ) for a TCP
 | 
			
		||||
                        connection
 | 
			
		||||
        @param server: server mode listens on the socket (bool)
 | 
			
		||||
        @raise socket.error on socket connection errors
 | 
			
		||||
        @note No connection is established, this is done by the connect() or
 | 
			
		||||
              accept() methods
 | 
			
		||||
        """
 | 
			
		||||
        self.__events = []
 | 
			
		||||
        self.__address = address
 | 
			
		||||
        self.__sock = self.__get_sock()
 | 
			
		||||
        if server:
 | 
			
		||||
            self.__sock.bind(self.__address)
 | 
			
		||||
            self.__sock.listen(1)
 | 
			
		||||
 | 
			
		||||
    def __get_sock(self):
 | 
			
		||||
        if isinstance(self.__address, tuple):
 | 
			
		||||
            family = socket.AF_INET
 | 
			
		||||
        else:
 | 
			
		||||
            family = socket.AF_UNIX
 | 
			
		||||
        return socket.socket(family, socket.SOCK_STREAM)
 | 
			
		||||
 | 
			
		||||
    def __negotiate_capabilities(self):
 | 
			
		||||
        self.__sockfile = self.__sock.makefile()
 | 
			
		||||
        greeting = self.__json_read()
 | 
			
		||||
        if greeting is None or not greeting.has_key('QMP'):
 | 
			
		||||
            raise QMPConnectError
 | 
			
		||||
        # Greeting seems ok, negotiate capabilities
 | 
			
		||||
        resp = self.cmd('qmp_capabilities')
 | 
			
		||||
        if "return" in resp:
 | 
			
		||||
            return greeting
 | 
			
		||||
        raise QMPCapabilitiesError
 | 
			
		||||
 | 
			
		||||
    def __json_read(self, only_event=False):
 | 
			
		||||
        while True:
 | 
			
		||||
            data = self.__sockfile.readline()
 | 
			
		||||
            if not data:
 | 
			
		||||
                return
 | 
			
		||||
            resp = json.loads(data)
 | 
			
		||||
            if 'event' in resp:
 | 
			
		||||
                self.__events.append(resp)
 | 
			
		||||
                if not only_event:
 | 
			
		||||
                    continue
 | 
			
		||||
            return resp
 | 
			
		||||
 | 
			
		||||
    error = socket.error
 | 
			
		||||
 | 
			
		||||
    def connect(self):
 | 
			
		||||
        """
 | 
			
		||||
        Connect to the QMP Monitor and perform capabilities negotiation.
 | 
			
		||||
 | 
			
		||||
        @return QMP greeting dict
 | 
			
		||||
        @raise socket.error on socket connection errors
 | 
			
		||||
        @raise QMPConnectError if the greeting is not received
 | 
			
		||||
        @raise QMPCapabilitiesError if fails to negotiate capabilities
 | 
			
		||||
        """
 | 
			
		||||
        self.__sock.connect(self.__address)
 | 
			
		||||
        return self.__negotiate_capabilities()
 | 
			
		||||
 | 
			
		||||
    def accept(self):
 | 
			
		||||
        """
 | 
			
		||||
        Await connection from QMP Monitor and perform capabilities negotiation.
 | 
			
		||||
 | 
			
		||||
        @return QMP greeting dict
 | 
			
		||||
        @raise socket.error on socket connection errors
 | 
			
		||||
        @raise QMPConnectError if the greeting is not received
 | 
			
		||||
        @raise QMPCapabilitiesError if fails to negotiate capabilities
 | 
			
		||||
        """
 | 
			
		||||
        self.__sock, _ = self.__sock.accept()
 | 
			
		||||
        return self.__negotiate_capabilities()
 | 
			
		||||
 | 
			
		||||
    def cmd_obj(self, qmp_cmd):
 | 
			
		||||
        """
 | 
			
		||||
        Send a QMP command to the QMP Monitor.
 | 
			
		||||
 | 
			
		||||
        @param qmp_cmd: QMP command to be sent as a Python dict
 | 
			
		||||
        @return QMP response as a Python dict or None if the connection has
 | 
			
		||||
                been closed
 | 
			
		||||
        """
 | 
			
		||||
        try:
 | 
			
		||||
            self.__sock.sendall(json.dumps(qmp_cmd))
 | 
			
		||||
        except socket.error, err:
 | 
			
		||||
            if err[0] == errno.EPIPE:
 | 
			
		||||
                return
 | 
			
		||||
            raise socket.error(err)
 | 
			
		||||
        return self.__json_read()
 | 
			
		||||
 | 
			
		||||
    def cmd(self, name, args=None, id=None):
 | 
			
		||||
        """
 | 
			
		||||
        Build a QMP command and send it to the QMP Monitor.
 | 
			
		||||
 | 
			
		||||
        @param name: command name (string)
 | 
			
		||||
        @param args: command arguments (dict)
 | 
			
		||||
        @param id: command id (dict, list, string or int)
 | 
			
		||||
        """
 | 
			
		||||
        qmp_cmd = { 'execute': name }
 | 
			
		||||
        if args:
 | 
			
		||||
            qmp_cmd['arguments'] = args
 | 
			
		||||
        if id:
 | 
			
		||||
            qmp_cmd['id'] = id
 | 
			
		||||
        return self.cmd_obj(qmp_cmd)
 | 
			
		||||
 | 
			
		||||
    def get_events(self, wait=False):
 | 
			
		||||
        """
 | 
			
		||||
        Get a list of available QMP events.
 | 
			
		||||
 | 
			
		||||
        @param wait: block until an event is available (bool)
 | 
			
		||||
        """
 | 
			
		||||
        self.__sock.setblocking(0)
 | 
			
		||||
        try:
 | 
			
		||||
            self.__json_read()
 | 
			
		||||
        except socket.error, err:
 | 
			
		||||
            if err[0] == errno.EAGAIN:
 | 
			
		||||
                # No data available
 | 
			
		||||
                pass
 | 
			
		||||
        self.__sock.setblocking(1)
 | 
			
		||||
        if not self.__events and wait:
 | 
			
		||||
            self.__json_read(only_event=True)
 | 
			
		||||
        return self.__events
 | 
			
		||||
 | 
			
		||||
    def clear_events(self):
 | 
			
		||||
        """
 | 
			
		||||
        Clear current list of pending events.
 | 
			
		||||
        """
 | 
			
		||||
        self.__events = []
 | 
			
		||||
 | 
			
		||||
    def close(self):
 | 
			
		||||
        self.__sock.close()
 | 
			
		||||
        self.__sockfile.close()
 | 
			
		||||
							
								
								
									
										140
									
								
								README
									
									
									
									
									
								
							
							
						
						
									
										140
									
								
								README
									
									
									
									
									
								
							@@ -1,139 +1,3 @@
 | 
			
		||||
         QEMU README
 | 
			
		||||
         ===========
 | 
			
		||||
Read the documentation in qemu-doc.html.
 | 
			
		||||
 | 
			
		||||
QEMU is a generic and open source machine & userspace emulator and
 | 
			
		||||
virtualizer.
 | 
			
		||||
 | 
			
		||||
QEMU is capable of emulating a complete machine in software without any
 | 
			
		||||
need for hardware virtualization support. By using dynamic translation,
 | 
			
		||||
it achieves very good performance. QEMU can also integrate with the Xen
 | 
			
		||||
and KVM hypervisors to provide emulated hardware while allowing the
 | 
			
		||||
hypervisor to manage the CPU. With hypervisor support, QEMU can achieve
 | 
			
		||||
near native performance for CPUs. When QEMU emulates CPUs directly it is
 | 
			
		||||
capable of running operating systems made for one machine (e.g. an ARMv7
 | 
			
		||||
board) on a different machine (e.g. an x86_64 PC board).
 | 
			
		||||
 | 
			
		||||
QEMU is also capable of providing userspace API virtualization for Linux
 | 
			
		||||
and BSD kernel interfaces. This allows binaries compiled against one
 | 
			
		||||
architecture ABI (e.g. the Linux PPC64 ABI) to be run on a host using a
 | 
			
		||||
different architecture ABI (e.g. the Linux x86_64 ABI). This does not
 | 
			
		||||
involve any hardware emulation, simply CPU and syscall emulation.
 | 
			
		||||
 | 
			
		||||
QEMU aims to fit into a variety of use cases. It can be invoked directly
 | 
			
		||||
by users wishing to have full control over its behaviour and settings.
 | 
			
		||||
It also aims to facilitate integration into higher level management
 | 
			
		||||
layers, by providing a stable command line interface and monitor API.
 | 
			
		||||
It is commonly invoked indirectly via the libvirt library when using
 | 
			
		||||
open source applications such as oVirt, OpenStack and virt-manager.
 | 
			
		||||
 | 
			
		||||
QEMU as a whole is released under the GNU General Public License,
 | 
			
		||||
version 2. For full licensing details, consult the LICENSE file.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Building
 | 
			
		||||
========
 | 
			
		||||
 | 
			
		||||
QEMU is multi-platform software intended to be buildable on all modern
 | 
			
		||||
Linux platforms, OS-X, Win32 (via the Mingw64 toolchain) and a variety
 | 
			
		||||
of other UNIX targets. The simple steps to build QEMU are:
 | 
			
		||||
 | 
			
		||||
  mkdir build
 | 
			
		||||
  cd build
 | 
			
		||||
  ../configure
 | 
			
		||||
  make
 | 
			
		||||
 | 
			
		||||
Additional information can also be found online via the QEMU website:
 | 
			
		||||
 | 
			
		||||
  https://qemu.org/Hosts/Linux
 | 
			
		||||
  https://qemu.org/Hosts/Mac
 | 
			
		||||
  https://qemu.org/Hosts/W32
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Submitting patches
 | 
			
		||||
==================
 | 
			
		||||
 | 
			
		||||
The QEMU source code is maintained under the GIT version control system.
 | 
			
		||||
 | 
			
		||||
   git clone https://git.qemu.org/git/qemu.git
 | 
			
		||||
 | 
			
		||||
When submitting patches, one common approach is to use 'git
 | 
			
		||||
format-patch' and/or 'git send-email' to format & send the mail to the
 | 
			
		||||
qemu-devel@nongnu.org mailing list. All patches submitted must contain
 | 
			
		||||
a 'Signed-off-by' line from the author. Patches should follow the
 | 
			
		||||
guidelines set out in the HACKING and CODING_STYLE files.
 | 
			
		||||
 | 
			
		||||
Additional information on submitting patches can be found online via
 | 
			
		||||
the QEMU website
 | 
			
		||||
 | 
			
		||||
  https://qemu.org/Contribute/SubmitAPatch
 | 
			
		||||
  https://qemu.org/Contribute/TrivialPatches
 | 
			
		||||
 | 
			
		||||
The QEMU website is also maintained under source control.
 | 
			
		||||
 | 
			
		||||
  git clone https://git.qemu.org/git/qemu-web.git
 | 
			
		||||
  https://www.qemu.org/2017/02/04/the-new-qemu-website-is-up/
 | 
			
		||||
 | 
			
		||||
A 'git-publish' utility was created to make above process less
 | 
			
		||||
cumbersome, and is highly recommended for making regular contributions,
 | 
			
		||||
or even just for sending consecutive patch series revisions. It also
 | 
			
		||||
requires a working 'git send-email' setup, and by default doesn't
 | 
			
		||||
automate everything, so you may want to go through the above steps
 | 
			
		||||
manually for once.
 | 
			
		||||
 | 
			
		||||
For installation instructions, please go to
 | 
			
		||||
 | 
			
		||||
  https://github.com/stefanha/git-publish
 | 
			
		||||
 | 
			
		||||
The workflow with 'git-publish' is:
 | 
			
		||||
 | 
			
		||||
  $ git checkout master -b my-feature
 | 
			
		||||
  $ # work on new commits, add your 'Signed-off-by' lines to each
 | 
			
		||||
  $ git publish
 | 
			
		||||
 | 
			
		||||
Your patch series will be sent and tagged as my-feature-v1 if you need to refer
 | 
			
		||||
back to it in the future.
 | 
			
		||||
 | 
			
		||||
Sending v2:
 | 
			
		||||
 | 
			
		||||
  $ git checkout my-feature # same topic branch
 | 
			
		||||
  $ # making changes to the commits (using 'git rebase', for example)
 | 
			
		||||
  $ git publish
 | 
			
		||||
 | 
			
		||||
Your patch series will be sent with 'v2' tag in the subject and the git tip
 | 
			
		||||
will be tagged as my-feature-v2.
 | 
			
		||||
 | 
			
		||||
Bug reporting
 | 
			
		||||
=============
 | 
			
		||||
 | 
			
		||||
The QEMU project uses Launchpad as its primary upstream bug tracker. Bugs
 | 
			
		||||
found when running code built from QEMU git or upstream released sources
 | 
			
		||||
should be reported via:
 | 
			
		||||
 | 
			
		||||
  https://bugs.launchpad.net/qemu/
 | 
			
		||||
 | 
			
		||||
If using QEMU via an operating system vendor pre-built binary package, it
 | 
			
		||||
is preferable to report bugs to the vendor's own bug tracker first. If
 | 
			
		||||
the bug is also known to affect latest upstream code, it can also be
 | 
			
		||||
reported via launchpad.
 | 
			
		||||
 | 
			
		||||
For additional information on bug reporting consult:
 | 
			
		||||
 | 
			
		||||
  https://qemu.org/Contribute/ReportABug
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Contact
 | 
			
		||||
=======
 | 
			
		||||
 | 
			
		||||
The QEMU community can be contacted in a number of ways, with the two
 | 
			
		||||
main methods being email and IRC
 | 
			
		||||
 | 
			
		||||
 - qemu-devel@nongnu.org
 | 
			
		||||
   https://lists.nongnu.org/mailman/listinfo/qemu-devel
 | 
			
		||||
 - #qemu on irc.oftc.net
 | 
			
		||||
 | 
			
		||||
Information on additional methods of contacting the community can be
 | 
			
		||||
found online via the QEMU website:
 | 
			
		||||
 | 
			
		||||
  https://qemu.org/Contribute/StartHere
 | 
			
		||||
 | 
			
		||||
-- End
 | 
			
		||||
Fabrice Bellard.
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										37
									
								
								TODO
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								TODO
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,37 @@
 | 
			
		||||
General:
 | 
			
		||||
-------
 | 
			
		||||
- cycle counter for all archs
 | 
			
		||||
- cpu_interrupt() win32/SMP fix
 | 
			
		||||
- merge PIC spurious interrupt patch
 | 
			
		||||
- warning for OS/2: must not use 128 MB memory (merge bochs cmos patch ?)
 | 
			
		||||
- config file (at least for windows/Mac OS X)
 | 
			
		||||
- update doc: PCI infos.
 | 
			
		||||
- basic VGA optimizations
 | 
			
		||||
- better code fetch
 | 
			
		||||
- do not resize vga if invalid size.
 | 
			
		||||
- TLB code protection support for PPC
 | 
			
		||||
- disable SMC handling for ARM/SPARC/PPC (not finished)
 | 
			
		||||
- see undefined flags for BTx insn
 | 
			
		||||
- keyboard output buffer filling timing emulation
 | 
			
		||||
- tests for each target CPU
 | 
			
		||||
- fix all remaining thread lock issues (must put TBs in a specific invalid
 | 
			
		||||
  state, find a solution for tb_flush()).
 | 
			
		||||
 | 
			
		||||
ppc specific:
 | 
			
		||||
------------
 | 
			
		||||
- TLB invalidate not needed if msr_pr changes
 | 
			
		||||
- enable shift optimizations ?
 | 
			
		||||
 | 
			
		||||
linux-user specific:
 | 
			
		||||
-------------------
 | 
			
		||||
- remove threading support as it cannot work at this point
 | 
			
		||||
- improve IPC syscalls
 | 
			
		||||
- more syscalls (in particular all 64 bit ones, IPCs, fix 64 bit
 | 
			
		||||
  issues, fix 16 bit uid issues)
 | 
			
		||||
- use kernel traps for unaligned accesses on ARM ?
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
lower priority:
 | 
			
		||||
--------------
 | 
			
		||||
- int15 ah=86: use better timing
 | 
			
		||||
- use -msoft-float on ARM
 | 
			
		||||
							
								
								
									
										430
									
								
								a.out.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										430
									
								
								a.out.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,430 @@
 | 
			
		||||
/* a.out.h
 | 
			
		||||
 | 
			
		||||
   Copyright 1997, 1998, 1999, 2001 Red Hat, Inc.
 | 
			
		||||
 | 
			
		||||
This file is part of Cygwin.
 | 
			
		||||
 | 
			
		||||
This software is a copyrighted work licensed under the terms of the
 | 
			
		||||
Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
 | 
			
		||||
details. */
 | 
			
		||||
 | 
			
		||||
#ifndef _A_OUT_H_
 | 
			
		||||
#define _A_OUT_H_
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
extern "C" {
 | 
			
		||||
#endif
 | 
			
		||||
#define COFF_IMAGE_WITH_PE
 | 
			
		||||
#define COFF_LONG_SECTION_NAMES
 | 
			
		||||
 | 
			
		||||
/*** coff information for Intel 386/486.  */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/********************** FILE HEADER **********************/
 | 
			
		||||
 | 
			
		||||
struct external_filehdr {
 | 
			
		||||
  short f_magic;	/* magic number			*/
 | 
			
		||||
  short f_nscns;	/* number of sections		*/
 | 
			
		||||
  host_ulong f_timdat;	/* time & date stamp		*/
 | 
			
		||||
  host_ulong f_symptr;	/* file pointer to symtab	*/
 | 
			
		||||
  host_ulong f_nsyms;	/* number of symtab entries	*/
 | 
			
		||||
  short f_opthdr;	/* sizeof(optional hdr)		*/
 | 
			
		||||
  short f_flags;	/* flags			*/
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* Bits for f_flags:
 | 
			
		||||
 *	F_RELFLG	relocation info stripped from file
 | 
			
		||||
 *	F_EXEC		file is executable (no unresolved external references)
 | 
			
		||||
 *	F_LNNO		line numbers stripped from file
 | 
			
		||||
 *	F_LSYMS		local symbols stripped from file
 | 
			
		||||
 *	F_AR32WR	file has byte ordering of an AR32WR machine (e.g. vax)
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#define F_RELFLG	(0x0001)
 | 
			
		||||
#define F_EXEC		(0x0002)
 | 
			
		||||
#define F_LNNO		(0x0004)
 | 
			
		||||
#define F_LSYMS		(0x0008)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define	I386MAGIC	0x14c
 | 
			
		||||
#define I386PTXMAGIC	0x154
 | 
			
		||||
#define I386AIXMAGIC	0x175
 | 
			
		||||
 | 
			
		||||
/* This is Lynx's all-platform magic number for executables. */
 | 
			
		||||
 | 
			
		||||
#define LYNXCOFFMAGIC	0415
 | 
			
		||||
 | 
			
		||||
#define I386BADMAG(x) (((x).f_magic != I386MAGIC) \
 | 
			
		||||
		       && (x).f_magic != I386AIXMAGIC \
 | 
			
		||||
		       && (x).f_magic != I386PTXMAGIC \
 | 
			
		||||
		       && (x).f_magic != LYNXCOFFMAGIC)
 | 
			
		||||
 | 
			
		||||
#define	FILHDR	struct external_filehdr
 | 
			
		||||
#define	FILHSZ	20
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/********************** AOUT "OPTIONAL HEADER"=
 | 
			
		||||
 **********************/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
typedef struct
 | 
			
		||||
{
 | 
			
		||||
  unsigned short magic;		/* type of file				*/
 | 
			
		||||
  unsigned short vstamp;	/* version stamp			*/
 | 
			
		||||
  host_ulong	tsize;		/* text size in bytes, padded to FW bdry*/
 | 
			
		||||
  host_ulong	dsize;		/* initialized data "  "		*/
 | 
			
		||||
  host_ulong	bsize;		/* uninitialized data "   "		*/
 | 
			
		||||
  host_ulong	entry;		/* entry pt.				*/
 | 
			
		||||
  host_ulong text_start;	/* base of text used for this file */
 | 
			
		||||
  host_ulong data_start;	/* base of data used for this file=
 | 
			
		||||
 */
 | 
			
		||||
}
 | 
			
		||||
AOUTHDR;
 | 
			
		||||
 | 
			
		||||
#define AOUTSZ 28
 | 
			
		||||
#define AOUTHDRSZ 28
 | 
			
		||||
 | 
			
		||||
#define OMAGIC          0404    /* object files, eg as output */
 | 
			
		||||
#define ZMAGIC          0413    /* demand load format, eg normal ld output */
 | 
			
		||||
#define STMAGIC		0401	/* target shlib */
 | 
			
		||||
#define SHMAGIC		0443	/* host   shlib */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/* define some NT default values */
 | 
			
		||||
/*  #define NT_IMAGE_BASE        0x400000 moved to internal.h */
 | 
			
		||||
#define NT_SECTION_ALIGNMENT 0x1000
 | 
			
		||||
#define NT_FILE_ALIGNMENT    0x200
 | 
			
		||||
#define NT_DEF_RESERVE       0x100000
 | 
			
		||||
#define NT_DEF_COMMIT        0x1000
 | 
			
		||||
 | 
			
		||||
/********************** SECTION HEADER **********************/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
struct external_scnhdr {
 | 
			
		||||
  char		s_name[8];	/* section name			*/
 | 
			
		||||
  host_ulong	s_paddr;	/* physical address, offset
 | 
			
		||||
				   of last addr in scn */
 | 
			
		||||
  host_ulong	s_vaddr;	/* virtual address		*/
 | 
			
		||||
  host_ulong	s_size;		/* section size			*/
 | 
			
		||||
  host_ulong	s_scnptr;	/* file ptr to raw data for section */
 | 
			
		||||
  host_ulong	s_relptr;	/* file ptr to relocation	*/
 | 
			
		||||
  host_ulong	s_lnnoptr;	/* file ptr to line numbers	*/
 | 
			
		||||
  unsigned short s_nreloc;	/* number of relocation entries	*/
 | 
			
		||||
  unsigned short s_nlnno;	/* number of line number entries*/
 | 
			
		||||
  host_ulong	s_flags;	/* flags			*/
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#define	SCNHDR	struct external_scnhdr
 | 
			
		||||
#define	SCNHSZ	40
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * names of "special" sections
 | 
			
		||||
 */
 | 
			
		||||
#define _TEXT	".text"
 | 
			
		||||
#define _DATA	".data"
 | 
			
		||||
#define _BSS	".bss"
 | 
			
		||||
#define _COMMENT ".comment"
 | 
			
		||||
#define _LIB ".lib"
 | 
			
		||||
 | 
			
		||||
/********************** LINE NUMBERS **********************/
 | 
			
		||||
 | 
			
		||||
/* 1 line number entry for every "breakpointable" source line in a section.
 | 
			
		||||
 * Line numbers are grouped on a per function basis; first entry in a function
 | 
			
		||||
 * grouping will have l_lnno = 0 and in place of physical address will be the
 | 
			
		||||
 * symbol table index of the function name.
 | 
			
		||||
 */
 | 
			
		||||
struct external_lineno {
 | 
			
		||||
  union {
 | 
			
		||||
    host_ulong l_symndx; /* function name symbol index, iff l_lnno 0 */
 | 
			
		||||
    host_ulong l_paddr;	/* (physical) address of line number	*/
 | 
			
		||||
  } l_addr;
 | 
			
		||||
  unsigned short l_lnno;	/* line number		*/
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#define	LINENO	struct external_lineno
 | 
			
		||||
#define	LINESZ	6
 | 
			
		||||
 | 
			
		||||
/********************** SYMBOLS **********************/
 | 
			
		||||
 | 
			
		||||
#define E_SYMNMLEN	8	/* # characters in a symbol name	*/
 | 
			
		||||
#define E_FILNMLEN	14	/* # characters in a file name		*/
 | 
			
		||||
#define E_DIMNUM	4	/* # array dimensions in auxiliary entry */
 | 
			
		||||
 | 
			
		||||
struct __attribute__((packed)) external_syment
 | 
			
		||||
{
 | 
			
		||||
  union {
 | 
			
		||||
    char e_name[E_SYMNMLEN];
 | 
			
		||||
    struct {
 | 
			
		||||
      host_ulong e_zeroes;
 | 
			
		||||
      host_ulong e_offset;
 | 
			
		||||
    } e;
 | 
			
		||||
  } e;
 | 
			
		||||
  host_ulong e_value;
 | 
			
		||||
  unsigned short e_scnum;
 | 
			
		||||
  unsigned short e_type;
 | 
			
		||||
  char e_sclass[1];
 | 
			
		||||
  char e_numaux[1];
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#define N_BTMASK	(0xf)
 | 
			
		||||
#define N_TMASK		(0x30)
 | 
			
		||||
#define N_BTSHFT	(4)
 | 
			
		||||
#define N_TSHIFT	(2)
 | 
			
		||||
 | 
			
		||||
union external_auxent {
 | 
			
		||||
  struct {
 | 
			
		||||
    host_ulong x_tagndx;	/* str, un, or enum tag indx */
 | 
			
		||||
    union {
 | 
			
		||||
      struct {
 | 
			
		||||
	unsigned short  x_lnno; /* declaration line number */
 | 
			
		||||
	unsigned short  x_size; /* str/union/array size */
 | 
			
		||||
      } x_lnsz;
 | 
			
		||||
      host_ulong x_fsize;	/* size of function */
 | 
			
		||||
    } x_misc;
 | 
			
		||||
    union {
 | 
			
		||||
      struct {			/* if ISFCN, tag, or .bb */
 | 
			
		||||
	host_ulong x_lnnoptr;/* ptr to fcn line # */
 | 
			
		||||
	host_ulong x_endndx;	/* entry ndx past block end */
 | 
			
		||||
      } x_fcn;
 | 
			
		||||
      struct {			/* if ISARY, up to 4 dimen. */
 | 
			
		||||
	char x_dimen[E_DIMNUM][2];
 | 
			
		||||
      } x_ary;
 | 
			
		||||
    } x_fcnary;
 | 
			
		||||
    unsigned short x_tvndx;	/* tv index */
 | 
			
		||||
  } x_sym;
 | 
			
		||||
 | 
			
		||||
  union {
 | 
			
		||||
    char x_fname[E_FILNMLEN];
 | 
			
		||||
    struct {
 | 
			
		||||
      host_ulong x_zeroes;
 | 
			
		||||
      host_ulong x_offset;
 | 
			
		||||
    } x_n;
 | 
			
		||||
  } x_file;
 | 
			
		||||
 | 
			
		||||
  struct {
 | 
			
		||||
    host_ulong x_scnlen;	/* section length */
 | 
			
		||||
    unsigned short x_nreloc;	/* # relocation entries */
 | 
			
		||||
    unsigned short x_nlinno;	/* # line numbers */
 | 
			
		||||
    host_ulong x_checksum;	/* section COMDAT checksum */
 | 
			
		||||
    unsigned short x_associated;/* COMDAT associated section index */
 | 
			
		||||
    char x_comdat[1];		/* COMDAT selection number */
 | 
			
		||||
  } x_scn;
 | 
			
		||||
 | 
			
		||||
  struct {
 | 
			
		||||
    host_ulong x_tvfill;	/* tv fill value */
 | 
			
		||||
    unsigned short x_tvlen;	/* length of .tv */
 | 
			
		||||
    char x_tvran[2][2];		/* tv range */
 | 
			
		||||
  } x_tv;	/* info about .tv section (in auxent of symbol .tv)) */
 | 
			
		||||
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#define	SYMENT	struct external_syment
 | 
			
		||||
#define	SYMESZ	18
 | 
			
		||||
#define	AUXENT	union external_auxent
 | 
			
		||||
#define	AUXESZ	18
 | 
			
		||||
 | 
			
		||||
#define _ETEXT	"etext"
 | 
			
		||||
 | 
			
		||||
/********************** RELOCATION DIRECTIVES **********************/
 | 
			
		||||
 | 
			
		||||
struct external_reloc {
 | 
			
		||||
  char r_vaddr[4];
 | 
			
		||||
  char r_symndx[4];
 | 
			
		||||
  char r_type[2];
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#define RELOC struct external_reloc
 | 
			
		||||
#define RELSZ 10
 | 
			
		||||
 | 
			
		||||
/* end of coff/i386.h */
 | 
			
		||||
 | 
			
		||||
/* PE COFF header information */
 | 
			
		||||
 | 
			
		||||
#ifndef _PE_H
 | 
			
		||||
#define _PE_H
 | 
			
		||||
 | 
			
		||||
/* NT specific file attributes */
 | 
			
		||||
#define IMAGE_FILE_RELOCS_STRIPPED           0x0001
 | 
			
		||||
#define IMAGE_FILE_EXECUTABLE_IMAGE          0x0002
 | 
			
		||||
#define IMAGE_FILE_LINE_NUMS_STRIPPED        0x0004
 | 
			
		||||
#define IMAGE_FILE_LOCAL_SYMS_STRIPPED       0x0008
 | 
			
		||||
#define IMAGE_FILE_BYTES_REVERSED_LO         0x0080
 | 
			
		||||
#define IMAGE_FILE_32BIT_MACHINE             0x0100
 | 
			
		||||
#define IMAGE_FILE_DEBUG_STRIPPED            0x0200
 | 
			
		||||
#define IMAGE_FILE_SYSTEM                    0x1000
 | 
			
		||||
#define IMAGE_FILE_DLL                       0x2000
 | 
			
		||||
#define IMAGE_FILE_BYTES_REVERSED_HI         0x8000
 | 
			
		||||
 | 
			
		||||
/* additional flags to be set for section headers to allow the NT loader to
 | 
			
		||||
   read and write to the section data (to replace the addresses of data in
 | 
			
		||||
   dlls for one thing); also to execute the section in .text's case=
 | 
			
		||||
 */
 | 
			
		||||
#define IMAGE_SCN_MEM_DISCARDABLE 0x02000000
 | 
			
		||||
#define IMAGE_SCN_MEM_EXECUTE     0x20000000
 | 
			
		||||
#define IMAGE_SCN_MEM_READ        0x40000000
 | 
			
		||||
#define IMAGE_SCN_MEM_WRITE       0x80000000
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Section characteristics added for ppc-nt
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#define IMAGE_SCN_TYPE_NO_PAD                0x00000008  /* Reserved.  */
 | 
			
		||||
 | 
			
		||||
#define IMAGE_SCN_CNT_CODE                   0x00000020  /* Section contains code. */
 | 
			
		||||
#define IMAGE_SCN_CNT_INITIALIZED_DATA       0x00000040  /* Section contains initialized data. */
 | 
			
		||||
#define IMAGE_SCN_CNT_UNINITIALIZED_DATA     0x00000080  /* Section contains uninitialized data. */
 | 
			
		||||
 | 
			
		||||
#define IMAGE_SCN_LNK_OTHER                  0x00000100  /* Reserved.  */
 | 
			
		||||
#define IMAGE_SCN_LNK_INFO                   0x00000200  /* Section contains comments or some other type of information. */
 | 
			
		||||
#define IMAGE_SCN_LNK_REMOVE                 0x00000800  /* Section contents will not become part of image. */
 | 
			
		||||
#define IMAGE_SCN_LNK_COMDAT                 0x00001000  /* Section contents comdat. */
 | 
			
		||||
 | 
			
		||||
#define IMAGE_SCN_MEM_FARDATA                0x00008000
 | 
			
		||||
 | 
			
		||||
#define IMAGE_SCN_MEM_PURGEABLE              0x00020000
 | 
			
		||||
#define IMAGE_SCN_MEM_16BIT                  0x00020000
 | 
			
		||||
#define IMAGE_SCN_MEM_LOCKED                 0x00040000
 | 
			
		||||
#define IMAGE_SCN_MEM_PRELOAD                0x00080000
 | 
			
		||||
 | 
			
		||||
#define IMAGE_SCN_ALIGN_1BYTES               0x00100000
 | 
			
		||||
#define IMAGE_SCN_ALIGN_2BYTES               0x00200000
 | 
			
		||||
#define IMAGE_SCN_ALIGN_4BYTES               0x00300000
 | 
			
		||||
#define IMAGE_SCN_ALIGN_8BYTES               0x00400000
 | 
			
		||||
#define IMAGE_SCN_ALIGN_16BYTES              0x00500000  /* Default alignment if no others are specified. */
 | 
			
		||||
#define IMAGE_SCN_ALIGN_32BYTES              0x00600000
 | 
			
		||||
#define IMAGE_SCN_ALIGN_64BYTES              0x00700000
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define IMAGE_SCN_LNK_NRELOC_OVFL            0x01000000  /* Section contains extended relocations. */
 | 
			
		||||
#define IMAGE_SCN_MEM_NOT_CACHED             0x04000000  /* Section is not cachable.               */
 | 
			
		||||
#define IMAGE_SCN_MEM_NOT_PAGED              0x08000000  /* Section is not pageable.               */
 | 
			
		||||
#define IMAGE_SCN_MEM_SHARED                 0x10000000  /* Section is shareable.                  */
 | 
			
		||||
 | 
			
		||||
/* COMDAT selection codes.  */
 | 
			
		||||
 | 
			
		||||
#define IMAGE_COMDAT_SELECT_NODUPLICATES     (1) /* Warn if duplicates.  */
 | 
			
		||||
#define IMAGE_COMDAT_SELECT_ANY		     (2) /* No warning.  */
 | 
			
		||||
#define IMAGE_COMDAT_SELECT_SAME_SIZE	     (3) /* Warn if different size.  */
 | 
			
		||||
#define IMAGE_COMDAT_SELECT_EXACT_MATCH	     (4) /* Warn if different.  */
 | 
			
		||||
#define IMAGE_COMDAT_SELECT_ASSOCIATIVE	     (5) /* Base on other section.  */
 | 
			
		||||
 | 
			
		||||
/* Magic values that are true for all dos/nt implementations */
 | 
			
		||||
#define DOSMAGIC       0x5a4d
 | 
			
		||||
#define NT_SIGNATURE   0x00004550
 | 
			
		||||
 | 
			
		||||
/* NT allows long filenames, we want to accommodate this.  This may break
 | 
			
		||||
     some of the bfd functions */
 | 
			
		||||
#undef  FILNMLEN
 | 
			
		||||
#define FILNMLEN	18	/* # characters in a file name		*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#ifdef COFF_IMAGE_WITH_PE
 | 
			
		||||
/* The filehdr is only weired in images */
 | 
			
		||||
 | 
			
		||||
#undef FILHDR
 | 
			
		||||
struct external_PE_filehdr
 | 
			
		||||
{
 | 
			
		||||
  /* DOS header fields */
 | 
			
		||||
  unsigned short e_magic;	/* Magic number, 0x5a4d */
 | 
			
		||||
  unsigned short e_cblp;	/* Bytes on last page of file, 0x90 */
 | 
			
		||||
  unsigned short e_cp;		/* Pages in file, 0x3 */
 | 
			
		||||
  unsigned short e_crlc;	/* Relocations, 0x0 */
 | 
			
		||||
  unsigned short e_cparhdr;	/* Size of header in paragraphs, 0x4 */
 | 
			
		||||
  unsigned short e_minalloc;	/* Minimum extra paragraphs needed, 0x0 */
 | 
			
		||||
  unsigned short e_maxalloc;	/* Maximum extra paragraphs needed, 0xFFFF */
 | 
			
		||||
  unsigned short e_ss;		/* Initial (relative) SS value, 0x0 */
 | 
			
		||||
  unsigned short e_sp;		/* Initial SP value, 0xb8 */
 | 
			
		||||
  unsigned short e_csum;	/* Checksum, 0x0 */
 | 
			
		||||
  unsigned short e_ip;		/* Initial IP value, 0x0 */
 | 
			
		||||
  unsigned short e_cs;		/* Initial (relative) CS value, 0x0 */
 | 
			
		||||
  unsigned short e_lfarlc;	/* File address of relocation table, 0x40 */
 | 
			
		||||
  unsigned short e_ovno;	/* Overlay number, 0x0 */
 | 
			
		||||
  char e_res[4][2];		/* Reserved words, all 0x0 */
 | 
			
		||||
  unsigned short e_oemid;	/* OEM identifier (for e_oeminfo), 0x0 */
 | 
			
		||||
  unsigned short e_oeminfo;	/* OEM information; e_oemid specific, 0x0 */
 | 
			
		||||
  char e_res2[10][2];		/* Reserved words, all 0x0 */
 | 
			
		||||
  host_ulong e_lfanew;	/* File address of new exe header, 0x80 */
 | 
			
		||||
  char dos_message[16][4];	/* other stuff, always follow DOS header */
 | 
			
		||||
  unsigned int nt_signature;	/* required NT signature, 0x4550 */
 | 
			
		||||
 | 
			
		||||
  /* From standard header */
 | 
			
		||||
 | 
			
		||||
  unsigned short f_magic;	/* magic number			*/
 | 
			
		||||
  unsigned short f_nscns;	/* number of sections		*/
 | 
			
		||||
  host_ulong f_timdat;	/* time & date stamp		*/
 | 
			
		||||
  host_ulong f_symptr;	/* file pointer to symtab	*/
 | 
			
		||||
  host_ulong f_nsyms;	/* number of symtab entries	*/
 | 
			
		||||
  unsigned short f_opthdr;	/* sizeof(optional hdr)		*/
 | 
			
		||||
  unsigned short f_flags;	/* flags			*/
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define FILHDR struct external_PE_filehdr
 | 
			
		||||
#undef FILHSZ
 | 
			
		||||
#define FILHSZ 152
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
typedef struct
 | 
			
		||||
{
 | 
			
		||||
  unsigned short magic;		/* type of file				*/
 | 
			
		||||
  unsigned short vstamp;	/* version stamp			*/
 | 
			
		||||
  host_ulong	tsize;		/* text size in bytes, padded to FW bdry*/
 | 
			
		||||
  host_ulong	dsize;		/* initialized data "  "		*/
 | 
			
		||||
  host_ulong	bsize;		/* uninitialized data "   "		*/
 | 
			
		||||
  host_ulong	entry;		/* entry pt.				*/
 | 
			
		||||
  host_ulong text_start;	/* base of text used for this file */
 | 
			
		||||
  host_ulong data_start;	/* base of all data used for this file */
 | 
			
		||||
 | 
			
		||||
  /* NT extra fields; see internal.h for descriptions */
 | 
			
		||||
  host_ulong  ImageBase;
 | 
			
		||||
  host_ulong  SectionAlignment;
 | 
			
		||||
  host_ulong  FileAlignment;
 | 
			
		||||
  unsigned short  MajorOperatingSystemVersion;
 | 
			
		||||
  unsigned short  MinorOperatingSystemVersion;
 | 
			
		||||
  unsigned short  MajorImageVersion;
 | 
			
		||||
  unsigned short  MinorImageVersion;
 | 
			
		||||
  unsigned short  MajorSubsystemVersion;
 | 
			
		||||
  unsigned short  MinorSubsystemVersion;
 | 
			
		||||
  char  Reserved1[4];
 | 
			
		||||
  host_ulong  SizeOfImage;
 | 
			
		||||
  host_ulong  SizeOfHeaders;
 | 
			
		||||
  host_ulong  CheckSum;
 | 
			
		||||
  unsigned short Subsystem;
 | 
			
		||||
  unsigned short DllCharacteristics;
 | 
			
		||||
  host_ulong  SizeOfStackReserve;
 | 
			
		||||
  host_ulong  SizeOfStackCommit;
 | 
			
		||||
  host_ulong  SizeOfHeapReserve;
 | 
			
		||||
  host_ulong  SizeOfHeapCommit;
 | 
			
		||||
  host_ulong  LoaderFlags;
 | 
			
		||||
  host_ulong  NumberOfRvaAndSizes;
 | 
			
		||||
  /* IMAGE_DATA_DIRECTORY DataDirectory[IMAGE_NUMBEROF_DIRECTORY_ENTRIES]; */
 | 
			
		||||
  char  DataDirectory[16][2][4]; /* 16 entries, 2 elements/entry, 4 chars */
 | 
			
		||||
 | 
			
		||||
} PEAOUTHDR;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#undef AOUTSZ
 | 
			
		||||
#define AOUTSZ (AOUTHDRSZ + 196)
 | 
			
		||||
 | 
			
		||||
#undef  E_FILNMLEN
 | 
			
		||||
#define E_FILNMLEN	18	/* # characters in a file name		*/
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/* end of coff/pe.h */
 | 
			
		||||
 | 
			
		||||
#define DT_NON		(0)	/* no derived type */
 | 
			
		||||
#define DT_PTR		(1)	/* pointer */
 | 
			
		||||
#define DT_FCN		(2)	/* function */
 | 
			
		||||
#define DT_ARY		(3)	/* array */
 | 
			
		||||
 | 
			
		||||
#define ISPTR(x)	(((x) & N_TMASK) == (DT_PTR << N_BTSHFT))
 | 
			
		||||
#define ISFCN(x)	(((x) & N_TMASK) == (DT_FCN << N_BTSHFT))
 | 
			
		||||
#define ISARY(x)	(((x) & N_TMASK) == (DT_ARY << N_BTSHFT))
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#endif /* _A_OUT_H_ */
 | 
			
		||||
@@ -1,5 +0,0 @@
 | 
			
		||||
obj-$(CONFIG_SOFTMMU) += accel.o
 | 
			
		||||
obj-$(call land,$(CONFIG_SOFTMMU),$(CONFIG_POSIX)) += qtest.o
 | 
			
		||||
obj-$(CONFIG_KVM) += kvm/
 | 
			
		||||
obj-$(CONFIG_TCG) += tcg/
 | 
			
		||||
obj-y += stubs/
 | 
			
		||||
							
								
								
									
										147
									
								
								accel/accel.c
									
									
									
									
									
								
							
							
						
						
									
										147
									
								
								accel/accel.c
									
									
									
									
									
								
							@@ -1,147 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * QEMU System Emulator, accelerator interfaces
 | 
			
		||||
 *
 | 
			
		||||
 * Copyright (c) 2003-2008 Fabrice Bellard
 | 
			
		||||
 * Copyright (c) 2014 Red Hat Inc.
 | 
			
		||||
 *
 | 
			
		||||
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
			
		||||
 * of this software and associated documentation files (the "Software"), to deal
 | 
			
		||||
 * in the Software without restriction, including without limitation the rights
 | 
			
		||||
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
			
		||||
 * copies of the Software, and to permit persons to whom the Software is
 | 
			
		||||
 * furnished to do so, subject to the following conditions:
 | 
			
		||||
 *
 | 
			
		||||
 * The above copyright notice and this permission notice shall be included in
 | 
			
		||||
 * all copies or substantial portions of the Software.
 | 
			
		||||
 *
 | 
			
		||||
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 | 
			
		||||
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
			
		||||
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
			
		||||
 * THE SOFTWARE.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "qemu/osdep.h"
 | 
			
		||||
#include "sysemu/accel.h"
 | 
			
		||||
#include "hw/boards.h"
 | 
			
		||||
#include "sysemu/arch_init.h"
 | 
			
		||||
#include "sysemu/sysemu.h"
 | 
			
		||||
#include "sysemu/kvm.h"
 | 
			
		||||
#include "sysemu/qtest.h"
 | 
			
		||||
#include "hw/xen/xen.h"
 | 
			
		||||
#include "qom/object.h"
 | 
			
		||||
#include "qemu/error-report.h"
 | 
			
		||||
#include "qemu/option.h"
 | 
			
		||||
#include "qapi/error.h"
 | 
			
		||||
 | 
			
		||||
static const TypeInfo accel_type = {
 | 
			
		||||
    .name = TYPE_ACCEL,
 | 
			
		||||
    .parent = TYPE_OBJECT,
 | 
			
		||||
    .class_size = sizeof(AccelClass),
 | 
			
		||||
    .instance_size = sizeof(AccelState),
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* Lookup AccelClass from opt_name. Returns NULL if not found */
 | 
			
		||||
static AccelClass *accel_find(const char *opt_name)
 | 
			
		||||
{
 | 
			
		||||
    char *class_name = g_strdup_printf(ACCEL_CLASS_NAME("%s"), opt_name);
 | 
			
		||||
    AccelClass *ac = ACCEL_CLASS(object_class_by_name(class_name));
 | 
			
		||||
    g_free(class_name);
 | 
			
		||||
    return ac;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int accel_init_machine(AccelClass *acc, MachineState *ms)
 | 
			
		||||
{
 | 
			
		||||
    ObjectClass *oc = OBJECT_CLASS(acc);
 | 
			
		||||
    const char *cname = object_class_get_name(oc);
 | 
			
		||||
    AccelState *accel = ACCEL(object_new(cname));
 | 
			
		||||
    int ret;
 | 
			
		||||
    ms->accelerator = accel;
 | 
			
		||||
    *(acc->allowed) = true;
 | 
			
		||||
    ret = acc->init_machine(ms);
 | 
			
		||||
    if (ret < 0) {
 | 
			
		||||
        ms->accelerator = NULL;
 | 
			
		||||
        *(acc->allowed) = false;
 | 
			
		||||
        object_unref(OBJECT(accel));
 | 
			
		||||
    } else {
 | 
			
		||||
        object_set_accelerator_compat_props(acc->compat_props);
 | 
			
		||||
    }
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void configure_accelerator(MachineState *ms, const char *progname)
 | 
			
		||||
{
 | 
			
		||||
    const char *accel;
 | 
			
		||||
    char **accel_list, **tmp;
 | 
			
		||||
    int ret;
 | 
			
		||||
    bool accel_initialised = false;
 | 
			
		||||
    bool init_failed = false;
 | 
			
		||||
    AccelClass *acc = NULL;
 | 
			
		||||
 | 
			
		||||
    accel = qemu_opt_get(qemu_get_machine_opts(), "accel");
 | 
			
		||||
    if (accel == NULL) {
 | 
			
		||||
        /* Select the default accelerator */
 | 
			
		||||
        int pnlen = strlen(progname);
 | 
			
		||||
        if (pnlen >= 3 && g_str_equal(&progname[pnlen - 3], "kvm")) {
 | 
			
		||||
            /* If the program name ends with "kvm", we prefer KVM */
 | 
			
		||||
            accel = "kvm:tcg";
 | 
			
		||||
        } else {
 | 
			
		||||
#if defined(CONFIG_TCG)
 | 
			
		||||
            accel = "tcg";
 | 
			
		||||
#elif defined(CONFIG_KVM)
 | 
			
		||||
            accel = "kvm";
 | 
			
		||||
#else
 | 
			
		||||
            error_report("No accelerator selected and"
 | 
			
		||||
                         " no default accelerator available");
 | 
			
		||||
            exit(1);
 | 
			
		||||
#endif
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    accel_list = g_strsplit(accel, ":", 0);
 | 
			
		||||
 | 
			
		||||
    for (tmp = accel_list; !accel_initialised && tmp && *tmp; tmp++) {
 | 
			
		||||
        acc = accel_find(*tmp);
 | 
			
		||||
        if (!acc) {
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
        ret = accel_init_machine(acc, ms);
 | 
			
		||||
        if (ret < 0) {
 | 
			
		||||
            init_failed = true;
 | 
			
		||||
            error_report("failed to initialize %s: %s",
 | 
			
		||||
                         acc->name, strerror(-ret));
 | 
			
		||||
        } else {
 | 
			
		||||
            accel_initialised = true;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    g_strfreev(accel_list);
 | 
			
		||||
 | 
			
		||||
    if (!accel_initialised) {
 | 
			
		||||
        if (!init_failed) {
 | 
			
		||||
            error_report("-machine accel=%s: No accelerator found", accel);
 | 
			
		||||
        }
 | 
			
		||||
        exit(1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (init_failed) {
 | 
			
		||||
        error_report("Back to %s accelerator", acc->name);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void accel_setup_post(MachineState *ms)
 | 
			
		||||
{
 | 
			
		||||
    AccelState *accel = ms->accelerator;
 | 
			
		||||
    AccelClass *acc = ACCEL_GET_CLASS(accel);
 | 
			
		||||
    if (acc->setup_post) {
 | 
			
		||||
        acc->setup_post(ms, accel);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void register_accel_types(void)
 | 
			
		||||
{
 | 
			
		||||
    type_register_static(&accel_type);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type_init(register_accel_types);
 | 
			
		||||
@@ -1,2 +0,0 @@
 | 
			
		||||
obj-y += kvm-all.o
 | 
			
		||||
obj-$(call lnot,$(CONFIG_SEV)) += sev-stub.o
 | 
			
		||||
							
								
								
									
										2889
									
								
								accel/kvm/kvm-all.c
									
									
									
									
									
								
							
							
						
						
									
										2889
									
								
								accel/kvm/kvm-all.c
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -1,26 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * QEMU SEV stub
 | 
			
		||||
 *
 | 
			
		||||
 * Copyright Advanced Micro Devices 2018
 | 
			
		||||
 *
 | 
			
		||||
 * Authors:
 | 
			
		||||
 *      Brijesh Singh <brijesh.singh@amd.com>
 | 
			
		||||
 *
 | 
			
		||||
 * This work is licensed under the terms of the GNU GPL, version 2 or later.
 | 
			
		||||
 * See the COPYING file in the top-level directory.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "qemu/osdep.h"
 | 
			
		||||
#include "qemu-common.h"
 | 
			
		||||
#include "sysemu/sev.h"
 | 
			
		||||
 | 
			
		||||
int sev_encrypt_data(void *handle, uint8_t *ptr, uint64_t len)
 | 
			
		||||
{
 | 
			
		||||
    abort();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void *sev_guest_init(const char *id)
 | 
			
		||||
{
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
@@ -1,19 +0,0 @@
 | 
			
		||||
# See docs/devel/tracing.txt for syntax documentation.
 | 
			
		||||
 | 
			
		||||
# kvm-all.c
 | 
			
		||||
kvm_ioctl(int type, void *arg) "type 0x%x, arg %p"
 | 
			
		||||
kvm_vm_ioctl(int type, void *arg) "type 0x%x, arg %p"
 | 
			
		||||
kvm_vcpu_ioctl(int cpu_index, int type, void *arg) "cpu_index %d, type 0x%x, arg %p"
 | 
			
		||||
kvm_run_exit(int cpu_index, uint32_t reason) "cpu_index %d, reason %d"
 | 
			
		||||
kvm_device_ioctl(int fd, int type, void *arg) "dev fd %d, type 0x%x, arg %p"
 | 
			
		||||
kvm_failed_reg_get(uint64_t id, const char *msg) "Warning: Unable to retrieve ONEREG %" PRIu64 " from KVM: %s"
 | 
			
		||||
kvm_failed_reg_set(uint64_t id, const char *msg) "Warning: Unable to set ONEREG %" PRIu64 " to KVM: %s"
 | 
			
		||||
kvm_irqchip_commit_routes(void) ""
 | 
			
		||||
kvm_irqchip_add_msi_route(char *name, int vector, int virq) "dev %s vector %d virq %d"
 | 
			
		||||
kvm_irqchip_update_msi_route(int virq) "Updating MSI route virq=%d"
 | 
			
		||||
kvm_irqchip_release_virq(int virq) "virq %d"
 | 
			
		||||
kvm_set_ioeventfd_mmio(int fd, uint64_t addr, uint32_t val, bool assign, uint32_t size, bool datamatch) "fd: %d @0x%" PRIx64 " val=0x%x assign: %d size: %d match: %d"
 | 
			
		||||
kvm_set_ioeventfd_pio(int fd, uint16_t addr, uint32_t val, bool assign, uint32_t size, bool datamatch) "fd: %d @0x%x val=0x%x assign: %d size: %d match: %d"
 | 
			
		||||
kvm_set_user_memory(uint32_t slot, uint32_t flags, uint64_t guest_phys_addr, uint64_t memory_size, uint64_t userspace_addr, int ret) "Slot#%d flags=0x%x gpa=0x%"PRIx64 " size=0x%"PRIx64 " ua=0x%"PRIx64 " ret=%d"
 | 
			
		||||
kvm_clear_dirty_log(uint32_t slot, uint64_t start, uint32_t size) "slot#%"PRId32" start 0x%"PRIx64" size 0x%"PRIx32
 | 
			
		||||
 | 
			
		||||
@@ -1,54 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * QTest accelerator code
 | 
			
		||||
 *
 | 
			
		||||
 * Copyright IBM, Corp. 2011
 | 
			
		||||
 *
 | 
			
		||||
 * Authors:
 | 
			
		||||
 *  Anthony Liguori   <aliguori@us.ibm.com>
 | 
			
		||||
 *
 | 
			
		||||
 * This work is licensed under the terms of the GNU GPL, version 2 or later.
 | 
			
		||||
 * See the COPYING file in the top-level directory.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "qemu/osdep.h"
 | 
			
		||||
#include "qapi/error.h"
 | 
			
		||||
#include "qemu/module.h"
 | 
			
		||||
#include "qemu/option.h"
 | 
			
		||||
#include "qemu/config-file.h"
 | 
			
		||||
#include "sysemu/accel.h"
 | 
			
		||||
#include "sysemu/qtest.h"
 | 
			
		||||
#include "sysemu/cpus.h"
 | 
			
		||||
 | 
			
		||||
static int qtest_init_accel(MachineState *ms)
 | 
			
		||||
{
 | 
			
		||||
    QemuOpts *opts = qemu_opts_create(qemu_find_opts("icount"), NULL, 0,
 | 
			
		||||
                                      &error_abort);
 | 
			
		||||
    qemu_opt_set(opts, "shift", "0", &error_abort);
 | 
			
		||||
    configure_icount(opts, &error_abort);
 | 
			
		||||
    qemu_opts_del(opts);
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void qtest_accel_class_init(ObjectClass *oc, void *data)
 | 
			
		||||
{
 | 
			
		||||
    AccelClass *ac = ACCEL_CLASS(oc);
 | 
			
		||||
    ac->name = "QTest";
 | 
			
		||||
    ac->init_machine = qtest_init_accel;
 | 
			
		||||
    ac->allowed = &qtest_allowed;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#define TYPE_QTEST_ACCEL ACCEL_CLASS_NAME("qtest")
 | 
			
		||||
 | 
			
		||||
static const TypeInfo qtest_accel_type = {
 | 
			
		||||
    .name = TYPE_QTEST_ACCEL,
 | 
			
		||||
    .parent = TYPE_ACCEL,
 | 
			
		||||
    .class_init = qtest_accel_class_init,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void qtest_type_init(void)
 | 
			
		||||
{
 | 
			
		||||
    type_register_static(&qtest_accel_type);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type_init(qtest_type_init);
 | 
			
		||||
@@ -1,5 +0,0 @@
 | 
			
		||||
obj-$(call lnot,$(CONFIG_HAX))  += hax-stub.o
 | 
			
		||||
obj-$(call lnot,$(CONFIG_HVF))  += hvf-stub.o
 | 
			
		||||
obj-$(call lnot,$(CONFIG_WHPX)) += whpx-stub.o
 | 
			
		||||
obj-$(call lnot,$(CONFIG_KVM))  += kvm-stub.o
 | 
			
		||||
obj-$(call lnot,$(CONFIG_TCG))  += tcg-stub.o
 | 
			
		||||
@@ -1,33 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * QEMU HAXM support
 | 
			
		||||
 *
 | 
			
		||||
 * Copyright (c) 2015, Intel Corporation
 | 
			
		||||
 *
 | 
			
		||||
 * Copyright 2016 Google, Inc.
 | 
			
		||||
 *
 | 
			
		||||
 * This software is licensed under the terms of the GNU General Public
 | 
			
		||||
 * License version 2, as published by the Free Software Foundation, and
 | 
			
		||||
 * may be copied, distributed, and modified under those terms.
 | 
			
		||||
 *
 | 
			
		||||
 * See the COPYING file in the top-level directory.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "qemu/osdep.h"
 | 
			
		||||
#include "cpu.h"
 | 
			
		||||
#include "sysemu/hax.h"
 | 
			
		||||
 | 
			
		||||
int hax_sync_vcpus(void)
 | 
			
		||||
{
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int hax_init_vcpu(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
    return -ENOSYS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int hax_smp_cpu_exec(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
    return -ENOSYS;
 | 
			
		||||
}
 | 
			
		||||
@@ -1,30 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * QEMU HVF support
 | 
			
		||||
 *
 | 
			
		||||
 * Copyright 2017 Red Hat, Inc.
 | 
			
		||||
 *
 | 
			
		||||
 * This software is licensed under the terms of the GNU General Public
 | 
			
		||||
 * License version 2 or later, as published by the Free Software Foundation,
 | 
			
		||||
 * and may be copied, distributed, and modified under those terms.
 | 
			
		||||
 *
 | 
			
		||||
 * See the COPYING file in the top-level directory.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "qemu/osdep.h"
 | 
			
		||||
#include "cpu.h"
 | 
			
		||||
#include "sysemu/hvf.h"
 | 
			
		||||
 | 
			
		||||
int hvf_init_vcpu(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
    return -ENOSYS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int hvf_vcpu_exec(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
    return -ENOSYS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void hvf_vcpu_destroy(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
@@ -1,172 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * QEMU KVM stub
 | 
			
		||||
 *
 | 
			
		||||
 * Copyright Red Hat, Inc. 2010
 | 
			
		||||
 *
 | 
			
		||||
 * Author: Paolo Bonzini     <pbonzini@redhat.com>
 | 
			
		||||
 *
 | 
			
		||||
 * This work is licensed under the terms of the GNU GPL, version 2 or later.
 | 
			
		||||
 * See the COPYING file in the top-level directory.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "qemu/osdep.h"
 | 
			
		||||
#include "cpu.h"
 | 
			
		||||
#include "sysemu/kvm.h"
 | 
			
		||||
 | 
			
		||||
#ifndef CONFIG_USER_ONLY
 | 
			
		||||
#include "hw/pci/msi.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
KVMState *kvm_state;
 | 
			
		||||
bool kvm_kernel_irqchip;
 | 
			
		||||
bool kvm_async_interrupts_allowed;
 | 
			
		||||
bool kvm_eventfds_allowed;
 | 
			
		||||
bool kvm_irqfds_allowed;
 | 
			
		||||
bool kvm_resamplefds_allowed;
 | 
			
		||||
bool kvm_msi_via_irqfd_allowed;
 | 
			
		||||
bool kvm_gsi_routing_allowed;
 | 
			
		||||
bool kvm_gsi_direct_mapping;
 | 
			
		||||
bool kvm_allowed;
 | 
			
		||||
bool kvm_readonly_mem_allowed;
 | 
			
		||||
bool kvm_ioeventfd_any_length_allowed;
 | 
			
		||||
bool kvm_msi_use_devid;
 | 
			
		||||
 | 
			
		||||
int kvm_destroy_vcpu(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
    return -ENOSYS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int kvm_init_vcpu(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
    return -ENOSYS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void kvm_flush_coalesced_mmio_buffer(void)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void kvm_cpu_synchronize_state(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void kvm_cpu_synchronize_post_reset(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void kvm_cpu_synchronize_post_init(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int kvm_cpu_exec(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
    abort();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool kvm_has_sync_mmu(void)
 | 
			
		||||
{
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int kvm_has_many_ioeventfds(void)
 | 
			
		||||
{
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int kvm_update_guest_debug(CPUState *cpu, unsigned long reinject_trap)
 | 
			
		||||
{
 | 
			
		||||
    return -ENOSYS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int kvm_insert_breakpoint(CPUState *cpu, target_ulong addr,
 | 
			
		||||
                          target_ulong len, int type)
 | 
			
		||||
{
 | 
			
		||||
    return -EINVAL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int kvm_remove_breakpoint(CPUState *cpu, target_ulong addr,
 | 
			
		||||
                          target_ulong len, int type)
 | 
			
		||||
{
 | 
			
		||||
    return -EINVAL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void kvm_remove_all_breakpoints(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int kvm_on_sigbus_vcpu(CPUState *cpu, int code, void *addr)
 | 
			
		||||
{
 | 
			
		||||
    return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int kvm_on_sigbus(int code, void *addr)
 | 
			
		||||
{
 | 
			
		||||
    return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool kvm_memcrypt_enabled(void)
 | 
			
		||||
{
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int kvm_memcrypt_encrypt_data(uint8_t *ptr, uint64_t len)
 | 
			
		||||
{
 | 
			
		||||
  return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifndef CONFIG_USER_ONLY
 | 
			
		||||
int kvm_irqchip_add_msi_route(KVMState *s, int vector, PCIDevice *dev)
 | 
			
		||||
{
 | 
			
		||||
    return -ENOSYS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void kvm_init_irq_routing(KVMState *s)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void kvm_irqchip_release_virq(KVMState *s, int virq)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg,
 | 
			
		||||
                                 PCIDevice *dev)
 | 
			
		||||
{
 | 
			
		||||
    return -ENOSYS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void kvm_irqchip_commit_routes(KVMState *s)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int kvm_irqchip_add_adapter_route(KVMState *s, AdapterInfo *adapter)
 | 
			
		||||
{
 | 
			
		||||
    return -ENOSYS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int kvm_irqchip_add_irqfd_notifier_gsi(KVMState *s, EventNotifier *n,
 | 
			
		||||
                                       EventNotifier *rn, int virq)
 | 
			
		||||
{
 | 
			
		||||
    return -ENOSYS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int kvm_irqchip_remove_irqfd_notifier_gsi(KVMState *s, EventNotifier *n,
 | 
			
		||||
                                          int virq)
 | 
			
		||||
{
 | 
			
		||||
    return -ENOSYS;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool kvm_has_free_slot(MachineState *ms)
 | 
			
		||||
{
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void kvm_init_cpu_signals(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
    abort();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool kvm_arm_supports_user_irq(void)
 | 
			
		||||
{
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
@@ -1,26 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * QEMU TCG accelerator stub
 | 
			
		||||
 *
 | 
			
		||||
 * Copyright Red Hat, Inc. 2013
 | 
			
		||||
 *
 | 
			
		||||
 * Author: Paolo Bonzini     <pbonzini@redhat.com>
 | 
			
		||||
 *
 | 
			
		||||
 * This work is licensed under the terms of the GNU GPL, version 2 or later.
 | 
			
		||||
 * See the COPYING file in the top-level directory.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "qemu/osdep.h"
 | 
			
		||||
#include "qemu-common.h"
 | 
			
		||||
#include "cpu.h"
 | 
			
		||||
#include "tcg/tcg.h"
 | 
			
		||||
#include "exec/cpu-common.h"
 | 
			
		||||
#include "exec/exec-all.h"
 | 
			
		||||
 | 
			
		||||
void tb_flush(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void tlb_set_dirty(CPUState *cpu, target_ulong vaddr)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
@@ -1,47 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * QEMU Windows Hypervisor Platform accelerator (WHPX) stub
 | 
			
		||||
 *
 | 
			
		||||
 * Copyright Microsoft Corp. 2017
 | 
			
		||||
 *
 | 
			
		||||
 * This work is licensed under the terms of the GNU GPL, version 2 or later.
 | 
			
		||||
 * See the COPYING file in the top-level directory.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "qemu/osdep.h"
 | 
			
		||||
#include "cpu.h"
 | 
			
		||||
#include "sysemu/whpx.h"
 | 
			
		||||
 | 
			
		||||
int whpx_init_vcpu(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
    return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int whpx_vcpu_exec(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
    return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void whpx_destroy_vcpu(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void whpx_vcpu_kick(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void whpx_cpu_synchronize_state(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void whpx_cpu_synchronize_post_reset(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void whpx_cpu_synchronize_post_init(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void whpx_cpu_synchronize_pre_loadvm(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
@@ -1,8 +0,0 @@
 | 
			
		||||
obj-$(CONFIG_SOFTMMU) += tcg-all.o
 | 
			
		||||
obj-$(CONFIG_SOFTMMU) += cputlb.o
 | 
			
		||||
obj-y += tcg-runtime.o tcg-runtime-gvec.o
 | 
			
		||||
obj-y += cpu-exec.o cpu-exec-common.o translate-all.o
 | 
			
		||||
obj-y += translator.o
 | 
			
		||||
 | 
			
		||||
obj-$(CONFIG_USER_ONLY) += user-exec.o
 | 
			
		||||
obj-$(call lnot,$(CONFIG_SOFTMMU)) += user-exec-stub.o
 | 
			
		||||
@@ -1,368 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Atomic helper templates
 | 
			
		||||
 * Included from tcg-runtime.c and cputlb.c.
 | 
			
		||||
 *
 | 
			
		||||
 * Copyright (c) 2016 Red Hat, Inc
 | 
			
		||||
 *
 | 
			
		||||
 * This library is free software; you can redistribute it and/or
 | 
			
		||||
 * modify it under the terms of the GNU Lesser General Public
 | 
			
		||||
 * License as published by the Free Software Foundation; either
 | 
			
		||||
 * version 2.1 of the License, or (at your option) any later version.
 | 
			
		||||
 *
 | 
			
		||||
 * This library is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 | 
			
		||||
 * Lesser General Public License for more details.
 | 
			
		||||
 *
 | 
			
		||||
 * You should have received a copy of the GNU Lesser General Public
 | 
			
		||||
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "trace/mem.h"
 | 
			
		||||
 | 
			
		||||
#if DATA_SIZE == 16
 | 
			
		||||
# define SUFFIX     o
 | 
			
		||||
# define DATA_TYPE  Int128
 | 
			
		||||
# define BSWAP      bswap128
 | 
			
		||||
# define SHIFT      4
 | 
			
		||||
#elif DATA_SIZE == 8
 | 
			
		||||
# define SUFFIX     q
 | 
			
		||||
# define DATA_TYPE  uint64_t
 | 
			
		||||
# define SDATA_TYPE int64_t
 | 
			
		||||
# define BSWAP      bswap64
 | 
			
		||||
# define SHIFT      3
 | 
			
		||||
#elif DATA_SIZE == 4
 | 
			
		||||
# define SUFFIX     l
 | 
			
		||||
# define DATA_TYPE  uint32_t
 | 
			
		||||
# define SDATA_TYPE int32_t
 | 
			
		||||
# define BSWAP      bswap32
 | 
			
		||||
# define SHIFT      2
 | 
			
		||||
#elif DATA_SIZE == 2
 | 
			
		||||
# define SUFFIX     w
 | 
			
		||||
# define DATA_TYPE  uint16_t
 | 
			
		||||
# define SDATA_TYPE int16_t
 | 
			
		||||
# define BSWAP      bswap16
 | 
			
		||||
# define SHIFT      1
 | 
			
		||||
#elif DATA_SIZE == 1
 | 
			
		||||
# define SUFFIX     b
 | 
			
		||||
# define DATA_TYPE  uint8_t
 | 
			
		||||
# define SDATA_TYPE int8_t
 | 
			
		||||
# define BSWAP
 | 
			
		||||
# define SHIFT      0
 | 
			
		||||
#else
 | 
			
		||||
# error unsupported data size
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if DATA_SIZE >= 4
 | 
			
		||||
# define ABI_TYPE  DATA_TYPE
 | 
			
		||||
#else
 | 
			
		||||
# define ABI_TYPE  uint32_t
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define ATOMIC_TRACE_RMW do {                                           \
 | 
			
		||||
        uint8_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false); \
 | 
			
		||||
                                                                        \
 | 
			
		||||
        trace_guest_mem_before_exec(env_cpu(env), addr, info);      \
 | 
			
		||||
        trace_guest_mem_before_exec(env_cpu(env), addr,             \
 | 
			
		||||
                                    info | TRACE_MEM_ST);               \
 | 
			
		||||
    } while (0)
 | 
			
		||||
 | 
			
		||||
#define ATOMIC_TRACE_LD do {                                            \
 | 
			
		||||
        uint8_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, false); \
 | 
			
		||||
                                                                        \
 | 
			
		||||
        trace_guest_mem_before_exec(env_cpu(env), addr, info);      \
 | 
			
		||||
    } while (0)
 | 
			
		||||
 | 
			
		||||
# define ATOMIC_TRACE_ST do {                                           \
 | 
			
		||||
        uint8_t info = glue(trace_mem_build_info_no_se, MEND)(SHIFT, true); \
 | 
			
		||||
                                                                        \
 | 
			
		||||
        trace_guest_mem_before_exec(env_cpu(env), addr, info);      \
 | 
			
		||||
    } while (0)
 | 
			
		||||
 | 
			
		||||
/* Define host-endian atomic operations.  Note that END is used within
 | 
			
		||||
   the ATOMIC_NAME macro, and redefined below.  */
 | 
			
		||||
#if DATA_SIZE == 1
 | 
			
		||||
# define END
 | 
			
		||||
# define MEND _be /* either le or be would be fine */
 | 
			
		||||
#elif defined(HOST_WORDS_BIGENDIAN)
 | 
			
		||||
# define END  _be
 | 
			
		||||
# define MEND _be
 | 
			
		||||
#else
 | 
			
		||||
# define END  _le
 | 
			
		||||
# define MEND _le
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
ABI_TYPE ATOMIC_NAME(cmpxchg)(CPUArchState *env, target_ulong addr,
 | 
			
		||||
                              ABI_TYPE cmpv, ABI_TYPE newv EXTRA_ARGS)
 | 
			
		||||
{
 | 
			
		||||
    ATOMIC_MMU_DECLS;
 | 
			
		||||
    DATA_TYPE *haddr = ATOMIC_MMU_LOOKUP;
 | 
			
		||||
    DATA_TYPE ret;
 | 
			
		||||
 | 
			
		||||
    ATOMIC_TRACE_RMW;
 | 
			
		||||
#if DATA_SIZE == 16
 | 
			
		||||
    ret = atomic16_cmpxchg(haddr, cmpv, newv);
 | 
			
		||||
#else
 | 
			
		||||
    ret = atomic_cmpxchg__nocheck(haddr, cmpv, newv);
 | 
			
		||||
#endif
 | 
			
		||||
    ATOMIC_MMU_CLEANUP;
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if DATA_SIZE >= 16
 | 
			
		||||
#if HAVE_ATOMIC128
 | 
			
		||||
ABI_TYPE ATOMIC_NAME(ld)(CPUArchState *env, target_ulong addr EXTRA_ARGS)
 | 
			
		||||
{
 | 
			
		||||
    ATOMIC_MMU_DECLS;
 | 
			
		||||
    DATA_TYPE val, *haddr = ATOMIC_MMU_LOOKUP;
 | 
			
		||||
 | 
			
		||||
    ATOMIC_TRACE_LD;
 | 
			
		||||
    val = atomic16_read(haddr);
 | 
			
		||||
    ATOMIC_MMU_CLEANUP;
 | 
			
		||||
    return val;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ATOMIC_NAME(st)(CPUArchState *env, target_ulong addr,
 | 
			
		||||
                     ABI_TYPE val EXTRA_ARGS)
 | 
			
		||||
{
 | 
			
		||||
    ATOMIC_MMU_DECLS;
 | 
			
		||||
    DATA_TYPE *haddr = ATOMIC_MMU_LOOKUP;
 | 
			
		||||
 | 
			
		||||
    ATOMIC_TRACE_ST;
 | 
			
		||||
    atomic16_set(haddr, val);
 | 
			
		||||
    ATOMIC_MMU_CLEANUP;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
#else
 | 
			
		||||
ABI_TYPE ATOMIC_NAME(xchg)(CPUArchState *env, target_ulong addr,
 | 
			
		||||
                           ABI_TYPE val EXTRA_ARGS)
 | 
			
		||||
{
 | 
			
		||||
    ATOMIC_MMU_DECLS;
 | 
			
		||||
    DATA_TYPE *haddr = ATOMIC_MMU_LOOKUP;
 | 
			
		||||
    DATA_TYPE ret;
 | 
			
		||||
 | 
			
		||||
    ATOMIC_TRACE_RMW;
 | 
			
		||||
    ret = atomic_xchg__nocheck(haddr, val);
 | 
			
		||||
    ATOMIC_MMU_CLEANUP;
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#define GEN_ATOMIC_HELPER(X)                                        \
 | 
			
		||||
ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, target_ulong addr,       \
 | 
			
		||||
                 ABI_TYPE val EXTRA_ARGS)                           \
 | 
			
		||||
{                                                                   \
 | 
			
		||||
    ATOMIC_MMU_DECLS;                                               \
 | 
			
		||||
    DATA_TYPE *haddr = ATOMIC_MMU_LOOKUP;                           \
 | 
			
		||||
    DATA_TYPE ret;                                                  \
 | 
			
		||||
                                                                    \
 | 
			
		||||
    ATOMIC_TRACE_RMW;                                               \
 | 
			
		||||
    ret = atomic_##X(haddr, val);                                   \
 | 
			
		||||
    ATOMIC_MMU_CLEANUP;                                             \
 | 
			
		||||
    return ret;                                                     \
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GEN_ATOMIC_HELPER(fetch_add)
 | 
			
		||||
GEN_ATOMIC_HELPER(fetch_and)
 | 
			
		||||
GEN_ATOMIC_HELPER(fetch_or)
 | 
			
		||||
GEN_ATOMIC_HELPER(fetch_xor)
 | 
			
		||||
GEN_ATOMIC_HELPER(add_fetch)
 | 
			
		||||
GEN_ATOMIC_HELPER(and_fetch)
 | 
			
		||||
GEN_ATOMIC_HELPER(or_fetch)
 | 
			
		||||
GEN_ATOMIC_HELPER(xor_fetch)
 | 
			
		||||
 | 
			
		||||
#undef GEN_ATOMIC_HELPER
 | 
			
		||||
 | 
			
		||||
/* These helpers are, as a whole, full barriers.  Within the helper,
 | 
			
		||||
 * the leading barrier is explicit and the trailing barrier is within
 | 
			
		||||
 * cmpxchg primitive.
 | 
			
		||||
 *
 | 
			
		||||
 * Trace this load + RMW loop as a single RMW op. This way, regardless
 | 
			
		||||
 * of CF_PARALLEL's value, we'll trace just a read and a write.
 | 
			
		||||
 */
 | 
			
		||||
#define GEN_ATOMIC_HELPER_FN(X, FN, XDATA_TYPE, RET)                \
 | 
			
		||||
ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, target_ulong addr,       \
 | 
			
		||||
                        ABI_TYPE xval EXTRA_ARGS)                   \
 | 
			
		||||
{                                                                   \
 | 
			
		||||
    ATOMIC_MMU_DECLS;                                               \
 | 
			
		||||
    XDATA_TYPE *haddr = ATOMIC_MMU_LOOKUP;                          \
 | 
			
		||||
    XDATA_TYPE cmp, old, new, val = xval;                           \
 | 
			
		||||
                                                                    \
 | 
			
		||||
    ATOMIC_TRACE_RMW;                                               \
 | 
			
		||||
    smp_mb();                                                       \
 | 
			
		||||
    cmp = atomic_read__nocheck(haddr);                              \
 | 
			
		||||
    do {                                                            \
 | 
			
		||||
        old = cmp; new = FN(old, val);                              \
 | 
			
		||||
        cmp = atomic_cmpxchg__nocheck(haddr, old, new);             \
 | 
			
		||||
    } while (cmp != old);                                           \
 | 
			
		||||
    ATOMIC_MMU_CLEANUP;                                             \
 | 
			
		||||
    return RET;                                                     \
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GEN_ATOMIC_HELPER_FN(fetch_smin, MIN, SDATA_TYPE, old)
 | 
			
		||||
GEN_ATOMIC_HELPER_FN(fetch_umin, MIN,  DATA_TYPE, old)
 | 
			
		||||
GEN_ATOMIC_HELPER_FN(fetch_smax, MAX, SDATA_TYPE, old)
 | 
			
		||||
GEN_ATOMIC_HELPER_FN(fetch_umax, MAX,  DATA_TYPE, old)
 | 
			
		||||
 | 
			
		||||
GEN_ATOMIC_HELPER_FN(smin_fetch, MIN, SDATA_TYPE, new)
 | 
			
		||||
GEN_ATOMIC_HELPER_FN(umin_fetch, MIN,  DATA_TYPE, new)
 | 
			
		||||
GEN_ATOMIC_HELPER_FN(smax_fetch, MAX, SDATA_TYPE, new)
 | 
			
		||||
GEN_ATOMIC_HELPER_FN(umax_fetch, MAX,  DATA_TYPE, new)
 | 
			
		||||
 | 
			
		||||
#undef GEN_ATOMIC_HELPER_FN
 | 
			
		||||
#endif /* DATA SIZE >= 16 */
 | 
			
		||||
 | 
			
		||||
#undef END
 | 
			
		||||
#undef MEND
 | 
			
		||||
 | 
			
		||||
#if DATA_SIZE > 1
 | 
			
		||||
 | 
			
		||||
/* Define reverse-host-endian atomic operations.  Note that END is used
 | 
			
		||||
   within the ATOMIC_NAME macro.  */
 | 
			
		||||
#ifdef HOST_WORDS_BIGENDIAN
 | 
			
		||||
# define END  _le
 | 
			
		||||
# define MEND _le
 | 
			
		||||
#else
 | 
			
		||||
# define END  _be
 | 
			
		||||
# define MEND _be
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
ABI_TYPE ATOMIC_NAME(cmpxchg)(CPUArchState *env, target_ulong addr,
 | 
			
		||||
                              ABI_TYPE cmpv, ABI_TYPE newv EXTRA_ARGS)
 | 
			
		||||
{
 | 
			
		||||
    ATOMIC_MMU_DECLS;
 | 
			
		||||
    DATA_TYPE *haddr = ATOMIC_MMU_LOOKUP;
 | 
			
		||||
    DATA_TYPE ret;
 | 
			
		||||
 | 
			
		||||
    ATOMIC_TRACE_RMW;
 | 
			
		||||
#if DATA_SIZE == 16
 | 
			
		||||
    ret = atomic16_cmpxchg(haddr, BSWAP(cmpv), BSWAP(newv));
 | 
			
		||||
#else
 | 
			
		||||
    ret = atomic_cmpxchg__nocheck(haddr, BSWAP(cmpv), BSWAP(newv));
 | 
			
		||||
#endif
 | 
			
		||||
    ATOMIC_MMU_CLEANUP;
 | 
			
		||||
    return BSWAP(ret);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if DATA_SIZE >= 16
 | 
			
		||||
#if HAVE_ATOMIC128
 | 
			
		||||
ABI_TYPE ATOMIC_NAME(ld)(CPUArchState *env, target_ulong addr EXTRA_ARGS)
 | 
			
		||||
{
 | 
			
		||||
    ATOMIC_MMU_DECLS;
 | 
			
		||||
    DATA_TYPE val, *haddr = ATOMIC_MMU_LOOKUP;
 | 
			
		||||
 | 
			
		||||
    ATOMIC_TRACE_LD;
 | 
			
		||||
    val = atomic16_read(haddr);
 | 
			
		||||
    ATOMIC_MMU_CLEANUP;
 | 
			
		||||
    return BSWAP(val);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ATOMIC_NAME(st)(CPUArchState *env, target_ulong addr,
 | 
			
		||||
                     ABI_TYPE val EXTRA_ARGS)
 | 
			
		||||
{
 | 
			
		||||
    ATOMIC_MMU_DECLS;
 | 
			
		||||
    DATA_TYPE *haddr = ATOMIC_MMU_LOOKUP;
 | 
			
		||||
 | 
			
		||||
    ATOMIC_TRACE_ST;
 | 
			
		||||
    val = BSWAP(val);
 | 
			
		||||
    atomic16_set(haddr, val);
 | 
			
		||||
    ATOMIC_MMU_CLEANUP;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
#else
 | 
			
		||||
ABI_TYPE ATOMIC_NAME(xchg)(CPUArchState *env, target_ulong addr,
 | 
			
		||||
                           ABI_TYPE val EXTRA_ARGS)
 | 
			
		||||
{
 | 
			
		||||
    ATOMIC_MMU_DECLS;
 | 
			
		||||
    DATA_TYPE *haddr = ATOMIC_MMU_LOOKUP;
 | 
			
		||||
    ABI_TYPE ret;
 | 
			
		||||
 | 
			
		||||
    ATOMIC_TRACE_RMW;
 | 
			
		||||
    ret = atomic_xchg__nocheck(haddr, BSWAP(val));
 | 
			
		||||
    ATOMIC_MMU_CLEANUP;
 | 
			
		||||
    return BSWAP(ret);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#define GEN_ATOMIC_HELPER(X)                                        \
 | 
			
		||||
ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, target_ulong addr,       \
 | 
			
		||||
                 ABI_TYPE val EXTRA_ARGS)                           \
 | 
			
		||||
{                                                                   \
 | 
			
		||||
    ATOMIC_MMU_DECLS;                                               \
 | 
			
		||||
    DATA_TYPE *haddr = ATOMIC_MMU_LOOKUP;                           \
 | 
			
		||||
    DATA_TYPE ret;                                                  \
 | 
			
		||||
                                                                    \
 | 
			
		||||
    ATOMIC_TRACE_RMW;                                               \
 | 
			
		||||
    ret = atomic_##X(haddr, BSWAP(val));                            \
 | 
			
		||||
    ATOMIC_MMU_CLEANUP;                                             \
 | 
			
		||||
    return BSWAP(ret);                                              \
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GEN_ATOMIC_HELPER(fetch_and)
 | 
			
		||||
GEN_ATOMIC_HELPER(fetch_or)
 | 
			
		||||
GEN_ATOMIC_HELPER(fetch_xor)
 | 
			
		||||
GEN_ATOMIC_HELPER(and_fetch)
 | 
			
		||||
GEN_ATOMIC_HELPER(or_fetch)
 | 
			
		||||
GEN_ATOMIC_HELPER(xor_fetch)
 | 
			
		||||
 | 
			
		||||
#undef GEN_ATOMIC_HELPER
 | 
			
		||||
 | 
			
		||||
/* These helpers are, as a whole, full barriers.  Within the helper,
 | 
			
		||||
 * the leading barrier is explicit and the trailing barrier is within
 | 
			
		||||
 * cmpxchg primitive.
 | 
			
		||||
 *
 | 
			
		||||
 * Trace this load + RMW loop as a single RMW op. This way, regardless
 | 
			
		||||
 * of CF_PARALLEL's value, we'll trace just a read and a write.
 | 
			
		||||
 */
 | 
			
		||||
#define GEN_ATOMIC_HELPER_FN(X, FN, XDATA_TYPE, RET)                \
 | 
			
		||||
ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, target_ulong addr,       \
 | 
			
		||||
                        ABI_TYPE xval EXTRA_ARGS)                   \
 | 
			
		||||
{                                                                   \
 | 
			
		||||
    ATOMIC_MMU_DECLS;                                               \
 | 
			
		||||
    XDATA_TYPE *haddr = ATOMIC_MMU_LOOKUP;                          \
 | 
			
		||||
    XDATA_TYPE ldo, ldn, old, new, val = xval;                      \
 | 
			
		||||
                                                                    \
 | 
			
		||||
    ATOMIC_TRACE_RMW;                                               \
 | 
			
		||||
    smp_mb();                                                       \
 | 
			
		||||
    ldn = atomic_read__nocheck(haddr);                              \
 | 
			
		||||
    do {                                                            \
 | 
			
		||||
        ldo = ldn; old = BSWAP(ldo); new = FN(old, val);            \
 | 
			
		||||
        ldn = atomic_cmpxchg__nocheck(haddr, ldo, BSWAP(new));      \
 | 
			
		||||
    } while (ldo != ldn);                                           \
 | 
			
		||||
    ATOMIC_MMU_CLEANUP;                                             \
 | 
			
		||||
    return RET;                                                     \
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
GEN_ATOMIC_HELPER_FN(fetch_smin, MIN, SDATA_TYPE, old)
 | 
			
		||||
GEN_ATOMIC_HELPER_FN(fetch_umin, MIN,  DATA_TYPE, old)
 | 
			
		||||
GEN_ATOMIC_HELPER_FN(fetch_smax, MAX, SDATA_TYPE, old)
 | 
			
		||||
GEN_ATOMIC_HELPER_FN(fetch_umax, MAX,  DATA_TYPE, old)
 | 
			
		||||
 | 
			
		||||
GEN_ATOMIC_HELPER_FN(smin_fetch, MIN, SDATA_TYPE, new)
 | 
			
		||||
GEN_ATOMIC_HELPER_FN(umin_fetch, MIN,  DATA_TYPE, new)
 | 
			
		||||
GEN_ATOMIC_HELPER_FN(smax_fetch, MAX, SDATA_TYPE, new)
 | 
			
		||||
GEN_ATOMIC_HELPER_FN(umax_fetch, MAX,  DATA_TYPE, new)
 | 
			
		||||
 | 
			
		||||
/* Note that for addition, we need to use a separate cmpxchg loop instead
 | 
			
		||||
   of bswaps for the reverse-host-endian helpers.  */
 | 
			
		||||
#define ADD(X, Y)   (X + Y)
 | 
			
		||||
GEN_ATOMIC_HELPER_FN(fetch_add, ADD, DATA_TYPE, old)
 | 
			
		||||
GEN_ATOMIC_HELPER_FN(add_fetch, ADD, DATA_TYPE, new)
 | 
			
		||||
#undef ADD
 | 
			
		||||
 | 
			
		||||
#undef GEN_ATOMIC_HELPER_FN
 | 
			
		||||
#endif /* DATA_SIZE >= 16 */
 | 
			
		||||
 | 
			
		||||
#undef END
 | 
			
		||||
#undef MEND
 | 
			
		||||
#endif /* DATA_SIZE > 1 */
 | 
			
		||||
 | 
			
		||||
#undef ATOMIC_TRACE_ST
 | 
			
		||||
#undef ATOMIC_TRACE_LD
 | 
			
		||||
#undef ATOMIC_TRACE_RMW
 | 
			
		||||
 | 
			
		||||
#undef BSWAP
 | 
			
		||||
#undef ABI_TYPE
 | 
			
		||||
#undef DATA_TYPE
 | 
			
		||||
#undef SDATA_TYPE
 | 
			
		||||
#undef SUFFIX
 | 
			
		||||
#undef DATA_SIZE
 | 
			
		||||
#undef SHIFT
 | 
			
		||||
@@ -1,84 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 *  emulator main execution loop
 | 
			
		||||
 *
 | 
			
		||||
 *  Copyright (c) 2003-2005 Fabrice Bellard
 | 
			
		||||
 *
 | 
			
		||||
 * This library is free software; you can redistribute it and/or
 | 
			
		||||
 * modify it under the terms of the GNU Lesser General Public
 | 
			
		||||
 * License as published by the Free Software Foundation; either
 | 
			
		||||
 * version 2.1 of the License, or (at your option) any later version.
 | 
			
		||||
 *
 | 
			
		||||
 * This library is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 | 
			
		||||
 * Lesser General Public License for more details.
 | 
			
		||||
 *
 | 
			
		||||
 * You should have received a copy of the GNU Lesser General Public
 | 
			
		||||
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "qemu/osdep.h"
 | 
			
		||||
#include "cpu.h"
 | 
			
		||||
#include "sysemu/cpus.h"
 | 
			
		||||
#include "sysemu/tcg.h"
 | 
			
		||||
#include "exec/exec-all.h"
 | 
			
		||||
 | 
			
		||||
bool tcg_allowed;
 | 
			
		||||
 | 
			
		||||
/* exit the current TB, but without causing any exception to be raised */
 | 
			
		||||
void cpu_loop_exit_noexc(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
    cpu->exception_index = -1;
 | 
			
		||||
    cpu_loop_exit(cpu);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if defined(CONFIG_SOFTMMU)
 | 
			
		||||
void cpu_reloading_memory_map(void)
 | 
			
		||||
{
 | 
			
		||||
    if (qemu_in_vcpu_thread() && current_cpu->running) {
 | 
			
		||||
        /* The guest can in theory prolong the RCU critical section as long
 | 
			
		||||
         * as it feels like. The major problem with this is that because it
 | 
			
		||||
         * can do multiple reconfigurations of the memory map within the
 | 
			
		||||
         * critical section, we could potentially accumulate an unbounded
 | 
			
		||||
         * collection of memory data structures awaiting reclamation.
 | 
			
		||||
         *
 | 
			
		||||
         * Because the only thing we're currently protecting with RCU is the
 | 
			
		||||
         * memory data structures, it's sufficient to break the critical section
 | 
			
		||||
         * in this callback, which we know will get called every time the
 | 
			
		||||
         * memory map is rearranged.
 | 
			
		||||
         *
 | 
			
		||||
         * (If we add anything else in the system that uses RCU to protect
 | 
			
		||||
         * its data structures, we will need to implement some other mechanism
 | 
			
		||||
         * to force TCG CPUs to exit the critical section, at which point this
 | 
			
		||||
         * part of this callback might become unnecessary.)
 | 
			
		||||
         *
 | 
			
		||||
         * This pair matches cpu_exec's rcu_read_lock()/rcu_read_unlock(), which
 | 
			
		||||
         * only protects cpu->as->dispatch. Since we know our caller is about
 | 
			
		||||
         * to reload it, it's safe to split the critical section.
 | 
			
		||||
         */
 | 
			
		||||
        rcu_read_unlock();
 | 
			
		||||
        rcu_read_lock();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
void cpu_loop_exit(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
    /* Undo the setting in cpu_tb_exec.  */
 | 
			
		||||
    cpu->can_do_io = 1;
 | 
			
		||||
    siglongjmp(cpu->jmp_env, 1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc)
 | 
			
		||||
{
 | 
			
		||||
    if (pc) {
 | 
			
		||||
        cpu_restore_state(cpu, pc, true);
 | 
			
		||||
    }
 | 
			
		||||
    cpu_loop_exit(cpu);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void cpu_loop_exit_atomic(CPUState *cpu, uintptr_t pc)
 | 
			
		||||
{
 | 
			
		||||
    cpu->exception_index = EXCP_ATOMIC;
 | 
			
		||||
    cpu_loop_exit_restore(cpu, pc);
 | 
			
		||||
}
 | 
			
		||||
@@ -1,743 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 *  emulator main execution loop
 | 
			
		||||
 *
 | 
			
		||||
 *  Copyright (c) 2003-2005 Fabrice Bellard
 | 
			
		||||
 *
 | 
			
		||||
 * This library is free software; you can redistribute it and/or
 | 
			
		||||
 * modify it under the terms of the GNU Lesser General Public
 | 
			
		||||
 * License as published by the Free Software Foundation; either
 | 
			
		||||
 * version 2.1 of the License, or (at your option) any later version.
 | 
			
		||||
 *
 | 
			
		||||
 * This library is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 | 
			
		||||
 * Lesser General Public License for more details.
 | 
			
		||||
 *
 | 
			
		||||
 * You should have received a copy of the GNU Lesser General Public
 | 
			
		||||
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "qemu/osdep.h"
 | 
			
		||||
#include "qemu-common.h"
 | 
			
		||||
#include "cpu.h"
 | 
			
		||||
#include "trace.h"
 | 
			
		||||
#include "disas/disas.h"
 | 
			
		||||
#include "exec/exec-all.h"
 | 
			
		||||
#include "tcg.h"
 | 
			
		||||
#include "qemu/atomic.h"
 | 
			
		||||
#include "sysemu/qtest.h"
 | 
			
		||||
#include "qemu/timer.h"
 | 
			
		||||
#include "qemu/rcu.h"
 | 
			
		||||
#include "exec/tb-hash.h"
 | 
			
		||||
#include "exec/tb-lookup.h"
 | 
			
		||||
#include "exec/log.h"
 | 
			
		||||
#include "qemu/main-loop.h"
 | 
			
		||||
#if defined(TARGET_I386) && !defined(CONFIG_USER_ONLY)
 | 
			
		||||
#include "hw/i386/apic.h"
 | 
			
		||||
#endif
 | 
			
		||||
#include "sysemu/cpus.h"
 | 
			
		||||
#include "sysemu/replay.h"
 | 
			
		||||
 | 
			
		||||
/* -icount align implementation. */
 | 
			
		||||
 | 
			
		||||
typedef struct SyncClocks {
 | 
			
		||||
    int64_t diff_clk;
 | 
			
		||||
    int64_t last_cpu_icount;
 | 
			
		||||
    int64_t realtime_clock;
 | 
			
		||||
} SyncClocks;
 | 
			
		||||
 | 
			
		||||
#if !defined(CONFIG_USER_ONLY)
 | 
			
		||||
/* Allow the guest to have a max 3ms advance.
 | 
			
		||||
 * The difference between the 2 clocks could therefore
 | 
			
		||||
 * oscillate around 0.
 | 
			
		||||
 */
 | 
			
		||||
#define VM_CLOCK_ADVANCE 3000000
 | 
			
		||||
#define THRESHOLD_REDUCE 1.5
 | 
			
		||||
#define MAX_DELAY_PRINT_RATE 2000000000LL
 | 
			
		||||
#define MAX_NB_PRINTS 100
 | 
			
		||||
 | 
			
		||||
static void align_clocks(SyncClocks *sc, CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
    int64_t cpu_icount;
 | 
			
		||||
 | 
			
		||||
    if (!icount_align_option) {
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    cpu_icount = cpu->icount_extra + cpu_neg(cpu)->icount_decr.u16.low;
 | 
			
		||||
    sc->diff_clk += cpu_icount_to_ns(sc->last_cpu_icount - cpu_icount);
 | 
			
		||||
    sc->last_cpu_icount = cpu_icount;
 | 
			
		||||
 | 
			
		||||
    if (sc->diff_clk > VM_CLOCK_ADVANCE) {
 | 
			
		||||
#ifndef _WIN32
 | 
			
		||||
        struct timespec sleep_delay, rem_delay;
 | 
			
		||||
        sleep_delay.tv_sec = sc->diff_clk / 1000000000LL;
 | 
			
		||||
        sleep_delay.tv_nsec = sc->diff_clk % 1000000000LL;
 | 
			
		||||
        if (nanosleep(&sleep_delay, &rem_delay) < 0) {
 | 
			
		||||
            sc->diff_clk = rem_delay.tv_sec * 1000000000LL + rem_delay.tv_nsec;
 | 
			
		||||
        } else {
 | 
			
		||||
            sc->diff_clk = 0;
 | 
			
		||||
        }
 | 
			
		||||
#else
 | 
			
		||||
        Sleep(sc->diff_clk / SCALE_MS);
 | 
			
		||||
        sc->diff_clk = 0;
 | 
			
		||||
#endif
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void print_delay(const SyncClocks *sc)
 | 
			
		||||
{
 | 
			
		||||
    static float threshold_delay;
 | 
			
		||||
    static int64_t last_realtime_clock;
 | 
			
		||||
    static int nb_prints;
 | 
			
		||||
 | 
			
		||||
    if (icount_align_option &&
 | 
			
		||||
        sc->realtime_clock - last_realtime_clock >= MAX_DELAY_PRINT_RATE &&
 | 
			
		||||
        nb_prints < MAX_NB_PRINTS) {
 | 
			
		||||
        if ((-sc->diff_clk / (float)1000000000LL > threshold_delay) ||
 | 
			
		||||
            (-sc->diff_clk / (float)1000000000LL <
 | 
			
		||||
             (threshold_delay - THRESHOLD_REDUCE))) {
 | 
			
		||||
            threshold_delay = (-sc->diff_clk / 1000000000LL) + 1;
 | 
			
		||||
            printf("Warning: The guest is now late by %.1f to %.1f seconds\n",
 | 
			
		||||
                   threshold_delay - 1,
 | 
			
		||||
                   threshold_delay);
 | 
			
		||||
            nb_prints++;
 | 
			
		||||
            last_realtime_clock = sc->realtime_clock;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void init_delay_params(SyncClocks *sc, CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
    if (!icount_align_option) {
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
    sc->realtime_clock = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL_RT);
 | 
			
		||||
    sc->diff_clk = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - sc->realtime_clock;
 | 
			
		||||
    sc->last_cpu_icount
 | 
			
		||||
        = cpu->icount_extra + cpu_neg(cpu)->icount_decr.u16.low;
 | 
			
		||||
    if (sc->diff_clk < max_delay) {
 | 
			
		||||
        max_delay = sc->diff_clk;
 | 
			
		||||
    }
 | 
			
		||||
    if (sc->diff_clk > max_advance) {
 | 
			
		||||
        max_advance = sc->diff_clk;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* Print every 2s max if the guest is late. We limit the number
 | 
			
		||||
       of printed messages to NB_PRINT_MAX(currently 100) */
 | 
			
		||||
    print_delay(sc);
 | 
			
		||||
}
 | 
			
		||||
#else
 | 
			
		||||
static void align_clocks(SyncClocks *sc, const CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void init_delay_params(SyncClocks *sc, const CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
#endif /* CONFIG USER ONLY */
 | 
			
		||||
 | 
			
		||||
/* Execute a TB, and fix up the CPU state afterwards if necessary */
 | 
			
		||||
static inline tcg_target_ulong cpu_tb_exec(CPUState *cpu, TranslationBlock *itb)
 | 
			
		||||
{
 | 
			
		||||
    CPUArchState *env = cpu->env_ptr;
 | 
			
		||||
    uintptr_t ret;
 | 
			
		||||
    TranslationBlock *last_tb;
 | 
			
		||||
    int tb_exit;
 | 
			
		||||
    uint8_t *tb_ptr = itb->tc.ptr;
 | 
			
		||||
 | 
			
		||||
    qemu_log_mask_and_addr(CPU_LOG_EXEC, itb->pc,
 | 
			
		||||
                           "Trace %d: %p ["
 | 
			
		||||
                           TARGET_FMT_lx "/" TARGET_FMT_lx "/%#x] %s\n",
 | 
			
		||||
                           cpu->cpu_index, itb->tc.ptr,
 | 
			
		||||
                           itb->cs_base, itb->pc, itb->flags,
 | 
			
		||||
                           lookup_symbol(itb->pc));
 | 
			
		||||
 | 
			
		||||
#if defined(DEBUG_DISAS)
 | 
			
		||||
    if (qemu_loglevel_mask(CPU_LOG_TB_CPU)
 | 
			
		||||
        && qemu_log_in_addr_range(itb->pc)) {
 | 
			
		||||
        qemu_log_lock();
 | 
			
		||||
        int flags = 0;
 | 
			
		||||
        if (qemu_loglevel_mask(CPU_LOG_TB_FPU)) {
 | 
			
		||||
            flags |= CPU_DUMP_FPU;
 | 
			
		||||
        }
 | 
			
		||||
#if defined(TARGET_I386)
 | 
			
		||||
        flags |= CPU_DUMP_CCOP;
 | 
			
		||||
#endif
 | 
			
		||||
        log_cpu_state(cpu, flags);
 | 
			
		||||
        qemu_log_unlock();
 | 
			
		||||
    }
 | 
			
		||||
#endif /* DEBUG_DISAS */
 | 
			
		||||
 | 
			
		||||
    cpu->can_do_io = !use_icount;
 | 
			
		||||
    ret = tcg_qemu_tb_exec(env, tb_ptr);
 | 
			
		||||
    cpu->can_do_io = 1;
 | 
			
		||||
    last_tb = (TranslationBlock *)(ret & ~TB_EXIT_MASK);
 | 
			
		||||
    tb_exit = ret & TB_EXIT_MASK;
 | 
			
		||||
    trace_exec_tb_exit(last_tb, tb_exit);
 | 
			
		||||
 | 
			
		||||
    if (tb_exit > TB_EXIT_IDX1) {
 | 
			
		||||
        /* We didn't start executing this TB (eg because the instruction
 | 
			
		||||
         * counter hit zero); we must restore the guest PC to the address
 | 
			
		||||
         * of the start of the TB.
 | 
			
		||||
         */
 | 
			
		||||
        CPUClass *cc = CPU_GET_CLASS(cpu);
 | 
			
		||||
        qemu_log_mask_and_addr(CPU_LOG_EXEC, last_tb->pc,
 | 
			
		||||
                               "Stopped execution of TB chain before %p ["
 | 
			
		||||
                               TARGET_FMT_lx "] %s\n",
 | 
			
		||||
                               last_tb->tc.ptr, last_tb->pc,
 | 
			
		||||
                               lookup_symbol(last_tb->pc));
 | 
			
		||||
        if (cc->synchronize_from_tb) {
 | 
			
		||||
            cc->synchronize_from_tb(cpu, last_tb);
 | 
			
		||||
        } else {
 | 
			
		||||
            assert(cc->set_pc);
 | 
			
		||||
            cc->set_pc(cpu, last_tb->pc);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifndef CONFIG_USER_ONLY
 | 
			
		||||
/* Execute the code without caching the generated code. An interpreter
 | 
			
		||||
   could be used if available. */
 | 
			
		||||
static void cpu_exec_nocache(CPUState *cpu, int max_cycles,
 | 
			
		||||
                             TranslationBlock *orig_tb, bool ignore_icount)
 | 
			
		||||
{
 | 
			
		||||
    TranslationBlock *tb;
 | 
			
		||||
    uint32_t cflags = curr_cflags() | CF_NOCACHE;
 | 
			
		||||
 | 
			
		||||
    if (ignore_icount) {
 | 
			
		||||
        cflags &= ~CF_USE_ICOUNT;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* Should never happen.
 | 
			
		||||
       We only end up here when an existing TB is too long.  */
 | 
			
		||||
    cflags |= MIN(max_cycles, CF_COUNT_MASK);
 | 
			
		||||
 | 
			
		||||
    mmap_lock();
 | 
			
		||||
    tb = tb_gen_code(cpu, orig_tb->pc, orig_tb->cs_base,
 | 
			
		||||
                     orig_tb->flags, cflags);
 | 
			
		||||
    tb->orig_tb = orig_tb;
 | 
			
		||||
    mmap_unlock();
 | 
			
		||||
 | 
			
		||||
    /* execute the generated code */
 | 
			
		||||
    trace_exec_tb_nocache(tb, tb->pc);
 | 
			
		||||
    cpu_tb_exec(cpu, tb);
 | 
			
		||||
 | 
			
		||||
    mmap_lock();
 | 
			
		||||
    tb_phys_invalidate(tb, -1);
 | 
			
		||||
    mmap_unlock();
 | 
			
		||||
    tcg_tb_remove(tb);
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
void cpu_exec_step_atomic(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
    CPUClass *cc = CPU_GET_CLASS(cpu);
 | 
			
		||||
    TranslationBlock *tb;
 | 
			
		||||
    target_ulong cs_base, pc;
 | 
			
		||||
    uint32_t flags;
 | 
			
		||||
    uint32_t cflags = 1;
 | 
			
		||||
    uint32_t cf_mask = cflags & CF_HASH_MASK;
 | 
			
		||||
    /* volatile because we modify it between setjmp and longjmp */
 | 
			
		||||
    volatile bool in_exclusive_region = false;
 | 
			
		||||
 | 
			
		||||
    if (sigsetjmp(cpu->jmp_env, 0) == 0) {
 | 
			
		||||
        tb = tb_lookup__cpu_state(cpu, &pc, &cs_base, &flags, cf_mask);
 | 
			
		||||
        if (tb == NULL) {
 | 
			
		||||
            mmap_lock();
 | 
			
		||||
            tb = tb_gen_code(cpu, pc, cs_base, flags, cflags);
 | 
			
		||||
            mmap_unlock();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        start_exclusive();
 | 
			
		||||
 | 
			
		||||
        /* Since we got here, we know that parallel_cpus must be true.  */
 | 
			
		||||
        parallel_cpus = false;
 | 
			
		||||
        in_exclusive_region = true;
 | 
			
		||||
        cc->cpu_exec_enter(cpu);
 | 
			
		||||
        /* execute the generated code */
 | 
			
		||||
        trace_exec_tb(tb, pc);
 | 
			
		||||
        cpu_tb_exec(cpu, tb);
 | 
			
		||||
        cc->cpu_exec_exit(cpu);
 | 
			
		||||
    } else {
 | 
			
		||||
        /*
 | 
			
		||||
         * The mmap_lock is dropped by tb_gen_code if it runs out of
 | 
			
		||||
         * memory.
 | 
			
		||||
         */
 | 
			
		||||
#ifndef CONFIG_SOFTMMU
 | 
			
		||||
        tcg_debug_assert(!have_mmap_lock());
 | 
			
		||||
#endif
 | 
			
		||||
        if (qemu_mutex_iothread_locked()) {
 | 
			
		||||
            qemu_mutex_unlock_iothread();
 | 
			
		||||
        }
 | 
			
		||||
        assert_no_pages_locked();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (in_exclusive_region) {
 | 
			
		||||
        /* We might longjump out of either the codegen or the
 | 
			
		||||
         * execution, so must make sure we only end the exclusive
 | 
			
		||||
         * region if we started it.
 | 
			
		||||
         */
 | 
			
		||||
        parallel_cpus = true;
 | 
			
		||||
        end_exclusive();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct tb_desc {
 | 
			
		||||
    target_ulong pc;
 | 
			
		||||
    target_ulong cs_base;
 | 
			
		||||
    CPUArchState *env;
 | 
			
		||||
    tb_page_addr_t phys_page1;
 | 
			
		||||
    uint32_t flags;
 | 
			
		||||
    uint32_t cf_mask;
 | 
			
		||||
    uint32_t trace_vcpu_dstate;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static bool tb_lookup_cmp(const void *p, const void *d)
 | 
			
		||||
{
 | 
			
		||||
    const TranslationBlock *tb = p;
 | 
			
		||||
    const struct tb_desc *desc = d;
 | 
			
		||||
 | 
			
		||||
    if (tb->pc == desc->pc &&
 | 
			
		||||
        tb->page_addr[0] == desc->phys_page1 &&
 | 
			
		||||
        tb->cs_base == desc->cs_base &&
 | 
			
		||||
        tb->flags == desc->flags &&
 | 
			
		||||
        tb->trace_vcpu_dstate == desc->trace_vcpu_dstate &&
 | 
			
		||||
        (tb_cflags(tb) & (CF_HASH_MASK | CF_INVALID)) == desc->cf_mask) {
 | 
			
		||||
        /* check next page if needed */
 | 
			
		||||
        if (tb->page_addr[1] == -1) {
 | 
			
		||||
            return true;
 | 
			
		||||
        } else {
 | 
			
		||||
            tb_page_addr_t phys_page2;
 | 
			
		||||
            target_ulong virt_page2;
 | 
			
		||||
 | 
			
		||||
            virt_page2 = (desc->pc & TARGET_PAGE_MASK) + TARGET_PAGE_SIZE;
 | 
			
		||||
            phys_page2 = get_page_addr_code(desc->env, virt_page2);
 | 
			
		||||
            if (tb->page_addr[1] == phys_page2) {
 | 
			
		||||
                return true;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TranslationBlock *tb_htable_lookup(CPUState *cpu, target_ulong pc,
 | 
			
		||||
                                   target_ulong cs_base, uint32_t flags,
 | 
			
		||||
                                   uint32_t cf_mask)
 | 
			
		||||
{
 | 
			
		||||
    tb_page_addr_t phys_pc;
 | 
			
		||||
    struct tb_desc desc;
 | 
			
		||||
    uint32_t h;
 | 
			
		||||
 | 
			
		||||
    desc.env = (CPUArchState *)cpu->env_ptr;
 | 
			
		||||
    desc.cs_base = cs_base;
 | 
			
		||||
    desc.flags = flags;
 | 
			
		||||
    desc.cf_mask = cf_mask;
 | 
			
		||||
    desc.trace_vcpu_dstate = *cpu->trace_dstate;
 | 
			
		||||
    desc.pc = pc;
 | 
			
		||||
    phys_pc = get_page_addr_code(desc.env, pc);
 | 
			
		||||
    if (phys_pc == -1) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
    desc.phys_page1 = phys_pc & TARGET_PAGE_MASK;
 | 
			
		||||
    h = tb_hash_func(phys_pc, pc, flags, cf_mask, *cpu->trace_dstate);
 | 
			
		||||
    return qht_lookup_custom(&tb_ctx.htable, &desc, h, tb_lookup_cmp);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void tb_set_jmp_target(TranslationBlock *tb, int n, uintptr_t addr)
 | 
			
		||||
{
 | 
			
		||||
    if (TCG_TARGET_HAS_direct_jump) {
 | 
			
		||||
        uintptr_t offset = tb->jmp_target_arg[n];
 | 
			
		||||
        uintptr_t tc_ptr = (uintptr_t)tb->tc.ptr;
 | 
			
		||||
        tb_target_set_jmp_target(tc_ptr, tc_ptr + offset, addr);
 | 
			
		||||
    } else {
 | 
			
		||||
        tb->jmp_target_arg[n] = addr;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void tb_add_jump(TranslationBlock *tb, int n,
 | 
			
		||||
                               TranslationBlock *tb_next)
 | 
			
		||||
{
 | 
			
		||||
    uintptr_t old;
 | 
			
		||||
 | 
			
		||||
    assert(n < ARRAY_SIZE(tb->jmp_list_next));
 | 
			
		||||
    qemu_spin_lock(&tb_next->jmp_lock);
 | 
			
		||||
 | 
			
		||||
    /* make sure the destination TB is valid */
 | 
			
		||||
    if (tb_next->cflags & CF_INVALID) {
 | 
			
		||||
        goto out_unlock_next;
 | 
			
		||||
    }
 | 
			
		||||
    /* Atomically claim the jump destination slot only if it was NULL */
 | 
			
		||||
    old = atomic_cmpxchg(&tb->jmp_dest[n], (uintptr_t)NULL, (uintptr_t)tb_next);
 | 
			
		||||
    if (old) {
 | 
			
		||||
        goto out_unlock_next;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* patch the native jump address */
 | 
			
		||||
    tb_set_jmp_target(tb, n, (uintptr_t)tb_next->tc.ptr);
 | 
			
		||||
 | 
			
		||||
    /* add in TB jmp list */
 | 
			
		||||
    tb->jmp_list_next[n] = tb_next->jmp_list_head;
 | 
			
		||||
    tb_next->jmp_list_head = (uintptr_t)tb | n;
 | 
			
		||||
 | 
			
		||||
    qemu_spin_unlock(&tb_next->jmp_lock);
 | 
			
		||||
 | 
			
		||||
    qemu_log_mask_and_addr(CPU_LOG_EXEC, tb->pc,
 | 
			
		||||
                           "Linking TBs %p [" TARGET_FMT_lx
 | 
			
		||||
                           "] index %d -> %p [" TARGET_FMT_lx "]\n",
 | 
			
		||||
                           tb->tc.ptr, tb->pc, n,
 | 
			
		||||
                           tb_next->tc.ptr, tb_next->pc);
 | 
			
		||||
    return;
 | 
			
		||||
 | 
			
		||||
 out_unlock_next:
 | 
			
		||||
    qemu_spin_unlock(&tb_next->jmp_lock);
 | 
			
		||||
    return;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline TranslationBlock *tb_find(CPUState *cpu,
 | 
			
		||||
                                        TranslationBlock *last_tb,
 | 
			
		||||
                                        int tb_exit, uint32_t cf_mask)
 | 
			
		||||
{
 | 
			
		||||
    TranslationBlock *tb;
 | 
			
		||||
    target_ulong cs_base, pc;
 | 
			
		||||
    uint32_t flags;
 | 
			
		||||
 | 
			
		||||
    tb = tb_lookup__cpu_state(cpu, &pc, &cs_base, &flags, cf_mask);
 | 
			
		||||
    if (tb == NULL) {
 | 
			
		||||
        mmap_lock();
 | 
			
		||||
        tb = tb_gen_code(cpu, pc, cs_base, flags, cf_mask);
 | 
			
		||||
        mmap_unlock();
 | 
			
		||||
        /* We add the TB in the virtual pc hash table for the fast lookup */
 | 
			
		||||
        atomic_set(&cpu->tb_jmp_cache[tb_jmp_cache_hash_func(pc)], tb);
 | 
			
		||||
    }
 | 
			
		||||
#ifndef CONFIG_USER_ONLY
 | 
			
		||||
    /* We don't take care of direct jumps when address mapping changes in
 | 
			
		||||
     * system emulation. So it's not safe to make a direct jump to a TB
 | 
			
		||||
     * spanning two pages because the mapping for the second page can change.
 | 
			
		||||
     */
 | 
			
		||||
    if (tb->page_addr[1] != -1) {
 | 
			
		||||
        last_tb = NULL;
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
    /* See if we can patch the calling TB. */
 | 
			
		||||
    if (last_tb) {
 | 
			
		||||
        tb_add_jump(last_tb, tb_exit, tb);
 | 
			
		||||
    }
 | 
			
		||||
    return tb;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline bool cpu_handle_halt(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
    if (cpu->halted) {
 | 
			
		||||
#if defined(TARGET_I386) && !defined(CONFIG_USER_ONLY)
 | 
			
		||||
        if ((cpu->interrupt_request & CPU_INTERRUPT_POLL)
 | 
			
		||||
            && replay_interrupt()) {
 | 
			
		||||
            X86CPU *x86_cpu = X86_CPU(cpu);
 | 
			
		||||
            qemu_mutex_lock_iothread();
 | 
			
		||||
            apic_poll_irq(x86_cpu->apic_state);
 | 
			
		||||
            cpu_reset_interrupt(cpu, CPU_INTERRUPT_POLL);
 | 
			
		||||
            qemu_mutex_unlock_iothread();
 | 
			
		||||
        }
 | 
			
		||||
#endif
 | 
			
		||||
        if (!cpu_has_work(cpu)) {
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        cpu->halted = 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void cpu_handle_debug_exception(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
    CPUClass *cc = CPU_GET_CLASS(cpu);
 | 
			
		||||
    CPUWatchpoint *wp;
 | 
			
		||||
 | 
			
		||||
    if (!cpu->watchpoint_hit) {
 | 
			
		||||
        QTAILQ_FOREACH(wp, &cpu->watchpoints, entry) {
 | 
			
		||||
            wp->flags &= ~BP_WATCHPOINT_HIT;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    cc->debug_excp_handler(cpu);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline bool cpu_handle_exception(CPUState *cpu, int *ret)
 | 
			
		||||
{
 | 
			
		||||
    if (cpu->exception_index < 0) {
 | 
			
		||||
#ifndef CONFIG_USER_ONLY
 | 
			
		||||
        if (replay_has_exception()
 | 
			
		||||
            && cpu_neg(cpu)->icount_decr.u16.low + cpu->icount_extra == 0) {
 | 
			
		||||
            /* try to cause an exception pending in the log */
 | 
			
		||||
            cpu_exec_nocache(cpu, 1, tb_find(cpu, NULL, 0, curr_cflags()), true);
 | 
			
		||||
        }
 | 
			
		||||
#endif
 | 
			
		||||
        if (cpu->exception_index < 0) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (cpu->exception_index >= EXCP_INTERRUPT) {
 | 
			
		||||
        /* exit request from the cpu execution loop */
 | 
			
		||||
        *ret = cpu->exception_index;
 | 
			
		||||
        if (*ret == EXCP_DEBUG) {
 | 
			
		||||
            cpu_handle_debug_exception(cpu);
 | 
			
		||||
        }
 | 
			
		||||
        cpu->exception_index = -1;
 | 
			
		||||
        return true;
 | 
			
		||||
    } else {
 | 
			
		||||
#if defined(CONFIG_USER_ONLY)
 | 
			
		||||
        /* if user mode only, we simulate a fake exception
 | 
			
		||||
           which will be handled outside the cpu execution
 | 
			
		||||
           loop */
 | 
			
		||||
#if defined(TARGET_I386)
 | 
			
		||||
        CPUClass *cc = CPU_GET_CLASS(cpu);
 | 
			
		||||
        cc->do_interrupt(cpu);
 | 
			
		||||
#endif
 | 
			
		||||
        *ret = cpu->exception_index;
 | 
			
		||||
        cpu->exception_index = -1;
 | 
			
		||||
        return true;
 | 
			
		||||
#else
 | 
			
		||||
        if (replay_exception()) {
 | 
			
		||||
            CPUClass *cc = CPU_GET_CLASS(cpu);
 | 
			
		||||
            qemu_mutex_lock_iothread();
 | 
			
		||||
            cc->do_interrupt(cpu);
 | 
			
		||||
            qemu_mutex_unlock_iothread();
 | 
			
		||||
            cpu->exception_index = -1;
 | 
			
		||||
        } else if (!replay_has_interrupt()) {
 | 
			
		||||
            /* give a chance to iothread in replay mode */
 | 
			
		||||
            *ret = EXCP_INTERRUPT;
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
#endif
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline bool cpu_handle_interrupt(CPUState *cpu,
 | 
			
		||||
                                        TranslationBlock **last_tb)
 | 
			
		||||
{
 | 
			
		||||
    CPUClass *cc = CPU_GET_CLASS(cpu);
 | 
			
		||||
 | 
			
		||||
    /* Clear the interrupt flag now since we're processing
 | 
			
		||||
     * cpu->interrupt_request and cpu->exit_request.
 | 
			
		||||
     * Ensure zeroing happens before reading cpu->exit_request or
 | 
			
		||||
     * cpu->interrupt_request (see also smp_wmb in cpu_exit())
 | 
			
		||||
     */
 | 
			
		||||
    atomic_mb_set(&cpu_neg(cpu)->icount_decr.u16.high, 0);
 | 
			
		||||
 | 
			
		||||
    if (unlikely(atomic_read(&cpu->interrupt_request))) {
 | 
			
		||||
        int interrupt_request;
 | 
			
		||||
        qemu_mutex_lock_iothread();
 | 
			
		||||
        interrupt_request = cpu->interrupt_request;
 | 
			
		||||
        if (unlikely(cpu->singlestep_enabled & SSTEP_NOIRQ)) {
 | 
			
		||||
            /* Mask out external interrupts for this step. */
 | 
			
		||||
            interrupt_request &= ~CPU_INTERRUPT_SSTEP_MASK;
 | 
			
		||||
        }
 | 
			
		||||
        if (interrupt_request & CPU_INTERRUPT_DEBUG) {
 | 
			
		||||
            cpu->interrupt_request &= ~CPU_INTERRUPT_DEBUG;
 | 
			
		||||
            cpu->exception_index = EXCP_DEBUG;
 | 
			
		||||
            qemu_mutex_unlock_iothread();
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
        if (replay_mode == REPLAY_MODE_PLAY && !replay_has_interrupt()) {
 | 
			
		||||
            /* Do nothing */
 | 
			
		||||
        } else if (interrupt_request & CPU_INTERRUPT_HALT) {
 | 
			
		||||
            replay_interrupt();
 | 
			
		||||
            cpu->interrupt_request &= ~CPU_INTERRUPT_HALT;
 | 
			
		||||
            cpu->halted = 1;
 | 
			
		||||
            cpu->exception_index = EXCP_HLT;
 | 
			
		||||
            qemu_mutex_unlock_iothread();
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
#if defined(TARGET_I386)
 | 
			
		||||
        else if (interrupt_request & CPU_INTERRUPT_INIT) {
 | 
			
		||||
            X86CPU *x86_cpu = X86_CPU(cpu);
 | 
			
		||||
            CPUArchState *env = &x86_cpu->env;
 | 
			
		||||
            replay_interrupt();
 | 
			
		||||
            cpu_svm_check_intercept_param(env, SVM_EXIT_INIT, 0, 0);
 | 
			
		||||
            do_cpu_init(x86_cpu);
 | 
			
		||||
            cpu->exception_index = EXCP_HALTED;
 | 
			
		||||
            qemu_mutex_unlock_iothread();
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
#else
 | 
			
		||||
        else if (interrupt_request & CPU_INTERRUPT_RESET) {
 | 
			
		||||
            replay_interrupt();
 | 
			
		||||
            cpu_reset(cpu);
 | 
			
		||||
            qemu_mutex_unlock_iothread();
 | 
			
		||||
            return true;
 | 
			
		||||
        }
 | 
			
		||||
#endif
 | 
			
		||||
        /* The target hook has 3 exit conditions:
 | 
			
		||||
           False when the interrupt isn't processed,
 | 
			
		||||
           True when it is, and we should restart on a new TB,
 | 
			
		||||
           and via longjmp via cpu_loop_exit.  */
 | 
			
		||||
        else {
 | 
			
		||||
            if (cc->cpu_exec_interrupt(cpu, interrupt_request)) {
 | 
			
		||||
                replay_interrupt();
 | 
			
		||||
                cpu->exception_index = -1;
 | 
			
		||||
                *last_tb = NULL;
 | 
			
		||||
            }
 | 
			
		||||
            /* The target hook may have updated the 'cpu->interrupt_request';
 | 
			
		||||
             * reload the 'interrupt_request' value */
 | 
			
		||||
            interrupt_request = cpu->interrupt_request;
 | 
			
		||||
        }
 | 
			
		||||
        if (interrupt_request & CPU_INTERRUPT_EXITTB) {
 | 
			
		||||
            cpu->interrupt_request &= ~CPU_INTERRUPT_EXITTB;
 | 
			
		||||
            /* ensure that no TB jump will be modified as
 | 
			
		||||
               the program flow was changed */
 | 
			
		||||
            *last_tb = NULL;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* If we exit via cpu_loop_exit/longjmp it is reset in cpu_exec */
 | 
			
		||||
        qemu_mutex_unlock_iothread();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* Finally, check if we need to exit to the main loop.  */
 | 
			
		||||
    if (unlikely(atomic_read(&cpu->exit_request))
 | 
			
		||||
        || (use_icount
 | 
			
		||||
            && cpu_neg(cpu)->icount_decr.u16.low + cpu->icount_extra == 0)) {
 | 
			
		||||
        atomic_set(&cpu->exit_request, 0);
 | 
			
		||||
        if (cpu->exception_index == -1) {
 | 
			
		||||
            cpu->exception_index = EXCP_INTERRUPT;
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void cpu_loop_exec_tb(CPUState *cpu, TranslationBlock *tb,
 | 
			
		||||
                                    TranslationBlock **last_tb, int *tb_exit)
 | 
			
		||||
{
 | 
			
		||||
    uintptr_t ret;
 | 
			
		||||
    int32_t insns_left;
 | 
			
		||||
 | 
			
		||||
    trace_exec_tb(tb, tb->pc);
 | 
			
		||||
    ret = cpu_tb_exec(cpu, tb);
 | 
			
		||||
    tb = (TranslationBlock *)(ret & ~TB_EXIT_MASK);
 | 
			
		||||
    *tb_exit = ret & TB_EXIT_MASK;
 | 
			
		||||
    if (*tb_exit != TB_EXIT_REQUESTED) {
 | 
			
		||||
        *last_tb = tb;
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    *last_tb = NULL;
 | 
			
		||||
    insns_left = atomic_read(&cpu_neg(cpu)->icount_decr.u32);
 | 
			
		||||
    if (insns_left < 0) {
 | 
			
		||||
        /* Something asked us to stop executing chained TBs; just
 | 
			
		||||
         * continue round the main loop. Whatever requested the exit
 | 
			
		||||
         * will also have set something else (eg exit_request or
 | 
			
		||||
         * interrupt_request) which will be handled by
 | 
			
		||||
         * cpu_handle_interrupt.  cpu_handle_interrupt will also
 | 
			
		||||
         * clear cpu->icount_decr.u16.high.
 | 
			
		||||
         */
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* Instruction counter expired.  */
 | 
			
		||||
    assert(use_icount);
 | 
			
		||||
#ifndef CONFIG_USER_ONLY
 | 
			
		||||
    /* Ensure global icount has gone forward */
 | 
			
		||||
    cpu_update_icount(cpu);
 | 
			
		||||
    /* Refill decrementer and continue execution.  */
 | 
			
		||||
    insns_left = MIN(0xffff, cpu->icount_budget);
 | 
			
		||||
    cpu_neg(cpu)->icount_decr.u16.low = insns_left;
 | 
			
		||||
    cpu->icount_extra = cpu->icount_budget - insns_left;
 | 
			
		||||
    if (!cpu->icount_extra) {
 | 
			
		||||
        /* Execute any remaining instructions, then let the main loop
 | 
			
		||||
         * handle the next event.
 | 
			
		||||
         */
 | 
			
		||||
        if (insns_left > 0) {
 | 
			
		||||
            cpu_exec_nocache(cpu, insns_left, tb, false);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* main execution loop */
 | 
			
		||||
 | 
			
		||||
int cpu_exec(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
    CPUClass *cc = CPU_GET_CLASS(cpu);
 | 
			
		||||
    int ret;
 | 
			
		||||
    SyncClocks sc = { 0 };
 | 
			
		||||
 | 
			
		||||
    /* replay_interrupt may need current_cpu */
 | 
			
		||||
    current_cpu = cpu;
 | 
			
		||||
 | 
			
		||||
    if (cpu_handle_halt(cpu)) {
 | 
			
		||||
        return EXCP_HALTED;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    rcu_read_lock();
 | 
			
		||||
 | 
			
		||||
    cc->cpu_exec_enter(cpu);
 | 
			
		||||
 | 
			
		||||
    /* Calculate difference between guest clock and host clock.
 | 
			
		||||
     * This delay includes the delay of the last cycle, so
 | 
			
		||||
     * what we have to do is sleep until it is 0. As for the
 | 
			
		||||
     * advance/delay we gain here, we try to fix it next time.
 | 
			
		||||
     */
 | 
			
		||||
    init_delay_params(&sc, cpu);
 | 
			
		||||
 | 
			
		||||
    /* prepare setjmp context for exception handling */
 | 
			
		||||
    if (sigsetjmp(cpu->jmp_env, 0) != 0) {
 | 
			
		||||
#if defined(__clang__) || !QEMU_GNUC_PREREQ(4, 6)
 | 
			
		||||
        /* Some compilers wrongly smash all local variables after
 | 
			
		||||
         * siglongjmp. There were bug reports for gcc 4.5.0 and clang.
 | 
			
		||||
         * Reload essential local variables here for those compilers.
 | 
			
		||||
         * Newer versions of gcc would complain about this code (-Wclobbered). */
 | 
			
		||||
        cpu = current_cpu;
 | 
			
		||||
        cc = CPU_GET_CLASS(cpu);
 | 
			
		||||
#else /* buggy compiler */
 | 
			
		||||
        /* Assert that the compiler does not smash local variables. */
 | 
			
		||||
        g_assert(cpu == current_cpu);
 | 
			
		||||
        g_assert(cc == CPU_GET_CLASS(cpu));
 | 
			
		||||
#endif /* buggy compiler */
 | 
			
		||||
#ifndef CONFIG_SOFTMMU
 | 
			
		||||
        tcg_debug_assert(!have_mmap_lock());
 | 
			
		||||
#endif
 | 
			
		||||
        if (qemu_mutex_iothread_locked()) {
 | 
			
		||||
            qemu_mutex_unlock_iothread();
 | 
			
		||||
        }
 | 
			
		||||
        assert_no_pages_locked();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* if an exception is pending, we execute it here */
 | 
			
		||||
    while (!cpu_handle_exception(cpu, &ret)) {
 | 
			
		||||
        TranslationBlock *last_tb = NULL;
 | 
			
		||||
        int tb_exit = 0;
 | 
			
		||||
 | 
			
		||||
        while (!cpu_handle_interrupt(cpu, &last_tb)) {
 | 
			
		||||
            uint32_t cflags = cpu->cflags_next_tb;
 | 
			
		||||
            TranslationBlock *tb;
 | 
			
		||||
 | 
			
		||||
            /* When requested, use an exact setting for cflags for the next
 | 
			
		||||
               execution.  This is used for icount, precise smc, and stop-
 | 
			
		||||
               after-access watchpoints.  Since this request should never
 | 
			
		||||
               have CF_INVALID set, -1 is a convenient invalid value that
 | 
			
		||||
               does not require tcg headers for cpu_common_reset.  */
 | 
			
		||||
            if (cflags == -1) {
 | 
			
		||||
                cflags = curr_cflags();
 | 
			
		||||
            } else {
 | 
			
		||||
                cpu->cflags_next_tb = -1;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            tb = tb_find(cpu, last_tb, tb_exit, cflags);
 | 
			
		||||
            cpu_loop_exec_tb(cpu, tb, &last_tb, &tb_exit);
 | 
			
		||||
            /* Try to align the host and virtual clocks
 | 
			
		||||
               if the guest is in advance */
 | 
			
		||||
            align_clocks(&sc, cpu);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    cc->cpu_exec_exit(cpu);
 | 
			
		||||
    rcu_read_unlock();
 | 
			
		||||
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										1817
									
								
								accel/tcg/cputlb.c
									
									
									
									
									
								
							
							
						
						
									
										1817
									
								
								accel/tcg/cputlb.c
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -1,90 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * QEMU System Emulator, accelerator interfaces
 | 
			
		||||
 *
 | 
			
		||||
 * Copyright (c) 2003-2008 Fabrice Bellard
 | 
			
		||||
 * Copyright (c) 2014 Red Hat Inc.
 | 
			
		||||
 *
 | 
			
		||||
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
			
		||||
 * of this software and associated documentation files (the "Software"), to deal
 | 
			
		||||
 * in the Software without restriction, including without limitation the rights
 | 
			
		||||
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
			
		||||
 * copies of the Software, and to permit persons to whom the Software is
 | 
			
		||||
 * furnished to do so, subject to the following conditions:
 | 
			
		||||
 *
 | 
			
		||||
 * The above copyright notice and this permission notice shall be included in
 | 
			
		||||
 * all copies or substantial portions of the Software.
 | 
			
		||||
 *
 | 
			
		||||
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 | 
			
		||||
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
			
		||||
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
			
		||||
 * THE SOFTWARE.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "qemu/osdep.h"
 | 
			
		||||
#include "sysemu/accel.h"
 | 
			
		||||
#include "sysemu/sysemu.h"
 | 
			
		||||
#include "sysemu/tcg.h"
 | 
			
		||||
#include "qom/object.h"
 | 
			
		||||
#include "cpu.h"
 | 
			
		||||
#include "sysemu/cpus.h"
 | 
			
		||||
#include "qemu/main-loop.h"
 | 
			
		||||
 | 
			
		||||
unsigned long tcg_tb_size;
 | 
			
		||||
 | 
			
		||||
/* mask must never be zero, except for A20 change call */
 | 
			
		||||
static void tcg_handle_interrupt(CPUState *cpu, int mask)
 | 
			
		||||
{
 | 
			
		||||
    int old_mask;
 | 
			
		||||
    g_assert(qemu_mutex_iothread_locked());
 | 
			
		||||
 | 
			
		||||
    old_mask = cpu->interrupt_request;
 | 
			
		||||
    cpu->interrupt_request |= mask;
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
     * If called from iothread context, wake the target cpu in
 | 
			
		||||
     * case its halted.
 | 
			
		||||
     */
 | 
			
		||||
    if (!qemu_cpu_is_self(cpu)) {
 | 
			
		||||
        qemu_cpu_kick(cpu);
 | 
			
		||||
    } else {
 | 
			
		||||
        atomic_set(&cpu_neg(cpu)->icount_decr.u16.high, -1);
 | 
			
		||||
        if (use_icount &&
 | 
			
		||||
            !cpu->can_do_io
 | 
			
		||||
            && (mask & ~old_mask) != 0) {
 | 
			
		||||
            cpu_abort(cpu, "Raised interrupt while not in I/O function");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int tcg_init(MachineState *ms)
 | 
			
		||||
{
 | 
			
		||||
    tcg_exec_init(tcg_tb_size * 1024 * 1024);
 | 
			
		||||
    cpu_interrupt_handler = tcg_handle_interrupt;
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void tcg_accel_class_init(ObjectClass *oc, void *data)
 | 
			
		||||
{
 | 
			
		||||
    AccelClass *ac = ACCEL_CLASS(oc);
 | 
			
		||||
    ac->name = "tcg";
 | 
			
		||||
    ac->init_machine = tcg_init;
 | 
			
		||||
    ac->allowed = &tcg_allowed;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#define TYPE_TCG_ACCEL ACCEL_CLASS_NAME("tcg")
 | 
			
		||||
 | 
			
		||||
static const TypeInfo tcg_accel_type = {
 | 
			
		||||
    .name = TYPE_TCG_ACCEL,
 | 
			
		||||
    .parent = TYPE_ACCEL,
 | 
			
		||||
    .class_init = tcg_accel_class_init,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void register_accel_types(void)
 | 
			
		||||
{
 | 
			
		||||
    type_register_static(&tcg_accel_type);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type_init(register_accel_types);
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -1,169 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Tiny Code Generator for QEMU
 | 
			
		||||
 *
 | 
			
		||||
 * Copyright (c) 2008 Fabrice Bellard
 | 
			
		||||
 *
 | 
			
		||||
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
			
		||||
 * of this software and associated documentation files (the "Software"), to deal
 | 
			
		||||
 * in the Software without restriction, including without limitation the rights
 | 
			
		||||
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
			
		||||
 * copies of the Software, and to permit persons to whom the Software is
 | 
			
		||||
 * furnished to do so, subject to the following conditions:
 | 
			
		||||
 *
 | 
			
		||||
 * The above copyright notice and this permission notice shall be included in
 | 
			
		||||
 * all copies or substantial portions of the Software.
 | 
			
		||||
 *
 | 
			
		||||
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 | 
			
		||||
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
			
		||||
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
			
		||||
 * THE SOFTWARE.
 | 
			
		||||
 */
 | 
			
		||||
#include "qemu/osdep.h"
 | 
			
		||||
#include "qemu/host-utils.h"
 | 
			
		||||
#include "cpu.h"
 | 
			
		||||
#include "exec/helper-proto.h"
 | 
			
		||||
#include "exec/cpu_ldst.h"
 | 
			
		||||
#include "exec/exec-all.h"
 | 
			
		||||
#include "exec/tb-lookup.h"
 | 
			
		||||
#include "disas/disas.h"
 | 
			
		||||
#include "exec/log.h"
 | 
			
		||||
 | 
			
		||||
/* 32-bit helpers */
 | 
			
		||||
 | 
			
		||||
int32_t HELPER(div_i32)(int32_t arg1, int32_t arg2)
 | 
			
		||||
{
 | 
			
		||||
    return arg1 / arg2;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int32_t HELPER(rem_i32)(int32_t arg1, int32_t arg2)
 | 
			
		||||
{
 | 
			
		||||
    return arg1 % arg2;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32_t HELPER(divu_i32)(uint32_t arg1, uint32_t arg2)
 | 
			
		||||
{
 | 
			
		||||
    return arg1 / arg2;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32_t HELPER(remu_i32)(uint32_t arg1, uint32_t arg2)
 | 
			
		||||
{
 | 
			
		||||
    return arg1 % arg2;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* 64-bit helpers */
 | 
			
		||||
 | 
			
		||||
uint64_t HELPER(shl_i64)(uint64_t arg1, uint64_t arg2)
 | 
			
		||||
{
 | 
			
		||||
    return arg1 << arg2;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint64_t HELPER(shr_i64)(uint64_t arg1, uint64_t arg2)
 | 
			
		||||
{
 | 
			
		||||
    return arg1 >> arg2;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int64_t HELPER(sar_i64)(int64_t arg1, int64_t arg2)
 | 
			
		||||
{
 | 
			
		||||
    return arg1 >> arg2;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int64_t HELPER(div_i64)(int64_t arg1, int64_t arg2)
 | 
			
		||||
{
 | 
			
		||||
    return arg1 / arg2;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int64_t HELPER(rem_i64)(int64_t arg1, int64_t arg2)
 | 
			
		||||
{
 | 
			
		||||
    return arg1 % arg2;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint64_t HELPER(divu_i64)(uint64_t arg1, uint64_t arg2)
 | 
			
		||||
{
 | 
			
		||||
    return arg1 / arg2;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint64_t HELPER(remu_i64)(uint64_t arg1, uint64_t arg2)
 | 
			
		||||
{
 | 
			
		||||
    return arg1 % arg2;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint64_t HELPER(muluh_i64)(uint64_t arg1, uint64_t arg2)
 | 
			
		||||
{
 | 
			
		||||
    uint64_t l, h;
 | 
			
		||||
    mulu64(&l, &h, arg1, arg2);
 | 
			
		||||
    return h;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int64_t HELPER(mulsh_i64)(int64_t arg1, int64_t arg2)
 | 
			
		||||
{
 | 
			
		||||
    uint64_t l, h;
 | 
			
		||||
    muls64(&l, &h, arg1, arg2);
 | 
			
		||||
    return h;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32_t HELPER(clz_i32)(uint32_t arg, uint32_t zero_val)
 | 
			
		||||
{
 | 
			
		||||
    return arg ? clz32(arg) : zero_val;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32_t HELPER(ctz_i32)(uint32_t arg, uint32_t zero_val)
 | 
			
		||||
{
 | 
			
		||||
    return arg ? ctz32(arg) : zero_val;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint64_t HELPER(clz_i64)(uint64_t arg, uint64_t zero_val)
 | 
			
		||||
{
 | 
			
		||||
    return arg ? clz64(arg) : zero_val;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint64_t HELPER(ctz_i64)(uint64_t arg, uint64_t zero_val)
 | 
			
		||||
{
 | 
			
		||||
    return arg ? ctz64(arg) : zero_val;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32_t HELPER(clrsb_i32)(uint32_t arg)
 | 
			
		||||
{
 | 
			
		||||
    return clrsb32(arg);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint64_t HELPER(clrsb_i64)(uint64_t arg)
 | 
			
		||||
{
 | 
			
		||||
    return clrsb64(arg);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint32_t HELPER(ctpop_i32)(uint32_t arg)
 | 
			
		||||
{
 | 
			
		||||
    return ctpop32(arg);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint64_t HELPER(ctpop_i64)(uint64_t arg)
 | 
			
		||||
{
 | 
			
		||||
    return ctpop64(arg);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void *HELPER(lookup_tb_ptr)(CPUArchState *env)
 | 
			
		||||
{
 | 
			
		||||
    CPUState *cpu = env_cpu(env);
 | 
			
		||||
    TranslationBlock *tb;
 | 
			
		||||
    target_ulong cs_base, pc;
 | 
			
		||||
    uint32_t flags;
 | 
			
		||||
 | 
			
		||||
    tb = tb_lookup__cpu_state(cpu, &pc, &cs_base, &flags, curr_cflags());
 | 
			
		||||
    if (tb == NULL) {
 | 
			
		||||
        return tcg_ctx->code_gen_epilogue;
 | 
			
		||||
    }
 | 
			
		||||
    qemu_log_mask_and_addr(CPU_LOG_EXEC, pc,
 | 
			
		||||
                           "Chain %d: %p ["
 | 
			
		||||
                           TARGET_FMT_lx "/" TARGET_FMT_lx "/%#x] %s\n",
 | 
			
		||||
                           cpu->cpu_index, tb->tc.ptr, cs_base, pc, flags,
 | 
			
		||||
                           lookup_symbol(pc));
 | 
			
		||||
    return tb->tc.ptr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void HELPER(exit_atomic)(CPUArchState *env)
 | 
			
		||||
{
 | 
			
		||||
    cpu_loop_exit_atomic(env_cpu(env), GETPC());
 | 
			
		||||
}
 | 
			
		||||
@@ -1,307 +0,0 @@
 | 
			
		||||
DEF_HELPER_FLAGS_2(div_i32, TCG_CALL_NO_RWG_SE, s32, s32, s32)
 | 
			
		||||
DEF_HELPER_FLAGS_2(rem_i32, TCG_CALL_NO_RWG_SE, s32, s32, s32)
 | 
			
		||||
DEF_HELPER_FLAGS_2(divu_i32, TCG_CALL_NO_RWG_SE, i32, i32, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_2(remu_i32, TCG_CALL_NO_RWG_SE, i32, i32, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_2(div_i64, TCG_CALL_NO_RWG_SE, s64, s64, s64)
 | 
			
		||||
DEF_HELPER_FLAGS_2(rem_i64, TCG_CALL_NO_RWG_SE, s64, s64, s64)
 | 
			
		||||
DEF_HELPER_FLAGS_2(divu_i64, TCG_CALL_NO_RWG_SE, i64, i64, i64)
 | 
			
		||||
DEF_HELPER_FLAGS_2(remu_i64, TCG_CALL_NO_RWG_SE, i64, i64, i64)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_2(shl_i64, TCG_CALL_NO_RWG_SE, i64, i64, i64)
 | 
			
		||||
DEF_HELPER_FLAGS_2(shr_i64, TCG_CALL_NO_RWG_SE, i64, i64, i64)
 | 
			
		||||
DEF_HELPER_FLAGS_2(sar_i64, TCG_CALL_NO_RWG_SE, s64, s64, s64)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_2(mulsh_i64, TCG_CALL_NO_RWG_SE, s64, s64, s64)
 | 
			
		||||
DEF_HELPER_FLAGS_2(muluh_i64, TCG_CALL_NO_RWG_SE, i64, i64, i64)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_2(clz_i32, TCG_CALL_NO_RWG_SE, i32, i32, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_2(ctz_i32, TCG_CALL_NO_RWG_SE, i32, i32, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_2(clz_i64, TCG_CALL_NO_RWG_SE, i64, i64, i64)
 | 
			
		||||
DEF_HELPER_FLAGS_2(ctz_i64, TCG_CALL_NO_RWG_SE, i64, i64, i64)
 | 
			
		||||
DEF_HELPER_FLAGS_1(clrsb_i32, TCG_CALL_NO_RWG_SE, i32, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_1(clrsb_i64, TCG_CALL_NO_RWG_SE, i64, i64)
 | 
			
		||||
DEF_HELPER_FLAGS_1(ctpop_i32, TCG_CALL_NO_RWG_SE, i32, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_1(ctpop_i64, TCG_CALL_NO_RWG_SE, i64, i64)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_1(lookup_tb_ptr, TCG_CALL_NO_WG_SE, ptr, env)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_1(exit_atomic, TCG_CALL_NO_WG, noreturn, env)
 | 
			
		||||
 | 
			
		||||
#ifdef CONFIG_SOFTMMU
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_5(atomic_cmpxchgb, TCG_CALL_NO_WG,
 | 
			
		||||
                   i32, env, tl, i32, i32, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_5(atomic_cmpxchgw_be, TCG_CALL_NO_WG,
 | 
			
		||||
                   i32, env, tl, i32, i32, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_5(atomic_cmpxchgw_le, TCG_CALL_NO_WG,
 | 
			
		||||
                   i32, env, tl, i32, i32, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_5(atomic_cmpxchgl_be, TCG_CALL_NO_WG,
 | 
			
		||||
                   i32, env, tl, i32, i32, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_5(atomic_cmpxchgl_le, TCG_CALL_NO_WG,
 | 
			
		||||
                   i32, env, tl, i32, i32, i32)
 | 
			
		||||
#ifdef CONFIG_ATOMIC64
 | 
			
		||||
DEF_HELPER_FLAGS_5(atomic_cmpxchgq_be, TCG_CALL_NO_WG,
 | 
			
		||||
                   i64, env, tl, i64, i64, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_5(atomic_cmpxchgq_le, TCG_CALL_NO_WG,
 | 
			
		||||
                   i64, env, tl, i64, i64, i32)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef CONFIG_ATOMIC64
 | 
			
		||||
#define GEN_ATOMIC_HELPERS(NAME)                                  \
 | 
			
		||||
    DEF_HELPER_FLAGS_4(glue(glue(atomic_, NAME), b),              \
 | 
			
		||||
                       TCG_CALL_NO_WG, i32, env, tl, i32, i32)    \
 | 
			
		||||
    DEF_HELPER_FLAGS_4(glue(glue(atomic_, NAME), w_le),           \
 | 
			
		||||
                       TCG_CALL_NO_WG, i32, env, tl, i32, i32)    \
 | 
			
		||||
    DEF_HELPER_FLAGS_4(glue(glue(atomic_, NAME), w_be),           \
 | 
			
		||||
                       TCG_CALL_NO_WG, i32, env, tl, i32, i32)    \
 | 
			
		||||
    DEF_HELPER_FLAGS_4(glue(glue(atomic_, NAME), l_le),           \
 | 
			
		||||
                       TCG_CALL_NO_WG, i32, env, tl, i32, i32)    \
 | 
			
		||||
    DEF_HELPER_FLAGS_4(glue(glue(atomic_, NAME), l_be),           \
 | 
			
		||||
                       TCG_CALL_NO_WG, i32, env, tl, i32, i32)    \
 | 
			
		||||
    DEF_HELPER_FLAGS_4(glue(glue(atomic_, NAME), q_le),           \
 | 
			
		||||
                       TCG_CALL_NO_WG, i64, env, tl, i64, i32)    \
 | 
			
		||||
    DEF_HELPER_FLAGS_4(glue(glue(atomic_, NAME), q_be),           \
 | 
			
		||||
                       TCG_CALL_NO_WG, i64, env, tl, i64, i32)
 | 
			
		||||
#else
 | 
			
		||||
#define GEN_ATOMIC_HELPERS(NAME)                                  \
 | 
			
		||||
    DEF_HELPER_FLAGS_4(glue(glue(atomic_, NAME), b),              \
 | 
			
		||||
                       TCG_CALL_NO_WG, i32, env, tl, i32, i32)    \
 | 
			
		||||
    DEF_HELPER_FLAGS_4(glue(glue(atomic_, NAME), w_le),           \
 | 
			
		||||
                       TCG_CALL_NO_WG, i32, env, tl, i32, i32)    \
 | 
			
		||||
    DEF_HELPER_FLAGS_4(glue(glue(atomic_, NAME), w_be),           \
 | 
			
		||||
                       TCG_CALL_NO_WG, i32, env, tl, i32, i32)    \
 | 
			
		||||
    DEF_HELPER_FLAGS_4(glue(glue(atomic_, NAME), l_le),           \
 | 
			
		||||
                       TCG_CALL_NO_WG, i32, env, tl, i32, i32)    \
 | 
			
		||||
    DEF_HELPER_FLAGS_4(glue(glue(atomic_, NAME), l_be),           \
 | 
			
		||||
                       TCG_CALL_NO_WG, i32, env, tl, i32, i32)
 | 
			
		||||
#endif /* CONFIG_ATOMIC64 */
 | 
			
		||||
 | 
			
		||||
#else
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_4(atomic_cmpxchgb, TCG_CALL_NO_WG, i32, env, tl, i32, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(atomic_cmpxchgw_be, TCG_CALL_NO_WG, i32, env, tl, i32, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(atomic_cmpxchgw_le, TCG_CALL_NO_WG, i32, env, tl, i32, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(atomic_cmpxchgl_be, TCG_CALL_NO_WG, i32, env, tl, i32, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(atomic_cmpxchgl_le, TCG_CALL_NO_WG, i32, env, tl, i32, i32)
 | 
			
		||||
#ifdef CONFIG_ATOMIC64
 | 
			
		||||
DEF_HELPER_FLAGS_4(atomic_cmpxchgq_be, TCG_CALL_NO_WG, i64, env, tl, i64, i64)
 | 
			
		||||
DEF_HELPER_FLAGS_4(atomic_cmpxchgq_le, TCG_CALL_NO_WG, i64, env, tl, i64, i64)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef CONFIG_ATOMIC64
 | 
			
		||||
#define GEN_ATOMIC_HELPERS(NAME)                             \
 | 
			
		||||
    DEF_HELPER_FLAGS_3(glue(glue(atomic_, NAME), b),         \
 | 
			
		||||
                       TCG_CALL_NO_WG, i32, env, tl, i32)    \
 | 
			
		||||
    DEF_HELPER_FLAGS_3(glue(glue(atomic_, NAME), w_le),      \
 | 
			
		||||
                       TCG_CALL_NO_WG, i32, env, tl, i32)    \
 | 
			
		||||
    DEF_HELPER_FLAGS_3(glue(glue(atomic_, NAME), w_be),      \
 | 
			
		||||
                       TCG_CALL_NO_WG, i32, env, tl, i32)    \
 | 
			
		||||
    DEF_HELPER_FLAGS_3(glue(glue(atomic_, NAME), l_le),      \
 | 
			
		||||
                       TCG_CALL_NO_WG, i32, env, tl, i32)    \
 | 
			
		||||
    DEF_HELPER_FLAGS_3(glue(glue(atomic_, NAME), l_be),      \
 | 
			
		||||
                       TCG_CALL_NO_WG, i32, env, tl, i32)    \
 | 
			
		||||
    DEF_HELPER_FLAGS_3(glue(glue(atomic_, NAME), q_le),      \
 | 
			
		||||
                       TCG_CALL_NO_WG, i64, env, tl, i64)    \
 | 
			
		||||
    DEF_HELPER_FLAGS_3(glue(glue(atomic_, NAME), q_be),      \
 | 
			
		||||
                       TCG_CALL_NO_WG, i64, env, tl, i64)
 | 
			
		||||
#else
 | 
			
		||||
#define GEN_ATOMIC_HELPERS(NAME)                             \
 | 
			
		||||
    DEF_HELPER_FLAGS_3(glue(glue(atomic_, NAME), b),         \
 | 
			
		||||
                       TCG_CALL_NO_WG, i32, env, tl, i32)    \
 | 
			
		||||
    DEF_HELPER_FLAGS_3(glue(glue(atomic_, NAME), w_le),      \
 | 
			
		||||
                       TCG_CALL_NO_WG, i32, env, tl, i32)    \
 | 
			
		||||
    DEF_HELPER_FLAGS_3(glue(glue(atomic_, NAME), w_be),      \
 | 
			
		||||
                       TCG_CALL_NO_WG, i32, env, tl, i32)    \
 | 
			
		||||
    DEF_HELPER_FLAGS_3(glue(glue(atomic_, NAME), l_le),      \
 | 
			
		||||
                       TCG_CALL_NO_WG, i32, env, tl, i32)    \
 | 
			
		||||
    DEF_HELPER_FLAGS_3(glue(glue(atomic_, NAME), l_be),      \
 | 
			
		||||
                       TCG_CALL_NO_WG, i32, env, tl, i32)
 | 
			
		||||
#endif /* CONFIG_ATOMIC64 */
 | 
			
		||||
 | 
			
		||||
#endif /* CONFIG_SOFTMMU */
 | 
			
		||||
 | 
			
		||||
GEN_ATOMIC_HELPERS(fetch_add)
 | 
			
		||||
GEN_ATOMIC_HELPERS(fetch_and)
 | 
			
		||||
GEN_ATOMIC_HELPERS(fetch_or)
 | 
			
		||||
GEN_ATOMIC_HELPERS(fetch_xor)
 | 
			
		||||
GEN_ATOMIC_HELPERS(fetch_smin)
 | 
			
		||||
GEN_ATOMIC_HELPERS(fetch_umin)
 | 
			
		||||
GEN_ATOMIC_HELPERS(fetch_smax)
 | 
			
		||||
GEN_ATOMIC_HELPERS(fetch_umax)
 | 
			
		||||
 | 
			
		||||
GEN_ATOMIC_HELPERS(add_fetch)
 | 
			
		||||
GEN_ATOMIC_HELPERS(and_fetch)
 | 
			
		||||
GEN_ATOMIC_HELPERS(or_fetch)
 | 
			
		||||
GEN_ATOMIC_HELPERS(xor_fetch)
 | 
			
		||||
GEN_ATOMIC_HELPERS(smin_fetch)
 | 
			
		||||
GEN_ATOMIC_HELPERS(umin_fetch)
 | 
			
		||||
GEN_ATOMIC_HELPERS(smax_fetch)
 | 
			
		||||
GEN_ATOMIC_HELPERS(umax_fetch)
 | 
			
		||||
 | 
			
		||||
GEN_ATOMIC_HELPERS(xchg)
 | 
			
		||||
 | 
			
		||||
#undef GEN_ATOMIC_HELPERS
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_3(gvec_mov, TCG_CALL_NO_RWG, void, ptr, ptr, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_3(gvec_dup8, TCG_CALL_NO_RWG, void, ptr, i32, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_3(gvec_dup16, TCG_CALL_NO_RWG, void, ptr, i32, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_3(gvec_dup32, TCG_CALL_NO_RWG, void, ptr, i32, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_3(gvec_dup64, TCG_CALL_NO_RWG, void, ptr, i32, i64)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_add8, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_add16, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_add32, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_add64, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_adds8, TCG_CALL_NO_RWG, void, ptr, ptr, i64, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_adds16, TCG_CALL_NO_RWG, void, ptr, ptr, i64, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_adds32, TCG_CALL_NO_RWG, void, ptr, ptr, i64, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_adds64, TCG_CALL_NO_RWG, void, ptr, ptr, i64, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_sub8, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_sub16, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_sub32, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_sub64, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_subs8, TCG_CALL_NO_RWG, void, ptr, ptr, i64, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_subs16, TCG_CALL_NO_RWG, void, ptr, ptr, i64, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_subs32, TCG_CALL_NO_RWG, void, ptr, ptr, i64, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_subs64, TCG_CALL_NO_RWG, void, ptr, ptr, i64, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_mul8, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_mul16, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_mul32, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_mul64, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_muls8, TCG_CALL_NO_RWG, void, ptr, ptr, i64, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_muls16, TCG_CALL_NO_RWG, void, ptr, ptr, i64, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_muls32, TCG_CALL_NO_RWG, void, ptr, ptr, i64, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_muls64, TCG_CALL_NO_RWG, void, ptr, ptr, i64, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_ssadd8, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_ssadd16, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_ssadd32, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_ssadd64, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_sssub8, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_sssub16, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_sssub32, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_sssub64, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_usadd8, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_usadd16, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_usadd32, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_usadd64, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_ussub8, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_ussub16, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_ussub32, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_ussub64, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_smin8, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_smin16, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_smin32, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_smin64, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_smax8, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_smax16, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_smax32, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_smax64, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_umin8, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_umin16, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_umin32, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_umin64, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_umax8, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_umax16, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_umax32, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_umax64, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_3(gvec_neg8, TCG_CALL_NO_RWG, void, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_3(gvec_neg16, TCG_CALL_NO_RWG, void, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_3(gvec_neg32, TCG_CALL_NO_RWG, void, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_3(gvec_neg64, TCG_CALL_NO_RWG, void, ptr, ptr, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_3(gvec_abs8, TCG_CALL_NO_RWG, void, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_3(gvec_abs16, TCG_CALL_NO_RWG, void, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_3(gvec_abs32, TCG_CALL_NO_RWG, void, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_3(gvec_abs64, TCG_CALL_NO_RWG, void, ptr, ptr, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_3(gvec_not, TCG_CALL_NO_RWG, void, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_and, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_or, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_xor, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_andc, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_orc, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_nand, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_nor, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_eqv, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_ands, TCG_CALL_NO_RWG, void, ptr, ptr, i64, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_xors, TCG_CALL_NO_RWG, void, ptr, ptr, i64, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_ors, TCG_CALL_NO_RWG, void, ptr, ptr, i64, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_3(gvec_shl8i, TCG_CALL_NO_RWG, void, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_3(gvec_shl16i, TCG_CALL_NO_RWG, void, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_3(gvec_shl32i, TCG_CALL_NO_RWG, void, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_3(gvec_shl64i, TCG_CALL_NO_RWG, void, ptr, ptr, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_3(gvec_shr8i, TCG_CALL_NO_RWG, void, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_3(gvec_shr16i, TCG_CALL_NO_RWG, void, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_3(gvec_shr32i, TCG_CALL_NO_RWG, void, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_3(gvec_shr64i, TCG_CALL_NO_RWG, void, ptr, ptr, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_3(gvec_sar8i, TCG_CALL_NO_RWG, void, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_3(gvec_sar16i, TCG_CALL_NO_RWG, void, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_3(gvec_sar32i, TCG_CALL_NO_RWG, void, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_3(gvec_sar64i, TCG_CALL_NO_RWG, void, ptr, ptr, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_shl8v, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_shl16v, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_shl32v, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_shl64v, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_shr8v, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_shr16v, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_shr32v, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_shr64v, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_sar8v, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_sar16v, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_sar32v, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_sar64v, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_eq8, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_eq16, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_eq32, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_eq64, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_ne8, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_ne16, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_ne32, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_ne64, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_lt8, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_lt16, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_lt32, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_lt64, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_le8, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_le16, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_le32, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_le64, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_ltu8, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_ltu16, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_ltu32, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_ltu64, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_leu8, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_leu16, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_leu32, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
DEF_HELPER_FLAGS_4(gvec_leu64, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32)
 | 
			
		||||
 | 
			
		||||
DEF_HELPER_FLAGS_5(gvec_bitsel, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32)
 | 
			
		||||
@@ -1,10 +0,0 @@
 | 
			
		||||
# See docs/devel/tracing.txt for syntax documentation.
 | 
			
		||||
 | 
			
		||||
# TCG related tracing (mostly disabled by default)
 | 
			
		||||
# cpu-exec.c
 | 
			
		||||
disable exec_tb(void *tb, uintptr_t pc) "tb:%p pc=0x%"PRIxPTR
 | 
			
		||||
disable exec_tb_nocache(void *tb, uintptr_t pc) "tb:%p pc=0x%"PRIxPTR
 | 
			
		||||
disable exec_tb_exit(void *last_tb, unsigned int flags) "tb:%p flags=0x%x"
 | 
			
		||||
 | 
			
		||||
# translate-all.c
 | 
			
		||||
translate_block(void *tb, uintptr_t pc, uint8_t *tb_code) "tb:%p, pc:0x%"PRIxPTR", tb_code:%p"
 | 
			
		||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -1,39 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 *  Translated block handling
 | 
			
		||||
 *
 | 
			
		||||
 *  Copyright (c) 2003 Fabrice Bellard
 | 
			
		||||
 *
 | 
			
		||||
 * This library is free software; you can redistribute it and/or
 | 
			
		||||
 * modify it under the terms of the GNU Lesser General Public
 | 
			
		||||
 * License as published by the Free Software Foundation; either
 | 
			
		||||
 * version 2.1 of the License, or (at your option) any later version.
 | 
			
		||||
 *
 | 
			
		||||
 * This library is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 | 
			
		||||
 * Lesser General Public License for more details.
 | 
			
		||||
 *
 | 
			
		||||
 * You should have received a copy of the GNU Lesser General Public
 | 
			
		||||
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
#ifndef TRANSLATE_ALL_H
 | 
			
		||||
#define TRANSLATE_ALL_H
 | 
			
		||||
 | 
			
		||||
#include "exec/exec-all.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/* translate-all.c */
 | 
			
		||||
struct page_collection *page_collection_lock(tb_page_addr_t start,
 | 
			
		||||
                                             tb_page_addr_t end);
 | 
			
		||||
void page_collection_unlock(struct page_collection *set);
 | 
			
		||||
void tb_invalidate_phys_page_fast(struct page_collection *pages,
 | 
			
		||||
                                  tb_page_addr_t start, int len);
 | 
			
		||||
void tb_invalidate_phys_page_range(tb_page_addr_t start, tb_page_addr_t end,
 | 
			
		||||
                                   int is_cpu_write_access);
 | 
			
		||||
void tb_check_watchpoint(CPUState *cpu);
 | 
			
		||||
 | 
			
		||||
#ifdef CONFIG_USER_ONLY
 | 
			
		||||
int page_unprotect(target_ulong address, uintptr_t pc);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#endif /* TRANSLATE_ALL_H */
 | 
			
		||||
@@ -1,129 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * Generic intermediate code generation.
 | 
			
		||||
 *
 | 
			
		||||
 * Copyright (C) 2016-2017 Lluís Vilanova <vilanova@ac.upc.edu>
 | 
			
		||||
 *
 | 
			
		||||
 * This work is licensed under the terms of the GNU GPL, version 2 or later.
 | 
			
		||||
 * See the COPYING file in the top-level directory.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "qemu/osdep.h"
 | 
			
		||||
#include "qemu/error-report.h"
 | 
			
		||||
#include "cpu.h"
 | 
			
		||||
#include "tcg/tcg.h"
 | 
			
		||||
#include "tcg/tcg-op.h"
 | 
			
		||||
#include "exec/exec-all.h"
 | 
			
		||||
#include "exec/gen-icount.h"
 | 
			
		||||
#include "exec/log.h"
 | 
			
		||||
#include "exec/translator.h"
 | 
			
		||||
 | 
			
		||||
/* Pairs with tcg_clear_temp_count.
 | 
			
		||||
   To be called by #TranslatorOps.{translate_insn,tb_stop} if
 | 
			
		||||
   (1) the target is sufficiently clean to support reporting,
 | 
			
		||||
   (2) as and when all temporaries are known to be consumed.
 | 
			
		||||
   For most targets, (2) is at the end of translate_insn.  */
 | 
			
		||||
void translator_loop_temp_check(DisasContextBase *db)
 | 
			
		||||
{
 | 
			
		||||
    if (tcg_check_temp_count()) {
 | 
			
		||||
        qemu_log("warning: TCG temporary leaks before "
 | 
			
		||||
                 TARGET_FMT_lx "\n", db->pc_next);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void translator_loop(const TranslatorOps *ops, DisasContextBase *db,
 | 
			
		||||
                     CPUState *cpu, TranslationBlock *tb, int max_insns)
 | 
			
		||||
{
 | 
			
		||||
    int bp_insn = 0;
 | 
			
		||||
 | 
			
		||||
    /* Initialize DisasContext */
 | 
			
		||||
    db->tb = tb;
 | 
			
		||||
    db->pc_first = tb->pc;
 | 
			
		||||
    db->pc_next = db->pc_first;
 | 
			
		||||
    db->is_jmp = DISAS_NEXT;
 | 
			
		||||
    db->num_insns = 0;
 | 
			
		||||
    db->max_insns = max_insns;
 | 
			
		||||
    db->singlestep_enabled = cpu->singlestep_enabled;
 | 
			
		||||
 | 
			
		||||
    ops->init_disas_context(db, cpu);
 | 
			
		||||
    tcg_debug_assert(db->is_jmp == DISAS_NEXT);  /* no early exit */
 | 
			
		||||
 | 
			
		||||
    /* Reset the temp count so that we can identify leaks */
 | 
			
		||||
    tcg_clear_temp_count();
 | 
			
		||||
 | 
			
		||||
    /* Start translating.  */
 | 
			
		||||
    gen_tb_start(db->tb);
 | 
			
		||||
    ops->tb_start(db, cpu);
 | 
			
		||||
    tcg_debug_assert(db->is_jmp == DISAS_NEXT);  /* no early exit */
 | 
			
		||||
 | 
			
		||||
    while (true) {
 | 
			
		||||
        db->num_insns++;
 | 
			
		||||
        ops->insn_start(db, cpu);
 | 
			
		||||
        tcg_debug_assert(db->is_jmp == DISAS_NEXT);  /* no early exit */
 | 
			
		||||
 | 
			
		||||
        /* Pass breakpoint hits to target for further processing */
 | 
			
		||||
        if (!db->singlestep_enabled
 | 
			
		||||
            && unlikely(!QTAILQ_EMPTY(&cpu->breakpoints))) {
 | 
			
		||||
            CPUBreakpoint *bp;
 | 
			
		||||
            QTAILQ_FOREACH(bp, &cpu->breakpoints, entry) {
 | 
			
		||||
                if (bp->pc == db->pc_next) {
 | 
			
		||||
                    if (ops->breakpoint_check(db, cpu, bp)) {
 | 
			
		||||
                        bp_insn = 1;
 | 
			
		||||
                        break;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            /* The breakpoint_check hook may use DISAS_TOO_MANY to indicate
 | 
			
		||||
               that only one more instruction is to be executed.  Otherwise
 | 
			
		||||
               it should use DISAS_NORETURN when generating an exception,
 | 
			
		||||
               but may use a DISAS_TARGET_* value for Something Else.  */
 | 
			
		||||
            if (db->is_jmp > DISAS_TOO_MANY) {
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* Disassemble one instruction.  The translate_insn hook should
 | 
			
		||||
           update db->pc_next and db->is_jmp to indicate what should be
 | 
			
		||||
           done next -- either exiting this loop or locate the start of
 | 
			
		||||
           the next instruction.  */
 | 
			
		||||
        if (db->num_insns == db->max_insns
 | 
			
		||||
            && (tb_cflags(db->tb) & CF_LAST_IO)) {
 | 
			
		||||
            /* Accept I/O on the last instruction.  */
 | 
			
		||||
            gen_io_start();
 | 
			
		||||
            ops->translate_insn(db, cpu);
 | 
			
		||||
            gen_io_end();
 | 
			
		||||
        } else {
 | 
			
		||||
            ops->translate_insn(db, cpu);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* Stop translation if translate_insn so indicated.  */
 | 
			
		||||
        if (db->is_jmp != DISAS_NEXT) {
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* Stop translation if the output buffer is full,
 | 
			
		||||
           or we have executed all of the allowed instructions.  */
 | 
			
		||||
        if (tcg_op_buf_full() || db->num_insns >= db->max_insns) {
 | 
			
		||||
            db->is_jmp = DISAS_TOO_MANY;
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* Emit code to exit the TB, as indicated by db->is_jmp.  */
 | 
			
		||||
    ops->tb_stop(db, cpu);
 | 
			
		||||
    gen_tb_end(db->tb, db->num_insns - bp_insn);
 | 
			
		||||
 | 
			
		||||
    /* The disas_log hook may use these values rather than recompute.  */
 | 
			
		||||
    db->tb->size = db->pc_next - db->pc_first;
 | 
			
		||||
    db->tb->icount = db->num_insns;
 | 
			
		||||
 | 
			
		||||
#ifdef DEBUG_DISAS
 | 
			
		||||
    if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)
 | 
			
		||||
        && qemu_log_in_addr_range(db->pc_first)) {
 | 
			
		||||
        qemu_log_lock();
 | 
			
		||||
        qemu_log("----------------\n");
 | 
			
		||||
        ops->disas_log(db, cpu);
 | 
			
		||||
        qemu_log("\n");
 | 
			
		||||
        qemu_log_unlock();
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
@@ -1,36 +0,0 @@
 | 
			
		||||
#include "qemu/osdep.h"
 | 
			
		||||
#include "qom/cpu.h"
 | 
			
		||||
#include "sysemu/replay.h"
 | 
			
		||||
#include "sysemu/sysemu.h"
 | 
			
		||||
 | 
			
		||||
bool enable_cpu_pm = false;
 | 
			
		||||
 | 
			
		||||
void cpu_resume(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void qemu_init_vcpu(CPUState *cpu)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* User mode emulation does not support record/replay yet.  */
 | 
			
		||||
 | 
			
		||||
bool replay_exception(void)
 | 
			
		||||
{
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool replay_has_exception(void)
 | 
			
		||||
{
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool replay_interrupt(void)
 | 
			
		||||
{
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool replay_has_interrupt(void)
 | 
			
		||||
{
 | 
			
		||||
    return false;
 | 
			
		||||
}
 | 
			
		||||
@@ -1,756 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 *  User emulator execution
 | 
			
		||||
 *
 | 
			
		||||
 *  Copyright (c) 2003-2005 Fabrice Bellard
 | 
			
		||||
 *
 | 
			
		||||
 * This library is free software; you can redistribute it and/or
 | 
			
		||||
 * modify it under the terms of the GNU Lesser General Public
 | 
			
		||||
 * License as published by the Free Software Foundation; either
 | 
			
		||||
 * version 2.1 of the License, or (at your option) any later version.
 | 
			
		||||
 *
 | 
			
		||||
 * This library is distributed in the hope that it will be useful,
 | 
			
		||||
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 | 
			
		||||
 * Lesser General Public License for more details.
 | 
			
		||||
 *
 | 
			
		||||
 * You should have received a copy of the GNU Lesser General Public
 | 
			
		||||
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
#include "qemu/osdep.h"
 | 
			
		||||
#include "cpu.h"
 | 
			
		||||
#include "disas/disas.h"
 | 
			
		||||
#include "exec/exec-all.h"
 | 
			
		||||
#include "tcg.h"
 | 
			
		||||
#include "qemu/bitops.h"
 | 
			
		||||
#include "exec/cpu_ldst.h"
 | 
			
		||||
#include "translate-all.h"
 | 
			
		||||
#include "exec/helper-proto.h"
 | 
			
		||||
#include "qemu/atomic128.h"
 | 
			
		||||
 | 
			
		||||
#undef EAX
 | 
			
		||||
#undef ECX
 | 
			
		||||
#undef EDX
 | 
			
		||||
#undef EBX
 | 
			
		||||
#undef ESP
 | 
			
		||||
#undef EBP
 | 
			
		||||
#undef ESI
 | 
			
		||||
#undef EDI
 | 
			
		||||
#undef EIP
 | 
			
		||||
#ifdef __linux__
 | 
			
		||||
#include <sys/ucontext.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
__thread uintptr_t helper_retaddr;
 | 
			
		||||
 | 
			
		||||
//#define DEBUG_SIGNAL
 | 
			
		||||
 | 
			
		||||
/* exit the current TB from a signal handler. The host registers are
 | 
			
		||||
   restored in a state compatible with the CPU emulator
 | 
			
		||||
 */
 | 
			
		||||
static void cpu_exit_tb_from_sighandler(CPUState *cpu, sigset_t *old_set)
 | 
			
		||||
{
 | 
			
		||||
    /* XXX: use siglongjmp ? */
 | 
			
		||||
    sigprocmask(SIG_SETMASK, old_set, NULL);
 | 
			
		||||
    cpu_loop_exit_noexc(cpu);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* 'pc' is the host PC at which the exception was raised. 'address' is
 | 
			
		||||
   the effective address of the memory exception. 'is_write' is 1 if a
 | 
			
		||||
   write caused the exception and otherwise 0'. 'old_set' is the
 | 
			
		||||
   signal set which should be restored */
 | 
			
		||||
static inline int handle_cpu_signal(uintptr_t pc, siginfo_t *info,
 | 
			
		||||
                                    int is_write, sigset_t *old_set)
 | 
			
		||||
{
 | 
			
		||||
    CPUState *cpu = current_cpu;
 | 
			
		||||
    CPUClass *cc;
 | 
			
		||||
    unsigned long address = (unsigned long)info->si_addr;
 | 
			
		||||
    MMUAccessType access_type = is_write ? MMU_DATA_STORE : MMU_DATA_LOAD;
 | 
			
		||||
 | 
			
		||||
    switch (helper_retaddr) {
 | 
			
		||||
    default:
 | 
			
		||||
        /*
 | 
			
		||||
         * Fault during host memory operation within a helper function.
 | 
			
		||||
         * The helper's host return address, saved here, gives us a
 | 
			
		||||
         * pointer into the generated code that will unwind to the
 | 
			
		||||
         * correct guest pc.
 | 
			
		||||
         */
 | 
			
		||||
        pc = helper_retaddr;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case 0:
 | 
			
		||||
        /*
 | 
			
		||||
         * Fault during host memory operation within generated code.
 | 
			
		||||
         * (Or, a unrelated bug within qemu, but we can't tell from here).
 | 
			
		||||
         *
 | 
			
		||||
         * We take the host pc from the signal frame.  However, we cannot
 | 
			
		||||
         * use that value directly.  Within cpu_restore_state_from_tb, we
 | 
			
		||||
         * assume PC comes from GETPC(), as used by the helper functions,
 | 
			
		||||
         * so we adjust the address by -GETPC_ADJ to form an address that
 | 
			
		||||
         * is within the call insn, so that the address does not accidentially
 | 
			
		||||
         * match the beginning of the next guest insn.  However, when the
 | 
			
		||||
         * pc comes from the signal frame it points to the actual faulting
 | 
			
		||||
         * host memory insn and not the return from a call insn.
 | 
			
		||||
         *
 | 
			
		||||
         * Therefore, adjust to compensate for what will be done later
 | 
			
		||||
         * by cpu_restore_state_from_tb.
 | 
			
		||||
         */
 | 
			
		||||
        pc += GETPC_ADJ;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case 1:
 | 
			
		||||
        /*
 | 
			
		||||
         * Fault during host read for translation, or loosely, "execution".
 | 
			
		||||
         *
 | 
			
		||||
         * The guest pc is already pointing to the start of the TB for which
 | 
			
		||||
         * code is being generated.  If the guest translator manages the
 | 
			
		||||
         * page crossings correctly, this is exactly the correct address
 | 
			
		||||
         * (and if the translator doesn't handle page boundaries correctly
 | 
			
		||||
         * there's little we can do about that here).  Therefore, do not
 | 
			
		||||
         * trigger the unwinder.
 | 
			
		||||
         *
 | 
			
		||||
         * Like tb_gen_code, release the memory lock before cpu_loop_exit.
 | 
			
		||||
         */
 | 
			
		||||
        pc = 0;
 | 
			
		||||
        access_type = MMU_INST_FETCH;
 | 
			
		||||
        mmap_unlock();
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* For synchronous signals we expect to be coming from the vCPU
 | 
			
		||||
     * thread (so current_cpu should be valid) and either from running
 | 
			
		||||
     * code or during translation which can fault as we cross pages.
 | 
			
		||||
     *
 | 
			
		||||
     * If neither is true then something has gone wrong and we should
 | 
			
		||||
     * abort rather than try and restart the vCPU execution.
 | 
			
		||||
     */
 | 
			
		||||
    if (!cpu || !cpu->running) {
 | 
			
		||||
        printf("qemu:%s received signal outside vCPU context @ pc=0x%"
 | 
			
		||||
               PRIxPTR "\n",  __func__, pc);
 | 
			
		||||
        abort();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
#if defined(DEBUG_SIGNAL)
 | 
			
		||||
    printf("qemu: SIGSEGV pc=0x%08lx address=%08lx w=%d oldset=0x%08lx\n",
 | 
			
		||||
           pc, address, is_write, *(unsigned long *)old_set);
 | 
			
		||||
#endif
 | 
			
		||||
    /* XXX: locking issue */
 | 
			
		||||
    /* Note that it is important that we don't call page_unprotect() unless
 | 
			
		||||
     * this is really a "write to nonwriteable page" fault, because
 | 
			
		||||
     * page_unprotect() assumes that if it is called for an access to
 | 
			
		||||
     * a page that's writeable this means we had two threads racing and
 | 
			
		||||
     * another thread got there first and already made the page writeable;
 | 
			
		||||
     * so we will retry the access. If we were to call page_unprotect()
 | 
			
		||||
     * for some other kind of fault that should really be passed to the
 | 
			
		||||
     * guest, we'd end up in an infinite loop of retrying the faulting
 | 
			
		||||
     * access.
 | 
			
		||||
     */
 | 
			
		||||
    if (is_write && info->si_signo == SIGSEGV && info->si_code == SEGV_ACCERR &&
 | 
			
		||||
        h2g_valid(address)) {
 | 
			
		||||
        switch (page_unprotect(h2g(address), pc)) {
 | 
			
		||||
        case 0:
 | 
			
		||||
            /* Fault not caused by a page marked unwritable to protect
 | 
			
		||||
             * cached translations, must be the guest binary's problem.
 | 
			
		||||
             */
 | 
			
		||||
            break;
 | 
			
		||||
        case 1:
 | 
			
		||||
            /* Fault caused by protection of cached translation; TBs
 | 
			
		||||
             * invalidated, so resume execution.  Retain helper_retaddr
 | 
			
		||||
             * for a possible second fault.
 | 
			
		||||
             */
 | 
			
		||||
            return 1;
 | 
			
		||||
        case 2:
 | 
			
		||||
            /* Fault caused by protection of cached translation, and the
 | 
			
		||||
             * currently executing TB was modified and must be exited
 | 
			
		||||
             * immediately.  Clear helper_retaddr for next execution.
 | 
			
		||||
             */
 | 
			
		||||
            clear_helper_retaddr();
 | 
			
		||||
            cpu_exit_tb_from_sighandler(cpu, old_set);
 | 
			
		||||
            /* NORETURN */
 | 
			
		||||
 | 
			
		||||
        default:
 | 
			
		||||
            g_assert_not_reached();
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* Convert forcefully to guest address space, invalid addresses
 | 
			
		||||
       are still valid segv ones */
 | 
			
		||||
    address = h2g_nocheck(address);
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
     * There is no way the target can handle this other than raising
 | 
			
		||||
     * an exception.  Undo signal and retaddr state prior to longjmp.
 | 
			
		||||
     */
 | 
			
		||||
    sigprocmask(SIG_SETMASK, old_set, NULL);
 | 
			
		||||
    clear_helper_retaddr();
 | 
			
		||||
 | 
			
		||||
    cc = CPU_GET_CLASS(cpu);
 | 
			
		||||
    cc->tlb_fill(cpu, address, 0, access_type, MMU_USER_IDX, false, pc);
 | 
			
		||||
    g_assert_not_reached();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if defined(__i386__)
 | 
			
		||||
 | 
			
		||||
#if defined(__NetBSD__)
 | 
			
		||||
#include <ucontext.h>
 | 
			
		||||
 | 
			
		||||
#define EIP_sig(context)     ((context)->uc_mcontext.__gregs[_REG_EIP])
 | 
			
		||||
#define TRAP_sig(context)    ((context)->uc_mcontext.__gregs[_REG_TRAPNO])
 | 
			
		||||
#define ERROR_sig(context)   ((context)->uc_mcontext.__gregs[_REG_ERR])
 | 
			
		||||
#define MASK_sig(context)    ((context)->uc_sigmask)
 | 
			
		||||
#elif defined(__FreeBSD__) || defined(__DragonFly__)
 | 
			
		||||
#include <ucontext.h>
 | 
			
		||||
 | 
			
		||||
#define EIP_sig(context)  (*((unsigned long *)&(context)->uc_mcontext.mc_eip))
 | 
			
		||||
#define TRAP_sig(context)    ((context)->uc_mcontext.mc_trapno)
 | 
			
		||||
#define ERROR_sig(context)   ((context)->uc_mcontext.mc_err)
 | 
			
		||||
#define MASK_sig(context)    ((context)->uc_sigmask)
 | 
			
		||||
#elif defined(__OpenBSD__)
 | 
			
		||||
#define EIP_sig(context)     ((context)->sc_eip)
 | 
			
		||||
#define TRAP_sig(context)    ((context)->sc_trapno)
 | 
			
		||||
#define ERROR_sig(context)   ((context)->sc_err)
 | 
			
		||||
#define MASK_sig(context)    ((context)->sc_mask)
 | 
			
		||||
#else
 | 
			
		||||
#define EIP_sig(context)     ((context)->uc_mcontext.gregs[REG_EIP])
 | 
			
		||||
#define TRAP_sig(context)    ((context)->uc_mcontext.gregs[REG_TRAPNO])
 | 
			
		||||
#define ERROR_sig(context)   ((context)->uc_mcontext.gregs[REG_ERR])
 | 
			
		||||
#define MASK_sig(context)    ((context)->uc_sigmask)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
int cpu_signal_handler(int host_signum, void *pinfo,
 | 
			
		||||
                       void *puc)
 | 
			
		||||
{
 | 
			
		||||
    siginfo_t *info = pinfo;
 | 
			
		||||
#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
 | 
			
		||||
    ucontext_t *uc = puc;
 | 
			
		||||
#elif defined(__OpenBSD__)
 | 
			
		||||
    struct sigcontext *uc = puc;
 | 
			
		||||
#else
 | 
			
		||||
    ucontext_t *uc = puc;
 | 
			
		||||
#endif
 | 
			
		||||
    unsigned long pc;
 | 
			
		||||
    int trapno;
 | 
			
		||||
 | 
			
		||||
#ifndef REG_EIP
 | 
			
		||||
/* for glibc 2.1 */
 | 
			
		||||
#define REG_EIP    EIP
 | 
			
		||||
#define REG_ERR    ERR
 | 
			
		||||
#define REG_TRAPNO TRAPNO
 | 
			
		||||
#endif
 | 
			
		||||
    pc = EIP_sig(uc);
 | 
			
		||||
    trapno = TRAP_sig(uc);
 | 
			
		||||
    return handle_cpu_signal(pc, info,
 | 
			
		||||
                             trapno == 0xe ? (ERROR_sig(uc) >> 1) & 1 : 0,
 | 
			
		||||
                             &MASK_sig(uc));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#elif defined(__x86_64__)
 | 
			
		||||
 | 
			
		||||
#ifdef __NetBSD__
 | 
			
		||||
#define PC_sig(context)       _UC_MACHINE_PC(context)
 | 
			
		||||
#define TRAP_sig(context)     ((context)->uc_mcontext.__gregs[_REG_TRAPNO])
 | 
			
		||||
#define ERROR_sig(context)    ((context)->uc_mcontext.__gregs[_REG_ERR])
 | 
			
		||||
#define MASK_sig(context)     ((context)->uc_sigmask)
 | 
			
		||||
#elif defined(__OpenBSD__)
 | 
			
		||||
#define PC_sig(context)       ((context)->sc_rip)
 | 
			
		||||
#define TRAP_sig(context)     ((context)->sc_trapno)
 | 
			
		||||
#define ERROR_sig(context)    ((context)->sc_err)
 | 
			
		||||
#define MASK_sig(context)     ((context)->sc_mask)
 | 
			
		||||
#elif defined(__FreeBSD__) || defined(__DragonFly__)
 | 
			
		||||
#include <ucontext.h>
 | 
			
		||||
 | 
			
		||||
#define PC_sig(context)  (*((unsigned long *)&(context)->uc_mcontext.mc_rip))
 | 
			
		||||
#define TRAP_sig(context)     ((context)->uc_mcontext.mc_trapno)
 | 
			
		||||
#define ERROR_sig(context)    ((context)->uc_mcontext.mc_err)
 | 
			
		||||
#define MASK_sig(context)     ((context)->uc_sigmask)
 | 
			
		||||
#else
 | 
			
		||||
#define PC_sig(context)       ((context)->uc_mcontext.gregs[REG_RIP])
 | 
			
		||||
#define TRAP_sig(context)     ((context)->uc_mcontext.gregs[REG_TRAPNO])
 | 
			
		||||
#define ERROR_sig(context)    ((context)->uc_mcontext.gregs[REG_ERR])
 | 
			
		||||
#define MASK_sig(context)     ((context)->uc_sigmask)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
int cpu_signal_handler(int host_signum, void *pinfo,
 | 
			
		||||
                       void *puc)
 | 
			
		||||
{
 | 
			
		||||
    siginfo_t *info = pinfo;
 | 
			
		||||
    unsigned long pc;
 | 
			
		||||
#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
 | 
			
		||||
    ucontext_t *uc = puc;
 | 
			
		||||
#elif defined(__OpenBSD__)
 | 
			
		||||
    struct sigcontext *uc = puc;
 | 
			
		||||
#else
 | 
			
		||||
    ucontext_t *uc = puc;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    pc = PC_sig(uc);
 | 
			
		||||
    return handle_cpu_signal(pc, info,
 | 
			
		||||
                             TRAP_sig(uc) == 0xe ? (ERROR_sig(uc) >> 1) & 1 : 0,
 | 
			
		||||
                             &MASK_sig(uc));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#elif defined(_ARCH_PPC)
 | 
			
		||||
 | 
			
		||||
/***********************************************************************
 | 
			
		||||
 * signal context platform-specific definitions
 | 
			
		||||
 * From Wine
 | 
			
		||||
 */
 | 
			
		||||
#ifdef linux
 | 
			
		||||
/* All Registers access - only for local access */
 | 
			
		||||
#define REG_sig(reg_name, context)              \
 | 
			
		||||
    ((context)->uc_mcontext.regs->reg_name)
 | 
			
		||||
/* Gpr Registers access  */
 | 
			
		||||
#define GPR_sig(reg_num, context)              REG_sig(gpr[reg_num], context)
 | 
			
		||||
/* Program counter */
 | 
			
		||||
#define IAR_sig(context)                       REG_sig(nip, context)
 | 
			
		||||
/* Machine State Register (Supervisor) */
 | 
			
		||||
#define MSR_sig(context)                       REG_sig(msr, context)
 | 
			
		||||
/* Count register */
 | 
			
		||||
#define CTR_sig(context)                       REG_sig(ctr, context)
 | 
			
		||||
/* User's integer exception register */
 | 
			
		||||
#define XER_sig(context)                       REG_sig(xer, context)
 | 
			
		||||
/* Link register */
 | 
			
		||||
#define LR_sig(context)                        REG_sig(link, context)
 | 
			
		||||
/* Condition register */
 | 
			
		||||
#define CR_sig(context)                        REG_sig(ccr, context)
 | 
			
		||||
 | 
			
		||||
/* Float Registers access  */
 | 
			
		||||
#define FLOAT_sig(reg_num, context)                                     \
 | 
			
		||||
    (((double *)((char *)((context)->uc_mcontext.regs + 48 * 4)))[reg_num])
 | 
			
		||||
#define FPSCR_sig(context) \
 | 
			
		||||
    (*(int *)((char *)((context)->uc_mcontext.regs + (48 + 32 * 2) * 4)))
 | 
			
		||||
/* Exception Registers access */
 | 
			
		||||
#define DAR_sig(context)                       REG_sig(dar, context)
 | 
			
		||||
#define DSISR_sig(context)                     REG_sig(dsisr, context)
 | 
			
		||||
#define TRAP_sig(context)                      REG_sig(trap, context)
 | 
			
		||||
#endif /* linux */
 | 
			
		||||
 | 
			
		||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
 | 
			
		||||
#include <ucontext.h>
 | 
			
		||||
#define IAR_sig(context)               ((context)->uc_mcontext.mc_srr0)
 | 
			
		||||
#define MSR_sig(context)               ((context)->uc_mcontext.mc_srr1)
 | 
			
		||||
#define CTR_sig(context)               ((context)->uc_mcontext.mc_ctr)
 | 
			
		||||
#define XER_sig(context)               ((context)->uc_mcontext.mc_xer)
 | 
			
		||||
#define LR_sig(context)                ((context)->uc_mcontext.mc_lr)
 | 
			
		||||
#define CR_sig(context)                ((context)->uc_mcontext.mc_cr)
 | 
			
		||||
/* Exception Registers access */
 | 
			
		||||
#define DAR_sig(context)               ((context)->uc_mcontext.mc_dar)
 | 
			
		||||
#define DSISR_sig(context)             ((context)->uc_mcontext.mc_dsisr)
 | 
			
		||||
#define TRAP_sig(context)              ((context)->uc_mcontext.mc_exc)
 | 
			
		||||
#endif /* __FreeBSD__|| __FreeBSD_kernel__ */
 | 
			
		||||
 | 
			
		||||
int cpu_signal_handler(int host_signum, void *pinfo,
 | 
			
		||||
                       void *puc)
 | 
			
		||||
{
 | 
			
		||||
    siginfo_t *info = pinfo;
 | 
			
		||||
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
 | 
			
		||||
    ucontext_t *uc = puc;
 | 
			
		||||
#else
 | 
			
		||||
    ucontext_t *uc = puc;
 | 
			
		||||
#endif
 | 
			
		||||
    unsigned long pc;
 | 
			
		||||
    int is_write;
 | 
			
		||||
 | 
			
		||||
    pc = IAR_sig(uc);
 | 
			
		||||
    is_write = 0;
 | 
			
		||||
#if 0
 | 
			
		||||
    /* ppc 4xx case */
 | 
			
		||||
    if (DSISR_sig(uc) & 0x00800000) {
 | 
			
		||||
        is_write = 1;
 | 
			
		||||
    }
 | 
			
		||||
#else
 | 
			
		||||
    if (TRAP_sig(uc) != 0x400 && (DSISR_sig(uc) & 0x02000000)) {
 | 
			
		||||
        is_write = 1;
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
    return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#elif defined(__alpha__)
 | 
			
		||||
 | 
			
		||||
int cpu_signal_handler(int host_signum, void *pinfo,
 | 
			
		||||
                           void *puc)
 | 
			
		||||
{
 | 
			
		||||
    siginfo_t *info = pinfo;
 | 
			
		||||
    ucontext_t *uc = puc;
 | 
			
		||||
    uint32_t *pc = uc->uc_mcontext.sc_pc;
 | 
			
		||||
    uint32_t insn = *pc;
 | 
			
		||||
    int is_write = 0;
 | 
			
		||||
 | 
			
		||||
    /* XXX: need kernel patch to get write flag faster */
 | 
			
		||||
    switch (insn >> 26) {
 | 
			
		||||
    case 0x0d: /* stw */
 | 
			
		||||
    case 0x0e: /* stb */
 | 
			
		||||
    case 0x0f: /* stq_u */
 | 
			
		||||
    case 0x24: /* stf */
 | 
			
		||||
    case 0x25: /* stg */
 | 
			
		||||
    case 0x26: /* sts */
 | 
			
		||||
    case 0x27: /* stt */
 | 
			
		||||
    case 0x2c: /* stl */
 | 
			
		||||
    case 0x2d: /* stq */
 | 
			
		||||
    case 0x2e: /* stl_c */
 | 
			
		||||
    case 0x2f: /* stq_c */
 | 
			
		||||
        is_write = 1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask);
 | 
			
		||||
}
 | 
			
		||||
#elif defined(__sparc__)
 | 
			
		||||
 | 
			
		||||
int cpu_signal_handler(int host_signum, void *pinfo,
 | 
			
		||||
                       void *puc)
 | 
			
		||||
{
 | 
			
		||||
    siginfo_t *info = pinfo;
 | 
			
		||||
    int is_write;
 | 
			
		||||
    uint32_t insn;
 | 
			
		||||
#if !defined(__arch64__) || defined(CONFIG_SOLARIS)
 | 
			
		||||
    uint32_t *regs = (uint32_t *)(info + 1);
 | 
			
		||||
    void *sigmask = (regs + 20);
 | 
			
		||||
    /* XXX: is there a standard glibc define ? */
 | 
			
		||||
    unsigned long pc = regs[1];
 | 
			
		||||
#else
 | 
			
		||||
#ifdef __linux__
 | 
			
		||||
    struct sigcontext *sc = puc;
 | 
			
		||||
    unsigned long pc = sc->sigc_regs.tpc;
 | 
			
		||||
    void *sigmask = (void *)sc->sigc_mask;
 | 
			
		||||
#elif defined(__OpenBSD__)
 | 
			
		||||
    struct sigcontext *uc = puc;
 | 
			
		||||
    unsigned long pc = uc->sc_pc;
 | 
			
		||||
    void *sigmask = (void *)(long)uc->sc_mask;
 | 
			
		||||
#elif defined(__NetBSD__)
 | 
			
		||||
    ucontext_t *uc = puc;
 | 
			
		||||
    unsigned long pc = _UC_MACHINE_PC(uc);
 | 
			
		||||
    void *sigmask = (void *)&uc->uc_sigmask;
 | 
			
		||||
#endif
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    /* XXX: need kernel patch to get write flag faster */
 | 
			
		||||
    is_write = 0;
 | 
			
		||||
    insn = *(uint32_t *)pc;
 | 
			
		||||
    if ((insn >> 30) == 3) {
 | 
			
		||||
        switch ((insn >> 19) & 0x3f) {
 | 
			
		||||
        case 0x05: /* stb */
 | 
			
		||||
        case 0x15: /* stba */
 | 
			
		||||
        case 0x06: /* sth */
 | 
			
		||||
        case 0x16: /* stha */
 | 
			
		||||
        case 0x04: /* st */
 | 
			
		||||
        case 0x14: /* sta */
 | 
			
		||||
        case 0x07: /* std */
 | 
			
		||||
        case 0x17: /* stda */
 | 
			
		||||
        case 0x0e: /* stx */
 | 
			
		||||
        case 0x1e: /* stxa */
 | 
			
		||||
        case 0x24: /* stf */
 | 
			
		||||
        case 0x34: /* stfa */
 | 
			
		||||
        case 0x27: /* stdf */
 | 
			
		||||
        case 0x37: /* stdfa */
 | 
			
		||||
        case 0x26: /* stqf */
 | 
			
		||||
        case 0x36: /* stqfa */
 | 
			
		||||
        case 0x25: /* stfsr */
 | 
			
		||||
        case 0x3c: /* casa */
 | 
			
		||||
        case 0x3e: /* casxa */
 | 
			
		||||
            is_write = 1;
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return handle_cpu_signal(pc, info, is_write, sigmask);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#elif defined(__arm__)
 | 
			
		||||
 | 
			
		||||
#if defined(__NetBSD__)
 | 
			
		||||
#include <ucontext.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
int cpu_signal_handler(int host_signum, void *pinfo,
 | 
			
		||||
                       void *puc)
 | 
			
		||||
{
 | 
			
		||||
    siginfo_t *info = pinfo;
 | 
			
		||||
#if defined(__NetBSD__)
 | 
			
		||||
    ucontext_t *uc = puc;
 | 
			
		||||
#else
 | 
			
		||||
    ucontext_t *uc = puc;
 | 
			
		||||
#endif
 | 
			
		||||
    unsigned long pc;
 | 
			
		||||
    int is_write;
 | 
			
		||||
 | 
			
		||||
#if defined(__NetBSD__)
 | 
			
		||||
    pc = uc->uc_mcontext.__gregs[_REG_R15];
 | 
			
		||||
#elif defined(__GLIBC__) && (__GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ <= 3))
 | 
			
		||||
    pc = uc->uc_mcontext.gregs[R15];
 | 
			
		||||
#else
 | 
			
		||||
    pc = uc->uc_mcontext.arm_pc;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    /* error_code is the FSR value, in which bit 11 is WnR (assuming a v6 or
 | 
			
		||||
     * later processor; on v5 we will always report this as a read).
 | 
			
		||||
     */
 | 
			
		||||
    is_write = extract32(uc->uc_mcontext.error_code, 11, 1);
 | 
			
		||||
    return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#elif defined(__aarch64__)
 | 
			
		||||
 | 
			
		||||
#ifndef ESR_MAGIC
 | 
			
		||||
/* Pre-3.16 kernel headers don't have these, so provide fallback definitions */
 | 
			
		||||
#define ESR_MAGIC 0x45535201
 | 
			
		||||
struct esr_context {
 | 
			
		||||
    struct _aarch64_ctx head;
 | 
			
		||||
    uint64_t esr;
 | 
			
		||||
};
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
static inline struct _aarch64_ctx *first_ctx(ucontext_t *uc)
 | 
			
		||||
{
 | 
			
		||||
    return (struct _aarch64_ctx *)&uc->uc_mcontext.__reserved;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline struct _aarch64_ctx *next_ctx(struct _aarch64_ctx *hdr)
 | 
			
		||||
{
 | 
			
		||||
    return (struct _aarch64_ctx *)((char *)hdr + hdr->size);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int cpu_signal_handler(int host_signum, void *pinfo, void *puc)
 | 
			
		||||
{
 | 
			
		||||
    siginfo_t *info = pinfo;
 | 
			
		||||
    ucontext_t *uc = puc;
 | 
			
		||||
    uintptr_t pc = uc->uc_mcontext.pc;
 | 
			
		||||
    bool is_write;
 | 
			
		||||
    struct _aarch64_ctx *hdr;
 | 
			
		||||
    struct esr_context const *esrctx = NULL;
 | 
			
		||||
 | 
			
		||||
    /* Find the esr_context, which has the WnR bit in it */
 | 
			
		||||
    for (hdr = first_ctx(uc); hdr->magic; hdr = next_ctx(hdr)) {
 | 
			
		||||
        if (hdr->magic == ESR_MAGIC) {
 | 
			
		||||
            esrctx = (struct esr_context const *)hdr;
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (esrctx) {
 | 
			
		||||
        /* For data aborts ESR.EC is 0b10010x: then bit 6 is the WnR bit */
 | 
			
		||||
        uint64_t esr = esrctx->esr;
 | 
			
		||||
        is_write = extract32(esr, 27, 5) == 0x12 && extract32(esr, 6, 1) == 1;
 | 
			
		||||
    } else {
 | 
			
		||||
        /*
 | 
			
		||||
         * Fall back to parsing instructions; will only be needed
 | 
			
		||||
         * for really ancient (pre-3.16) kernels.
 | 
			
		||||
         */
 | 
			
		||||
        uint32_t insn = *(uint32_t *)pc;
 | 
			
		||||
 | 
			
		||||
        is_write = ((insn & 0xbfff0000) == 0x0c000000   /* C3.3.1 */
 | 
			
		||||
                    || (insn & 0xbfe00000) == 0x0c800000   /* C3.3.2 */
 | 
			
		||||
                    || (insn & 0xbfdf0000) == 0x0d000000   /* C3.3.3 */
 | 
			
		||||
                    || (insn & 0xbfc00000) == 0x0d800000   /* C3.3.4 */
 | 
			
		||||
                    || (insn & 0x3f400000) == 0x08000000   /* C3.3.6 */
 | 
			
		||||
                    || (insn & 0x3bc00000) == 0x39000000   /* C3.3.13 */
 | 
			
		||||
                    || (insn & 0x3fc00000) == 0x3d800000   /* ... 128bit */
 | 
			
		||||
                    /* Ignore bits 10, 11 & 21, controlling indexing.  */
 | 
			
		||||
                    || (insn & 0x3bc00000) == 0x38000000   /* C3.3.8-12 */
 | 
			
		||||
                    || (insn & 0x3fe00000) == 0x3c800000   /* ... 128bit */
 | 
			
		||||
                    /* Ignore bits 23 & 24, controlling indexing.  */
 | 
			
		||||
                    || (insn & 0x3a400000) == 0x28000000); /* C3.3.7,14-16 */
 | 
			
		||||
    }
 | 
			
		||||
    return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#elif defined(__s390__)
 | 
			
		||||
 | 
			
		||||
int cpu_signal_handler(int host_signum, void *pinfo,
 | 
			
		||||
                       void *puc)
 | 
			
		||||
{
 | 
			
		||||
    siginfo_t *info = pinfo;
 | 
			
		||||
    ucontext_t *uc = puc;
 | 
			
		||||
    unsigned long pc;
 | 
			
		||||
    uint16_t *pinsn;
 | 
			
		||||
    int is_write = 0;
 | 
			
		||||
 | 
			
		||||
    pc = uc->uc_mcontext.psw.addr;
 | 
			
		||||
 | 
			
		||||
    /* ??? On linux, the non-rt signal handler has 4 (!) arguments instead
 | 
			
		||||
       of the normal 2 arguments.  The 3rd argument contains the "int_code"
 | 
			
		||||
       from the hardware which does in fact contain the is_write value.
 | 
			
		||||
       The rt signal handler, as far as I can tell, does not give this value
 | 
			
		||||
       at all.  Not that we could get to it from here even if it were.  */
 | 
			
		||||
    /* ??? This is not even close to complete, since it ignores all
 | 
			
		||||
       of the read-modify-write instructions.  */
 | 
			
		||||
    pinsn = (uint16_t *)pc;
 | 
			
		||||
    switch (pinsn[0] >> 8) {
 | 
			
		||||
    case 0x50: /* ST */
 | 
			
		||||
    case 0x42: /* STC */
 | 
			
		||||
    case 0x40: /* STH */
 | 
			
		||||
        is_write = 1;
 | 
			
		||||
        break;
 | 
			
		||||
    case 0xc4: /* RIL format insns */
 | 
			
		||||
        switch (pinsn[0] & 0xf) {
 | 
			
		||||
        case 0xf: /* STRL */
 | 
			
		||||
        case 0xb: /* STGRL */
 | 
			
		||||
        case 0x7: /* STHRL */
 | 
			
		||||
            is_write = 1;
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    case 0xe3: /* RXY format insns */
 | 
			
		||||
        switch (pinsn[2] & 0xff) {
 | 
			
		||||
        case 0x50: /* STY */
 | 
			
		||||
        case 0x24: /* STG */
 | 
			
		||||
        case 0x72: /* STCY */
 | 
			
		||||
        case 0x70: /* STHY */
 | 
			
		||||
        case 0x8e: /* STPQ */
 | 
			
		||||
        case 0x3f: /* STRVH */
 | 
			
		||||
        case 0x3e: /* STRV */
 | 
			
		||||
        case 0x2f: /* STRVG */
 | 
			
		||||
            is_write = 1;
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#elif defined(__mips__)
 | 
			
		||||
 | 
			
		||||
int cpu_signal_handler(int host_signum, void *pinfo,
 | 
			
		||||
                       void *puc)
 | 
			
		||||
{
 | 
			
		||||
    siginfo_t *info = pinfo;
 | 
			
		||||
    ucontext_t *uc = puc;
 | 
			
		||||
    greg_t pc = uc->uc_mcontext.pc;
 | 
			
		||||
    int is_write;
 | 
			
		||||
 | 
			
		||||
    /* XXX: compute is_write */
 | 
			
		||||
    is_write = 0;
 | 
			
		||||
    return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#elif defined(__riscv)
 | 
			
		||||
 | 
			
		||||
int cpu_signal_handler(int host_signum, void *pinfo,
 | 
			
		||||
                       void *puc)
 | 
			
		||||
{
 | 
			
		||||
    siginfo_t *info = pinfo;
 | 
			
		||||
    ucontext_t *uc = puc;
 | 
			
		||||
    greg_t pc = uc->uc_mcontext.__gregs[REG_PC];
 | 
			
		||||
    uint32_t insn = *(uint32_t *)pc;
 | 
			
		||||
    int is_write = 0;
 | 
			
		||||
 | 
			
		||||
    /* Detect store by reading the instruction at the program
 | 
			
		||||
       counter. Note: we currently only generate 32-bit
 | 
			
		||||
       instructions so we thus only detect 32-bit stores */
 | 
			
		||||
    switch (((insn >> 0) & 0b11)) {
 | 
			
		||||
    case 3:
 | 
			
		||||
        switch (((insn >> 2) & 0b11111)) {
 | 
			
		||||
        case 8:
 | 
			
		||||
            switch (((insn >> 12) & 0b111)) {
 | 
			
		||||
            case 0: /* sb */
 | 
			
		||||
            case 1: /* sh */
 | 
			
		||||
            case 2: /* sw */
 | 
			
		||||
            case 3: /* sd */
 | 
			
		||||
            case 4: /* sq */
 | 
			
		||||
                is_write = 1;
 | 
			
		||||
                break;
 | 
			
		||||
            default:
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
            break;
 | 
			
		||||
        case 9:
 | 
			
		||||
            switch (((insn >> 12) & 0b111)) {
 | 
			
		||||
            case 2: /* fsw */
 | 
			
		||||
            case 3: /* fsd */
 | 
			
		||||
            case 4: /* fsq */
 | 
			
		||||
                is_write = 1;
 | 
			
		||||
                break;
 | 
			
		||||
            default:
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
            break;
 | 
			
		||||
        default:
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* Check for compressed instructions */
 | 
			
		||||
    switch (((insn >> 13) & 0b111)) {
 | 
			
		||||
    case 7:
 | 
			
		||||
        switch (insn & 0b11) {
 | 
			
		||||
        case 0: /*c.sd */
 | 
			
		||||
        case 2: /* c.sdsp */
 | 
			
		||||
            is_write = 1;
 | 
			
		||||
            break;
 | 
			
		||||
        default:
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    case 6:
 | 
			
		||||
        switch (insn & 0b11) {
 | 
			
		||||
        case 0: /* c.sw */
 | 
			
		||||
        case 3: /* c.swsp */
 | 
			
		||||
            is_write = 1;
 | 
			
		||||
            break;
 | 
			
		||||
        default:
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    default:
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return handle_cpu_signal(pc, info, is_write, &uc->uc_sigmask);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#else
 | 
			
		||||
 | 
			
		||||
#error host CPU specific signal handler needed
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/* The softmmu versions of these helpers are in cputlb.c.  */
 | 
			
		||||
 | 
			
		||||
/* Do not allow unaligned operations to proceed.  Return the host address.  */
 | 
			
		||||
static void *atomic_mmu_lookup(CPUArchState *env, target_ulong addr,
 | 
			
		||||
                               int size, uintptr_t retaddr)
 | 
			
		||||
{
 | 
			
		||||
    /* Enforce qemu required alignment.  */
 | 
			
		||||
    if (unlikely(addr & (size - 1))) {
 | 
			
		||||
        cpu_loop_exit_atomic(env_cpu(env), retaddr);
 | 
			
		||||
    }
 | 
			
		||||
    void *ret = g2h(addr);
 | 
			
		||||
    set_helper_retaddr(retaddr);
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Macro to call the above, with local variables from the use context.  */
 | 
			
		||||
#define ATOMIC_MMU_DECLS do {} while (0)
 | 
			
		||||
#define ATOMIC_MMU_LOOKUP  atomic_mmu_lookup(env, addr, DATA_SIZE, GETPC())
 | 
			
		||||
#define ATOMIC_MMU_CLEANUP do { clear_helper_retaddr(); } while (0)
 | 
			
		||||
 | 
			
		||||
#define ATOMIC_NAME(X)   HELPER(glue(glue(atomic_ ## X, SUFFIX), END))
 | 
			
		||||
#define EXTRA_ARGS
 | 
			
		||||
 | 
			
		||||
#define DATA_SIZE 1
 | 
			
		||||
#include "atomic_template.h"
 | 
			
		||||
 | 
			
		||||
#define DATA_SIZE 2
 | 
			
		||||
#include "atomic_template.h"
 | 
			
		||||
 | 
			
		||||
#define DATA_SIZE 4
 | 
			
		||||
#include "atomic_template.h"
 | 
			
		||||
 | 
			
		||||
#ifdef CONFIG_ATOMIC64
 | 
			
		||||
#define DATA_SIZE 8
 | 
			
		||||
#include "atomic_template.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
/* The following is only callable from other helpers, and matches up
 | 
			
		||||
   with the softmmu version.  */
 | 
			
		||||
 | 
			
		||||
#if HAVE_ATOMIC128 || HAVE_CMPXCHG128
 | 
			
		||||
 | 
			
		||||
#undef EXTRA_ARGS
 | 
			
		||||
#undef ATOMIC_NAME
 | 
			
		||||
#undef ATOMIC_MMU_LOOKUP
 | 
			
		||||
 | 
			
		||||
#define EXTRA_ARGS     , TCGMemOpIdx oi, uintptr_t retaddr
 | 
			
		||||
#define ATOMIC_NAME(X) \
 | 
			
		||||
    HELPER(glue(glue(glue(atomic_ ## X, SUFFIX), END), _mmu))
 | 
			
		||||
#define ATOMIC_MMU_LOOKUP  atomic_mmu_lookup(env, addr, DATA_SIZE, retaddr)
 | 
			
		||||
 | 
			
		||||
#define DATA_SIZE 16
 | 
			
		||||
#include "atomic_template.h"
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										184
									
								
								acl.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										184
									
								
								acl.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,184 @@
 | 
			
		||||
/*
 | 
			
		||||
 * QEMU access control list management
 | 
			
		||||
 *
 | 
			
		||||
 * Copyright (C) 2009 Red Hat, Inc
 | 
			
		||||
 *
 | 
			
		||||
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
			
		||||
 * of this software and associated documentation files (the "Software"), to deal
 | 
			
		||||
 * in the Software without restriction, including without limitation the rights
 | 
			
		||||
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
			
		||||
 * copies of the Software, and to permit persons to whom the Software is
 | 
			
		||||
 * furnished to do so, subject to the following conditions:
 | 
			
		||||
 *
 | 
			
		||||
 * The above copyright notice and this permission notice shall be included in
 | 
			
		||||
 * all copies or substantial portions of the Software.
 | 
			
		||||
 *
 | 
			
		||||
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 | 
			
		||||
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
			
		||||
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
			
		||||
 * THE SOFTWARE.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "qemu-common.h"
 | 
			
		||||
#include "acl.h"
 | 
			
		||||
 | 
			
		||||
#ifdef CONFIG_FNMATCH
 | 
			
		||||
#include <fnmatch.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static unsigned int nacls = 0;
 | 
			
		||||
static qemu_acl **acls = NULL;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
qemu_acl *qemu_acl_find(const char *aclname)
 | 
			
		||||
{
 | 
			
		||||
    int i;
 | 
			
		||||
    for (i = 0 ; i < nacls ; i++) {
 | 
			
		||||
        if (strcmp(acls[i]->aclname, aclname) == 0)
 | 
			
		||||
            return acls[i];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
qemu_acl *qemu_acl_init(const char *aclname)
 | 
			
		||||
{
 | 
			
		||||
    qemu_acl *acl;
 | 
			
		||||
 | 
			
		||||
    acl = qemu_acl_find(aclname);
 | 
			
		||||
    if (acl)
 | 
			
		||||
        return acl;
 | 
			
		||||
 | 
			
		||||
    acl = qemu_malloc(sizeof(*acl));
 | 
			
		||||
    acl->aclname = qemu_strdup(aclname);
 | 
			
		||||
    /* Deny by default, so there is no window of "open
 | 
			
		||||
     * access" between QEMU starting, and the user setting
 | 
			
		||||
     * up ACLs in the monitor */
 | 
			
		||||
    acl->defaultDeny = 1;
 | 
			
		||||
 | 
			
		||||
    acl->nentries = 0;
 | 
			
		||||
    QTAILQ_INIT(&acl->entries);
 | 
			
		||||
 | 
			
		||||
    acls = qemu_realloc(acls, sizeof(*acls) * (nacls +1));
 | 
			
		||||
    acls[nacls] = acl;
 | 
			
		||||
    nacls++;
 | 
			
		||||
 | 
			
		||||
    return acl;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int qemu_acl_party_is_allowed(qemu_acl *acl,
 | 
			
		||||
                              const char *party)
 | 
			
		||||
{
 | 
			
		||||
    qemu_acl_entry *entry;
 | 
			
		||||
 | 
			
		||||
    QTAILQ_FOREACH(entry, &acl->entries, next) {
 | 
			
		||||
#ifdef CONFIG_FNMATCH
 | 
			
		||||
        if (fnmatch(entry->match, party, 0) == 0)
 | 
			
		||||
            return entry->deny ? 0 : 1;
 | 
			
		||||
#else
 | 
			
		||||
        /* No fnmatch, so fallback to exact string matching
 | 
			
		||||
         * instead of allowing wildcards */
 | 
			
		||||
        if (strcmp(entry->match, party) == 0)
 | 
			
		||||
            return entry->deny ? 0 : 1;
 | 
			
		||||
#endif
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return acl->defaultDeny ? 0 : 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void qemu_acl_reset(qemu_acl *acl)
 | 
			
		||||
{
 | 
			
		||||
    qemu_acl_entry *entry;
 | 
			
		||||
 | 
			
		||||
    /* Put back to deny by default, so there is no window
 | 
			
		||||
     * of "open access" while the user re-initializes the
 | 
			
		||||
     * access control list */
 | 
			
		||||
    acl->defaultDeny = 1;
 | 
			
		||||
    QTAILQ_FOREACH(entry, &acl->entries, next) {
 | 
			
		||||
        QTAILQ_REMOVE(&acl->entries, entry, next);
 | 
			
		||||
        free(entry->match);
 | 
			
		||||
        free(entry);
 | 
			
		||||
    }
 | 
			
		||||
    acl->nentries = 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int qemu_acl_append(qemu_acl *acl,
 | 
			
		||||
                    int deny,
 | 
			
		||||
                    const char *match)
 | 
			
		||||
{
 | 
			
		||||
    qemu_acl_entry *entry;
 | 
			
		||||
 | 
			
		||||
    entry = qemu_malloc(sizeof(*entry));
 | 
			
		||||
    entry->match = qemu_strdup(match);
 | 
			
		||||
    entry->deny = deny;
 | 
			
		||||
 | 
			
		||||
    QTAILQ_INSERT_TAIL(&acl->entries, entry, next);
 | 
			
		||||
    acl->nentries++;
 | 
			
		||||
 | 
			
		||||
    return acl->nentries;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
int qemu_acl_insert(qemu_acl *acl,
 | 
			
		||||
                    int deny,
 | 
			
		||||
                    const char *match,
 | 
			
		||||
                    int index)
 | 
			
		||||
{
 | 
			
		||||
    qemu_acl_entry *entry;
 | 
			
		||||
    qemu_acl_entry *tmp;
 | 
			
		||||
    int i = 0;
 | 
			
		||||
 | 
			
		||||
    if (index <= 0)
 | 
			
		||||
        return -1;
 | 
			
		||||
    if (index >= acl->nentries)
 | 
			
		||||
        return qemu_acl_append(acl, deny, match);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    entry = qemu_malloc(sizeof(*entry));
 | 
			
		||||
    entry->match = qemu_strdup(match);
 | 
			
		||||
    entry->deny = deny;
 | 
			
		||||
 | 
			
		||||
    QTAILQ_FOREACH(tmp, &acl->entries, next) {
 | 
			
		||||
        i++;
 | 
			
		||||
        if (i == index) {
 | 
			
		||||
            QTAILQ_INSERT_BEFORE(tmp, entry, next);
 | 
			
		||||
            acl->nentries++;
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return i;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int qemu_acl_remove(qemu_acl *acl,
 | 
			
		||||
                    const char *match)
 | 
			
		||||
{
 | 
			
		||||
    qemu_acl_entry *entry;
 | 
			
		||||
    int i = 0;
 | 
			
		||||
 | 
			
		||||
    QTAILQ_FOREACH(entry, &acl->entries, next) {
 | 
			
		||||
        i++;
 | 
			
		||||
        if (strcmp(entry->match, match) == 0) {
 | 
			
		||||
            QTAILQ_REMOVE(&acl->entries, entry, next);
 | 
			
		||||
            return i;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Local variables:
 | 
			
		||||
 *  c-indent-level: 4
 | 
			
		||||
 *  c-basic-offset: 4
 | 
			
		||||
 *  tab-width: 8
 | 
			
		||||
 * End:
 | 
			
		||||
 */
 | 
			
		||||
							
								
								
									
										74
									
								
								acl.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								acl.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,74 @@
 | 
			
		||||
/*
 | 
			
		||||
 * QEMU access control list management
 | 
			
		||||
 *
 | 
			
		||||
 * Copyright (C) 2009 Red Hat, Inc
 | 
			
		||||
 *
 | 
			
		||||
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
			
		||||
 * of this software and associated documentation files (the "Software"), to deal
 | 
			
		||||
 * in the Software without restriction, including without limitation the rights
 | 
			
		||||
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
			
		||||
 * copies of the Software, and to permit persons to whom the Software is
 | 
			
		||||
 * furnished to do so, subject to the following conditions:
 | 
			
		||||
 *
 | 
			
		||||
 * The above copyright notice and this permission notice shall be included in
 | 
			
		||||
 * all copies or substantial portions of the Software.
 | 
			
		||||
 *
 | 
			
		||||
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 | 
			
		||||
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
			
		||||
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
			
		||||
 * THE SOFTWARE.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef __QEMU_ACL_H__
 | 
			
		||||
#define __QEMU_ACL_H__
 | 
			
		||||
 | 
			
		||||
#include "qemu-queue.h"
 | 
			
		||||
 | 
			
		||||
typedef struct qemu_acl_entry qemu_acl_entry;
 | 
			
		||||
typedef struct qemu_acl qemu_acl;
 | 
			
		||||
 | 
			
		||||
struct qemu_acl_entry {
 | 
			
		||||
    char *match;
 | 
			
		||||
    int deny;
 | 
			
		||||
 | 
			
		||||
    QTAILQ_ENTRY(qemu_acl_entry) next;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct qemu_acl {
 | 
			
		||||
    char *aclname;
 | 
			
		||||
    unsigned int nentries;
 | 
			
		||||
    QTAILQ_HEAD(,qemu_acl_entry) entries;
 | 
			
		||||
    int defaultDeny;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
qemu_acl *qemu_acl_init(const char *aclname);
 | 
			
		||||
 | 
			
		||||
qemu_acl *qemu_acl_find(const char *aclname);
 | 
			
		||||
 | 
			
		||||
int qemu_acl_party_is_allowed(qemu_acl *acl,
 | 
			
		||||
			      const char *party);
 | 
			
		||||
 | 
			
		||||
void qemu_acl_reset(qemu_acl *acl);
 | 
			
		||||
 | 
			
		||||
int qemu_acl_append(qemu_acl *acl,
 | 
			
		||||
		    int deny,
 | 
			
		||||
		    const char *match);
 | 
			
		||||
int qemu_acl_insert(qemu_acl *acl,
 | 
			
		||||
		    int deny,
 | 
			
		||||
		    const char *match,
 | 
			
		||||
		    int index);
 | 
			
		||||
int qemu_acl_remove(qemu_acl *acl,
 | 
			
		||||
		    const char *match);
 | 
			
		||||
 | 
			
		||||
#endif /* __QEMU_ACL_H__ */
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Local variables:
 | 
			
		||||
 *  c-indent-level: 4
 | 
			
		||||
 *  c-basic-offset: 4
 | 
			
		||||
 *  tab-width: 8
 | 
			
		||||
 * End:
 | 
			
		||||
 */
 | 
			
		||||
							
								
								
									
										26
									
								
								aes.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								aes.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,26 @@
 | 
			
		||||
#ifndef QEMU_AES_H
 | 
			
		||||
#define QEMU_AES_H
 | 
			
		||||
 | 
			
		||||
#define AES_MAXNR 14
 | 
			
		||||
#define AES_BLOCK_SIZE 16
 | 
			
		||||
 | 
			
		||||
struct aes_key_st {
 | 
			
		||||
    uint32_t rd_key[4 *(AES_MAXNR + 1)];
 | 
			
		||||
    int rounds;
 | 
			
		||||
};
 | 
			
		||||
typedef struct aes_key_st AES_KEY;
 | 
			
		||||
 | 
			
		||||
int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
 | 
			
		||||
	AES_KEY *key);
 | 
			
		||||
int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
 | 
			
		||||
	AES_KEY *key);
 | 
			
		||||
 | 
			
		||||
void AES_encrypt(const unsigned char *in, unsigned char *out,
 | 
			
		||||
	const AES_KEY *key);
 | 
			
		||||
void AES_decrypt(const unsigned char *in, unsigned char *out,
 | 
			
		||||
	const AES_KEY *key);
 | 
			
		||||
void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
 | 
			
		||||
		     const unsigned long length, const AES_KEY *key,
 | 
			
		||||
		     unsigned char *ivec, const int enc);
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										230
									
								
								aio.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										230
									
								
								aio.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,230 @@
 | 
			
		||||
/*
 | 
			
		||||
 * QEMU aio implementation
 | 
			
		||||
 *
 | 
			
		||||
 * Copyright IBM, Corp. 2008
 | 
			
		||||
 *
 | 
			
		||||
 * Authors:
 | 
			
		||||
 *  Anthony Liguori   <aliguori@us.ibm.com>
 | 
			
		||||
 *
 | 
			
		||||
 * This work is licensed under the terms of the GNU GPL, version 2.  See
 | 
			
		||||
 * the COPYING file in the top-level directory.
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "qemu-common.h"
 | 
			
		||||
#include "block.h"
 | 
			
		||||
#include "qemu-queue.h"
 | 
			
		||||
#include "qemu_socket.h"
 | 
			
		||||
 | 
			
		||||
typedef struct AioHandler AioHandler;
 | 
			
		||||
 | 
			
		||||
/* The list of registered AIO handlers */
 | 
			
		||||
static QLIST_HEAD(, AioHandler) aio_handlers;
 | 
			
		||||
 | 
			
		||||
/* This is a simple lock used to protect the aio_handlers list.  Specifically,
 | 
			
		||||
 * it's used to ensure that no callbacks are removed while we're walking and
 | 
			
		||||
 * dispatching callbacks.
 | 
			
		||||
 */
 | 
			
		||||
static int walking_handlers;
 | 
			
		||||
 | 
			
		||||
struct AioHandler
 | 
			
		||||
{
 | 
			
		||||
    int fd;
 | 
			
		||||
    IOHandler *io_read;
 | 
			
		||||
    IOHandler *io_write;
 | 
			
		||||
    AioFlushHandler *io_flush;
 | 
			
		||||
    AioProcessQueue *io_process_queue;
 | 
			
		||||
    int deleted;
 | 
			
		||||
    void *opaque;
 | 
			
		||||
    QLIST_ENTRY(AioHandler) node;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static AioHandler *find_aio_handler(int fd)
 | 
			
		||||
{
 | 
			
		||||
    AioHandler *node;
 | 
			
		||||
 | 
			
		||||
    QLIST_FOREACH(node, &aio_handlers, node) {
 | 
			
		||||
        if (node->fd == fd)
 | 
			
		||||
            if (!node->deleted)
 | 
			
		||||
                return node;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int qemu_aio_set_fd_handler(int fd,
 | 
			
		||||
                            IOHandler *io_read,
 | 
			
		||||
                            IOHandler *io_write,
 | 
			
		||||
                            AioFlushHandler *io_flush,
 | 
			
		||||
                            AioProcessQueue *io_process_queue,
 | 
			
		||||
                            void *opaque)
 | 
			
		||||
{
 | 
			
		||||
    AioHandler *node;
 | 
			
		||||
 | 
			
		||||
    node = find_aio_handler(fd);
 | 
			
		||||
 | 
			
		||||
    /* Are we deleting the fd handler? */
 | 
			
		||||
    if (!io_read && !io_write) {
 | 
			
		||||
        if (node) {
 | 
			
		||||
            /* If the lock is held, just mark the node as deleted */
 | 
			
		||||
            if (walking_handlers)
 | 
			
		||||
                node->deleted = 1;
 | 
			
		||||
            else {
 | 
			
		||||
                /* Otherwise, delete it for real.  We can't just mark it as
 | 
			
		||||
                 * deleted because deleted nodes are only cleaned up after
 | 
			
		||||
                 * releasing the walking_handlers lock.
 | 
			
		||||
                 */
 | 
			
		||||
                QLIST_REMOVE(node, node);
 | 
			
		||||
                qemu_free(node);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    } else {
 | 
			
		||||
        if (node == NULL) {
 | 
			
		||||
            /* Alloc and insert if it's not already there */
 | 
			
		||||
            node = qemu_mallocz(sizeof(AioHandler));
 | 
			
		||||
            node->fd = fd;
 | 
			
		||||
            QLIST_INSERT_HEAD(&aio_handlers, node, node);
 | 
			
		||||
        }
 | 
			
		||||
        /* Update handler with latest information */
 | 
			
		||||
        node->io_read = io_read;
 | 
			
		||||
        node->io_write = io_write;
 | 
			
		||||
        node->io_flush = io_flush;
 | 
			
		||||
        node->io_process_queue = io_process_queue;
 | 
			
		||||
        node->opaque = opaque;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    qemu_set_fd_handler2(fd, NULL, io_read, io_write, opaque);
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void qemu_aio_flush(void)
 | 
			
		||||
{
 | 
			
		||||
    AioHandler *node;
 | 
			
		||||
    int ret;
 | 
			
		||||
 | 
			
		||||
    do {
 | 
			
		||||
        ret = 0;
 | 
			
		||||
 | 
			
		||||
	/*
 | 
			
		||||
	 * If there are pending emulated aio start them now so flush
 | 
			
		||||
	 * will be able to return 1.
 | 
			
		||||
	 */
 | 
			
		||||
        qemu_aio_wait();
 | 
			
		||||
 | 
			
		||||
        QLIST_FOREACH(node, &aio_handlers, node) {
 | 
			
		||||
            if (node->io_flush) {
 | 
			
		||||
                ret |= node->io_flush(node->opaque);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    } while (qemu_bh_poll() || ret > 0);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int qemu_aio_process_queue(void)
 | 
			
		||||
{
 | 
			
		||||
    AioHandler *node;
 | 
			
		||||
    int ret = 0;
 | 
			
		||||
 | 
			
		||||
    walking_handlers = 1;
 | 
			
		||||
 | 
			
		||||
    QLIST_FOREACH(node, &aio_handlers, node) {
 | 
			
		||||
        if (node->io_process_queue) {
 | 
			
		||||
            if (node->io_process_queue(node->opaque)) {
 | 
			
		||||
                ret = 1;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    walking_handlers = 0;
 | 
			
		||||
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void qemu_aio_wait(void)
 | 
			
		||||
{
 | 
			
		||||
    int ret;
 | 
			
		||||
 | 
			
		||||
    if (qemu_bh_poll())
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
     * If there are callbacks left that have been queued, we need to call then.
 | 
			
		||||
     * Return afterwards to avoid waiting needlessly in select().
 | 
			
		||||
     */
 | 
			
		||||
    if (qemu_aio_process_queue())
 | 
			
		||||
        return;
 | 
			
		||||
 | 
			
		||||
    do {
 | 
			
		||||
        AioHandler *node;
 | 
			
		||||
        fd_set rdfds, wrfds;
 | 
			
		||||
        int max_fd = -1;
 | 
			
		||||
 | 
			
		||||
        walking_handlers = 1;
 | 
			
		||||
 | 
			
		||||
        FD_ZERO(&rdfds);
 | 
			
		||||
        FD_ZERO(&wrfds);
 | 
			
		||||
 | 
			
		||||
        /* fill fd sets */
 | 
			
		||||
        QLIST_FOREACH(node, &aio_handlers, node) {
 | 
			
		||||
            /* If there aren't pending AIO operations, don't invoke callbacks.
 | 
			
		||||
             * Otherwise, if there are no AIO requests, qemu_aio_wait() would
 | 
			
		||||
             * wait indefinitely.
 | 
			
		||||
             */
 | 
			
		||||
            if (node->io_flush && node->io_flush(node->opaque) == 0)
 | 
			
		||||
                continue;
 | 
			
		||||
 | 
			
		||||
            if (!node->deleted && node->io_read) {
 | 
			
		||||
                FD_SET(node->fd, &rdfds);
 | 
			
		||||
                max_fd = MAX(max_fd, node->fd + 1);
 | 
			
		||||
            }
 | 
			
		||||
            if (!node->deleted && node->io_write) {
 | 
			
		||||
                FD_SET(node->fd, &wrfds);
 | 
			
		||||
                max_fd = MAX(max_fd, node->fd + 1);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        walking_handlers = 0;
 | 
			
		||||
 | 
			
		||||
        /* No AIO operations?  Get us out of here */
 | 
			
		||||
        if (max_fd == -1)
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        /* wait until next event */
 | 
			
		||||
        ret = select(max_fd, &rdfds, &wrfds, NULL, NULL);
 | 
			
		||||
        if (ret == -1 && errno == EINTR)
 | 
			
		||||
            continue;
 | 
			
		||||
 | 
			
		||||
        /* if we have any readable fds, dispatch event */
 | 
			
		||||
        if (ret > 0) {
 | 
			
		||||
            walking_handlers = 1;
 | 
			
		||||
 | 
			
		||||
            /* we have to walk very carefully in case
 | 
			
		||||
             * qemu_aio_set_fd_handler is called while we're walking */
 | 
			
		||||
            node = QLIST_FIRST(&aio_handlers);
 | 
			
		||||
            while (node) {
 | 
			
		||||
                AioHandler *tmp;
 | 
			
		||||
 | 
			
		||||
                if (!node->deleted &&
 | 
			
		||||
                    FD_ISSET(node->fd, &rdfds) &&
 | 
			
		||||
                    node->io_read) {
 | 
			
		||||
                    node->io_read(node->opaque);
 | 
			
		||||
                }
 | 
			
		||||
                if (!node->deleted &&
 | 
			
		||||
                    FD_ISSET(node->fd, &wrfds) &&
 | 
			
		||||
                    node->io_write) {
 | 
			
		||||
                    node->io_write(node->opaque);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                tmp = node;
 | 
			
		||||
                node = QLIST_NEXT(node, node);
 | 
			
		||||
 | 
			
		||||
                if (tmp->deleted) {
 | 
			
		||||
                    QLIST_REMOVE(tmp, node);
 | 
			
		||||
                    qemu_free(tmp);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            walking_handlers = 0;
 | 
			
		||||
        }
 | 
			
		||||
    } while (ret == 0);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										1916
									
								
								alpha-dis.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1916
									
								
								alpha-dis.c
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										127
									
								
								alpha.ld
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										127
									
								
								alpha.ld
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,127 @@
 | 
			
		||||
OUTPUT_FORMAT("elf64-alpha", "elf64-alpha",
 | 
			
		||||
	      "elf64-alpha")
 | 
			
		||||
OUTPUT_ARCH(alpha)
 | 
			
		||||
ENTRY(__start)
 | 
			
		||||
SECTIONS
 | 
			
		||||
{
 | 
			
		||||
  /* Read-only sections, merged into text segment: */
 | 
			
		||||
  . = 0x60000000 + SIZEOF_HEADERS;
 | 
			
		||||
  .interp     : { *(.interp) 	}
 | 
			
		||||
  .hash          : { *(.hash)		}
 | 
			
		||||
  .dynsym        : { *(.dynsym)		}
 | 
			
		||||
  .dynstr        : { *(.dynstr)		}
 | 
			
		||||
  .gnu.version   : { *(.gnu.version)	}
 | 
			
		||||
  .gnu.version_d   : { *(.gnu.version_d)	}
 | 
			
		||||
  .gnu.version_r   : { *(.gnu.version_r)	}
 | 
			
		||||
  .rel.text      :
 | 
			
		||||
    { *(.rel.text) *(.rel.gnu.linkonce.t*) }
 | 
			
		||||
  .rela.text     :
 | 
			
		||||
    { *(.rela.text) *(.rela.gnu.linkonce.t*) }
 | 
			
		||||
  .rel.data      :
 | 
			
		||||
    { *(.rel.data) *(.rel.gnu.linkonce.d*) }
 | 
			
		||||
  .rela.data     :
 | 
			
		||||
    { *(.rela.data) *(.rela.gnu.linkonce.d*) }
 | 
			
		||||
  .rel.rodata    :
 | 
			
		||||
    { *(.rel.rodata) *(.rel.gnu.linkonce.r*) }
 | 
			
		||||
  .rela.rodata   :
 | 
			
		||||
    { *(.rela.rodata) *(.rela.gnu.linkonce.r*) }
 | 
			
		||||
  .rel.got       : { *(.rel.got)		}
 | 
			
		||||
  .rela.got      : { *(.rela.got)		}
 | 
			
		||||
  .rel.ctors     : { *(.rel.ctors)	}
 | 
			
		||||
  .rela.ctors    : { *(.rela.ctors)	}
 | 
			
		||||
  .rel.dtors     : { *(.rel.dtors)	}
 | 
			
		||||
  .rela.dtors    : { *(.rela.dtors)	}
 | 
			
		||||
  .rel.init      : { *(.rel.init)	}
 | 
			
		||||
  .rela.init     : { *(.rela.init)	}
 | 
			
		||||
  .rel.fini      : { *(.rel.fini)	}
 | 
			
		||||
  .rela.fini     : { *(.rela.fini)	}
 | 
			
		||||
  .rel.bss       : { *(.rel.bss)		}
 | 
			
		||||
  .rela.bss      : { *(.rela.bss)		}
 | 
			
		||||
  .rel.plt       : { *(.rel.plt)		}
 | 
			
		||||
  .rela.plt      : { *(.rela.plt)		}
 | 
			
		||||
  .init          : { *(.init)	} =0x47ff041f
 | 
			
		||||
  .text      :
 | 
			
		||||
  {
 | 
			
		||||
    *(.text)
 | 
			
		||||
    /* .gnu.warning sections are handled specially by elf32.em.  */
 | 
			
		||||
    *(.gnu.warning)
 | 
			
		||||
    *(.gnu.linkonce.t*)
 | 
			
		||||
  } =0x47ff041f
 | 
			
		||||
  _etext = .;
 | 
			
		||||
  PROVIDE (etext = .);
 | 
			
		||||
  .fini      : { *(.fini)    } =0x47ff041f
 | 
			
		||||
  .rodata    : { *(.rodata) *(.gnu.linkonce.r*) }
 | 
			
		||||
  .rodata1   : { *(.rodata1) }
 | 
			
		||||
  .reginfo : { *(.reginfo) }
 | 
			
		||||
  /* Adjust the address for the data segment.  We want to adjust up to
 | 
			
		||||
     the same address within the page on the next page up.  */
 | 
			
		||||
  . = ALIGN(0x100000) + (. & (0x100000 - 1));
 | 
			
		||||
  .data    :
 | 
			
		||||
  {
 | 
			
		||||
    *(.data)
 | 
			
		||||
    *(.gnu.linkonce.d*)
 | 
			
		||||
    CONSTRUCTORS
 | 
			
		||||
  }
 | 
			
		||||
  .data1   : { *(.data1) }
 | 
			
		||||
  .ctors         :
 | 
			
		||||
  {
 | 
			
		||||
    *(.ctors)
 | 
			
		||||
  }
 | 
			
		||||
  .dtors         :
 | 
			
		||||
  {
 | 
			
		||||
    *(.dtors)
 | 
			
		||||
  }
 | 
			
		||||
  .plt      : { *(.plt)	}
 | 
			
		||||
  .got           : { *(.got.plt) *(.got) }
 | 
			
		||||
  .dynamic       : { *(.dynamic) }
 | 
			
		||||
  /* We want the small data sections together, so single-instruction offsets
 | 
			
		||||
     can access them all, and initialized data all before uninitialized, so
 | 
			
		||||
     we can shorten the on-disk segment size.  */
 | 
			
		||||
  .sdata     : { *(.sdata) }
 | 
			
		||||
  _edata  =  .;
 | 
			
		||||
  PROVIDE (edata = .);
 | 
			
		||||
  __bss_start = .;
 | 
			
		||||
  .sbss      : { *(.sbss) *(.scommon) }
 | 
			
		||||
  .bss       :
 | 
			
		||||
  {
 | 
			
		||||
   *(.dynbss)
 | 
			
		||||
   *(.bss)
 | 
			
		||||
   *(COMMON)
 | 
			
		||||
  }
 | 
			
		||||
  _end = . ;
 | 
			
		||||
  PROVIDE (end = .);
 | 
			
		||||
  /* Stabs debugging sections.  */
 | 
			
		||||
  .stab 0 : { *(.stab) }
 | 
			
		||||
  .stabstr 0 : { *(.stabstr) }
 | 
			
		||||
  .stab.excl 0 : { *(.stab.excl) }
 | 
			
		||||
  .stab.exclstr 0 : { *(.stab.exclstr) }
 | 
			
		||||
  .stab.index 0 : { *(.stab.index) }
 | 
			
		||||
  .stab.indexstr 0 : { *(.stab.indexstr) }
 | 
			
		||||
  .comment 0 : { *(.comment) }
 | 
			
		||||
  /* DWARF debug sections.
 | 
			
		||||
     Symbols in the DWARF debugging sections are relative to the beginning
 | 
			
		||||
     of the section so we begin them at 0.  */
 | 
			
		||||
  /* DWARF 1 */
 | 
			
		||||
  .debug          0 : { *(.debug) }
 | 
			
		||||
  .line           0 : { *(.line) }
 | 
			
		||||
  /* GNU DWARF 1 extensions */
 | 
			
		||||
  .debug_srcinfo  0 : { *(.debug_srcinfo) }
 | 
			
		||||
  .debug_sfnames  0 : { *(.debug_sfnames) }
 | 
			
		||||
  /* DWARF 1.1 and DWARF 2 */
 | 
			
		||||
  .debug_aranges  0 : { *(.debug_aranges) }
 | 
			
		||||
  .debug_pubnames 0 : { *(.debug_pubnames) }
 | 
			
		||||
  /* DWARF 2 */
 | 
			
		||||
  .debug_info     0 : { *(.debug_info) }
 | 
			
		||||
  .debug_abbrev   0 : { *(.debug_abbrev) }
 | 
			
		||||
  .debug_line     0 : { *(.debug_line) }
 | 
			
		||||
  .debug_frame    0 : { *(.debug_frame) }
 | 
			
		||||
  .debug_str      0 : { *(.debug_str) }
 | 
			
		||||
  .debug_loc      0 : { *(.debug_loc) }
 | 
			
		||||
  .debug_macinfo  0 : { *(.debug_macinfo) }
 | 
			
		||||
  /* SGI/MIPS DWARF 2 extensions */
 | 
			
		||||
  .debug_weaknames 0 : { *(.debug_weaknames) }
 | 
			
		||||
  .debug_funcnames 0 : { *(.debug_funcnames) }
 | 
			
		||||
  .debug_typenames 0 : { *(.debug_typenames) }
 | 
			
		||||
  .debug_varnames  0 : { *(.debug_varnames) }
 | 
			
		||||
  /* These must appear regardless of  .  */
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										698
									
								
								arch_init.c
									
									
									
									
									
								
							
							
						
						
									
										698
									
								
								arch_init.c
									
									
									
									
									
								
							@@ -21,18 +21,26 @@
 | 
			
		||||
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
			
		||||
 * THE SOFTWARE.
 | 
			
		||||
 */
 | 
			
		||||
#include "qemu/osdep.h"
 | 
			
		||||
#include "cpu.h"
 | 
			
		||||
#include "sysemu/sysemu.h"
 | 
			
		||||
#include "sysemu/arch_init.h"
 | 
			
		||||
#include "hw/pci/pci.h"
 | 
			
		||||
#include "hw/audio/soundhw.h"
 | 
			
		||||
#include "qapi/qapi-commands-misc.h"
 | 
			
		||||
#include "qapi/error.h"
 | 
			
		||||
#include "qemu/config-file.h"
 | 
			
		||||
#include "qemu/error-report.h"
 | 
			
		||||
#include "hw/acpi/acpi.h"
 | 
			
		||||
#include "qemu/help_option.h"
 | 
			
		||||
#include <stdint.h>
 | 
			
		||||
#include <stdarg.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#ifndef _WIN32
 | 
			
		||||
#include <sys/types.h>
 | 
			
		||||
#include <sys/mman.h>
 | 
			
		||||
#endif
 | 
			
		||||
#include "config.h"
 | 
			
		||||
#include "monitor.h"
 | 
			
		||||
#include "sysemu.h"
 | 
			
		||||
#include "arch_init.h"
 | 
			
		||||
#include "audio/audio.h"
 | 
			
		||||
#include "hw/pc.h"
 | 
			
		||||
#include "hw/pci.h"
 | 
			
		||||
#include "hw/audiodev.h"
 | 
			
		||||
#include "kvm.h"
 | 
			
		||||
#include "migration.h"
 | 
			
		||||
#include "net.h"
 | 
			
		||||
#include "gdbstub.h"
 | 
			
		||||
#include "hw/smbios.h"
 | 
			
		||||
 | 
			
		||||
#ifdef TARGET_SPARC
 | 
			
		||||
int graphic_width = 1024;
 | 
			
		||||
@@ -41,9 +49,10 @@ int graphic_depth = 8;
 | 
			
		||||
#else
 | 
			
		||||
int graphic_width = 800;
 | 
			
		||||
int graphic_height = 600;
 | 
			
		||||
int graphic_depth = 32;
 | 
			
		||||
int graphic_depth = 15;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
const char arch_config_name[] = CONFIG_QEMU_CONFDIR "/target-" TARGET_ARCH ".conf";
 | 
			
		||||
 | 
			
		||||
#if defined(TARGET_ALPHA)
 | 
			
		||||
#define QEMU_ARCH QEMU_ARCH_ALPHA
 | 
			
		||||
@@ -51,44 +60,660 @@ int graphic_depth = 32;
 | 
			
		||||
#define QEMU_ARCH QEMU_ARCH_ARM
 | 
			
		||||
#elif defined(TARGET_CRIS)
 | 
			
		||||
#define QEMU_ARCH QEMU_ARCH_CRIS
 | 
			
		||||
#elif defined(TARGET_HPPA)
 | 
			
		||||
#define QEMU_ARCH QEMU_ARCH_HPPA
 | 
			
		||||
#elif defined(TARGET_I386)
 | 
			
		||||
#define QEMU_ARCH QEMU_ARCH_I386
 | 
			
		||||
#elif defined(TARGET_LM32)
 | 
			
		||||
#define QEMU_ARCH QEMU_ARCH_LM32
 | 
			
		||||
#elif defined(TARGET_M68K)
 | 
			
		||||
#define QEMU_ARCH QEMU_ARCH_M68K
 | 
			
		||||
#elif defined(TARGET_LM32)
 | 
			
		||||
#define QEMU_ARCH QEMU_ARCH_LM32
 | 
			
		||||
#elif defined(TARGET_MICROBLAZE)
 | 
			
		||||
#define QEMU_ARCH QEMU_ARCH_MICROBLAZE
 | 
			
		||||
#elif defined(TARGET_MIPS)
 | 
			
		||||
#define QEMU_ARCH QEMU_ARCH_MIPS
 | 
			
		||||
#elif defined(TARGET_MOXIE)
 | 
			
		||||
#define QEMU_ARCH QEMU_ARCH_MOXIE
 | 
			
		||||
#elif defined(TARGET_NIOS2)
 | 
			
		||||
#define QEMU_ARCH QEMU_ARCH_NIOS2
 | 
			
		||||
#elif defined(TARGET_OPENRISC)
 | 
			
		||||
#define QEMU_ARCH QEMU_ARCH_OPENRISC
 | 
			
		||||
#elif defined(TARGET_PPC)
 | 
			
		||||
#define QEMU_ARCH QEMU_ARCH_PPC
 | 
			
		||||
#elif defined(TARGET_RISCV)
 | 
			
		||||
#define QEMU_ARCH QEMU_ARCH_RISCV
 | 
			
		||||
#elif defined(TARGET_S390X)
 | 
			
		||||
#define QEMU_ARCH QEMU_ARCH_S390X
 | 
			
		||||
#elif defined(TARGET_SH4)
 | 
			
		||||
#define QEMU_ARCH QEMU_ARCH_SH4
 | 
			
		||||
#elif defined(TARGET_SPARC)
 | 
			
		||||
#define QEMU_ARCH QEMU_ARCH_SPARC
 | 
			
		||||
#elif defined(TARGET_TRICORE)
 | 
			
		||||
#define QEMU_ARCH QEMU_ARCH_TRICORE
 | 
			
		||||
#elif defined(TARGET_UNICORE32)
 | 
			
		||||
#define QEMU_ARCH QEMU_ARCH_UNICORE32
 | 
			
		||||
#elif defined(TARGET_XTENSA)
 | 
			
		||||
#define QEMU_ARCH QEMU_ARCH_XTENSA
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
const uint32_t arch_type = QEMU_ARCH;
 | 
			
		||||
 | 
			
		||||
/***********************************************************/
 | 
			
		||||
/* ram save/restore */
 | 
			
		||||
 | 
			
		||||
#define RAM_SAVE_FLAG_FULL     0x01 /* Obsolete, not used anymore */
 | 
			
		||||
#define RAM_SAVE_FLAG_COMPRESS 0x02
 | 
			
		||||
#define RAM_SAVE_FLAG_MEM_SIZE 0x04
 | 
			
		||||
#define RAM_SAVE_FLAG_PAGE     0x08
 | 
			
		||||
#define RAM_SAVE_FLAG_EOS      0x10
 | 
			
		||||
#define RAM_SAVE_FLAG_CONTINUE 0x20
 | 
			
		||||
 | 
			
		||||
static int is_dup_page(uint8_t *page, uint8_t ch)
 | 
			
		||||
{
 | 
			
		||||
    uint32_t val = ch << 24 | ch << 16 | ch << 8 | ch;
 | 
			
		||||
    uint32_t *array = (uint32_t *)page;
 | 
			
		||||
    int i;
 | 
			
		||||
 | 
			
		||||
    for (i = 0; i < (TARGET_PAGE_SIZE / 4); i++) {
 | 
			
		||||
        if (array[i] != val) {
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static RAMBlock *last_block;
 | 
			
		||||
static ram_addr_t last_offset;
 | 
			
		||||
 | 
			
		||||
static int ram_save_block(QEMUFile *f)
 | 
			
		||||
{
 | 
			
		||||
    RAMBlock *block = last_block;
 | 
			
		||||
    ram_addr_t offset = last_offset;
 | 
			
		||||
    ram_addr_t current_addr;
 | 
			
		||||
    int bytes_sent = 0;
 | 
			
		||||
 | 
			
		||||
    if (!block)
 | 
			
		||||
        block = QLIST_FIRST(&ram_list.blocks);
 | 
			
		||||
 | 
			
		||||
    current_addr = block->offset + offset;
 | 
			
		||||
 | 
			
		||||
    do {
 | 
			
		||||
        if (cpu_physical_memory_get_dirty(current_addr, MIGRATION_DIRTY_FLAG)) {
 | 
			
		||||
            uint8_t *p;
 | 
			
		||||
            int cont = (block == last_block) ? RAM_SAVE_FLAG_CONTINUE : 0;
 | 
			
		||||
 | 
			
		||||
            cpu_physical_memory_reset_dirty(current_addr,
 | 
			
		||||
                                            current_addr + TARGET_PAGE_SIZE,
 | 
			
		||||
                                            MIGRATION_DIRTY_FLAG);
 | 
			
		||||
 | 
			
		||||
            p = block->host + offset;
 | 
			
		||||
 | 
			
		||||
            if (is_dup_page(p, *p)) {
 | 
			
		||||
                qemu_put_be64(f, offset | cont | RAM_SAVE_FLAG_COMPRESS);
 | 
			
		||||
                if (!cont) {
 | 
			
		||||
                    qemu_put_byte(f, strlen(block->idstr));
 | 
			
		||||
                    qemu_put_buffer(f, (uint8_t *)block->idstr,
 | 
			
		||||
                                    strlen(block->idstr));
 | 
			
		||||
                }
 | 
			
		||||
                qemu_put_byte(f, *p);
 | 
			
		||||
                bytes_sent = 1;
 | 
			
		||||
            } else {
 | 
			
		||||
                qemu_put_be64(f, offset | cont | RAM_SAVE_FLAG_PAGE);
 | 
			
		||||
                if (!cont) {
 | 
			
		||||
                    qemu_put_byte(f, strlen(block->idstr));
 | 
			
		||||
                    qemu_put_buffer(f, (uint8_t *)block->idstr,
 | 
			
		||||
                                    strlen(block->idstr));
 | 
			
		||||
                }
 | 
			
		||||
                qemu_put_buffer(f, p, TARGET_PAGE_SIZE);
 | 
			
		||||
                bytes_sent = TARGET_PAGE_SIZE;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        offset += TARGET_PAGE_SIZE;
 | 
			
		||||
        if (offset >= block->length) {
 | 
			
		||||
            offset = 0;
 | 
			
		||||
            block = QLIST_NEXT(block, next);
 | 
			
		||||
            if (!block)
 | 
			
		||||
                block = QLIST_FIRST(&ram_list.blocks);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        current_addr = block->offset + offset;
 | 
			
		||||
 | 
			
		||||
    } while (current_addr != last_block->offset + last_offset);
 | 
			
		||||
 | 
			
		||||
    last_block = block;
 | 
			
		||||
    last_offset = offset;
 | 
			
		||||
 | 
			
		||||
    return bytes_sent;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static uint64_t bytes_transferred;
 | 
			
		||||
 | 
			
		||||
static ram_addr_t ram_save_remaining(void)
 | 
			
		||||
{
 | 
			
		||||
    RAMBlock *block;
 | 
			
		||||
    ram_addr_t count = 0;
 | 
			
		||||
 | 
			
		||||
    QLIST_FOREACH(block, &ram_list.blocks, next) {
 | 
			
		||||
        ram_addr_t addr;
 | 
			
		||||
        for (addr = block->offset; addr < block->offset + block->length;
 | 
			
		||||
             addr += TARGET_PAGE_SIZE) {
 | 
			
		||||
            if (cpu_physical_memory_get_dirty(addr, MIGRATION_DIRTY_FLAG)) {
 | 
			
		||||
                count++;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return count;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint64_t ram_bytes_remaining(void)
 | 
			
		||||
{
 | 
			
		||||
    return ram_save_remaining() * TARGET_PAGE_SIZE;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint64_t ram_bytes_transferred(void)
 | 
			
		||||
{
 | 
			
		||||
    return bytes_transferred;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint64_t ram_bytes_total(void)
 | 
			
		||||
{
 | 
			
		||||
    RAMBlock *block;
 | 
			
		||||
    uint64_t total = 0;
 | 
			
		||||
 | 
			
		||||
    QLIST_FOREACH(block, &ram_list.blocks, next)
 | 
			
		||||
        total += block->length;
 | 
			
		||||
 | 
			
		||||
    return total;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int block_compar(const void *a, const void *b)
 | 
			
		||||
{
 | 
			
		||||
    RAMBlock * const *ablock = a;
 | 
			
		||||
    RAMBlock * const *bblock = b;
 | 
			
		||||
    if ((*ablock)->offset < (*bblock)->offset) {
 | 
			
		||||
        return -1;
 | 
			
		||||
    } else if ((*ablock)->offset > (*bblock)->offset) {
 | 
			
		||||
        return 1;
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void sort_ram_list(void)
 | 
			
		||||
{
 | 
			
		||||
    RAMBlock *block, *nblock, **blocks;
 | 
			
		||||
    int n;
 | 
			
		||||
    n = 0;
 | 
			
		||||
    QLIST_FOREACH(block, &ram_list.blocks, next) {
 | 
			
		||||
        ++n;
 | 
			
		||||
    }
 | 
			
		||||
    blocks = qemu_malloc(n * sizeof *blocks);
 | 
			
		||||
    n = 0;
 | 
			
		||||
    QLIST_FOREACH_SAFE(block, &ram_list.blocks, next, nblock) {
 | 
			
		||||
        blocks[n++] = block;
 | 
			
		||||
        QLIST_REMOVE(block, next);
 | 
			
		||||
    }
 | 
			
		||||
    qsort(blocks, n, sizeof *blocks, block_compar);
 | 
			
		||||
    while (--n >= 0) {
 | 
			
		||||
        QLIST_INSERT_HEAD(&ram_list.blocks, blocks[n], next);
 | 
			
		||||
    }
 | 
			
		||||
    qemu_free(blocks);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int ram_save_live(Monitor *mon, QEMUFile *f, int stage, void *opaque)
 | 
			
		||||
{
 | 
			
		||||
    ram_addr_t addr;
 | 
			
		||||
    uint64_t bytes_transferred_last;
 | 
			
		||||
    double bwidth = 0;
 | 
			
		||||
    uint64_t expected_time = 0;
 | 
			
		||||
 | 
			
		||||
    if (stage < 0) {
 | 
			
		||||
        cpu_physical_memory_set_dirty_tracking(0);
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (cpu_physical_sync_dirty_bitmap(0, TARGET_PHYS_ADDR_MAX) != 0) {
 | 
			
		||||
        qemu_file_set_error(f);
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (stage == 1) {
 | 
			
		||||
        RAMBlock *block;
 | 
			
		||||
        bytes_transferred = 0;
 | 
			
		||||
        last_block = NULL;
 | 
			
		||||
        last_offset = 0;
 | 
			
		||||
        sort_ram_list();
 | 
			
		||||
 | 
			
		||||
        /* Make sure all dirty bits are set */
 | 
			
		||||
        QLIST_FOREACH(block, &ram_list.blocks, next) {
 | 
			
		||||
            for (addr = block->offset; addr < block->offset + block->length;
 | 
			
		||||
                 addr += TARGET_PAGE_SIZE) {
 | 
			
		||||
                if (!cpu_physical_memory_get_dirty(addr,
 | 
			
		||||
                                                   MIGRATION_DIRTY_FLAG)) {
 | 
			
		||||
                    cpu_physical_memory_set_dirty(addr);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* Enable dirty memory tracking */
 | 
			
		||||
        cpu_physical_memory_set_dirty_tracking(1);
 | 
			
		||||
 | 
			
		||||
        qemu_put_be64(f, ram_bytes_total() | RAM_SAVE_FLAG_MEM_SIZE);
 | 
			
		||||
 | 
			
		||||
        QLIST_FOREACH(block, &ram_list.blocks, next) {
 | 
			
		||||
            qemu_put_byte(f, strlen(block->idstr));
 | 
			
		||||
            qemu_put_buffer(f, (uint8_t *)block->idstr, strlen(block->idstr));
 | 
			
		||||
            qemu_put_be64(f, block->length);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bytes_transferred_last = bytes_transferred;
 | 
			
		||||
    bwidth = qemu_get_clock_ns(rt_clock);
 | 
			
		||||
 | 
			
		||||
    while (!qemu_file_rate_limit(f)) {
 | 
			
		||||
        int bytes_sent;
 | 
			
		||||
 | 
			
		||||
        bytes_sent = ram_save_block(f);
 | 
			
		||||
        bytes_transferred += bytes_sent;
 | 
			
		||||
        if (bytes_sent == 0) { /* no more blocks */
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    bwidth = qemu_get_clock_ns(rt_clock) - bwidth;
 | 
			
		||||
    bwidth = (bytes_transferred - bytes_transferred_last) / bwidth;
 | 
			
		||||
 | 
			
		||||
    /* if we haven't transferred anything this round, force expected_time to a
 | 
			
		||||
     * a very high value, but without crashing */
 | 
			
		||||
    if (bwidth == 0) {
 | 
			
		||||
        bwidth = 0.000001;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* try transferring iterative blocks of memory */
 | 
			
		||||
    if (stage == 3) {
 | 
			
		||||
        int bytes_sent;
 | 
			
		||||
 | 
			
		||||
        /* flush all remaining blocks regardless of rate limiting */
 | 
			
		||||
        while ((bytes_sent = ram_save_block(f)) != 0) {
 | 
			
		||||
            bytes_transferred += bytes_sent;
 | 
			
		||||
        }
 | 
			
		||||
        cpu_physical_memory_set_dirty_tracking(0);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
 | 
			
		||||
 | 
			
		||||
    expected_time = ram_save_remaining() * TARGET_PAGE_SIZE / bwidth;
 | 
			
		||||
 | 
			
		||||
    return (stage == 2) && (expected_time <= migrate_max_downtime());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline void *host_from_stream_offset(QEMUFile *f,
 | 
			
		||||
                                            ram_addr_t offset,
 | 
			
		||||
                                            int flags)
 | 
			
		||||
{
 | 
			
		||||
    static RAMBlock *block = NULL;
 | 
			
		||||
    char id[256];
 | 
			
		||||
    uint8_t len;
 | 
			
		||||
 | 
			
		||||
    if (flags & RAM_SAVE_FLAG_CONTINUE) {
 | 
			
		||||
        if (!block) {
 | 
			
		||||
            fprintf(stderr, "Ack, bad migration stream!\n");
 | 
			
		||||
            return NULL;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return block->host + offset;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    len = qemu_get_byte(f);
 | 
			
		||||
    qemu_get_buffer(f, (uint8_t *)id, len);
 | 
			
		||||
    id[len] = 0;
 | 
			
		||||
 | 
			
		||||
    QLIST_FOREACH(block, &ram_list.blocks, next) {
 | 
			
		||||
        if (!strncmp(id, block->idstr, sizeof(id)))
 | 
			
		||||
            return block->host + offset;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fprintf(stderr, "Can't find block %s!\n", id);
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int ram_load(QEMUFile *f, void *opaque, int version_id)
 | 
			
		||||
{
 | 
			
		||||
    ram_addr_t addr;
 | 
			
		||||
    int flags;
 | 
			
		||||
 | 
			
		||||
    if (version_id < 3 || version_id > 4) {
 | 
			
		||||
        return -EINVAL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    do {
 | 
			
		||||
        addr = qemu_get_be64(f);
 | 
			
		||||
 | 
			
		||||
        flags = addr & ~TARGET_PAGE_MASK;
 | 
			
		||||
        addr &= TARGET_PAGE_MASK;
 | 
			
		||||
 | 
			
		||||
        if (flags & RAM_SAVE_FLAG_MEM_SIZE) {
 | 
			
		||||
            if (version_id == 3) {
 | 
			
		||||
                if (addr != ram_bytes_total()) {
 | 
			
		||||
                    return -EINVAL;
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                /* Synchronize RAM block list */
 | 
			
		||||
                char id[256];
 | 
			
		||||
                ram_addr_t length;
 | 
			
		||||
                ram_addr_t total_ram_bytes = addr;
 | 
			
		||||
 | 
			
		||||
                while (total_ram_bytes) {
 | 
			
		||||
                    RAMBlock *block;
 | 
			
		||||
                    uint8_t len;
 | 
			
		||||
 | 
			
		||||
                    len = qemu_get_byte(f);
 | 
			
		||||
                    qemu_get_buffer(f, (uint8_t *)id, len);
 | 
			
		||||
                    id[len] = 0;
 | 
			
		||||
                    length = qemu_get_be64(f);
 | 
			
		||||
 | 
			
		||||
                    QLIST_FOREACH(block, &ram_list.blocks, next) {
 | 
			
		||||
                        if (!strncmp(id, block->idstr, sizeof(id))) {
 | 
			
		||||
                            if (block->length != length)
 | 
			
		||||
                                return -EINVAL;
 | 
			
		||||
                            break;
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    if (!block) {
 | 
			
		||||
                        fprintf(stderr, "Unknown ramblock \"%s\", cannot "
 | 
			
		||||
                                "accept migration\n", id);
 | 
			
		||||
                        return -EINVAL;
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    total_ram_bytes -= length;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (flags & RAM_SAVE_FLAG_COMPRESS) {
 | 
			
		||||
            void *host;
 | 
			
		||||
            uint8_t ch;
 | 
			
		||||
 | 
			
		||||
            if (version_id == 3)
 | 
			
		||||
                host = qemu_get_ram_ptr(addr);
 | 
			
		||||
            else
 | 
			
		||||
                host = host_from_stream_offset(f, addr, flags);
 | 
			
		||||
            if (!host) {
 | 
			
		||||
                return -EINVAL;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            ch = qemu_get_byte(f);
 | 
			
		||||
            memset(host, ch, TARGET_PAGE_SIZE);
 | 
			
		||||
#ifndef _WIN32
 | 
			
		||||
            if (ch == 0 &&
 | 
			
		||||
                (!kvm_enabled() || kvm_has_sync_mmu())) {
 | 
			
		||||
                qemu_madvise(host, TARGET_PAGE_SIZE, QEMU_MADV_DONTNEED);
 | 
			
		||||
            }
 | 
			
		||||
#endif
 | 
			
		||||
        } else if (flags & RAM_SAVE_FLAG_PAGE) {
 | 
			
		||||
            void *host;
 | 
			
		||||
 | 
			
		||||
            if (version_id == 3)
 | 
			
		||||
                host = qemu_get_ram_ptr(addr);
 | 
			
		||||
            else
 | 
			
		||||
                host = host_from_stream_offset(f, addr, flags);
 | 
			
		||||
 | 
			
		||||
            qemu_get_buffer(f, host, TARGET_PAGE_SIZE);
 | 
			
		||||
        }
 | 
			
		||||
        if (qemu_file_has_error(f)) {
 | 
			
		||||
            return -EIO;
 | 
			
		||||
        }
 | 
			
		||||
    } while (!(flags & RAM_SAVE_FLAG_EOS));
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void qemu_service_io(void)
 | 
			
		||||
{
 | 
			
		||||
    qemu_notify_event();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef HAS_AUDIO
 | 
			
		||||
struct soundhw {
 | 
			
		||||
    const char *name;
 | 
			
		||||
    const char *descr;
 | 
			
		||||
    int enabled;
 | 
			
		||||
    int isa;
 | 
			
		||||
    union {
 | 
			
		||||
        int (*init_isa) (qemu_irq *pic);
 | 
			
		||||
        int (*init_pci) (PCIBus *bus);
 | 
			
		||||
    } init;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static struct soundhw soundhw[] = {
 | 
			
		||||
#ifdef HAS_AUDIO_CHOICE
 | 
			
		||||
#if defined(TARGET_I386) || defined(TARGET_MIPS)
 | 
			
		||||
    {
 | 
			
		||||
        "pcspk",
 | 
			
		||||
        "PC speaker",
 | 
			
		||||
        0,
 | 
			
		||||
        1,
 | 
			
		||||
        { .init_isa = pcspk_audio_init }
 | 
			
		||||
    },
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef CONFIG_SB16
 | 
			
		||||
    {
 | 
			
		||||
        "sb16",
 | 
			
		||||
        "Creative Sound Blaster 16",
 | 
			
		||||
        0,
 | 
			
		||||
        1,
 | 
			
		||||
        { .init_isa = SB16_init }
 | 
			
		||||
    },
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef CONFIG_CS4231A
 | 
			
		||||
    {
 | 
			
		||||
        "cs4231a",
 | 
			
		||||
        "CS4231A",
 | 
			
		||||
        0,
 | 
			
		||||
        1,
 | 
			
		||||
        { .init_isa = cs4231a_init }
 | 
			
		||||
    },
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef CONFIG_ADLIB
 | 
			
		||||
    {
 | 
			
		||||
        "adlib",
 | 
			
		||||
#ifdef HAS_YMF262
 | 
			
		||||
        "Yamaha YMF262 (OPL3)",
 | 
			
		||||
#else
 | 
			
		||||
        "Yamaha YM3812 (OPL2)",
 | 
			
		||||
#endif
 | 
			
		||||
        0,
 | 
			
		||||
        1,
 | 
			
		||||
        { .init_isa = Adlib_init }
 | 
			
		||||
    },
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef CONFIG_GUS
 | 
			
		||||
    {
 | 
			
		||||
        "gus",
 | 
			
		||||
        "Gravis Ultrasound GF1",
 | 
			
		||||
        0,
 | 
			
		||||
        1,
 | 
			
		||||
        { .init_isa = GUS_init }
 | 
			
		||||
    },
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef CONFIG_AC97
 | 
			
		||||
    {
 | 
			
		||||
        "ac97",
 | 
			
		||||
        "Intel 82801AA AC97 Audio",
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        { .init_pci = ac97_init }
 | 
			
		||||
    },
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef CONFIG_ES1370
 | 
			
		||||
    {
 | 
			
		||||
        "es1370",
 | 
			
		||||
        "ENSONIQ AudioPCI ES1370",
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        { .init_pci = es1370_init }
 | 
			
		||||
    },
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef CONFIG_HDA
 | 
			
		||||
    {
 | 
			
		||||
        "hda",
 | 
			
		||||
        "Intel HD Audio",
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        { .init_pci = intel_hda_and_codec_init }
 | 
			
		||||
    },
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#endif /* HAS_AUDIO_CHOICE */
 | 
			
		||||
 | 
			
		||||
    { NULL, NULL, 0, 0, { NULL } }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void select_soundhw(const char *optarg)
 | 
			
		||||
{
 | 
			
		||||
    struct soundhw *c;
 | 
			
		||||
 | 
			
		||||
    if (*optarg == '?') {
 | 
			
		||||
    show_valid_cards:
 | 
			
		||||
 | 
			
		||||
        printf("Valid sound card names (comma separated):\n");
 | 
			
		||||
        for (c = soundhw; c->name; ++c) {
 | 
			
		||||
            printf ("%-11s %s\n", c->name, c->descr);
 | 
			
		||||
        }
 | 
			
		||||
        printf("\n-soundhw all will enable all of the above\n");
 | 
			
		||||
        exit(*optarg != '?');
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
        size_t l;
 | 
			
		||||
        const char *p;
 | 
			
		||||
        char *e;
 | 
			
		||||
        int bad_card = 0;
 | 
			
		||||
 | 
			
		||||
        if (!strcmp(optarg, "all")) {
 | 
			
		||||
            for (c = soundhw; c->name; ++c) {
 | 
			
		||||
                c->enabled = 1;
 | 
			
		||||
            }
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        p = optarg;
 | 
			
		||||
        while (*p) {
 | 
			
		||||
            e = strchr(p, ',');
 | 
			
		||||
            l = !e ? strlen(p) : (size_t) (e - p);
 | 
			
		||||
 | 
			
		||||
            for (c = soundhw; c->name; ++c) {
 | 
			
		||||
                if (!strncmp(c->name, p, l) && !c->name[l]) {
 | 
			
		||||
                    c->enabled = 1;
 | 
			
		||||
                    break;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (!c->name) {
 | 
			
		||||
                if (l > 80) {
 | 
			
		||||
                    fprintf(stderr,
 | 
			
		||||
                            "Unknown sound card name (too big to show)\n");
 | 
			
		||||
                }
 | 
			
		||||
                else {
 | 
			
		||||
                    fprintf(stderr, "Unknown sound card name `%.*s'\n",
 | 
			
		||||
                            (int) l, p);
 | 
			
		||||
                }
 | 
			
		||||
                bad_card = 1;
 | 
			
		||||
            }
 | 
			
		||||
            p += l + (e != NULL);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (bad_card) {
 | 
			
		||||
            goto show_valid_cards;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void audio_init(qemu_irq *isa_pic, PCIBus *pci_bus)
 | 
			
		||||
{
 | 
			
		||||
    struct soundhw *c;
 | 
			
		||||
 | 
			
		||||
    for (c = soundhw; c->name; ++c) {
 | 
			
		||||
        if (c->enabled) {
 | 
			
		||||
            if (c->isa) {
 | 
			
		||||
                if (isa_pic) {
 | 
			
		||||
                    c->init.init_isa(isa_pic);
 | 
			
		||||
                }
 | 
			
		||||
            } else {
 | 
			
		||||
                if (pci_bus) {
 | 
			
		||||
                    c->init.init_pci(pci_bus);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
#else
 | 
			
		||||
void select_soundhw(const char *optarg)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
void audio_init(qemu_irq *isa_pic, PCIBus *pci_bus)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
int qemu_uuid_parse(const char *str, uint8_t *uuid)
 | 
			
		||||
{
 | 
			
		||||
    int ret;
 | 
			
		||||
 | 
			
		||||
    if (strlen(str) != 36) {
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ret = sscanf(str, UUID_FMT, &uuid[0], &uuid[1], &uuid[2], &uuid[3],
 | 
			
		||||
                 &uuid[4], &uuid[5], &uuid[6], &uuid[7], &uuid[8], &uuid[9],
 | 
			
		||||
                 &uuid[10], &uuid[11], &uuid[12], &uuid[13], &uuid[14],
 | 
			
		||||
                 &uuid[15]);
 | 
			
		||||
 | 
			
		||||
    if (ret != 16) {
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
#ifdef TARGET_I386
 | 
			
		||||
    smbios_add_field(1, offsetof(struct smbios_type_1, uuid), 16, uuid);
 | 
			
		||||
#endif
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void do_acpitable_option(const char *optarg)
 | 
			
		||||
{
 | 
			
		||||
#ifdef TARGET_I386
 | 
			
		||||
    if (acpi_table_add(optarg) < 0) {
 | 
			
		||||
        fprintf(stderr, "Wrong acpi table provided\n");
 | 
			
		||||
        exit(1);
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void do_smbios_option(const char *optarg)
 | 
			
		||||
{
 | 
			
		||||
#ifdef TARGET_I386
 | 
			
		||||
    if (smbios_entry_add(optarg) < 0) {
 | 
			
		||||
        fprintf(stderr, "Wrong smbios provided\n");
 | 
			
		||||
        exit(1);
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void cpudef_init(void)
 | 
			
		||||
{
 | 
			
		||||
#if defined(cpudef_setup)
 | 
			
		||||
    cpudef_setup(); /* parse cpu definitions in target config file */
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int audio_available(void)
 | 
			
		||||
{
 | 
			
		||||
#ifdef HAS_AUDIO
 | 
			
		||||
    return 1;
 | 
			
		||||
#else
 | 
			
		||||
    return 0;
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int tcg_available(void)
 | 
			
		||||
{
 | 
			
		||||
    return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int kvm_available(void)
 | 
			
		||||
{
 | 
			
		||||
#ifdef CONFIG_KVM
 | 
			
		||||
@@ -106,14 +731,3 @@ int xen_available(void)
 | 
			
		||||
    return 0;
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
TargetInfo *qmp_query_target(Error **errp)
 | 
			
		||||
{
 | 
			
		||||
    TargetInfo *info = g_malloc0(sizeof(*info));
 | 
			
		||||
 | 
			
		||||
    info->arch = qapi_enum_parse(&SysEmuTarget_lookup, TARGET_NAME, -1,
 | 
			
		||||
                                 &error_abort);
 | 
			
		||||
 | 
			
		||||
    return info;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										34
									
								
								arch_init.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								arch_init.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
			
		||||
#ifndef QEMU_ARCH_INIT_H
 | 
			
		||||
#define QEMU_ARCH_INIT_H
 | 
			
		||||
 | 
			
		||||
extern const char arch_config_name[];
 | 
			
		||||
 | 
			
		||||
enum {
 | 
			
		||||
    QEMU_ARCH_ALL = -1,
 | 
			
		||||
    QEMU_ARCH_ALPHA = 1,
 | 
			
		||||
    QEMU_ARCH_ARM = 2,
 | 
			
		||||
    QEMU_ARCH_CRIS = 4,
 | 
			
		||||
    QEMU_ARCH_I386 = 8,
 | 
			
		||||
    QEMU_ARCH_M68K = 16,
 | 
			
		||||
    QEMU_ARCH_LM32 = 32,
 | 
			
		||||
    QEMU_ARCH_MICROBLAZE = 64,
 | 
			
		||||
    QEMU_ARCH_MIPS = 128,
 | 
			
		||||
    QEMU_ARCH_PPC = 256,
 | 
			
		||||
    QEMU_ARCH_S390X = 512,
 | 
			
		||||
    QEMU_ARCH_SH4 = 1024,
 | 
			
		||||
    QEMU_ARCH_SPARC = 2048,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
extern const uint32_t arch_type;
 | 
			
		||||
 | 
			
		||||
void select_soundhw(const char *optarg);
 | 
			
		||||
void do_acpitable_option(const char *optarg);
 | 
			
		||||
void do_smbios_option(const char *optarg);
 | 
			
		||||
void cpudef_init(void);
 | 
			
		||||
int audio_available(void);
 | 
			
		||||
void audio_init(qemu_irq *isa_pic, PCIBus *pci_bus);
 | 
			
		||||
int tcg_available(void);
 | 
			
		||||
int kvm_available(void);
 | 
			
		||||
int xen_available(void);
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
							
								
								
									
										509
									
								
								arm-semi.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										509
									
								
								arm-semi.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,509 @@
 | 
			
		||||
/*
 | 
			
		||||
 *  Arm "Angel" semihosting syscalls
 | 
			
		||||
 *
 | 
			
		||||
 *  Copyright (c) 2005, 2007 CodeSourcery.
 | 
			
		||||
 *  Written by Paul Brook.
 | 
			
		||||
 *
 | 
			
		||||
 *  This program is free software; you can redistribute it and/or modify
 | 
			
		||||
 *  it under the terms of the GNU General Public License as published by
 | 
			
		||||
 *  the Free Software Foundation; either version 2 of the License, or
 | 
			
		||||
 *  (at your option) any later version.
 | 
			
		||||
 *
 | 
			
		||||
 *  This program is distributed in the hope that it will be useful,
 | 
			
		||||
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
 *  GNU General Public License for more details.
 | 
			
		||||
 *
 | 
			
		||||
 *  You should have received a copy of the GNU General Public License
 | 
			
		||||
 *  along with this program; if not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include <sys/types.h>
 | 
			
		||||
#include <sys/stat.h>
 | 
			
		||||
#include <fcntl.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <time.h>
 | 
			
		||||
 | 
			
		||||
#include "cpu.h"
 | 
			
		||||
#ifdef CONFIG_USER_ONLY
 | 
			
		||||
#include "qemu.h"
 | 
			
		||||
 | 
			
		||||
#define ARM_ANGEL_HEAP_SIZE (128 * 1024 * 1024)
 | 
			
		||||
#else
 | 
			
		||||
#include "qemu-common.h"
 | 
			
		||||
#include "gdbstub.h"
 | 
			
		||||
#include "hw/arm-misc.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define SYS_OPEN        0x01
 | 
			
		||||
#define SYS_CLOSE       0x02
 | 
			
		||||
#define SYS_WRITEC      0x03
 | 
			
		||||
#define SYS_WRITE0      0x04
 | 
			
		||||
#define SYS_WRITE       0x05
 | 
			
		||||
#define SYS_READ        0x06
 | 
			
		||||
#define SYS_READC       0x07
 | 
			
		||||
#define SYS_ISTTY       0x09
 | 
			
		||||
#define SYS_SEEK        0x0a
 | 
			
		||||
#define SYS_FLEN        0x0c
 | 
			
		||||
#define SYS_TMPNAM      0x0d
 | 
			
		||||
#define SYS_REMOVE      0x0e
 | 
			
		||||
#define SYS_RENAME      0x0f
 | 
			
		||||
#define SYS_CLOCK       0x10
 | 
			
		||||
#define SYS_TIME        0x11
 | 
			
		||||
#define SYS_SYSTEM      0x12
 | 
			
		||||
#define SYS_ERRNO       0x13
 | 
			
		||||
#define SYS_GET_CMDLINE 0x15
 | 
			
		||||
#define SYS_HEAPINFO    0x16
 | 
			
		||||
#define SYS_EXIT        0x18
 | 
			
		||||
 | 
			
		||||
#ifndef O_BINARY
 | 
			
		||||
#define O_BINARY 0
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define GDB_O_RDONLY  0x000
 | 
			
		||||
#define GDB_O_WRONLY  0x001
 | 
			
		||||
#define GDB_O_RDWR    0x002
 | 
			
		||||
#define GDB_O_APPEND  0x008
 | 
			
		||||
#define GDB_O_CREAT   0x200
 | 
			
		||||
#define GDB_O_TRUNC   0x400
 | 
			
		||||
#define GDB_O_BINARY  0
 | 
			
		||||
 | 
			
		||||
static int gdb_open_modeflags[12] = {
 | 
			
		||||
    GDB_O_RDONLY,
 | 
			
		||||
    GDB_O_RDONLY | GDB_O_BINARY,
 | 
			
		||||
    GDB_O_RDWR,
 | 
			
		||||
    GDB_O_RDWR | GDB_O_BINARY,
 | 
			
		||||
    GDB_O_WRONLY | GDB_O_CREAT | GDB_O_TRUNC,
 | 
			
		||||
    GDB_O_WRONLY | GDB_O_CREAT | GDB_O_TRUNC | GDB_O_BINARY,
 | 
			
		||||
    GDB_O_RDWR | GDB_O_CREAT | GDB_O_TRUNC,
 | 
			
		||||
    GDB_O_RDWR | GDB_O_CREAT | GDB_O_TRUNC | GDB_O_BINARY,
 | 
			
		||||
    GDB_O_WRONLY | GDB_O_CREAT | GDB_O_APPEND,
 | 
			
		||||
    GDB_O_WRONLY | GDB_O_CREAT | GDB_O_APPEND | GDB_O_BINARY,
 | 
			
		||||
    GDB_O_RDWR | GDB_O_CREAT | GDB_O_APPEND,
 | 
			
		||||
    GDB_O_RDWR | GDB_O_CREAT | GDB_O_APPEND | GDB_O_BINARY
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static int open_modeflags[12] = {
 | 
			
		||||
    O_RDONLY,
 | 
			
		||||
    O_RDONLY | O_BINARY,
 | 
			
		||||
    O_RDWR,
 | 
			
		||||
    O_RDWR | O_BINARY,
 | 
			
		||||
    O_WRONLY | O_CREAT | O_TRUNC,
 | 
			
		||||
    O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
 | 
			
		||||
    O_RDWR | O_CREAT | O_TRUNC,
 | 
			
		||||
    O_RDWR | O_CREAT | O_TRUNC | O_BINARY,
 | 
			
		||||
    O_WRONLY | O_CREAT | O_APPEND,
 | 
			
		||||
    O_WRONLY | O_CREAT | O_APPEND | O_BINARY,
 | 
			
		||||
    O_RDWR | O_CREAT | O_APPEND,
 | 
			
		||||
    O_RDWR | O_CREAT | O_APPEND | O_BINARY
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#ifdef CONFIG_USER_ONLY
 | 
			
		||||
static inline uint32_t set_swi_errno(TaskState *ts, uint32_t code)
 | 
			
		||||
{
 | 
			
		||||
    if (code == (uint32_t)-1)
 | 
			
		||||
        ts->swi_errno = errno;
 | 
			
		||||
    return code;
 | 
			
		||||
}
 | 
			
		||||
#else
 | 
			
		||||
static inline uint32_t set_swi_errno(CPUState *env, uint32_t code)
 | 
			
		||||
{
 | 
			
		||||
    return code;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#include "softmmu-semi.h"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
static target_ulong arm_semi_syscall_len;
 | 
			
		||||
 | 
			
		||||
#if !defined(CONFIG_USER_ONLY)
 | 
			
		||||
static target_ulong syscall_err;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
static void arm_semi_cb(CPUState *env, target_ulong ret, target_ulong err)
 | 
			
		||||
{
 | 
			
		||||
#ifdef CONFIG_USER_ONLY
 | 
			
		||||
    TaskState *ts = env->opaque;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    if (ret == (target_ulong)-1) {
 | 
			
		||||
#ifdef CONFIG_USER_ONLY
 | 
			
		||||
        ts->swi_errno = err;
 | 
			
		||||
#else
 | 
			
		||||
	syscall_err = err;
 | 
			
		||||
#endif
 | 
			
		||||
        env->regs[0] = ret;
 | 
			
		||||
    } else {
 | 
			
		||||
        /* Fixup syscalls that use nonstardard return conventions.  */
 | 
			
		||||
        switch (env->regs[0]) {
 | 
			
		||||
        case SYS_WRITE:
 | 
			
		||||
        case SYS_READ:
 | 
			
		||||
            env->regs[0] = arm_semi_syscall_len - ret;
 | 
			
		||||
            break;
 | 
			
		||||
        case SYS_SEEK:
 | 
			
		||||
            env->regs[0] = 0;
 | 
			
		||||
            break;
 | 
			
		||||
        default:
 | 
			
		||||
            env->regs[0] = ret;
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void arm_semi_flen_cb(CPUState *env, target_ulong ret, target_ulong err)
 | 
			
		||||
{
 | 
			
		||||
    /* The size is always stored in big-endian order, extract
 | 
			
		||||
       the value. We assume the size always fit in 32 bits.  */
 | 
			
		||||
    uint32_t size;
 | 
			
		||||
    cpu_memory_rw_debug(env, env->regs[13]-64+32, (uint8_t *)&size, 4, 0);
 | 
			
		||||
    env->regs[0] = be32_to_cpu(size);
 | 
			
		||||
#ifdef CONFIG_USER_ONLY
 | 
			
		||||
    ((TaskState *)env->opaque)->swi_errno = err;
 | 
			
		||||
#else
 | 
			
		||||
    syscall_err = err;
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#define ARG(n)					\
 | 
			
		||||
({						\
 | 
			
		||||
    target_ulong __arg;				\
 | 
			
		||||
    /* FIXME - handle get_user() failure */	\
 | 
			
		||||
    get_user_ual(__arg, args + (n) * 4);	\
 | 
			
		||||
    __arg;					\
 | 
			
		||||
})
 | 
			
		||||
#define SET_ARG(n, val) put_user_ual(val, args + (n) * 4)
 | 
			
		||||
uint32_t do_arm_semihosting(CPUState *env)
 | 
			
		||||
{
 | 
			
		||||
    target_ulong args;
 | 
			
		||||
    char * s;
 | 
			
		||||
    int nr;
 | 
			
		||||
    uint32_t ret;
 | 
			
		||||
    uint32_t len;
 | 
			
		||||
#ifdef CONFIG_USER_ONLY
 | 
			
		||||
    TaskState *ts = env->opaque;
 | 
			
		||||
#else
 | 
			
		||||
    CPUState *ts = env;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    nr = env->regs[0];
 | 
			
		||||
    args = env->regs[1];
 | 
			
		||||
    switch (nr) {
 | 
			
		||||
    case SYS_OPEN:
 | 
			
		||||
        if (!(s = lock_user_string(ARG(0))))
 | 
			
		||||
            /* FIXME - should this error code be -TARGET_EFAULT ? */
 | 
			
		||||
            return (uint32_t)-1;
 | 
			
		||||
        if (ARG(1) >= 12)
 | 
			
		||||
            return (uint32_t)-1;
 | 
			
		||||
        if (strcmp(s, ":tt") == 0) {
 | 
			
		||||
            if (ARG(1) < 4)
 | 
			
		||||
                return STDIN_FILENO;
 | 
			
		||||
            else
 | 
			
		||||
                return STDOUT_FILENO;
 | 
			
		||||
        }
 | 
			
		||||
        if (use_gdb_syscalls()) {
 | 
			
		||||
            gdb_do_syscall(arm_semi_cb, "open,%s,%x,1a4", ARG(0),
 | 
			
		||||
			   (int)ARG(2)+1, gdb_open_modeflags[ARG(1)]);
 | 
			
		||||
            return env->regs[0];
 | 
			
		||||
        } else {
 | 
			
		||||
            ret = set_swi_errno(ts, open(s, open_modeflags[ARG(1)], 0644));
 | 
			
		||||
        }
 | 
			
		||||
        unlock_user(s, ARG(0), 0);
 | 
			
		||||
        return ret;
 | 
			
		||||
    case SYS_CLOSE:
 | 
			
		||||
        if (use_gdb_syscalls()) {
 | 
			
		||||
            gdb_do_syscall(arm_semi_cb, "close,%x", ARG(0));
 | 
			
		||||
            return env->regs[0];
 | 
			
		||||
        } else {
 | 
			
		||||
            return set_swi_errno(ts, close(ARG(0)));
 | 
			
		||||
        }
 | 
			
		||||
    case SYS_WRITEC:
 | 
			
		||||
        {
 | 
			
		||||
          char c;
 | 
			
		||||
 | 
			
		||||
          if (get_user_u8(c, args))
 | 
			
		||||
              /* FIXME - should this error code be -TARGET_EFAULT ? */
 | 
			
		||||
              return (uint32_t)-1;
 | 
			
		||||
          /* Write to debug console.  stderr is near enough.  */
 | 
			
		||||
          if (use_gdb_syscalls()) {
 | 
			
		||||
                gdb_do_syscall(arm_semi_cb, "write,2,%x,1", args);
 | 
			
		||||
                return env->regs[0];
 | 
			
		||||
          } else {
 | 
			
		||||
                return write(STDERR_FILENO, &c, 1);
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
    case SYS_WRITE0:
 | 
			
		||||
        if (!(s = lock_user_string(args)))
 | 
			
		||||
            /* FIXME - should this error code be -TARGET_EFAULT ? */
 | 
			
		||||
            return (uint32_t)-1;
 | 
			
		||||
        len = strlen(s);
 | 
			
		||||
        if (use_gdb_syscalls()) {
 | 
			
		||||
            gdb_do_syscall(arm_semi_cb, "write,2,%x,%x\n", args, len);
 | 
			
		||||
            ret = env->regs[0];
 | 
			
		||||
        } else {
 | 
			
		||||
            ret = write(STDERR_FILENO, s, len);
 | 
			
		||||
        }
 | 
			
		||||
        unlock_user(s, args, 0);
 | 
			
		||||
        return ret;
 | 
			
		||||
    case SYS_WRITE:
 | 
			
		||||
        len = ARG(2);
 | 
			
		||||
        if (use_gdb_syscalls()) {
 | 
			
		||||
            arm_semi_syscall_len = len;
 | 
			
		||||
            gdb_do_syscall(arm_semi_cb, "write,%x,%x,%x", ARG(0), ARG(1), len);
 | 
			
		||||
            return env->regs[0];
 | 
			
		||||
        } else {
 | 
			
		||||
            if (!(s = lock_user(VERIFY_READ, ARG(1), len, 1)))
 | 
			
		||||
                /* FIXME - should this error code be -TARGET_EFAULT ? */
 | 
			
		||||
                return (uint32_t)-1;
 | 
			
		||||
            ret = set_swi_errno(ts, write(ARG(0), s, len));
 | 
			
		||||
            unlock_user(s, ARG(1), 0);
 | 
			
		||||
            if (ret == (uint32_t)-1)
 | 
			
		||||
                return -1;
 | 
			
		||||
            return len - ret;
 | 
			
		||||
        }
 | 
			
		||||
    case SYS_READ:
 | 
			
		||||
        len = ARG(2);
 | 
			
		||||
        if (use_gdb_syscalls()) {
 | 
			
		||||
            arm_semi_syscall_len = len;
 | 
			
		||||
            gdb_do_syscall(arm_semi_cb, "read,%x,%x,%x", ARG(0), ARG(1), len);
 | 
			
		||||
            return env->regs[0];
 | 
			
		||||
        } else {
 | 
			
		||||
            if (!(s = lock_user(VERIFY_WRITE, ARG(1), len, 0)))
 | 
			
		||||
                /* FIXME - should this error code be -TARGET_EFAULT ? */
 | 
			
		||||
                return (uint32_t)-1;
 | 
			
		||||
            do
 | 
			
		||||
              ret = set_swi_errno(ts, read(ARG(0), s, len));
 | 
			
		||||
            while (ret == -1 && errno == EINTR);
 | 
			
		||||
            unlock_user(s, ARG(1), len);
 | 
			
		||||
            if (ret == (uint32_t)-1)
 | 
			
		||||
                return -1;
 | 
			
		||||
            return len - ret;
 | 
			
		||||
        }
 | 
			
		||||
    case SYS_READC:
 | 
			
		||||
       /* XXX: Read from debug cosole. Not implemented.  */
 | 
			
		||||
        return 0;
 | 
			
		||||
    case SYS_ISTTY:
 | 
			
		||||
        if (use_gdb_syscalls()) {
 | 
			
		||||
            gdb_do_syscall(arm_semi_cb, "isatty,%x", ARG(0));
 | 
			
		||||
            return env->regs[0];
 | 
			
		||||
        } else {
 | 
			
		||||
            return isatty(ARG(0));
 | 
			
		||||
        }
 | 
			
		||||
    case SYS_SEEK:
 | 
			
		||||
        if (use_gdb_syscalls()) {
 | 
			
		||||
            gdb_do_syscall(arm_semi_cb, "lseek,%x,%x,0", ARG(0), ARG(1));
 | 
			
		||||
            return env->regs[0];
 | 
			
		||||
        } else {
 | 
			
		||||
            ret = set_swi_errno(ts, lseek(ARG(0), ARG(1), SEEK_SET));
 | 
			
		||||
            if (ret == (uint32_t)-1)
 | 
			
		||||
              return -1;
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
    case SYS_FLEN:
 | 
			
		||||
        if (use_gdb_syscalls()) {
 | 
			
		||||
            gdb_do_syscall(arm_semi_flen_cb, "fstat,%x,%x",
 | 
			
		||||
			   ARG(0), env->regs[13]-64);
 | 
			
		||||
            return env->regs[0];
 | 
			
		||||
        } else {
 | 
			
		||||
            struct stat buf;
 | 
			
		||||
            ret = set_swi_errno(ts, fstat(ARG(0), &buf));
 | 
			
		||||
            if (ret == (uint32_t)-1)
 | 
			
		||||
                return -1;
 | 
			
		||||
            return buf.st_size;
 | 
			
		||||
        }
 | 
			
		||||
    case SYS_TMPNAM:
 | 
			
		||||
        /* XXX: Not implemented.  */
 | 
			
		||||
        return -1;
 | 
			
		||||
    case SYS_REMOVE:
 | 
			
		||||
        if (use_gdb_syscalls()) {
 | 
			
		||||
            gdb_do_syscall(arm_semi_cb, "unlink,%s", ARG(0), (int)ARG(1)+1);
 | 
			
		||||
            ret = env->regs[0];
 | 
			
		||||
        } else {
 | 
			
		||||
            if (!(s = lock_user_string(ARG(0))))
 | 
			
		||||
                /* FIXME - should this error code be -TARGET_EFAULT ? */
 | 
			
		||||
                return (uint32_t)-1;
 | 
			
		||||
            ret =  set_swi_errno(ts, remove(s));
 | 
			
		||||
            unlock_user(s, ARG(0), 0);
 | 
			
		||||
        }
 | 
			
		||||
        return ret;
 | 
			
		||||
    case SYS_RENAME:
 | 
			
		||||
        if (use_gdb_syscalls()) {
 | 
			
		||||
            gdb_do_syscall(arm_semi_cb, "rename,%s,%s",
 | 
			
		||||
                           ARG(0), (int)ARG(1)+1, ARG(2), (int)ARG(3)+1);
 | 
			
		||||
            return env->regs[0];
 | 
			
		||||
        } else {
 | 
			
		||||
            char *s2;
 | 
			
		||||
            s = lock_user_string(ARG(0));
 | 
			
		||||
            s2 = lock_user_string(ARG(2));
 | 
			
		||||
            if (!s || !s2)
 | 
			
		||||
                /* FIXME - should this error code be -TARGET_EFAULT ? */
 | 
			
		||||
                ret = (uint32_t)-1;
 | 
			
		||||
            else
 | 
			
		||||
                ret = set_swi_errno(ts, rename(s, s2));
 | 
			
		||||
            if (s2)
 | 
			
		||||
                unlock_user(s2, ARG(2), 0);
 | 
			
		||||
            if (s)
 | 
			
		||||
                unlock_user(s, ARG(0), 0);
 | 
			
		||||
            return ret;
 | 
			
		||||
        }
 | 
			
		||||
    case SYS_CLOCK:
 | 
			
		||||
        return clock() / (CLOCKS_PER_SEC / 100);
 | 
			
		||||
    case SYS_TIME:
 | 
			
		||||
        return set_swi_errno(ts, time(NULL));
 | 
			
		||||
    case SYS_SYSTEM:
 | 
			
		||||
        if (use_gdb_syscalls()) {
 | 
			
		||||
            gdb_do_syscall(arm_semi_cb, "system,%s", ARG(0), (int)ARG(1)+1);
 | 
			
		||||
            return env->regs[0];
 | 
			
		||||
        } else {
 | 
			
		||||
            if (!(s = lock_user_string(ARG(0))))
 | 
			
		||||
                /* FIXME - should this error code be -TARGET_EFAULT ? */
 | 
			
		||||
                return (uint32_t)-1;
 | 
			
		||||
            ret = set_swi_errno(ts, system(s));
 | 
			
		||||
            unlock_user(s, ARG(0), 0);
 | 
			
		||||
            return ret;
 | 
			
		||||
        }
 | 
			
		||||
    case SYS_ERRNO:
 | 
			
		||||
#ifdef CONFIG_USER_ONLY
 | 
			
		||||
        return ts->swi_errno;
 | 
			
		||||
#else
 | 
			
		||||
        return syscall_err;
 | 
			
		||||
#endif
 | 
			
		||||
    case SYS_GET_CMDLINE:
 | 
			
		||||
        {
 | 
			
		||||
            /* Build a command-line from the original argv.
 | 
			
		||||
             *
 | 
			
		||||
             * The inputs are:
 | 
			
		||||
             *     * ARG(0), pointer to a buffer of at least the size
 | 
			
		||||
             *               specified in ARG(1).
 | 
			
		||||
             *     * ARG(1), size of the buffer pointed to by ARG(0) in
 | 
			
		||||
             *               bytes.
 | 
			
		||||
             *
 | 
			
		||||
             * The outputs are:
 | 
			
		||||
             *     * ARG(0), pointer to null-terminated string of the
 | 
			
		||||
             *               command line.
 | 
			
		||||
             *     * ARG(1), length of the string pointed to by ARG(0).
 | 
			
		||||
             */
 | 
			
		||||
 | 
			
		||||
            char *output_buffer;
 | 
			
		||||
            size_t input_size = ARG(1);
 | 
			
		||||
            size_t output_size;
 | 
			
		||||
            int status = 0;
 | 
			
		||||
 | 
			
		||||
            /* Compute the size of the output string.  */
 | 
			
		||||
#if !defined(CONFIG_USER_ONLY)
 | 
			
		||||
            output_size = strlen(ts->boot_info->kernel_filename)
 | 
			
		||||
                        + 1  /* Separating space.  */
 | 
			
		||||
                        + strlen(ts->boot_info->kernel_cmdline)
 | 
			
		||||
                        + 1; /* Terminating null byte.  */
 | 
			
		||||
#else
 | 
			
		||||
            unsigned int i;
 | 
			
		||||
 | 
			
		||||
            output_size = ts->info->arg_end - ts->info->arg_start;
 | 
			
		||||
            if (!output_size) {
 | 
			
		||||
                /* We special-case the "empty command line" case (argc==0).
 | 
			
		||||
                   Just provide the terminating 0. */
 | 
			
		||||
                output_size = 1;
 | 
			
		||||
            }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
            if (output_size > input_size) {
 | 
			
		||||
                 /* Not enough space to store command-line arguments.  */
 | 
			
		||||
                return -1;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            /* Adjust the command-line length.  */
 | 
			
		||||
            SET_ARG(1, output_size - 1);
 | 
			
		||||
 | 
			
		||||
            /* Lock the buffer on the ARM side.  */
 | 
			
		||||
            output_buffer = lock_user(VERIFY_WRITE, ARG(0), output_size, 0);
 | 
			
		||||
            if (!output_buffer) {
 | 
			
		||||
                return -1;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            /* Copy the command-line arguments.  */
 | 
			
		||||
#if !defined(CONFIG_USER_ONLY)
 | 
			
		||||
            pstrcpy(output_buffer, output_size, ts->boot_info->kernel_filename);
 | 
			
		||||
            pstrcat(output_buffer, output_size, " ");
 | 
			
		||||
            pstrcat(output_buffer, output_size, ts->boot_info->kernel_cmdline);
 | 
			
		||||
#else
 | 
			
		||||
            if (output_size == 1) {
 | 
			
		||||
                /* Empty command-line.  */
 | 
			
		||||
                output_buffer[0] = '\0';
 | 
			
		||||
                goto out;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (copy_from_user(output_buffer, ts->info->arg_start,
 | 
			
		||||
                               output_size)) {
 | 
			
		||||
                status = -1;
 | 
			
		||||
                goto out;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            /* Separate arguments by white spaces.  */
 | 
			
		||||
            for (i = 0; i < output_size - 1; i++) {
 | 
			
		||||
                if (output_buffer[i] == 0) {
 | 
			
		||||
                    output_buffer[i] = ' ';
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        out:
 | 
			
		||||
#endif
 | 
			
		||||
            /* Unlock the buffer on the ARM side.  */
 | 
			
		||||
            unlock_user(output_buffer, ARG(0), output_size);
 | 
			
		||||
 | 
			
		||||
            return status;
 | 
			
		||||
        }
 | 
			
		||||
    case SYS_HEAPINFO:
 | 
			
		||||
        {
 | 
			
		||||
            uint32_t *ptr;
 | 
			
		||||
            uint32_t limit;
 | 
			
		||||
 | 
			
		||||
#ifdef CONFIG_USER_ONLY
 | 
			
		||||
            /* Some C libraries assume the heap immediately follows .bss, so
 | 
			
		||||
               allocate it using sbrk.  */
 | 
			
		||||
            if (!ts->heap_limit) {
 | 
			
		||||
                abi_ulong ret;
 | 
			
		||||
 | 
			
		||||
                ts->heap_base = do_brk(0);
 | 
			
		||||
                limit = ts->heap_base + ARM_ANGEL_HEAP_SIZE;
 | 
			
		||||
                /* Try a big heap, and reduce the size if that fails.  */
 | 
			
		||||
                for (;;) {
 | 
			
		||||
                    ret = do_brk(limit);
 | 
			
		||||
                    if (ret >= limit) {
 | 
			
		||||
                        break;
 | 
			
		||||
                    }
 | 
			
		||||
                    limit = (ts->heap_base >> 1) + (limit >> 1);
 | 
			
		||||
                }
 | 
			
		||||
                ts->heap_limit = limit;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (!(ptr = lock_user(VERIFY_WRITE, ARG(0), 16, 0)))
 | 
			
		||||
                /* FIXME - should this error code be -TARGET_EFAULT ? */
 | 
			
		||||
                return (uint32_t)-1;
 | 
			
		||||
            ptr[0] = tswap32(ts->heap_base);
 | 
			
		||||
            ptr[1] = tswap32(ts->heap_limit);
 | 
			
		||||
            ptr[2] = tswap32(ts->stack_base);
 | 
			
		||||
            ptr[3] = tswap32(0); /* Stack limit.  */
 | 
			
		||||
            unlock_user(ptr, ARG(0), 16);
 | 
			
		||||
#else
 | 
			
		||||
            limit = ram_size;
 | 
			
		||||
            if (!(ptr = lock_user(VERIFY_WRITE, ARG(0), 16, 0)))
 | 
			
		||||
                /* FIXME - should this error code be -TARGET_EFAULT ? */
 | 
			
		||||
                return (uint32_t)-1;
 | 
			
		||||
            /* TODO: Make this use the limit of the loaded application.  */
 | 
			
		||||
            ptr[0] = tswap32(limit / 2);
 | 
			
		||||
            ptr[1] = tswap32(limit);
 | 
			
		||||
            ptr[2] = tswap32(limit); /* Stack base */
 | 
			
		||||
            ptr[3] = tswap32(0); /* Stack limit.  */
 | 
			
		||||
            unlock_user(ptr, ARG(0), 16);
 | 
			
		||||
#endif
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
    case SYS_EXIT:
 | 
			
		||||
        gdb_exit(env, 0);
 | 
			
		||||
        exit(0);
 | 
			
		||||
    default:
 | 
			
		||||
        fprintf(stderr, "qemu: Unsupported SemiHosting SWI 0x%02x\n", nr);
 | 
			
		||||
        cpu_dump_state(env, stderr, fprintf, 0);
 | 
			
		||||
        abort();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										153
									
								
								arm.ld
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										153
									
								
								arm.ld
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,153 @@
 | 
			
		||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm",
 | 
			
		||||
	      "elf32-littlearm")
 | 
			
		||||
OUTPUT_ARCH(arm)
 | 
			
		||||
ENTRY(_start)
 | 
			
		||||
SECTIONS
 | 
			
		||||
{
 | 
			
		||||
  /* Read-only sections, merged into text segment: */
 | 
			
		||||
  . = 0x60000000 + SIZEOF_HEADERS;
 | 
			
		||||
  .interp     : { *(.interp) 	}
 | 
			
		||||
  .hash          : { *(.hash)		}
 | 
			
		||||
  .dynsym        : { *(.dynsym)		}
 | 
			
		||||
  .dynstr        : { *(.dynstr)		}
 | 
			
		||||
  .gnu.version   : { *(.gnu.version)	}
 | 
			
		||||
  .gnu.version_d   : { *(.gnu.version_d)	}
 | 
			
		||||
  .gnu.version_r   : { *(.gnu.version_r)	}
 | 
			
		||||
  .rel.text      :
 | 
			
		||||
    { *(.rel.text) *(.rel.gnu.linkonce.t*) }
 | 
			
		||||
  .rela.text     :
 | 
			
		||||
    { *(.rela.text) *(.rela.gnu.linkonce.t*) }
 | 
			
		||||
  .rel.data      :
 | 
			
		||||
    { *(.rel.data) *(.rel.gnu.linkonce.d*) }
 | 
			
		||||
  .rela.data     :
 | 
			
		||||
    { *(.rela.data) *(.rela.gnu.linkonce.d*) }
 | 
			
		||||
  .rel.rodata    :
 | 
			
		||||
    { *(.rel.rodata) *(.rel.gnu.linkonce.r*) }
 | 
			
		||||
  .rela.rodata   :
 | 
			
		||||
    { *(.rela.rodata) *(.rela.gnu.linkonce.r*) }
 | 
			
		||||
  .rel.got       : { *(.rel.got)		}
 | 
			
		||||
  .rela.got      : { *(.rela.got)		}
 | 
			
		||||
  .rel.ctors     : { *(.rel.ctors)	}
 | 
			
		||||
  .rela.ctors    : { *(.rela.ctors)	}
 | 
			
		||||
  .rel.dtors     : { *(.rel.dtors)	}
 | 
			
		||||
  .rela.dtors    : { *(.rela.dtors)	}
 | 
			
		||||
  .rel.init      : { *(.rel.init)	}
 | 
			
		||||
  .rela.init     : { *(.rela.init)	}
 | 
			
		||||
  .rel.fini      : { *(.rel.fini)	}
 | 
			
		||||
  .rela.fini     : { *(.rela.fini)	}
 | 
			
		||||
  .rel.bss       : { *(.rel.bss)		}
 | 
			
		||||
  .rela.bss      : { *(.rela.bss)		}
 | 
			
		||||
  .rel.plt       : { *(.rel.plt)		}
 | 
			
		||||
  .rela.plt      : { *(.rela.plt)		}
 | 
			
		||||
  .init          : { *(.init)	} =0x47ff041f
 | 
			
		||||
  .text      :
 | 
			
		||||
  {
 | 
			
		||||
    *(.text)
 | 
			
		||||
    /* .gnu.warning sections are handled specially by elf32.em.  */
 | 
			
		||||
    *(.gnu.warning)
 | 
			
		||||
    *(.gnu.linkonce.t*)
 | 
			
		||||
  } =0x47ff041f
 | 
			
		||||
  _etext = .;
 | 
			
		||||
  PROVIDE (etext = .);
 | 
			
		||||
  .fini      : { *(.fini)    } =0x47ff041f
 | 
			
		||||
  .rodata    : { *(.rodata) *(.gnu.linkonce.r*) }
 | 
			
		||||
  .rodata1   : { *(.rodata1) }
 | 
			
		||||
  .ARM.extab   : { *(.ARM.extab* .gnu.linkonce.armextab.*) }
 | 
			
		||||
   __exidx_start = .;
 | 
			
		||||
  .ARM.exidx   : { *(.ARM.exidx* .gnu.linkonce.armexidx.*) }
 | 
			
		||||
   __exidx_end = .;
 | 
			
		||||
  .reginfo : { *(.reginfo) }
 | 
			
		||||
  /* Adjust the address for the data segment.  We want to adjust up to
 | 
			
		||||
     the same address within the page on the next page up.  */
 | 
			
		||||
  . = ALIGN(0x100000) + (. & (0x100000 - 1));
 | 
			
		||||
  .data    :
 | 
			
		||||
  {
 | 
			
		||||
    *(.gen_code)
 | 
			
		||||
    *(.data)
 | 
			
		||||
    *(.gnu.linkonce.d*)
 | 
			
		||||
    CONSTRUCTORS
 | 
			
		||||
  }
 | 
			
		||||
  .tbss           : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
 | 
			
		||||
  .data1   : { *(.data1) }
 | 
			
		||||
  .preinit_array     :
 | 
			
		||||
  {
 | 
			
		||||
    PROVIDE (__preinit_array_start = .);
 | 
			
		||||
    KEEP (*(.preinit_array))
 | 
			
		||||
    PROVIDE (__preinit_array_end = .);
 | 
			
		||||
  }
 | 
			
		||||
  .init_array     :
 | 
			
		||||
  {
 | 
			
		||||
     PROVIDE (__init_array_start = .);
 | 
			
		||||
     KEEP (*(SORT(.init_array.*)))
 | 
			
		||||
     KEEP (*(.init_array))
 | 
			
		||||
     PROVIDE (__init_array_end = .);
 | 
			
		||||
  }
 | 
			
		||||
  .fini_array     :
 | 
			
		||||
  {
 | 
			
		||||
    PROVIDE (__fini_array_start = .);
 | 
			
		||||
    KEEP (*(.fini_array))
 | 
			
		||||
    KEEP (*(SORT(.fini_array.*)))
 | 
			
		||||
    PROVIDE (__fini_array_end = .);
 | 
			
		||||
  }
 | 
			
		||||
  .ctors         :
 | 
			
		||||
  {
 | 
			
		||||
    *(.ctors)
 | 
			
		||||
  }
 | 
			
		||||
  .dtors         :
 | 
			
		||||
  {
 | 
			
		||||
    *(.dtors)
 | 
			
		||||
  }
 | 
			
		||||
  .plt      : { *(.plt)	}
 | 
			
		||||
  .got           : { *(.got.plt) *(.got) }
 | 
			
		||||
  .dynamic       : { *(.dynamic) }
 | 
			
		||||
  /* We want the small data sections together, so single-instruction offsets
 | 
			
		||||
     can access them all, and initialized data all before uninitialized, so
 | 
			
		||||
     we can shorten the on-disk segment size.  */
 | 
			
		||||
  .sdata     : { *(.sdata) }
 | 
			
		||||
  _edata  =  .;
 | 
			
		||||
  PROVIDE (edata = .);
 | 
			
		||||
  __bss_start = .;
 | 
			
		||||
  .sbss      : { *(.sbss) *(.scommon) }
 | 
			
		||||
  .bss       :
 | 
			
		||||
  {
 | 
			
		||||
   *(.dynbss)
 | 
			
		||||
   *(.bss)
 | 
			
		||||
   *(COMMON)
 | 
			
		||||
  }
 | 
			
		||||
  _end = . ;
 | 
			
		||||
  PROVIDE (end = .);
 | 
			
		||||
  /* Stabs debugging sections.  */
 | 
			
		||||
  .stab 0 : { *(.stab) }
 | 
			
		||||
  .stabstr 0 : { *(.stabstr) }
 | 
			
		||||
  .stab.excl 0 : { *(.stab.excl) }
 | 
			
		||||
  .stab.exclstr 0 : { *(.stab.exclstr) }
 | 
			
		||||
  .stab.index 0 : { *(.stab.index) }
 | 
			
		||||
  .stab.indexstr 0 : { *(.stab.indexstr) }
 | 
			
		||||
  .comment 0 : { *(.comment) }
 | 
			
		||||
  /* DWARF debug sections.
 | 
			
		||||
     Symbols in the DWARF debugging sections are relative to the beginning
 | 
			
		||||
     of the section so we begin them at 0.  */
 | 
			
		||||
  /* DWARF 1 */
 | 
			
		||||
  .debug          0 : { *(.debug) }
 | 
			
		||||
  .line           0 : { *(.line) }
 | 
			
		||||
  /* GNU DWARF 1 extensions */
 | 
			
		||||
  .debug_srcinfo  0 : { *(.debug_srcinfo) }
 | 
			
		||||
  .debug_sfnames  0 : { *(.debug_sfnames) }
 | 
			
		||||
  /* DWARF 1.1 and DWARF 2 */
 | 
			
		||||
  .debug_aranges  0 : { *(.debug_aranges) }
 | 
			
		||||
  .debug_pubnames 0 : { *(.debug_pubnames) }
 | 
			
		||||
  /* DWARF 2 */
 | 
			
		||||
  .debug_info     0 : { *(.debug_info) }
 | 
			
		||||
  .debug_abbrev   0 : { *(.debug_abbrev) }
 | 
			
		||||
  .debug_line     0 : { *(.debug_line) }
 | 
			
		||||
  .debug_frame    0 : { *(.debug_frame) }
 | 
			
		||||
  .debug_str      0 : { *(.debug_str) }
 | 
			
		||||
  .debug_loc      0 : { *(.debug_loc) }
 | 
			
		||||
  .debug_macinfo  0 : { *(.debug_macinfo) }
 | 
			
		||||
  /* SGI/MIPS DWARF 2 extensions */
 | 
			
		||||
  .debug_weaknames 0 : { *(.debug_weaknames) }
 | 
			
		||||
  .debug_funcnames 0 : { *(.debug_funcnames) }
 | 
			
		||||
  .debug_typenames 0 : { *(.debug_typenames) }
 | 
			
		||||
  .debug_varnames  0 : { *(.debug_varnames) }
 | 
			
		||||
  /* These must appear regardless of  .  */
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										217
									
								
								async.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										217
									
								
								async.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,217 @@
 | 
			
		||||
/*
 | 
			
		||||
 * QEMU System Emulator
 | 
			
		||||
 *
 | 
			
		||||
 * Copyright (c) 2003-2008 Fabrice Bellard
 | 
			
		||||
 *
 | 
			
		||||
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
			
		||||
 * of this software and associated documentation files (the "Software"), to deal
 | 
			
		||||
 * in the Software without restriction, including without limitation the rights
 | 
			
		||||
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
			
		||||
 * copies of the Software, and to permit persons to whom the Software is
 | 
			
		||||
 * furnished to do so, subject to the following conditions:
 | 
			
		||||
 *
 | 
			
		||||
 * The above copyright notice and this permission notice shall be included in
 | 
			
		||||
 * all copies or substantial portions of the Software.
 | 
			
		||||
 *
 | 
			
		||||
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 | 
			
		||||
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
			
		||||
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
			
		||||
 * THE SOFTWARE.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "qemu-common.h"
 | 
			
		||||
#include "qemu-aio.h"
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * An AsyncContext protects the callbacks of AIO requests and Bottom Halves
 | 
			
		||||
 * against interfering with each other. A typical example is qcow2 that accepts
 | 
			
		||||
 * asynchronous requests, but relies for manipulation of its metadata on
 | 
			
		||||
 * synchronous bdrv_read/write that doesn't trigger any callbacks.
 | 
			
		||||
 *
 | 
			
		||||
 * However, these functions are often emulated using AIO which means that AIO
 | 
			
		||||
 * callbacks must be run - but at the same time we must not run callbacks of
 | 
			
		||||
 * other requests as they might start to modify metadata and corrupt the
 | 
			
		||||
 * internal state of the caller of bdrv_read/write.
 | 
			
		||||
 *
 | 
			
		||||
 * To achieve the desired semantics we switch into a new AsyncContext.
 | 
			
		||||
 * Callbacks must only be run if they belong to the current AsyncContext.
 | 
			
		||||
 * Otherwise they need to be queued until their own context is active again.
 | 
			
		||||
 * This is how you can make qemu_aio_wait() wait only for your own callbacks.
 | 
			
		||||
 *
 | 
			
		||||
 * The AsyncContexts form a stack. When you leave a AsyncContexts, you always
 | 
			
		||||
 * return to the old ("parent") context.
 | 
			
		||||
 */
 | 
			
		||||
struct AsyncContext {
 | 
			
		||||
    /* Consecutive number of the AsyncContext (position in the stack) */
 | 
			
		||||
    int id;
 | 
			
		||||
 | 
			
		||||
    /* Anchor of the list of Bottom Halves belonging to the context */
 | 
			
		||||
    struct QEMUBH *first_bh;
 | 
			
		||||
 | 
			
		||||
    /* Link to parent context */
 | 
			
		||||
    struct AsyncContext *parent;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
/* The currently active AsyncContext */
 | 
			
		||||
static struct AsyncContext *async_context = &(struct AsyncContext) { 0 };
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Enter a new AsyncContext. Already scheduled Bottom Halves and AIO callbacks
 | 
			
		||||
 * won't be called until this context is left again.
 | 
			
		||||
 */
 | 
			
		||||
void async_context_push(void)
 | 
			
		||||
{
 | 
			
		||||
    struct AsyncContext *new = qemu_mallocz(sizeof(*new));
 | 
			
		||||
    new->parent = async_context;
 | 
			
		||||
    new->id = async_context->id + 1;
 | 
			
		||||
    async_context = new;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* Run queued AIO completions and destroy Bottom Half */
 | 
			
		||||
static void bh_run_aio_completions(void *opaque)
 | 
			
		||||
{
 | 
			
		||||
    QEMUBH **bh = opaque;
 | 
			
		||||
    qemu_bh_delete(*bh);
 | 
			
		||||
    qemu_free(bh);
 | 
			
		||||
    qemu_aio_process_queue();
 | 
			
		||||
}
 | 
			
		||||
/*
 | 
			
		||||
 * Leave the currently active AsyncContext. All Bottom Halves belonging to the
 | 
			
		||||
 * old context are executed before changing the context.
 | 
			
		||||
 */
 | 
			
		||||
void async_context_pop(void)
 | 
			
		||||
{
 | 
			
		||||
    struct AsyncContext *old = async_context;
 | 
			
		||||
    QEMUBH **bh;
 | 
			
		||||
 | 
			
		||||
    /* Flush the bottom halves, we don't want to lose them */
 | 
			
		||||
    while (qemu_bh_poll());
 | 
			
		||||
 | 
			
		||||
    /* Switch back to the parent context */
 | 
			
		||||
    async_context = async_context->parent;
 | 
			
		||||
    qemu_free(old);
 | 
			
		||||
 | 
			
		||||
    if (async_context == NULL) {
 | 
			
		||||
        abort();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* Schedule BH to run any queued AIO completions as soon as possible */
 | 
			
		||||
    bh = qemu_malloc(sizeof(*bh));
 | 
			
		||||
    *bh = qemu_bh_new(bh_run_aio_completions, bh);
 | 
			
		||||
    qemu_bh_schedule(*bh);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Returns the ID of the currently active AsyncContext
 | 
			
		||||
 */
 | 
			
		||||
int get_async_context_id(void)
 | 
			
		||||
{
 | 
			
		||||
    return async_context->id;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/***********************************************************/
 | 
			
		||||
/* bottom halves (can be seen as timers which expire ASAP) */
 | 
			
		||||
 | 
			
		||||
struct QEMUBH {
 | 
			
		||||
    QEMUBHFunc *cb;
 | 
			
		||||
    void *opaque;
 | 
			
		||||
    int scheduled;
 | 
			
		||||
    int idle;
 | 
			
		||||
    int deleted;
 | 
			
		||||
    QEMUBH *next;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
QEMUBH *qemu_bh_new(QEMUBHFunc *cb, void *opaque)
 | 
			
		||||
{
 | 
			
		||||
    QEMUBH *bh;
 | 
			
		||||
    bh = qemu_mallocz(sizeof(QEMUBH));
 | 
			
		||||
    bh->cb = cb;
 | 
			
		||||
    bh->opaque = opaque;
 | 
			
		||||
    bh->next = async_context->first_bh;
 | 
			
		||||
    async_context->first_bh = bh;
 | 
			
		||||
    return bh;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int qemu_bh_poll(void)
 | 
			
		||||
{
 | 
			
		||||
    QEMUBH *bh, **bhp, *next;
 | 
			
		||||
    int ret;
 | 
			
		||||
 | 
			
		||||
    ret = 0;
 | 
			
		||||
    for (bh = async_context->first_bh; bh; bh = next) {
 | 
			
		||||
        next = bh->next;
 | 
			
		||||
        if (!bh->deleted && bh->scheduled) {
 | 
			
		||||
            bh->scheduled = 0;
 | 
			
		||||
            if (!bh->idle)
 | 
			
		||||
                ret = 1;
 | 
			
		||||
            bh->idle = 0;
 | 
			
		||||
            bh->cb(bh->opaque);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* remove deleted bhs */
 | 
			
		||||
    bhp = &async_context->first_bh;
 | 
			
		||||
    while (*bhp) {
 | 
			
		||||
        bh = *bhp;
 | 
			
		||||
        if (bh->deleted) {
 | 
			
		||||
            *bhp = bh->next;
 | 
			
		||||
            qemu_free(bh);
 | 
			
		||||
        } else
 | 
			
		||||
            bhp = &bh->next;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void qemu_bh_schedule_idle(QEMUBH *bh)
 | 
			
		||||
{
 | 
			
		||||
    if (bh->scheduled)
 | 
			
		||||
        return;
 | 
			
		||||
    bh->scheduled = 1;
 | 
			
		||||
    bh->idle = 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void qemu_bh_schedule(QEMUBH *bh)
 | 
			
		||||
{
 | 
			
		||||
    if (bh->scheduled)
 | 
			
		||||
        return;
 | 
			
		||||
    bh->scheduled = 1;
 | 
			
		||||
    bh->idle = 0;
 | 
			
		||||
    /* stop the currently executing CPU to execute the BH ASAP */
 | 
			
		||||
    qemu_notify_event();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void qemu_bh_cancel(QEMUBH *bh)
 | 
			
		||||
{
 | 
			
		||||
    bh->scheduled = 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void qemu_bh_delete(QEMUBH *bh)
 | 
			
		||||
{
 | 
			
		||||
    bh->scheduled = 0;
 | 
			
		||||
    bh->deleted = 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void qemu_bh_update_timeout(int *timeout)
 | 
			
		||||
{
 | 
			
		||||
    QEMUBH *bh;
 | 
			
		||||
 | 
			
		||||
    for (bh = async_context->first_bh; bh; bh = bh->next) {
 | 
			
		||||
        if (!bh->deleted && bh->scheduled) {
 | 
			
		||||
            if (bh->idle) {
 | 
			
		||||
                /* idle bottom halves will be polled at least
 | 
			
		||||
                 * every 10ms */
 | 
			
		||||
                *timeout = MIN(10, *timeout);
 | 
			
		||||
            } else {
 | 
			
		||||
                /* non-idle bottom halves will be executed
 | 
			
		||||
                 * immediately */
 | 
			
		||||
                *timeout = 0;
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -1,31 +0,0 @@
 | 
			
		||||
common-obj-y = audio.o audio_legacy.o noaudio.o wavaudio.o mixeng.o
 | 
			
		||||
common-obj-$(CONFIG_SPICE) += spiceaudio.o
 | 
			
		||||
common-obj-$(CONFIG_AUDIO_COREAUDIO) += coreaudio.o
 | 
			
		||||
common-obj-$(CONFIG_AUDIO_DSOUND) += dsoundaudio.o
 | 
			
		||||
common-obj-$(CONFIG_AUDIO_PT_INT) += audio_pt_int.o
 | 
			
		||||
common-obj-$(CONFIG_AUDIO_WIN_INT) += audio_win_int.o
 | 
			
		||||
common-obj-y += wavcapture.o
 | 
			
		||||
 | 
			
		||||
coreaudio.o-libs := $(COREAUDIO_LIBS)
 | 
			
		||||
dsoundaudio.o-libs := $(DSOUND_LIBS)
 | 
			
		||||
 | 
			
		||||
# alsa module
 | 
			
		||||
common-obj-$(CONFIG_AUDIO_ALSA) += alsa.mo
 | 
			
		||||
alsa.mo-objs = alsaaudio.o
 | 
			
		||||
alsa.mo-libs := $(ALSA_LIBS)
 | 
			
		||||
 | 
			
		||||
# oss module
 | 
			
		||||
common-obj-$(CONFIG_AUDIO_OSS) += oss.mo
 | 
			
		||||
oss.mo-objs = ossaudio.o
 | 
			
		||||
oss.mo-libs := $(OSS_LIBS)
 | 
			
		||||
 | 
			
		||||
# pulseaudio module
 | 
			
		||||
common-obj-$(CONFIG_AUDIO_PA) += pa.mo
 | 
			
		||||
pa.mo-objs = paaudio.o
 | 
			
		||||
pa.mo-libs := $(PULSE_LIBS)
 | 
			
		||||
 | 
			
		||||
# sdl module
 | 
			
		||||
common-obj-$(CONFIG_AUDIO_SDL) += sdl.mo
 | 
			
		||||
sdl.mo-objs = sdlaudio.o
 | 
			
		||||
sdl.mo-cflags := $(SDL_CFLAGS)
 | 
			
		||||
sdl.mo-libs := $(SDL_LIBS)
 | 
			
		||||
@@ -21,15 +21,14 @@
 | 
			
		||||
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
			
		||||
 * THE SOFTWARE.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "qemu/osdep.h"
 | 
			
		||||
#include <alsa/asoundlib.h>
 | 
			
		||||
#include "qemu/main-loop.h"
 | 
			
		||||
#include "qemu/module.h"
 | 
			
		||||
#include "qemu-common.h"
 | 
			
		||||
#include "qemu-char.h"
 | 
			
		||||
#include "audio.h"
 | 
			
		||||
#include "trace.h"
 | 
			
		||||
 | 
			
		||||
#if QEMU_GNUC_PREREQ(4, 3)
 | 
			
		||||
#pragma GCC diagnostic ignored "-Waddress"
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define AUDIO_CAP "alsa"
 | 
			
		||||
#include "audio_int.h"
 | 
			
		||||
@@ -48,7 +47,6 @@ typedef struct ALSAVoiceOut {
 | 
			
		||||
    void *pcm_buf;
 | 
			
		||||
    snd_pcm_t *handle;
 | 
			
		||||
    struct pollhlp pollhlp;
 | 
			
		||||
    Audiodev *dev;
 | 
			
		||||
} ALSAVoiceOut;
 | 
			
		||||
 | 
			
		||||
typedef struct ALSAVoiceIn {
 | 
			
		||||
@@ -56,18 +54,45 @@ typedef struct ALSAVoiceIn {
 | 
			
		||||
    snd_pcm_t *handle;
 | 
			
		||||
    void *pcm_buf;
 | 
			
		||||
    struct pollhlp pollhlp;
 | 
			
		||||
    Audiodev *dev;
 | 
			
		||||
} ALSAVoiceIn;
 | 
			
		||||
 | 
			
		||||
static struct {
 | 
			
		||||
    int size_in_usec_in;
 | 
			
		||||
    int size_in_usec_out;
 | 
			
		||||
    const char *pcm_name_in;
 | 
			
		||||
    const char *pcm_name_out;
 | 
			
		||||
    unsigned int buffer_size_in;
 | 
			
		||||
    unsigned int period_size_in;
 | 
			
		||||
    unsigned int buffer_size_out;
 | 
			
		||||
    unsigned int period_size_out;
 | 
			
		||||
    unsigned int threshold;
 | 
			
		||||
 | 
			
		||||
    int buffer_size_in_overridden;
 | 
			
		||||
    int period_size_in_overridden;
 | 
			
		||||
 | 
			
		||||
    int buffer_size_out_overridden;
 | 
			
		||||
    int period_size_out_overridden;
 | 
			
		||||
    int verbose;
 | 
			
		||||
} conf = {
 | 
			
		||||
    .buffer_size_out = 4096,
 | 
			
		||||
    .period_size_out = 1024,
 | 
			
		||||
    .pcm_name_out = "default",
 | 
			
		||||
    .pcm_name_in = "default",
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct alsa_params_req {
 | 
			
		||||
    int freq;
 | 
			
		||||
    snd_pcm_format_t fmt;
 | 
			
		||||
    int nchannels;
 | 
			
		||||
    int size_in_usec;
 | 
			
		||||
    int override_mask;
 | 
			
		||||
    unsigned int buffer_size;
 | 
			
		||||
    unsigned int period_size;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct alsa_params_obt {
 | 
			
		||||
    int freq;
 | 
			
		||||
    AudioFormat fmt;
 | 
			
		||||
    audfmt_e fmt;
 | 
			
		||||
    int endianness;
 | 
			
		||||
    int nchannels;
 | 
			
		||||
    snd_pcm_uframes_t samples;
 | 
			
		||||
@@ -111,7 +136,7 @@ static void alsa_fini_poll (struct pollhlp *hlp)
 | 
			
		||||
        for (i = 0; i < hlp->count; ++i) {
 | 
			
		||||
            qemu_set_fd_handler (pfds[i].fd, NULL, NULL, NULL);
 | 
			
		||||
        }
 | 
			
		||||
        g_free (pfds);
 | 
			
		||||
        qemu_free (pfds);
 | 
			
		||||
    }
 | 
			
		||||
    hlp->pfds = NULL;
 | 
			
		||||
    hlp->count = 0;
 | 
			
		||||
@@ -180,7 +205,9 @@ static void alsa_poll_handler (void *opaque)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!(revents & hlp->mask)) {
 | 
			
		||||
        trace_alsa_revents(revents);
 | 
			
		||||
        if (conf.verbose) {
 | 
			
		||||
            dolog ("revents = %d\n", revents);
 | 
			
		||||
        }
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -233,20 +260,37 @@ static int alsa_poll_helper (snd_pcm_t *handle, struct pollhlp *hlp, int mask)
 | 
			
		||||
    if (err < 0) {
 | 
			
		||||
        alsa_logerr (err, "Could not initialize poll mode\n"
 | 
			
		||||
                     "Could not obtain poll descriptors\n");
 | 
			
		||||
        g_free (pfds);
 | 
			
		||||
        qemu_free (pfds);
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    for (i = 0; i < count; ++i) {
 | 
			
		||||
        if (pfds[i].events & POLLIN) {
 | 
			
		||||
            qemu_set_fd_handler (pfds[i].fd, alsa_poll_handler, NULL, hlp);
 | 
			
		||||
            err = qemu_set_fd_handler (pfds[i].fd, alsa_poll_handler,
 | 
			
		||||
                                       NULL, hlp);
 | 
			
		||||
        }
 | 
			
		||||
        if (pfds[i].events & POLLOUT) {
 | 
			
		||||
            trace_alsa_pollout(i, pfds[i].fd);
 | 
			
		||||
            qemu_set_fd_handler (pfds[i].fd, NULL, alsa_poll_handler, hlp);
 | 
			
		||||
            if (conf.verbose) {
 | 
			
		||||
                dolog ("POLLOUT %d %d\n", i, pfds[i].fd);
 | 
			
		||||
            }
 | 
			
		||||
            err = qemu_set_fd_handler (pfds[i].fd, NULL,
 | 
			
		||||
                                       alsa_poll_handler, hlp);
 | 
			
		||||
        }
 | 
			
		||||
        if (conf.verbose) {
 | 
			
		||||
            dolog ("Set handler events=%#x index=%d fd=%d err=%d\n",
 | 
			
		||||
                   pfds[i].events, i, pfds[i].fd, err);
 | 
			
		||||
        }
 | 
			
		||||
        trace_alsa_set_handler(pfds[i].events, i, pfds[i].fd, err);
 | 
			
		||||
 | 
			
		||||
        if (err) {
 | 
			
		||||
            dolog ("Failed to set handler events=%#x index=%d fd=%d err=%d\n",
 | 
			
		||||
                   pfds[i].events, i, pfds[i].fd, err);
 | 
			
		||||
 | 
			
		||||
            while (i--) {
 | 
			
		||||
                qemu_set_fd_handler (pfds[i].fd, NULL, NULL, NULL);
 | 
			
		||||
            }
 | 
			
		||||
            qemu_free (pfds);
 | 
			
		||||
            return -1;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    hlp->pfds = pfds;
 | 
			
		||||
    hlp->count = count;
 | 
			
		||||
@@ -274,16 +318,16 @@ static int alsa_write (SWVoiceOut *sw, void *buf, int len)
 | 
			
		||||
    return audio_pcm_sw_write (sw, buf, len);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static snd_pcm_format_t aud_to_alsafmt (AudioFormat fmt, int endianness)
 | 
			
		||||
static snd_pcm_format_t aud_to_alsafmt (audfmt_e fmt, int endianness)
 | 
			
		||||
{
 | 
			
		||||
    switch (fmt) {
 | 
			
		||||
    case AUDIO_FORMAT_S8:
 | 
			
		||||
    case AUD_FMT_S8:
 | 
			
		||||
        return SND_PCM_FORMAT_S8;
 | 
			
		||||
 | 
			
		||||
    case AUDIO_FORMAT_U8:
 | 
			
		||||
    case AUD_FMT_U8:
 | 
			
		||||
        return SND_PCM_FORMAT_U8;
 | 
			
		||||
 | 
			
		||||
    case AUDIO_FORMAT_S16:
 | 
			
		||||
    case AUD_FMT_S16:
 | 
			
		||||
        if (endianness) {
 | 
			
		||||
            return SND_PCM_FORMAT_S16_BE;
 | 
			
		||||
        }
 | 
			
		||||
@@ -291,7 +335,7 @@ static snd_pcm_format_t aud_to_alsafmt (AudioFormat fmt, int endianness)
 | 
			
		||||
            return SND_PCM_FORMAT_S16_LE;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    case AUDIO_FORMAT_U16:
 | 
			
		||||
    case AUD_FMT_U16:
 | 
			
		||||
        if (endianness) {
 | 
			
		||||
            return SND_PCM_FORMAT_U16_BE;
 | 
			
		||||
        }
 | 
			
		||||
@@ -299,7 +343,7 @@ static snd_pcm_format_t aud_to_alsafmt (AudioFormat fmt, int endianness)
 | 
			
		||||
            return SND_PCM_FORMAT_U16_LE;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    case AUDIO_FORMAT_S32:
 | 
			
		||||
    case AUD_FMT_S32:
 | 
			
		||||
        if (endianness) {
 | 
			
		||||
            return SND_PCM_FORMAT_S32_BE;
 | 
			
		||||
        }
 | 
			
		||||
@@ -307,7 +351,7 @@ static snd_pcm_format_t aud_to_alsafmt (AudioFormat fmt, int endianness)
 | 
			
		||||
            return SND_PCM_FORMAT_S32_LE;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    case AUDIO_FORMAT_U32:
 | 
			
		||||
    case AUD_FMT_U32:
 | 
			
		||||
        if (endianness) {
 | 
			
		||||
            return SND_PCM_FORMAT_U32_BE;
 | 
			
		||||
        }
 | 
			
		||||
@@ -324,58 +368,58 @@ static snd_pcm_format_t aud_to_alsafmt (AudioFormat fmt, int endianness)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int alsa_to_audfmt (snd_pcm_format_t alsafmt, AudioFormat *fmt,
 | 
			
		||||
static int alsa_to_audfmt (snd_pcm_format_t alsafmt, audfmt_e *fmt,
 | 
			
		||||
                           int *endianness)
 | 
			
		||||
{
 | 
			
		||||
    switch (alsafmt) {
 | 
			
		||||
    case SND_PCM_FORMAT_S8:
 | 
			
		||||
        *endianness = 0;
 | 
			
		||||
        *fmt = AUDIO_FORMAT_S8;
 | 
			
		||||
        *fmt = AUD_FMT_S8;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case SND_PCM_FORMAT_U8:
 | 
			
		||||
        *endianness = 0;
 | 
			
		||||
        *fmt = AUDIO_FORMAT_U8;
 | 
			
		||||
        *fmt = AUD_FMT_U8;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case SND_PCM_FORMAT_S16_LE:
 | 
			
		||||
        *endianness = 0;
 | 
			
		||||
        *fmt = AUDIO_FORMAT_S16;
 | 
			
		||||
        *fmt = AUD_FMT_S16;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case SND_PCM_FORMAT_U16_LE:
 | 
			
		||||
        *endianness = 0;
 | 
			
		||||
        *fmt = AUDIO_FORMAT_U16;
 | 
			
		||||
        *fmt = AUD_FMT_U16;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case SND_PCM_FORMAT_S16_BE:
 | 
			
		||||
        *endianness = 1;
 | 
			
		||||
        *fmt = AUDIO_FORMAT_S16;
 | 
			
		||||
        *fmt = AUD_FMT_S16;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case SND_PCM_FORMAT_U16_BE:
 | 
			
		||||
        *endianness = 1;
 | 
			
		||||
        *fmt = AUDIO_FORMAT_U16;
 | 
			
		||||
        *fmt = AUD_FMT_U16;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case SND_PCM_FORMAT_S32_LE:
 | 
			
		||||
        *endianness = 0;
 | 
			
		||||
        *fmt = AUDIO_FORMAT_S32;
 | 
			
		||||
        *fmt = AUD_FMT_S32;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case SND_PCM_FORMAT_U32_LE:
 | 
			
		||||
        *endianness = 0;
 | 
			
		||||
        *fmt = AUDIO_FORMAT_U32;
 | 
			
		||||
        *fmt = AUD_FMT_U32;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case SND_PCM_FORMAT_S32_BE:
 | 
			
		||||
        *endianness = 1;
 | 
			
		||||
        *fmt = AUDIO_FORMAT_S32;
 | 
			
		||||
        *fmt = AUD_FMT_S32;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case SND_PCM_FORMAT_U32_BE:
 | 
			
		||||
        *endianness = 1;
 | 
			
		||||
        *fmt = AUDIO_FORMAT_U32;
 | 
			
		||||
        *fmt = AUD_FMT_U32;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    default:
 | 
			
		||||
@@ -388,8 +432,7 @@ static int alsa_to_audfmt (snd_pcm_format_t alsafmt, AudioFormat *fmt,
 | 
			
		||||
 | 
			
		||||
static void alsa_dump_info (struct alsa_params_req *req,
 | 
			
		||||
                            struct alsa_params_obt *obt,
 | 
			
		||||
                            snd_pcm_format_t obtfmt,
 | 
			
		||||
                            AudiodevAlsaPerDirectionOptions *apdo)
 | 
			
		||||
                            snd_pcm_format_t obtfmt)
 | 
			
		||||
{
 | 
			
		||||
    dolog ("parameter | requested value | obtained value\n");
 | 
			
		||||
    dolog ("format    |      %10d |     %10d\n", req->fmt, obtfmt);
 | 
			
		||||
@@ -397,8 +440,8 @@ static void alsa_dump_info (struct alsa_params_req *req,
 | 
			
		||||
           req->nchannels, obt->nchannels);
 | 
			
		||||
    dolog ("frequency |      %10d |     %10d\n", req->freq, obt->freq);
 | 
			
		||||
    dolog ("============================================\n");
 | 
			
		||||
    dolog("requested: buffer len %" PRId32 " period len %" PRId32 "\n",
 | 
			
		||||
          apdo->buffer_length, apdo->period_length);
 | 
			
		||||
    dolog ("requested: buffer size %d period size %d\n",
 | 
			
		||||
           req->buffer_size, req->period_size);
 | 
			
		||||
    dolog ("obtained: samples %ld\n", obt->samples);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -432,23 +475,22 @@ static void alsa_set_threshold (snd_pcm_t *handle, snd_pcm_uframes_t threshold)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int alsa_open(bool in, struct alsa_params_req *req,
 | 
			
		||||
                     struct alsa_params_obt *obt, snd_pcm_t **handlep,
 | 
			
		||||
                     Audiodev *dev)
 | 
			
		||||
static int alsa_open (int in, struct alsa_params_req *req,
 | 
			
		||||
                      struct alsa_params_obt *obt, snd_pcm_t **handlep)
 | 
			
		||||
{
 | 
			
		||||
    AudiodevAlsaOptions *aopts = &dev->u.alsa;
 | 
			
		||||
    AudiodevAlsaPerDirectionOptions *apdo = in ? aopts->in : aopts->out;
 | 
			
		||||
    snd_pcm_t *handle;
 | 
			
		||||
    snd_pcm_hw_params_t *hw_params;
 | 
			
		||||
    int err;
 | 
			
		||||
    int size_in_usec;
 | 
			
		||||
    unsigned int freq, nchannels;
 | 
			
		||||
    const char *pcm_name = apdo->has_dev ? apdo->dev : "default";
 | 
			
		||||
    const char *pcm_name = in ? conf.pcm_name_in : conf.pcm_name_out;
 | 
			
		||||
    snd_pcm_uframes_t obt_buffer_size;
 | 
			
		||||
    const char *typ = in ? "ADC" : "DAC";
 | 
			
		||||
    snd_pcm_format_t obtfmt;
 | 
			
		||||
 | 
			
		||||
    freq = req->freq;
 | 
			
		||||
    nchannels = req->nchannels;
 | 
			
		||||
    size_in_usec = req->size_in_usec;
 | 
			
		||||
 | 
			
		||||
    snd_pcm_hw_params_alloca (&hw_params);
 | 
			
		||||
 | 
			
		||||
@@ -480,7 +522,7 @@ static int alsa_open(bool in, struct alsa_params_req *req,
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    err = snd_pcm_hw_params_set_format (handle, hw_params, req->fmt);
 | 
			
		||||
    if (err < 0) {
 | 
			
		||||
    if (err < 0 && conf.verbose) {
 | 
			
		||||
        alsa_logerr2 (err, typ, "Failed to set format %d\n", req->fmt);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -508,42 +550,79 @@ static int alsa_open(bool in, struct alsa_params_req *req,
 | 
			
		||||
        goto err;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (apdo->buffer_length) {
 | 
			
		||||
    if (req->buffer_size) {
 | 
			
		||||
        unsigned long obt;
 | 
			
		||||
 | 
			
		||||
        if (size_in_usec) {
 | 
			
		||||
            int dir = 0;
 | 
			
		||||
        unsigned int btime = apdo->buffer_length;
 | 
			
		||||
            unsigned int btime = req->buffer_size;
 | 
			
		||||
 | 
			
		||||
            err = snd_pcm_hw_params_set_buffer_time_near (
 | 
			
		||||
            handle, hw_params, &btime, &dir);
 | 
			
		||||
                handle,
 | 
			
		||||
                hw_params,
 | 
			
		||||
                &btime,
 | 
			
		||||
                &dir
 | 
			
		||||
                );
 | 
			
		||||
            obt = btime;
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            snd_pcm_uframes_t bsize = req->buffer_size;
 | 
			
		||||
 | 
			
		||||
            err = snd_pcm_hw_params_set_buffer_size_near (
 | 
			
		||||
                handle,
 | 
			
		||||
                hw_params,
 | 
			
		||||
                &bsize
 | 
			
		||||
                );
 | 
			
		||||
            obt = bsize;
 | 
			
		||||
        }
 | 
			
		||||
        if (err < 0) {
 | 
			
		||||
            alsa_logerr2(err, typ, "Failed to set buffer time to %" PRId32 "\n",
 | 
			
		||||
                         apdo->buffer_length);
 | 
			
		||||
            alsa_logerr2 (err, typ, "Failed to set buffer %s to %d\n",
 | 
			
		||||
                          size_in_usec ? "time" : "size", req->buffer_size);
 | 
			
		||||
            goto err;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (apdo->has_buffer_length && btime != apdo->buffer_length) {
 | 
			
		||||
            dolog("Requested buffer time %" PRId32
 | 
			
		||||
                  " was rejected, using %u\n", apdo->buffer_length, btime);
 | 
			
		||||
        }
 | 
			
		||||
        if ((req->override_mask & 2) && (obt - req->buffer_size))
 | 
			
		||||
            dolog ("Requested buffer %s %u was rejected, using %lu\n",
 | 
			
		||||
                   size_in_usec ? "time" : "size", req->buffer_size, obt);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (apdo->period_length) {
 | 
			
		||||
    if (req->period_size) {
 | 
			
		||||
        unsigned long obt;
 | 
			
		||||
 | 
			
		||||
        if (size_in_usec) {
 | 
			
		||||
            int dir = 0;
 | 
			
		||||
        unsigned int ptime = apdo->period_length;
 | 
			
		||||
            unsigned int ptime = req->period_size;
 | 
			
		||||
 | 
			
		||||
        err = snd_pcm_hw_params_set_period_time_near(handle, hw_params, &ptime,
 | 
			
		||||
                                                     &dir);
 | 
			
		||||
            err = snd_pcm_hw_params_set_period_time_near (
 | 
			
		||||
                handle,
 | 
			
		||||
                hw_params,
 | 
			
		||||
                &ptime,
 | 
			
		||||
                &dir
 | 
			
		||||
                );
 | 
			
		||||
            obt = ptime;
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            int dir = 0;
 | 
			
		||||
            snd_pcm_uframes_t psize = req->period_size;
 | 
			
		||||
 | 
			
		||||
            err = snd_pcm_hw_params_set_period_size_near (
 | 
			
		||||
                handle,
 | 
			
		||||
                hw_params,
 | 
			
		||||
                &psize,
 | 
			
		||||
                &dir
 | 
			
		||||
                );
 | 
			
		||||
            obt = psize;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (err < 0) {
 | 
			
		||||
            alsa_logerr2(err, typ, "Failed to set period time to %" PRId32 "\n",
 | 
			
		||||
                         apdo->period_length);
 | 
			
		||||
            alsa_logerr2 (err, typ, "Failed to set period %s to %d\n",
 | 
			
		||||
                          size_in_usec ? "time" : "size", req->period_size);
 | 
			
		||||
            goto err;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (apdo->has_period_length && ptime != apdo->period_length) {
 | 
			
		||||
            dolog("Requested period time %" PRId32 " was rejected, using %d\n",
 | 
			
		||||
                  apdo->period_length, ptime);
 | 
			
		||||
        }
 | 
			
		||||
        if (((req->override_mask & 1) && (obt - req->period_size)))
 | 
			
		||||
            dolog ("Requested period %s %u was rejected, using %lu\n",
 | 
			
		||||
                   size_in_usec ? "time" : "size", req->period_size, obt);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    err = snd_pcm_hw_params (handle, hw_params);
 | 
			
		||||
@@ -575,12 +654,30 @@ static int alsa_open(bool in, struct alsa_params_req *req,
 | 
			
		||||
        goto err;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!in && aopts->has_threshold && aopts->threshold) {
 | 
			
		||||
        struct audsettings as = { .freq = freq };
 | 
			
		||||
        alsa_set_threshold(
 | 
			
		||||
            handle,
 | 
			
		||||
            audio_buffer_frames(qapi_AudiodevAlsaPerDirectionOptions_base(apdo),
 | 
			
		||||
                                &as, aopts->threshold));
 | 
			
		||||
    if (!in && conf.threshold) {
 | 
			
		||||
        snd_pcm_uframes_t threshold;
 | 
			
		||||
        int bytes_per_sec;
 | 
			
		||||
 | 
			
		||||
        bytes_per_sec = freq << (nchannels == 2);
 | 
			
		||||
 | 
			
		||||
        switch (obt->fmt) {
 | 
			
		||||
        case AUD_FMT_S8:
 | 
			
		||||
        case AUD_FMT_U8:
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case AUD_FMT_S16:
 | 
			
		||||
        case AUD_FMT_U16:
 | 
			
		||||
            bytes_per_sec <<= 1;
 | 
			
		||||
            break;
 | 
			
		||||
 | 
			
		||||
        case AUD_FMT_S32:
 | 
			
		||||
        case AUD_FMT_U32:
 | 
			
		||||
            bytes_per_sec <<= 2;
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        threshold = (conf.threshold * bytes_per_sec) / 1000;
 | 
			
		||||
        alsa_set_threshold (handle, threshold);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    obt->nchannels = nchannels;
 | 
			
		||||
@@ -589,15 +686,16 @@ static int alsa_open(bool in, struct alsa_params_req *req,
 | 
			
		||||
 | 
			
		||||
    *handlep = handle;
 | 
			
		||||
 | 
			
		||||
    if (obtfmt != req->fmt ||
 | 
			
		||||
    if (conf.verbose &&
 | 
			
		||||
        (obtfmt != req->fmt ||
 | 
			
		||||
         obt->nchannels != req->nchannels ||
 | 
			
		||||
         obt->freq != req->freq) {
 | 
			
		||||
         obt->freq != req->freq)) {
 | 
			
		||||
        dolog ("Audio parameters for %s\n", typ);
 | 
			
		||||
        alsa_dump_info(req, obt, obtfmt, apdo);
 | 
			
		||||
        alsa_dump_info (req, obt, obtfmt);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
#ifdef DEBUG
 | 
			
		||||
    alsa_dump_info(req, obt, obtfmt, pdo);
 | 
			
		||||
    alsa_dump_info (req, obt, obtfmt);
 | 
			
		||||
#endif
 | 
			
		||||
    return 0;
 | 
			
		||||
 | 
			
		||||
@@ -645,7 +743,9 @@ static void alsa_write_pending (ALSAVoiceOut *alsa)
 | 
			
		||||
            if (written <= 0) {
 | 
			
		||||
                switch (written) {
 | 
			
		||||
                case 0:
 | 
			
		||||
                    trace_alsa_wrote_zero(len);
 | 
			
		||||
                    if (conf.verbose) {
 | 
			
		||||
                        dolog ("Failed to write %d frames (wrote zero)\n", len);
 | 
			
		||||
                    }
 | 
			
		||||
                    return;
 | 
			
		||||
 | 
			
		||||
                case -EPIPE:
 | 
			
		||||
@@ -654,7 +754,9 @@ static void alsa_write_pending (ALSAVoiceOut *alsa)
 | 
			
		||||
                                     len);
 | 
			
		||||
                        return;
 | 
			
		||||
                    }
 | 
			
		||||
                    trace_alsa_xrun_out();
 | 
			
		||||
                    if (conf.verbose) {
 | 
			
		||||
                        dolog ("Recovering from playback xrun\n");
 | 
			
		||||
                    }
 | 
			
		||||
                    continue;
 | 
			
		||||
 | 
			
		||||
                case -ESTRPIPE:
 | 
			
		||||
@@ -665,7 +767,9 @@ static void alsa_write_pending (ALSAVoiceOut *alsa)
 | 
			
		||||
                                     len);
 | 
			
		||||
                        return;
 | 
			
		||||
                    }
 | 
			
		||||
                    trace_alsa_resume_out();
 | 
			
		||||
                    if (conf.verbose) {
 | 
			
		||||
                        dolog ("Resuming suspended output stream\n");
 | 
			
		||||
                    }
 | 
			
		||||
                    continue;
 | 
			
		||||
 | 
			
		||||
                case -EAGAIN:
 | 
			
		||||
@@ -711,25 +815,31 @@ static void alsa_fini_out (HWVoiceOut *hw)
 | 
			
		||||
    ldebug ("alsa_fini\n");
 | 
			
		||||
    alsa_anal_close (&alsa->handle, &alsa->pollhlp);
 | 
			
		||||
 | 
			
		||||
    g_free(alsa->pcm_buf);
 | 
			
		||||
    if (alsa->pcm_buf) {
 | 
			
		||||
        qemu_free (alsa->pcm_buf);
 | 
			
		||||
        alsa->pcm_buf = NULL;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int alsa_init_out(HWVoiceOut *hw, struct audsettings *as,
 | 
			
		||||
                         void *drv_opaque)
 | 
			
		||||
static int alsa_init_out (HWVoiceOut *hw, struct audsettings *as)
 | 
			
		||||
{
 | 
			
		||||
    ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw;
 | 
			
		||||
    struct alsa_params_req req;
 | 
			
		||||
    struct alsa_params_obt obt;
 | 
			
		||||
    snd_pcm_t *handle;
 | 
			
		||||
    struct audsettings obt_as;
 | 
			
		||||
    Audiodev *dev = drv_opaque;
 | 
			
		||||
 | 
			
		||||
    req.fmt = aud_to_alsafmt (as->fmt, as->endianness);
 | 
			
		||||
    req.freq = as->freq;
 | 
			
		||||
    req.nchannels = as->nchannels;
 | 
			
		||||
    req.period_size = conf.period_size_out;
 | 
			
		||||
    req.buffer_size = conf.buffer_size_out;
 | 
			
		||||
    req.size_in_usec = conf.size_in_usec_out;
 | 
			
		||||
    req.override_mask =
 | 
			
		||||
        (conf.period_size_out_overridden ? 1 : 0) |
 | 
			
		||||
        (conf.buffer_size_out_overridden ? 2 : 0);
 | 
			
		||||
 | 
			
		||||
    if (alsa_open(0, &req, &obt, &handle, dev)) {
 | 
			
		||||
    if (alsa_open (0, &req, &obt, &handle)) {
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -741,7 +851,7 @@ static int alsa_init_out(HWVoiceOut *hw, struct audsettings *as,
 | 
			
		||||
    audio_pcm_init_info (&hw->info, &obt_as);
 | 
			
		||||
    hw->samples = obt.samples;
 | 
			
		||||
 | 
			
		||||
    alsa->pcm_buf = audio_calloc(__func__, obt.samples, 1 << hw->info.shift);
 | 
			
		||||
    alsa->pcm_buf = audio_calloc (AUDIO_FUNC, obt.samples, 1 << hw->info.shift);
 | 
			
		||||
    if (!alsa->pcm_buf) {
 | 
			
		||||
        dolog ("Could not allocate DAC buffer (%d samples, each %d bytes)\n",
 | 
			
		||||
               hw->samples, 1 << hw->info.shift);
 | 
			
		||||
@@ -750,7 +860,6 @@ static int alsa_init_out(HWVoiceOut *hw, struct audsettings *as,
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    alsa->handle = handle;
 | 
			
		||||
    alsa->dev = dev;
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -790,12 +899,16 @@ static int alsa_voice_ctl (snd_pcm_t *handle, const char *typ, int ctl)
 | 
			
		||||
static int alsa_ctl_out (HWVoiceOut *hw, int cmd, ...)
 | 
			
		||||
{
 | 
			
		||||
    ALSAVoiceOut *alsa = (ALSAVoiceOut *) hw;
 | 
			
		||||
    AudiodevAlsaPerDirectionOptions *apdo = alsa->dev->u.alsa.out;
 | 
			
		||||
 | 
			
		||||
    switch (cmd) {
 | 
			
		||||
    case VOICE_ENABLE:
 | 
			
		||||
        {
 | 
			
		||||
            bool poll_mode = apdo->try_poll;
 | 
			
		||||
            va_list ap;
 | 
			
		||||
            int poll_mode;
 | 
			
		||||
 | 
			
		||||
            va_start (ap, cmd);
 | 
			
		||||
            poll_mode = va_arg (ap, int);
 | 
			
		||||
            va_end (ap);
 | 
			
		||||
 | 
			
		||||
            ldebug ("enabling voice\n");
 | 
			
		||||
            if (poll_mode && alsa_poll_out (hw)) {
 | 
			
		||||
@@ -817,20 +930,25 @@ static int alsa_ctl_out (HWVoiceOut *hw, int cmd, ...)
 | 
			
		||||
    return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int alsa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
 | 
			
		||||
static int alsa_init_in (HWVoiceIn *hw, struct audsettings *as)
 | 
			
		||||
{
 | 
			
		||||
    ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw;
 | 
			
		||||
    struct alsa_params_req req;
 | 
			
		||||
    struct alsa_params_obt obt;
 | 
			
		||||
    snd_pcm_t *handle;
 | 
			
		||||
    struct audsettings obt_as;
 | 
			
		||||
    Audiodev *dev = drv_opaque;
 | 
			
		||||
 | 
			
		||||
    req.fmt = aud_to_alsafmt (as->fmt, as->endianness);
 | 
			
		||||
    req.freq = as->freq;
 | 
			
		||||
    req.nchannels = as->nchannels;
 | 
			
		||||
    req.period_size = conf.period_size_in;
 | 
			
		||||
    req.buffer_size = conf.buffer_size_in;
 | 
			
		||||
    req.size_in_usec = conf.size_in_usec_in;
 | 
			
		||||
    req.override_mask =
 | 
			
		||||
        (conf.period_size_in_overridden ? 1 : 0) |
 | 
			
		||||
        (conf.buffer_size_in_overridden ? 2 : 0);
 | 
			
		||||
 | 
			
		||||
    if (alsa_open(1, &req, &obt, &handle, dev)) {
 | 
			
		||||
    if (alsa_open (1, &req, &obt, &handle)) {
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -842,7 +960,7 @@ static int alsa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
 | 
			
		||||
    audio_pcm_init_info (&hw->info, &obt_as);
 | 
			
		||||
    hw->samples = obt.samples;
 | 
			
		||||
 | 
			
		||||
    alsa->pcm_buf = audio_calloc(__func__, hw->samples, 1 << hw->info.shift);
 | 
			
		||||
    alsa->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift);
 | 
			
		||||
    if (!alsa->pcm_buf) {
 | 
			
		||||
        dolog ("Could not allocate ADC buffer (%d samples, each %d bytes)\n",
 | 
			
		||||
               hw->samples, 1 << hw->info.shift);
 | 
			
		||||
@@ -851,7 +969,6 @@ static int alsa_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    alsa->handle = handle;
 | 
			
		||||
    alsa->dev = dev;
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -861,9 +978,11 @@ static void alsa_fini_in (HWVoiceIn *hw)
 | 
			
		||||
 | 
			
		||||
    alsa_anal_close (&alsa->handle, &alsa->pollhlp);
 | 
			
		||||
 | 
			
		||||
    g_free(alsa->pcm_buf);
 | 
			
		||||
    if (alsa->pcm_buf) {
 | 
			
		||||
        qemu_free (alsa->pcm_buf);
 | 
			
		||||
        alsa->pcm_buf = NULL;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int alsa_run_in (HWVoiceIn *hw)
 | 
			
		||||
{
 | 
			
		||||
@@ -907,10 +1026,14 @@ static int alsa_run_in (HWVoiceIn *hw)
 | 
			
		||||
                dolog ("Failed to resume suspended input stream\n");
 | 
			
		||||
                return 0;
 | 
			
		||||
            }
 | 
			
		||||
            trace_alsa_resume_in();
 | 
			
		||||
            if (conf.verbose) {
 | 
			
		||||
                dolog ("Resuming suspended input stream\n");
 | 
			
		||||
            }
 | 
			
		||||
            break;
 | 
			
		||||
        default:
 | 
			
		||||
            trace_alsa_no_frames(state);
 | 
			
		||||
            if (conf.verbose) {
 | 
			
		||||
                dolog ("No frames available and ALSA state is %d\n", state);
 | 
			
		||||
            }
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
@@ -945,7 +1068,9 @@ static int alsa_run_in (HWVoiceIn *hw)
 | 
			
		||||
            if (nread <= 0) {
 | 
			
		||||
                switch (nread) {
 | 
			
		||||
                case 0:
 | 
			
		||||
                    trace_alsa_read_zero(len);
 | 
			
		||||
                    if (conf.verbose) {
 | 
			
		||||
                        dolog ("Failed to read %ld frames (read zero)\n", len);
 | 
			
		||||
                    }
 | 
			
		||||
                    goto exit;
 | 
			
		||||
 | 
			
		||||
                case -EPIPE:
 | 
			
		||||
@@ -953,7 +1078,9 @@ static int alsa_run_in (HWVoiceIn *hw)
 | 
			
		||||
                        alsa_logerr (nread, "Failed to read %ld frames\n", len);
 | 
			
		||||
                        goto exit;
 | 
			
		||||
                    }
 | 
			
		||||
                    trace_alsa_xrun_in();
 | 
			
		||||
                    if (conf.verbose) {
 | 
			
		||||
                        dolog ("Recovering from capture xrun\n");
 | 
			
		||||
                    }
 | 
			
		||||
                    continue;
 | 
			
		||||
 | 
			
		||||
                case -EAGAIN:
 | 
			
		||||
@@ -993,12 +1120,16 @@ static int alsa_read (SWVoiceIn *sw, void *buf, int size)
 | 
			
		||||
static int alsa_ctl_in (HWVoiceIn *hw, int cmd, ...)
 | 
			
		||||
{
 | 
			
		||||
    ALSAVoiceIn *alsa = (ALSAVoiceIn *) hw;
 | 
			
		||||
    AudiodevAlsaPerDirectionOptions *apdo = alsa->dev->u.alsa.in;
 | 
			
		||||
 | 
			
		||||
    switch (cmd) {
 | 
			
		||||
    case VOICE_ENABLE:
 | 
			
		||||
        {
 | 
			
		||||
            bool poll_mode = apdo->try_poll;
 | 
			
		||||
            va_list ap;
 | 
			
		||||
            int poll_mode;
 | 
			
		||||
 | 
			
		||||
            va_start (ap, cmd);
 | 
			
		||||
            poll_mode = va_arg (ap, int);
 | 
			
		||||
            va_end (ap);
 | 
			
		||||
 | 
			
		||||
            ldebug ("enabling voice\n");
 | 
			
		||||
            if (poll_mode && alsa_poll_in (hw)) {
 | 
			
		||||
@@ -1021,54 +1152,85 @@ static int alsa_ctl_in (HWVoiceIn *hw, int cmd, ...)
 | 
			
		||||
    return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void alsa_init_per_direction(AudiodevAlsaPerDirectionOptions *apdo)
 | 
			
		||||
static void *alsa_audio_init (void)
 | 
			
		||||
{
 | 
			
		||||
    if (!apdo->has_try_poll) {
 | 
			
		||||
        apdo->try_poll = true;
 | 
			
		||||
        apdo->has_try_poll = true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void *alsa_audio_init(Audiodev *dev)
 | 
			
		||||
{
 | 
			
		||||
    AudiodevAlsaOptions *aopts;
 | 
			
		||||
    assert(dev->driver == AUDIODEV_DRIVER_ALSA);
 | 
			
		||||
 | 
			
		||||
    aopts = &dev->u.alsa;
 | 
			
		||||
    alsa_init_per_direction(aopts->in);
 | 
			
		||||
    alsa_init_per_direction(aopts->out);
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
     * need to define them, as otherwise alsa produces no sound
 | 
			
		||||
     * doesn't set has_* so alsa_open can identify it wasn't set by the user
 | 
			
		||||
     */
 | 
			
		||||
    if (!dev->u.alsa.out->has_period_length) {
 | 
			
		||||
        /* 1024 frames assuming 44100Hz */
 | 
			
		||||
        dev->u.alsa.out->period_length = 1024 * 1000000 / 44100;
 | 
			
		||||
    }
 | 
			
		||||
    if (!dev->u.alsa.out->has_buffer_length) {
 | 
			
		||||
        /* 4096 frames assuming 44100Hz */
 | 
			
		||||
        dev->u.alsa.out->buffer_length = 4096ll * 1000000 / 44100;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /*
 | 
			
		||||
     * OptsVisitor sets unspecified optional fields to zero, but do not depend
 | 
			
		||||
     * on it...
 | 
			
		||||
     */
 | 
			
		||||
    if (!dev->u.alsa.in->has_period_length) {
 | 
			
		||||
        dev->u.alsa.in->period_length = 0;
 | 
			
		||||
    }
 | 
			
		||||
    if (!dev->u.alsa.in->has_buffer_length) {
 | 
			
		||||
        dev->u.alsa.in->buffer_length = 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return dev;
 | 
			
		||||
    return &conf;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void alsa_audio_fini (void *opaque)
 | 
			
		||||
{
 | 
			
		||||
    (void) opaque;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static struct audio_option alsa_options[] = {
 | 
			
		||||
    {
 | 
			
		||||
        .name        = "DAC_SIZE_IN_USEC",
 | 
			
		||||
        .tag         = AUD_OPT_BOOL,
 | 
			
		||||
        .valp        = &conf.size_in_usec_out,
 | 
			
		||||
        .descr       = "DAC period/buffer size in microseconds (otherwise in frames)"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name        = "DAC_PERIOD_SIZE",
 | 
			
		||||
        .tag         = AUD_OPT_INT,
 | 
			
		||||
        .valp        = &conf.period_size_out,
 | 
			
		||||
        .descr       = "DAC period size (0 to go with system default)",
 | 
			
		||||
        .overriddenp = &conf.period_size_out_overridden
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name        = "DAC_BUFFER_SIZE",
 | 
			
		||||
        .tag         = AUD_OPT_INT,
 | 
			
		||||
        .valp        = &conf.buffer_size_out,
 | 
			
		||||
        .descr       = "DAC buffer size (0 to go with system default)",
 | 
			
		||||
        .overriddenp = &conf.buffer_size_out_overridden
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name        = "ADC_SIZE_IN_USEC",
 | 
			
		||||
        .tag         = AUD_OPT_BOOL,
 | 
			
		||||
        .valp        = &conf.size_in_usec_in,
 | 
			
		||||
        .descr       =
 | 
			
		||||
        "ADC period/buffer size in microseconds (otherwise in frames)"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name        = "ADC_PERIOD_SIZE",
 | 
			
		||||
        .tag         = AUD_OPT_INT,
 | 
			
		||||
        .valp        = &conf.period_size_in,
 | 
			
		||||
        .descr       = "ADC period size (0 to go with system default)",
 | 
			
		||||
        .overriddenp = &conf.period_size_in_overridden
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name        = "ADC_BUFFER_SIZE",
 | 
			
		||||
        .tag         = AUD_OPT_INT,
 | 
			
		||||
        .valp        = &conf.buffer_size_in,
 | 
			
		||||
        .descr       = "ADC buffer size (0 to go with system default)",
 | 
			
		||||
        .overriddenp = &conf.buffer_size_in_overridden
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name        = "THRESHOLD",
 | 
			
		||||
        .tag         = AUD_OPT_INT,
 | 
			
		||||
        .valp        = &conf.threshold,
 | 
			
		||||
        .descr       = "(undocumented)"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name        = "DAC_DEV",
 | 
			
		||||
        .tag         = AUD_OPT_STR,
 | 
			
		||||
        .valp        = &conf.pcm_name_out,
 | 
			
		||||
        .descr       = "DAC device name (for instance dmix)"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name        = "ADC_DEV",
 | 
			
		||||
        .tag         = AUD_OPT_STR,
 | 
			
		||||
        .valp        = &conf.pcm_name_in,
 | 
			
		||||
        .descr       = "ADC device name"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name        = "VERBOSE",
 | 
			
		||||
        .tag         = AUD_OPT_BOOL,
 | 
			
		||||
        .valp        = &conf.verbose,
 | 
			
		||||
        .descr       = "Behave in a more verbose way"
 | 
			
		||||
    },
 | 
			
		||||
    { /* End of list */ }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static struct audio_pcm_ops alsa_pcm_ops = {
 | 
			
		||||
    .init_out = alsa_init_out,
 | 
			
		||||
    .fini_out = alsa_fini_out,
 | 
			
		||||
@@ -1083,9 +1245,10 @@ static struct audio_pcm_ops alsa_pcm_ops = {
 | 
			
		||||
    .ctl_in   = alsa_ctl_in,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static struct audio_driver alsa_audio_driver = {
 | 
			
		||||
struct audio_driver alsa_audio_driver = {
 | 
			
		||||
    .name           = "alsa",
 | 
			
		||||
    .descr          = "ALSA http://www.alsa-project.org",
 | 
			
		||||
    .options        = alsa_options,
 | 
			
		||||
    .init           = alsa_audio_init,
 | 
			
		||||
    .fini           = alsa_audio_fini,
 | 
			
		||||
    .pcm_ops        = &alsa_pcm_ops,
 | 
			
		||||
@@ -1095,9 +1258,3 @@ static struct audio_driver alsa_audio_driver = {
 | 
			
		||||
    .voice_size_out = sizeof (ALSAVoiceOut),
 | 
			
		||||
    .voice_size_in  = sizeof (ALSAVoiceIn)
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void register_audio_alsa(void)
 | 
			
		||||
{
 | 
			
		||||
    audio_driver_register(&alsa_audio_driver);
 | 
			
		||||
}
 | 
			
		||||
type_init(register_audio_alsa);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1146
									
								
								audio/audio.c
									
									
									
									
									
								
							
							
						
						
									
										1146
									
								
								audio/audio.c
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -21,36 +21,35 @@
 | 
			
		||||
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
			
		||||
 * THE SOFTWARE.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef QEMU_AUDIO_H
 | 
			
		||||
#define QEMU_AUDIO_H
 | 
			
		||||
 | 
			
		||||
#include "qemu/queue.h"
 | 
			
		||||
#include "qapi/qapi-types-audio.h"
 | 
			
		||||
#include "config-host.h"
 | 
			
		||||
#include "qemu-queue.h"
 | 
			
		||||
 | 
			
		||||
typedef void (*audio_callback_fn) (void *opaque, int avail);
 | 
			
		||||
 | 
			
		||||
typedef enum {
 | 
			
		||||
    AUD_FMT_U8,
 | 
			
		||||
    AUD_FMT_S8,
 | 
			
		||||
    AUD_FMT_U16,
 | 
			
		||||
    AUD_FMT_S16,
 | 
			
		||||
    AUD_FMT_U32,
 | 
			
		||||
    AUD_FMT_S32
 | 
			
		||||
} audfmt_e;
 | 
			
		||||
 | 
			
		||||
#ifdef HOST_WORDS_BIGENDIAN
 | 
			
		||||
#define AUDIO_HOST_ENDIANNESS 1
 | 
			
		||||
#else
 | 
			
		||||
#define AUDIO_HOST_ENDIANNESS 0
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
typedef struct audsettings {
 | 
			
		||||
struct audsettings {
 | 
			
		||||
    int freq;
 | 
			
		||||
    int nchannels;
 | 
			
		||||
    AudioFormat fmt;
 | 
			
		||||
    audfmt_e fmt;
 | 
			
		||||
    int endianness;
 | 
			
		||||
} audsettings;
 | 
			
		||||
 | 
			
		||||
audsettings audiodev_to_audsettings(AudiodevPerDirectionOptions *pdo);
 | 
			
		||||
int audioformat_bytes_per_sample(AudioFormat fmt);
 | 
			
		||||
int audio_buffer_frames(AudiodevPerDirectionOptions *pdo,
 | 
			
		||||
                        audsettings *as, int def_usecs);
 | 
			
		||||
int audio_buffer_samples(AudiodevPerDirectionOptions *pdo,
 | 
			
		||||
                         audsettings *as, int def_usecs);
 | 
			
		||||
int audio_buffer_bytes(AudiodevPerDirectionOptions *pdo,
 | 
			
		||||
                       audsettings *as, int def_usecs);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
typedef enum {
 | 
			
		||||
    AUD_CNOTIFY_ENABLE,
 | 
			
		||||
@@ -90,6 +89,7 @@ typedef struct QEMUAudioTimeStamp {
 | 
			
		||||
void AUD_vlog (const char *cap, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0);
 | 
			
		||||
void AUD_log (const char *cap, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
 | 
			
		||||
 | 
			
		||||
void AUD_help (void);
 | 
			
		||||
void AUD_register_card (const char *name, QEMUSoundCard *card);
 | 
			
		||||
void AUD_remove_card (QEMUSoundCard *card);
 | 
			
		||||
CaptureVoiceOut *AUD_add_capture (
 | 
			
		||||
@@ -163,16 +163,4 @@ static inline void *advance (void *p, int incr)
 | 
			
		||||
int wav_start_capture (CaptureState *s, const char *path, int freq,
 | 
			
		||||
                       int bits, int nchannels);
 | 
			
		||||
 | 
			
		||||
bool audio_is_cleaning_up(void);
 | 
			
		||||
void audio_cleanup(void);
 | 
			
		||||
 | 
			
		||||
void audio_sample_to_uint64(void *samples, int pos,
 | 
			
		||||
                            uint64_t *left, uint64_t *right);
 | 
			
		||||
void audio_sample_from_uint64(void *samples, int pos,
 | 
			
		||||
                            uint64_t left, uint64_t right);
 | 
			
		||||
 | 
			
		||||
void audio_parse_option(const char *opt);
 | 
			
		||||
void audio_init_audiodevs(void);
 | 
			
		||||
void audio_legacy_help(void);
 | 
			
		||||
 | 
			
		||||
#endif /* QEMU_AUDIO_H */
 | 
			
		||||
#endif  /* audio.h */
 | 
			
		||||
 
 | 
			
		||||
@@ -21,11 +21,10 @@
 | 
			
		||||
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
			
		||||
 * THE SOFTWARE.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef QEMU_AUDIO_INT_H
 | 
			
		||||
#define QEMU_AUDIO_INT_H
 | 
			
		||||
 | 
			
		||||
#ifdef CONFIG_AUDIO_COREAUDIO
 | 
			
		||||
#ifdef CONFIG_COREAUDIO
 | 
			
		||||
#define FLOAT_MIXENG
 | 
			
		||||
/* #define RECIPROCAL */
 | 
			
		||||
#endif
 | 
			
		||||
@@ -33,6 +32,22 @@
 | 
			
		||||
 | 
			
		||||
struct audio_pcm_ops;
 | 
			
		||||
 | 
			
		||||
typedef enum {
 | 
			
		||||
    AUD_OPT_INT,
 | 
			
		||||
    AUD_OPT_FMT,
 | 
			
		||||
    AUD_OPT_STR,
 | 
			
		||||
    AUD_OPT_BOOL
 | 
			
		||||
} audio_option_tag_e;
 | 
			
		||||
 | 
			
		||||
struct audio_option {
 | 
			
		||||
    const char *name;
 | 
			
		||||
    audio_option_tag_e tag;
 | 
			
		||||
    void *valp;
 | 
			
		||||
    const char *descr;
 | 
			
		||||
    int *overriddenp;
 | 
			
		||||
    int overridden;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct audio_callback {
 | 
			
		||||
    void *opaque;
 | 
			
		||||
    audio_callback_fn fn;
 | 
			
		||||
@@ -67,7 +82,6 @@ typedef struct HWVoiceOut {
 | 
			
		||||
    int samples;
 | 
			
		||||
    QLIST_HEAD (sw_out_listhead, SWVoiceOut) sw_head;
 | 
			
		||||
    QLIST_HEAD (sw_cap_listhead, SWVoiceCap) cap_head;
 | 
			
		||||
    int ctl_caps;
 | 
			
		||||
    struct audio_pcm_ops *pcm_ops;
 | 
			
		||||
    QLIST_ENTRY (HWVoiceOut) entries;
 | 
			
		||||
} HWVoiceOut;
 | 
			
		||||
@@ -87,7 +101,6 @@ typedef struct HWVoiceIn {
 | 
			
		||||
 | 
			
		||||
    int samples;
 | 
			
		||||
    QLIST_HEAD (sw_in_listhead, SWVoiceIn) sw_head;
 | 
			
		||||
    int ctl_caps;
 | 
			
		||||
    struct audio_pcm_ops *pcm_ops;
 | 
			
		||||
    QLIST_ENTRY (HWVoiceIn) entries;
 | 
			
		||||
} HWVoiceIn;
 | 
			
		||||
@@ -125,11 +138,11 @@ struct SWVoiceIn {
 | 
			
		||||
    QLIST_ENTRY (SWVoiceIn) entries;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
typedef struct audio_driver audio_driver;
 | 
			
		||||
struct audio_driver {
 | 
			
		||||
    const char *name;
 | 
			
		||||
    const char *descr;
 | 
			
		||||
    void *(*init) (Audiodev *);
 | 
			
		||||
    struct audio_option *options;
 | 
			
		||||
    void *(*init) (void);
 | 
			
		||||
    void (*fini) (void *);
 | 
			
		||||
    struct audio_pcm_ops *pcm_ops;
 | 
			
		||||
    int can_be_default;
 | 
			
		||||
@@ -137,18 +150,16 @@ struct audio_driver {
 | 
			
		||||
    int max_voices_in;
 | 
			
		||||
    int voice_size_out;
 | 
			
		||||
    int voice_size_in;
 | 
			
		||||
    int ctl_caps;
 | 
			
		||||
    QLIST_ENTRY(audio_driver) next;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct audio_pcm_ops {
 | 
			
		||||
    int  (*init_out)(HWVoiceOut *hw, struct audsettings *as, void *drv_opaque);
 | 
			
		||||
    int  (*init_out)(HWVoiceOut *hw, struct audsettings *as);
 | 
			
		||||
    void (*fini_out)(HWVoiceOut *hw);
 | 
			
		||||
    int  (*run_out) (HWVoiceOut *hw, int live);
 | 
			
		||||
    int  (*write)   (SWVoiceOut *sw, void *buf, int size);
 | 
			
		||||
    int  (*ctl_out) (HWVoiceOut *hw, int cmd, ...);
 | 
			
		||||
 | 
			
		||||
    int  (*init_in) (HWVoiceIn *hw, struct audsettings *as, void *drv_opaque);
 | 
			
		||||
    int  (*init_in) (HWVoiceIn *hw, struct audsettings *as);
 | 
			
		||||
    void (*fini_in) (HWVoiceIn *hw);
 | 
			
		||||
    int  (*run_in)  (HWVoiceIn *hw);
 | 
			
		||||
    int  (*read)    (SWVoiceIn *sw, void *buf, int size);
 | 
			
		||||
@@ -174,9 +185,8 @@ struct SWVoiceCap {
 | 
			
		||||
    QLIST_ENTRY (SWVoiceCap) entries;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
typedef struct AudioState {
 | 
			
		||||
struct AudioState {
 | 
			
		||||
    struct audio_driver *drv;
 | 
			
		||||
    Audiodev *dev;
 | 
			
		||||
    void *drv_opaque;
 | 
			
		||||
 | 
			
		||||
    QEMUTimer *ts;
 | 
			
		||||
@@ -187,16 +197,22 @@ typedef struct AudioState {
 | 
			
		||||
    int nb_hw_voices_out;
 | 
			
		||||
    int nb_hw_voices_in;
 | 
			
		||||
    int vm_running;
 | 
			
		||||
    int64_t period_ticks;
 | 
			
		||||
} AudioState;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
extern struct audio_driver no_audio_driver;
 | 
			
		||||
extern struct audio_driver oss_audio_driver;
 | 
			
		||||
extern struct audio_driver sdl_audio_driver;
 | 
			
		||||
extern struct audio_driver wav_audio_driver;
 | 
			
		||||
extern struct audio_driver fmod_audio_driver;
 | 
			
		||||
extern struct audio_driver alsa_audio_driver;
 | 
			
		||||
extern struct audio_driver coreaudio_audio_driver;
 | 
			
		||||
extern struct audio_driver dsound_audio_driver;
 | 
			
		||||
extern struct audio_driver esd_audio_driver;
 | 
			
		||||
extern struct audio_driver pa_audio_driver;
 | 
			
		||||
extern struct audio_driver spice_audio_driver;
 | 
			
		||||
extern struct audio_driver winwave_audio_driver;
 | 
			
		||||
extern const struct mixeng_volume nominal_volume;
 | 
			
		||||
 | 
			
		||||
extern const char *audio_prio_list[];
 | 
			
		||||
 | 
			
		||||
void audio_driver_register(audio_driver *drv);
 | 
			
		||||
audio_driver *audio_driver_lookup(const char *name);
 | 
			
		||||
 | 
			
		||||
void audio_pcm_init_info (struct audio_pcm_info *info, struct audsettings *as);
 | 
			
		||||
void audio_pcm_info_clear_buf (struct audio_pcm_info *info, void *buf, int len);
 | 
			
		||||
 | 
			
		||||
@@ -215,38 +231,52 @@ void audio_run (const char *msg);
 | 
			
		||||
 | 
			
		||||
#define VOICE_ENABLE 1
 | 
			
		||||
#define VOICE_DISABLE 2
 | 
			
		||||
#define VOICE_VOLUME 3
 | 
			
		||||
 | 
			
		||||
#define VOICE_VOLUME_CAP (1 << VOICE_VOLUME)
 | 
			
		||||
 | 
			
		||||
static inline int audio_ring_dist (int dst, int src, int len)
 | 
			
		||||
{
 | 
			
		||||
    return (dst >= src) ? (dst - src) : (len - src + dst);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#define dolog(fmt, ...) AUD_log(AUDIO_CAP, fmt, ## __VA_ARGS__)
 | 
			
		||||
static void GCC_ATTR dolog (const char *fmt, ...)
 | 
			
		||||
{
 | 
			
		||||
    va_list ap;
 | 
			
		||||
 | 
			
		||||
    va_start (ap, fmt);
 | 
			
		||||
    AUD_vlog (AUDIO_CAP, fmt, ap);
 | 
			
		||||
    va_end (ap);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef DEBUG
 | 
			
		||||
#define ldebug(fmt, ...) AUD_log(AUDIO_CAP, fmt, ## __VA_ARGS__)
 | 
			
		||||
static void GCC_ATTR ldebug (const char *fmt, ...)
 | 
			
		||||
{
 | 
			
		||||
    va_list ap;
 | 
			
		||||
 | 
			
		||||
    va_start (ap, fmt);
 | 
			
		||||
    AUD_vlog (AUDIO_CAP, fmt, ap);
 | 
			
		||||
    va_end (ap);
 | 
			
		||||
}
 | 
			
		||||
#else
 | 
			
		||||
#define ldebug(fmt, ...) (void)0
 | 
			
		||||
#if defined NDEBUG && defined __GNUC__
 | 
			
		||||
#define ldebug(...)
 | 
			
		||||
#elif defined NDEBUG && defined _MSC_VER
 | 
			
		||||
#define ldebug __noop
 | 
			
		||||
#else
 | 
			
		||||
static void GCC_ATTR ldebug (const char *fmt, ...)
 | 
			
		||||
{
 | 
			
		||||
    (void) fmt;
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#undef GCC_ATTR
 | 
			
		||||
 | 
			
		||||
#define AUDIO_STRINGIFY_(n) #n
 | 
			
		||||
#define AUDIO_STRINGIFY(n) AUDIO_STRINGIFY_(n)
 | 
			
		||||
 | 
			
		||||
typedef struct AudiodevListEntry {
 | 
			
		||||
    Audiodev *dev;
 | 
			
		||||
    QSIMPLEQ_ENTRY(AudiodevListEntry) next;
 | 
			
		||||
} AudiodevListEntry;
 | 
			
		||||
#if defined _MSC_VER || defined __GNUC__
 | 
			
		||||
#define AUDIO_FUNC __FUNCTION__
 | 
			
		||||
#else
 | 
			
		||||
#define AUDIO_FUNC __FILE__ ":" AUDIO_STRINGIFY (__LINE__)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
typedef QSIMPLEQ_HEAD(, AudiodevListEntry) AudiodevListHead;
 | 
			
		||||
AudiodevListHead audio_handle_legacy_opts(void);
 | 
			
		||||
 | 
			
		||||
void audio_free_audiodev_list(AudiodevListHead *head);
 | 
			
		||||
 | 
			
		||||
void audio_create_pdos(Audiodev *dev);
 | 
			
		||||
AudiodevPerDirectionOptions *audio_get_pdo_in(Audiodev *dev);
 | 
			
		||||
AudiodevPerDirectionOptions *audio_get_pdo_out(Audiodev *dev);
 | 
			
		||||
 | 
			
		||||
#endif /* QEMU_AUDIO_INT_H */
 | 
			
		||||
#endif /* audio_int.h */
 | 
			
		||||
 
 | 
			
		||||
@@ -1,549 +0,0 @@
 | 
			
		||||
/*
 | 
			
		||||
 * QEMU Audio subsystem: legacy configuration handling
 | 
			
		||||
 *
 | 
			
		||||
 * Copyright (c) 2015-2019 Zoltán Kővágó <DirtY.iCE.hu@gmail.com>
 | 
			
		||||
 *
 | 
			
		||||
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
			
		||||
 * of this software and associated documentation files (the "Software"), to deal
 | 
			
		||||
 * in the Software without restriction, including without limitation the rights
 | 
			
		||||
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
			
		||||
 * copies of the Software, and to permit persons to whom the Software is
 | 
			
		||||
 * furnished to do so, subject to the following conditions:
 | 
			
		||||
 *
 | 
			
		||||
 * The above copyright notice and this permission notice shall be included in
 | 
			
		||||
 * all copies or substantial portions of the Software.
 | 
			
		||||
 *
 | 
			
		||||
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 | 
			
		||||
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
			
		||||
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
			
		||||
 * THE SOFTWARE.
 | 
			
		||||
 */
 | 
			
		||||
#include "qemu/osdep.h"
 | 
			
		||||
#include "audio.h"
 | 
			
		||||
#include "audio_int.h"
 | 
			
		||||
#include "qemu/cutils.h"
 | 
			
		||||
#include "qemu/timer.h"
 | 
			
		||||
#include "qapi/error.h"
 | 
			
		||||
#include "qapi/qapi-visit-audio.h"
 | 
			
		||||
#include "qapi/visitor-impl.h"
 | 
			
		||||
 | 
			
		||||
#define AUDIO_CAP "audio-legacy"
 | 
			
		||||
#include "audio_int.h"
 | 
			
		||||
 | 
			
		||||
static uint32_t toui32(const char *str)
 | 
			
		||||
{
 | 
			
		||||
    unsigned long long ret;
 | 
			
		||||
    if (parse_uint_full(str, &ret, 10) || ret > UINT32_MAX) {
 | 
			
		||||
        dolog("Invalid integer value `%s'\n", str);
 | 
			
		||||
        exit(1);
 | 
			
		||||
    }
 | 
			
		||||
    return ret;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* helper functions to convert env variables */
 | 
			
		||||
static void get_bool(const char *env, bool *dst, bool *has_dst)
 | 
			
		||||
{
 | 
			
		||||
    const char *val = getenv(env);
 | 
			
		||||
    if (val) {
 | 
			
		||||
        *dst = toui32(val) != 0;
 | 
			
		||||
        *has_dst = true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void get_int(const char *env, uint32_t *dst, bool *has_dst)
 | 
			
		||||
{
 | 
			
		||||
    const char *val = getenv(env);
 | 
			
		||||
    if (val) {
 | 
			
		||||
        *dst = toui32(val);
 | 
			
		||||
        *has_dst = true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void get_str(const char *env, char **dst, bool *has_dst)
 | 
			
		||||
{
 | 
			
		||||
    const char *val = getenv(env);
 | 
			
		||||
    if (val) {
 | 
			
		||||
        if (*has_dst) {
 | 
			
		||||
            g_free(*dst);
 | 
			
		||||
        }
 | 
			
		||||
        *dst = g_strdup(val);
 | 
			
		||||
        *has_dst = true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void get_fmt(const char *env, AudioFormat *dst, bool *has_dst)
 | 
			
		||||
{
 | 
			
		||||
    const char *val = getenv(env);
 | 
			
		||||
    if (val) {
 | 
			
		||||
        size_t i;
 | 
			
		||||
        for (i = 0; AudioFormat_lookup.size; ++i) {
 | 
			
		||||
            if (strcasecmp(val, AudioFormat_lookup.array[i]) == 0) {
 | 
			
		||||
                *dst = i;
 | 
			
		||||
                *has_dst = true;
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        dolog("Invalid audio format `%s'\n", val);
 | 
			
		||||
        exit(1);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void get_millis_to_usecs(const char *env, uint32_t *dst, bool *has_dst)
 | 
			
		||||
{
 | 
			
		||||
    const char *val = getenv(env);
 | 
			
		||||
    if (val) {
 | 
			
		||||
        *dst = toui32(val) * 1000;
 | 
			
		||||
        *has_dst = true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static uint32_t frames_to_usecs(uint32_t frames,
 | 
			
		||||
                                AudiodevPerDirectionOptions *pdo)
 | 
			
		||||
{
 | 
			
		||||
    uint32_t freq = pdo->has_frequency ? pdo->frequency : 44100;
 | 
			
		||||
    return (frames * 1000000 + freq / 2) / freq;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
static void get_frames_to_usecs(const char *env, uint32_t *dst, bool *has_dst,
 | 
			
		||||
                                AudiodevPerDirectionOptions *pdo)
 | 
			
		||||
{
 | 
			
		||||
    const char *val = getenv(env);
 | 
			
		||||
    if (val) {
 | 
			
		||||
        *dst = frames_to_usecs(toui32(val), pdo);
 | 
			
		||||
        *has_dst = true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static uint32_t samples_to_usecs(uint32_t samples,
 | 
			
		||||
                                 AudiodevPerDirectionOptions *pdo)
 | 
			
		||||
{
 | 
			
		||||
    uint32_t channels = pdo->has_channels ? pdo->channels : 2;
 | 
			
		||||
    return frames_to_usecs(samples / channels, pdo);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void get_samples_to_usecs(const char *env, uint32_t *dst, bool *has_dst,
 | 
			
		||||
                                 AudiodevPerDirectionOptions *pdo)
 | 
			
		||||
{
 | 
			
		||||
    const char *val = getenv(env);
 | 
			
		||||
    if (val) {
 | 
			
		||||
        *dst = samples_to_usecs(toui32(val), pdo);
 | 
			
		||||
        *has_dst = true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static uint32_t bytes_to_usecs(uint32_t bytes, AudiodevPerDirectionOptions *pdo)
 | 
			
		||||
{
 | 
			
		||||
    AudioFormat fmt = pdo->has_format ? pdo->format : AUDIO_FORMAT_S16;
 | 
			
		||||
    uint32_t bytes_per_sample = audioformat_bytes_per_sample(fmt);
 | 
			
		||||
    return samples_to_usecs(bytes / bytes_per_sample, pdo);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void get_bytes_to_usecs(const char *env, uint32_t *dst, bool *has_dst,
 | 
			
		||||
                               AudiodevPerDirectionOptions *pdo)
 | 
			
		||||
{
 | 
			
		||||
    const char *val = getenv(env);
 | 
			
		||||
    if (val) {
 | 
			
		||||
        *dst = bytes_to_usecs(toui32(val), pdo);
 | 
			
		||||
        *has_dst = true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* backend specific functions */
 | 
			
		||||
/* ALSA */
 | 
			
		||||
static void handle_alsa_per_direction(
 | 
			
		||||
    AudiodevAlsaPerDirectionOptions *apdo, const char *prefix)
 | 
			
		||||
{
 | 
			
		||||
    char buf[64];
 | 
			
		||||
    size_t len = strlen(prefix);
 | 
			
		||||
    bool size_in_usecs = false;
 | 
			
		||||
    bool dummy;
 | 
			
		||||
 | 
			
		||||
    memcpy(buf, prefix, len);
 | 
			
		||||
    strcpy(buf + len, "TRY_POLL");
 | 
			
		||||
    get_bool(buf, &apdo->try_poll, &apdo->has_try_poll);
 | 
			
		||||
 | 
			
		||||
    strcpy(buf + len, "DEV");
 | 
			
		||||
    get_str(buf, &apdo->dev, &apdo->has_dev);
 | 
			
		||||
 | 
			
		||||
    strcpy(buf + len, "SIZE_IN_USEC");
 | 
			
		||||
    get_bool(buf, &size_in_usecs, &dummy);
 | 
			
		||||
 | 
			
		||||
    strcpy(buf + len, "PERIOD_SIZE");
 | 
			
		||||
    get_int(buf, &apdo->period_length, &apdo->has_period_length);
 | 
			
		||||
    if (apdo->has_period_length && !size_in_usecs) {
 | 
			
		||||
        apdo->period_length = frames_to_usecs(
 | 
			
		||||
            apdo->period_length,
 | 
			
		||||
            qapi_AudiodevAlsaPerDirectionOptions_base(apdo));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    strcpy(buf + len, "BUFFER_SIZE");
 | 
			
		||||
    get_int(buf, &apdo->buffer_length, &apdo->has_buffer_length);
 | 
			
		||||
    if (apdo->has_buffer_length && !size_in_usecs) {
 | 
			
		||||
        apdo->buffer_length = frames_to_usecs(
 | 
			
		||||
            apdo->buffer_length,
 | 
			
		||||
            qapi_AudiodevAlsaPerDirectionOptions_base(apdo));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void handle_alsa(Audiodev *dev)
 | 
			
		||||
{
 | 
			
		||||
    AudiodevAlsaOptions *aopt = &dev->u.alsa;
 | 
			
		||||
    handle_alsa_per_direction(aopt->in, "QEMU_ALSA_ADC_");
 | 
			
		||||
    handle_alsa_per_direction(aopt->out, "QEMU_ALSA_DAC_");
 | 
			
		||||
 | 
			
		||||
    get_millis_to_usecs("QEMU_ALSA_THRESHOLD",
 | 
			
		||||
                        &aopt->threshold, &aopt->has_threshold);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* coreaudio */
 | 
			
		||||
static void handle_coreaudio(Audiodev *dev)
 | 
			
		||||
{
 | 
			
		||||
    get_frames_to_usecs(
 | 
			
		||||
        "QEMU_COREAUDIO_BUFFER_SIZE",
 | 
			
		||||
        &dev->u.coreaudio.out->buffer_length,
 | 
			
		||||
        &dev->u.coreaudio.out->has_buffer_length,
 | 
			
		||||
        qapi_AudiodevCoreaudioPerDirectionOptions_base(dev->u.coreaudio.out));
 | 
			
		||||
    get_int("QEMU_COREAUDIO_BUFFER_COUNT",
 | 
			
		||||
            &dev->u.coreaudio.out->buffer_count,
 | 
			
		||||
            &dev->u.coreaudio.out->has_buffer_count);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* dsound */
 | 
			
		||||
static void handle_dsound(Audiodev *dev)
 | 
			
		||||
{
 | 
			
		||||
    get_millis_to_usecs("QEMU_DSOUND_LATENCY_MILLIS",
 | 
			
		||||
                        &dev->u.dsound.latency, &dev->u.dsound.has_latency);
 | 
			
		||||
    get_bytes_to_usecs("QEMU_DSOUND_BUFSIZE_OUT",
 | 
			
		||||
                       &dev->u.dsound.out->buffer_length,
 | 
			
		||||
                       &dev->u.dsound.out->has_buffer_length,
 | 
			
		||||
                       dev->u.dsound.out);
 | 
			
		||||
    get_bytes_to_usecs("QEMU_DSOUND_BUFSIZE_IN",
 | 
			
		||||
                       &dev->u.dsound.in->buffer_length,
 | 
			
		||||
                       &dev->u.dsound.in->has_buffer_length,
 | 
			
		||||
                       dev->u.dsound.in);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* OSS */
 | 
			
		||||
static void handle_oss_per_direction(
 | 
			
		||||
    AudiodevOssPerDirectionOptions *opdo, const char *try_poll_env,
 | 
			
		||||
    const char *dev_env)
 | 
			
		||||
{
 | 
			
		||||
    get_bool(try_poll_env, &opdo->try_poll, &opdo->has_try_poll);
 | 
			
		||||
    get_str(dev_env, &opdo->dev, &opdo->has_dev);
 | 
			
		||||
 | 
			
		||||
    get_bytes_to_usecs("QEMU_OSS_FRAGSIZE",
 | 
			
		||||
                       &opdo->buffer_length, &opdo->has_buffer_length,
 | 
			
		||||
                       qapi_AudiodevOssPerDirectionOptions_base(opdo));
 | 
			
		||||
    get_int("QEMU_OSS_NFRAGS", &opdo->buffer_count,
 | 
			
		||||
            &opdo->has_buffer_count);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void handle_oss(Audiodev *dev)
 | 
			
		||||
{
 | 
			
		||||
    AudiodevOssOptions *oopt = &dev->u.oss;
 | 
			
		||||
    handle_oss_per_direction(oopt->in, "QEMU_AUDIO_ADC_TRY_POLL",
 | 
			
		||||
                             "QEMU_OSS_ADC_DEV");
 | 
			
		||||
    handle_oss_per_direction(oopt->out, "QEMU_AUDIO_DAC_TRY_POLL",
 | 
			
		||||
                             "QEMU_OSS_DAC_DEV");
 | 
			
		||||
 | 
			
		||||
    get_bool("QEMU_OSS_MMAP", &oopt->try_mmap, &oopt->has_try_mmap);
 | 
			
		||||
    get_bool("QEMU_OSS_EXCLUSIVE", &oopt->exclusive, &oopt->has_exclusive);
 | 
			
		||||
    get_int("QEMU_OSS_POLICY", &oopt->dsp_policy, &oopt->has_dsp_policy);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* pulseaudio */
 | 
			
		||||
static void handle_pa_per_direction(
 | 
			
		||||
    AudiodevPaPerDirectionOptions *ppdo, const char *env)
 | 
			
		||||
{
 | 
			
		||||
    get_str(env, &ppdo->name, &ppdo->has_name);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void handle_pa(Audiodev *dev)
 | 
			
		||||
{
 | 
			
		||||
    handle_pa_per_direction(dev->u.pa.in, "QEMU_PA_SOURCE");
 | 
			
		||||
    handle_pa_per_direction(dev->u.pa.out, "QEMU_PA_SINK");
 | 
			
		||||
 | 
			
		||||
    get_samples_to_usecs(
 | 
			
		||||
        "QEMU_PA_SAMPLES", &dev->u.pa.in->buffer_length,
 | 
			
		||||
        &dev->u.pa.in->has_buffer_length,
 | 
			
		||||
        qapi_AudiodevPaPerDirectionOptions_base(dev->u.pa.in));
 | 
			
		||||
    get_samples_to_usecs(
 | 
			
		||||
        "QEMU_PA_SAMPLES", &dev->u.pa.out->buffer_length,
 | 
			
		||||
        &dev->u.pa.out->has_buffer_length,
 | 
			
		||||
        qapi_AudiodevPaPerDirectionOptions_base(dev->u.pa.out));
 | 
			
		||||
 | 
			
		||||
    get_str("QEMU_PA_SERVER", &dev->u.pa.server, &dev->u.pa.has_server);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* SDL */
 | 
			
		||||
static void handle_sdl(Audiodev *dev)
 | 
			
		||||
{
 | 
			
		||||
    /* SDL is output only */
 | 
			
		||||
    get_samples_to_usecs("QEMU_SDL_SAMPLES", &dev->u.sdl.out->buffer_length,
 | 
			
		||||
                         &dev->u.sdl.out->has_buffer_length, dev->u.sdl.out);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* wav */
 | 
			
		||||
static void handle_wav(Audiodev *dev)
 | 
			
		||||
{
 | 
			
		||||
    get_int("QEMU_WAV_FREQUENCY",
 | 
			
		||||
            &dev->u.wav.out->frequency, &dev->u.wav.out->has_frequency);
 | 
			
		||||
    get_fmt("QEMU_WAV_FORMAT", &dev->u.wav.out->format,
 | 
			
		||||
            &dev->u.wav.out->has_format);
 | 
			
		||||
    get_int("QEMU_WAV_DAC_FIXED_CHANNELS",
 | 
			
		||||
            &dev->u.wav.out->channels, &dev->u.wav.out->has_channels);
 | 
			
		||||
    get_str("QEMU_WAV_PATH", &dev->u.wav.path, &dev->u.wav.has_path);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* general */
 | 
			
		||||
static void handle_per_direction(
 | 
			
		||||
    AudiodevPerDirectionOptions *pdo, const char *prefix)
 | 
			
		||||
{
 | 
			
		||||
    char buf[64];
 | 
			
		||||
    size_t len = strlen(prefix);
 | 
			
		||||
 | 
			
		||||
    memcpy(buf, prefix, len);
 | 
			
		||||
    strcpy(buf + len, "FIXED_SETTINGS");
 | 
			
		||||
    get_bool(buf, &pdo->fixed_settings, &pdo->has_fixed_settings);
 | 
			
		||||
 | 
			
		||||
    strcpy(buf + len, "FIXED_FREQ");
 | 
			
		||||
    get_int(buf, &pdo->frequency, &pdo->has_frequency);
 | 
			
		||||
 | 
			
		||||
    strcpy(buf + len, "FIXED_FMT");
 | 
			
		||||
    get_fmt(buf, &pdo->format, &pdo->has_format);
 | 
			
		||||
 | 
			
		||||
    strcpy(buf + len, "FIXED_CHANNELS");
 | 
			
		||||
    get_int(buf, &pdo->channels, &pdo->has_channels);
 | 
			
		||||
 | 
			
		||||
    strcpy(buf + len, "VOICES");
 | 
			
		||||
    get_int(buf, &pdo->voices, &pdo->has_voices);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static AudiodevListEntry *legacy_opt(const char *drvname)
 | 
			
		||||
{
 | 
			
		||||
    AudiodevListEntry *e = g_malloc0(sizeof(AudiodevListEntry));
 | 
			
		||||
    e->dev = g_malloc0(sizeof(Audiodev));
 | 
			
		||||
    e->dev->id = g_strdup(drvname);
 | 
			
		||||
    e->dev->driver = qapi_enum_parse(
 | 
			
		||||
        &AudiodevDriver_lookup, drvname, -1, &error_abort);
 | 
			
		||||
 | 
			
		||||
    audio_create_pdos(e->dev);
 | 
			
		||||
 | 
			
		||||
    handle_per_direction(audio_get_pdo_in(e->dev), "QEMU_AUDIO_ADC_");
 | 
			
		||||
    handle_per_direction(audio_get_pdo_out(e->dev), "QEMU_AUDIO_DAC_");
 | 
			
		||||
 | 
			
		||||
    /* Original description: Timer period in HZ (0 - use lowest possible) */
 | 
			
		||||
    get_int("QEMU_AUDIO_TIMER_PERIOD",
 | 
			
		||||
            &e->dev->timer_period, &e->dev->has_timer_period);
 | 
			
		||||
    if (e->dev->has_timer_period && e->dev->timer_period) {
 | 
			
		||||
        e->dev->timer_period = NANOSECONDS_PER_SECOND / 1000 /
 | 
			
		||||
                               e->dev->timer_period;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    switch (e->dev->driver) {
 | 
			
		||||
    case AUDIODEV_DRIVER_ALSA:
 | 
			
		||||
        handle_alsa(e->dev);
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case AUDIODEV_DRIVER_COREAUDIO:
 | 
			
		||||
        handle_coreaudio(e->dev);
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case AUDIODEV_DRIVER_DSOUND:
 | 
			
		||||
        handle_dsound(e->dev);
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case AUDIODEV_DRIVER_OSS:
 | 
			
		||||
        handle_oss(e->dev);
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case AUDIODEV_DRIVER_PA:
 | 
			
		||||
        handle_pa(e->dev);
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case AUDIODEV_DRIVER_SDL:
 | 
			
		||||
        handle_sdl(e->dev);
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case AUDIODEV_DRIVER_WAV:
 | 
			
		||||
        handle_wav(e->dev);
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    default:
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return e;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
AudiodevListHead audio_handle_legacy_opts(void)
 | 
			
		||||
{
 | 
			
		||||
    const char *drvname = getenv("QEMU_AUDIO_DRV");
 | 
			
		||||
    AudiodevListHead head = QSIMPLEQ_HEAD_INITIALIZER(head);
 | 
			
		||||
 | 
			
		||||
    if (drvname) {
 | 
			
		||||
        AudiodevListEntry *e;
 | 
			
		||||
        audio_driver *driver = audio_driver_lookup(drvname);
 | 
			
		||||
        if (!driver) {
 | 
			
		||||
            dolog("Unknown audio driver `%s'\n", drvname);
 | 
			
		||||
            exit(1);
 | 
			
		||||
        }
 | 
			
		||||
        e = legacy_opt(drvname);
 | 
			
		||||
        QSIMPLEQ_INSERT_TAIL(&head, e, next);
 | 
			
		||||
    } else {
 | 
			
		||||
        for (int i = 0; audio_prio_list[i]; i++) {
 | 
			
		||||
            audio_driver *driver = audio_driver_lookup(audio_prio_list[i]);
 | 
			
		||||
            if (driver && driver->can_be_default) {
 | 
			
		||||
                AudiodevListEntry *e = legacy_opt(driver->name);
 | 
			
		||||
                QSIMPLEQ_INSERT_TAIL(&head, e, next);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        if (QSIMPLEQ_EMPTY(&head)) {
 | 
			
		||||
            dolog("Internal error: no default audio driver available\n");
 | 
			
		||||
            exit(1);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return head;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* visitor to print -audiodev option */
 | 
			
		||||
typedef struct {
 | 
			
		||||
    Visitor visitor;
 | 
			
		||||
 | 
			
		||||
    bool comma;
 | 
			
		||||
    GList *path;
 | 
			
		||||
} LegacyPrintVisitor;
 | 
			
		||||
 | 
			
		||||
static void lv_start_struct(Visitor *v, const char *name, void **obj,
 | 
			
		||||
                            size_t size, Error **errp)
 | 
			
		||||
{
 | 
			
		||||
    LegacyPrintVisitor *lv = (LegacyPrintVisitor *) v;
 | 
			
		||||
    lv->path = g_list_append(lv->path, g_strdup(name));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void lv_end_struct(Visitor *v, void **obj)
 | 
			
		||||
{
 | 
			
		||||
    LegacyPrintVisitor *lv = (LegacyPrintVisitor *) v;
 | 
			
		||||
    lv->path = g_list_delete_link(lv->path, g_list_last(lv->path));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void lv_print_key(Visitor *v, const char *name)
 | 
			
		||||
{
 | 
			
		||||
    GList *e;
 | 
			
		||||
    LegacyPrintVisitor *lv = (LegacyPrintVisitor *) v;
 | 
			
		||||
    if (lv->comma) {
 | 
			
		||||
        putchar(',');
 | 
			
		||||
    } else {
 | 
			
		||||
        lv->comma = true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    for (e = lv->path; e; e = e->next) {
 | 
			
		||||
        if (e->data) {
 | 
			
		||||
            printf("%s.", (const char *) e->data);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    printf("%s=", name);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void lv_type_int64(Visitor *v, const char *name, int64_t *obj,
 | 
			
		||||
                          Error **errp)
 | 
			
		||||
{
 | 
			
		||||
    lv_print_key(v, name);
 | 
			
		||||
    printf("%" PRIi64, *obj);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void lv_type_uint64(Visitor *v, const char *name, uint64_t *obj,
 | 
			
		||||
                           Error **errp)
 | 
			
		||||
{
 | 
			
		||||
    lv_print_key(v, name);
 | 
			
		||||
    printf("%" PRIu64, *obj);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void lv_type_bool(Visitor *v, const char *name, bool *obj, Error **errp)
 | 
			
		||||
{
 | 
			
		||||
    lv_print_key(v, name);
 | 
			
		||||
    printf("%s", *obj ? "on" : "off");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void lv_type_str(Visitor *v, const char *name, char **obj, Error **errp)
 | 
			
		||||
{
 | 
			
		||||
    const char *str = *obj;
 | 
			
		||||
    lv_print_key(v, name);
 | 
			
		||||
 | 
			
		||||
    while (*str) {
 | 
			
		||||
        if (*str == ',') {
 | 
			
		||||
            putchar(',');
 | 
			
		||||
        }
 | 
			
		||||
        putchar(*str++);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void lv_complete(Visitor *v, void *opaque)
 | 
			
		||||
{
 | 
			
		||||
    LegacyPrintVisitor *lv = (LegacyPrintVisitor *) v;
 | 
			
		||||
    assert(lv->path == NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void lv_free(Visitor *v)
 | 
			
		||||
{
 | 
			
		||||
    LegacyPrintVisitor *lv = (LegacyPrintVisitor *) v;
 | 
			
		||||
 | 
			
		||||
    g_list_free_full(lv->path, g_free);
 | 
			
		||||
    g_free(lv);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static Visitor *legacy_visitor_new(void)
 | 
			
		||||
{
 | 
			
		||||
    LegacyPrintVisitor *lv = g_malloc0(sizeof(LegacyPrintVisitor));
 | 
			
		||||
 | 
			
		||||
    lv->visitor.start_struct = lv_start_struct;
 | 
			
		||||
    lv->visitor.end_struct = lv_end_struct;
 | 
			
		||||
    /* lists not supported */
 | 
			
		||||
    lv->visitor.type_int64 = lv_type_int64;
 | 
			
		||||
    lv->visitor.type_uint64 = lv_type_uint64;
 | 
			
		||||
    lv->visitor.type_bool = lv_type_bool;
 | 
			
		||||
    lv->visitor.type_str = lv_type_str;
 | 
			
		||||
 | 
			
		||||
    lv->visitor.type = VISITOR_OUTPUT;
 | 
			
		||||
    lv->visitor.complete = lv_complete;
 | 
			
		||||
    lv->visitor.free = lv_free;
 | 
			
		||||
 | 
			
		||||
    return &lv->visitor;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void audio_legacy_help(void)
 | 
			
		||||
{
 | 
			
		||||
    AudiodevListHead head;
 | 
			
		||||
    AudiodevListEntry *e;
 | 
			
		||||
 | 
			
		||||
    printf("Environment variable based configuration deprecated.\n");
 | 
			
		||||
    printf("Please use the new -audiodev option.\n");
 | 
			
		||||
 | 
			
		||||
    head = audio_handle_legacy_opts();
 | 
			
		||||
    printf("\nEquivalent -audiodev to your current environment variables:\n");
 | 
			
		||||
    if (!getenv("QEMU_AUDIO_DRV")) {
 | 
			
		||||
        printf("(Since you didn't specify QEMU_AUDIO_DRV, I'll list all "
 | 
			
		||||
               "possibilities)\n");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    QSIMPLEQ_FOREACH(e, &head, next) {
 | 
			
		||||
        Visitor *v;
 | 
			
		||||
        Audiodev *dev = e->dev;
 | 
			
		||||
        printf("-audiodev ");
 | 
			
		||||
 | 
			
		||||
        v = legacy_visitor_new();
 | 
			
		||||
        visit_type_Audiodev(v, NULL, &dev, &error_abort);
 | 
			
		||||
        visit_free(v);
 | 
			
		||||
 | 
			
		||||
        printf("\n");
 | 
			
		||||
    }
 | 
			
		||||
    audio_free_audiodev_list(&head);
 | 
			
		||||
}
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
#include "qemu/osdep.h"
 | 
			
		||||
#include "qemu-common.h"
 | 
			
		||||
#include "audio.h"
 | 
			
		||||
 | 
			
		||||
#define AUDIO_CAP "audio-pt"
 | 
			
		||||
@@ -30,7 +30,7 @@ int audio_pt_init (struct audio_pt *p, void *(*func) (void *),
 | 
			
		||||
 | 
			
		||||
    err = sigfillset (&set);
 | 
			
		||||
    if (err) {
 | 
			
		||||
        logerr(p, errno, "%s(%s): sigfillset failed", cap, __func__);
 | 
			
		||||
        logerr (p, errno, "%s(%s): sigfillset failed", cap, AUDIO_FUNC);
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -57,7 +57,7 @@ int audio_pt_init (struct audio_pt *p, void *(*func) (void *),
 | 
			
		||||
    err2 = pthread_sigmask (SIG_SETMASK, &old_set, NULL);
 | 
			
		||||
    if (err2) {
 | 
			
		||||
        logerr (p, err2, "%s(%s): pthread_sigmask (restore) failed",
 | 
			
		||||
               cap, __func__);
 | 
			
		||||
                cap, AUDIO_FUNC);
 | 
			
		||||
        /* We have failed to restore original signal mask, all bets are off,
 | 
			
		||||
           so terminate the process */
 | 
			
		||||
        exit (EXIT_FAILURE);
 | 
			
		||||
@@ -73,17 +73,17 @@ int audio_pt_init (struct audio_pt *p, void *(*func) (void *),
 | 
			
		||||
 err2:
 | 
			
		||||
    err2 = pthread_cond_destroy (&p->cond);
 | 
			
		||||
    if (err2) {
 | 
			
		||||
        logerr(p, err2, "%s(%s): pthread_cond_destroy failed", cap, __func__);
 | 
			
		||||
        logerr (p, err2, "%s(%s): pthread_cond_destroy failed", cap, AUDIO_FUNC);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 err1:
 | 
			
		||||
    err2 = pthread_mutex_destroy (&p->mutex);
 | 
			
		||||
    if (err2) {
 | 
			
		||||
        logerr(p, err2, "%s(%s): pthread_mutex_destroy failed", cap, __func__);
 | 
			
		||||
        logerr (p, err2, "%s(%s): pthread_mutex_destroy failed", cap, AUDIO_FUNC);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 err0:
 | 
			
		||||
    logerr(p, err, "%s(%s): %s failed", cap, __func__, efunc);
 | 
			
		||||
    logerr (p, err, "%s(%s): %s failed", cap, AUDIO_FUNC, efunc);
 | 
			
		||||
    return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -93,13 +93,13 @@ int audio_pt_fini (struct audio_pt *p, const char *cap)
 | 
			
		||||
 | 
			
		||||
    err = pthread_cond_destroy (&p->cond);
 | 
			
		||||
    if (err) {
 | 
			
		||||
        logerr(p, err, "%s(%s): pthread_cond_destroy failed", cap, __func__);
 | 
			
		||||
        logerr (p, err, "%s(%s): pthread_cond_destroy failed", cap, AUDIO_FUNC);
 | 
			
		||||
        ret = -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    err = pthread_mutex_destroy (&p->mutex);
 | 
			
		||||
    if (err) {
 | 
			
		||||
        logerr(p, err, "%s(%s): pthread_mutex_destroy failed", cap, __func__);
 | 
			
		||||
        logerr (p, err, "%s(%s): pthread_mutex_destroy failed", cap, AUDIO_FUNC);
 | 
			
		||||
        ret = -1;
 | 
			
		||||
    }
 | 
			
		||||
    return ret;
 | 
			
		||||
@@ -111,7 +111,7 @@ int audio_pt_lock (struct audio_pt *p, const char *cap)
 | 
			
		||||
 | 
			
		||||
    err = pthread_mutex_lock (&p->mutex);
 | 
			
		||||
    if (err) {
 | 
			
		||||
        logerr(p, err, "%s(%s): pthread_mutex_lock failed", cap, __func__);
 | 
			
		||||
        logerr (p, err, "%s(%s): pthread_mutex_lock failed", cap, AUDIO_FUNC);
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
@@ -123,7 +123,7 @@ int audio_pt_unlock (struct audio_pt *p, const char *cap)
 | 
			
		||||
 | 
			
		||||
    err = pthread_mutex_unlock (&p->mutex);
 | 
			
		||||
    if (err) {
 | 
			
		||||
        logerr(p, err, "%s(%s): pthread_mutex_unlock failed", cap, __func__);
 | 
			
		||||
        logerr (p, err, "%s(%s): pthread_mutex_unlock failed", cap, AUDIO_FUNC);
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
@@ -135,7 +135,7 @@ int audio_pt_wait (struct audio_pt *p, const char *cap)
 | 
			
		||||
 | 
			
		||||
    err = pthread_cond_wait (&p->cond, &p->mutex);
 | 
			
		||||
    if (err) {
 | 
			
		||||
        logerr(p, err, "%s(%s): pthread_cond_wait failed", cap, __func__);
 | 
			
		||||
        logerr (p, err, "%s(%s): pthread_cond_wait failed", cap, AUDIO_FUNC);
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
@@ -147,12 +147,12 @@ int audio_pt_unlock_and_signal (struct audio_pt *p, const char *cap)
 | 
			
		||||
 | 
			
		||||
    err = pthread_mutex_unlock (&p->mutex);
 | 
			
		||||
    if (err) {
 | 
			
		||||
        logerr(p, err, "%s(%s): pthread_mutex_unlock failed", cap, __func__);
 | 
			
		||||
        logerr (p, err, "%s(%s): pthread_mutex_unlock failed", cap, AUDIO_FUNC);
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
    err = pthread_cond_signal (&p->cond);
 | 
			
		||||
    if (err) {
 | 
			
		||||
        logerr(p, err, "%s(%s): pthread_cond_signal failed", cap, __func__);
 | 
			
		||||
        logerr (p, err, "%s(%s): pthread_cond_signal failed", cap, AUDIO_FUNC);
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
@@ -165,7 +165,7 @@ int audio_pt_join (struct audio_pt *p, void **arg, const char *cap)
 | 
			
		||||
 | 
			
		||||
    err = pthread_join (p->thread, &ret);
 | 
			
		||||
    if (err) {
 | 
			
		||||
        logerr(p, err, "%s(%s): pthread_join failed", cap, __func__);
 | 
			
		||||
        logerr (p, err, "%s(%s): pthread_join failed", cap, AUDIO_FUNC);
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
    *arg = ret;
 | 
			
		||||
 
 | 
			
		||||
@@ -19,4 +19,4 @@ int audio_pt_wait (struct audio_pt *, const char *);
 | 
			
		||||
int audio_pt_unlock_and_signal (struct audio_pt *, const char *);
 | 
			
		||||
int audio_pt_join (struct audio_pt *, void **, const char *);
 | 
			
		||||
 | 
			
		||||
#endif /* QEMU_AUDIO_PT_INT_H */
 | 
			
		||||
#endif /* audio_pt_int.h */
 | 
			
		||||
 
 | 
			
		||||
@@ -57,13 +57,13 @@ static void glue (audio_init_nb_voices_, TYPE) (struct audio_driver *drv)
 | 
			
		||||
        glue (s->nb_hw_voices_, TYPE) = max_voices;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (audio_bug(__func__, !voice_size && max_voices)) {
 | 
			
		||||
    if (audio_bug (AUDIO_FUNC, !voice_size && max_voices)) {
 | 
			
		||||
        dolog ("drv=`%s' voice_size=0 max_voices=%d\n",
 | 
			
		||||
               drv->name, max_voices);
 | 
			
		||||
        glue (s->nb_hw_voices_, TYPE) = 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (audio_bug(__func__, voice_size && !max_voices)) {
 | 
			
		||||
    if (audio_bug (AUDIO_FUNC, voice_size && !max_voices)) {
 | 
			
		||||
        dolog ("drv=`%s' voice_size=%d max_voices=0\n",
 | 
			
		||||
               drv->name, voice_size);
 | 
			
		||||
    }
 | 
			
		||||
@@ -71,13 +71,16 @@ static void glue (audio_init_nb_voices_, TYPE) (struct audio_driver *drv)
 | 
			
		||||
 | 
			
		||||
static void glue (audio_pcm_hw_free_resources_, TYPE) (HW *hw)
 | 
			
		||||
{
 | 
			
		||||
    g_free (HWBUF);
 | 
			
		||||
    if (HWBUF) {
 | 
			
		||||
        qemu_free (HWBUF);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    HWBUF = NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int glue (audio_pcm_hw_alloc_resources_, TYPE) (HW *hw)
 | 
			
		||||
{
 | 
			
		||||
    HWBUF = audio_calloc(__func__, hw->samples, sizeof(struct st_sample));
 | 
			
		||||
    HWBUF = audio_calloc (AUDIO_FUNC, hw->samples, sizeof (struct st_sample));
 | 
			
		||||
    if (!HWBUF) {
 | 
			
		||||
        dolog ("Could not allocate " NAME " buffer (%d samples)\n",
 | 
			
		||||
               hw->samples);
 | 
			
		||||
@@ -89,7 +92,9 @@ static int glue (audio_pcm_hw_alloc_resources_, TYPE) (HW *hw)
 | 
			
		||||
 | 
			
		||||
static void glue (audio_pcm_sw_free_resources_, TYPE) (SW *sw)
 | 
			
		||||
{
 | 
			
		||||
    g_free (sw->buf);
 | 
			
		||||
    if (sw->buf) {
 | 
			
		||||
        qemu_free (sw->buf);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (sw->rate) {
 | 
			
		||||
        st_rate_stop (sw->rate);
 | 
			
		||||
@@ -105,7 +110,7 @@ static int glue (audio_pcm_sw_alloc_resources_, TYPE) (SW *sw)
 | 
			
		||||
 | 
			
		||||
    samples = ((int64_t) sw->hw->samples << 32) / sw->ratio;
 | 
			
		||||
 | 
			
		||||
    sw->buf = audio_calloc(__func__, samples, sizeof(struct st_sample));
 | 
			
		||||
    sw->buf = audio_calloc (AUDIO_FUNC, samples, sizeof (struct st_sample));
 | 
			
		||||
    if (!sw->buf) {
 | 
			
		||||
        dolog ("Could not allocate buffer for `%s' (%d samples)\n",
 | 
			
		||||
               SW_NAME (sw), samples);
 | 
			
		||||
@@ -118,7 +123,7 @@ static int glue (audio_pcm_sw_alloc_resources_, TYPE) (SW *sw)
 | 
			
		||||
    sw->rate = st_rate_start (sw->hw->info.freq, sw->info.freq);
 | 
			
		||||
#endif
 | 
			
		||||
    if (!sw->rate) {
 | 
			
		||||
        g_free (sw->buf);
 | 
			
		||||
        qemu_free (sw->buf);
 | 
			
		||||
        sw->buf = NULL;
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
@@ -155,10 +160,10 @@ static int glue (audio_pcm_sw_init_, TYPE) (
 | 
			
		||||
        [sw->info.swap_endianness]
 | 
			
		||||
        [audio_bits_to_index (sw->info.bits)];
 | 
			
		||||
 | 
			
		||||
    sw->name = g_strdup (name);
 | 
			
		||||
    sw->name = qemu_strdup (name);
 | 
			
		||||
    err = glue (audio_pcm_sw_alloc_resources_, TYPE) (sw);
 | 
			
		||||
    if (err) {
 | 
			
		||||
        g_free (sw->name);
 | 
			
		||||
        qemu_free (sw->name);
 | 
			
		||||
        sw->name = NULL;
 | 
			
		||||
    }
 | 
			
		||||
    return err;
 | 
			
		||||
@@ -167,9 +172,11 @@ static int glue (audio_pcm_sw_init_, TYPE) (
 | 
			
		||||
static void glue (audio_pcm_sw_fini_, TYPE) (SW *sw)
 | 
			
		||||
{
 | 
			
		||||
    glue (audio_pcm_sw_free_resources_, TYPE) (sw);
 | 
			
		||||
    g_free (sw->name);
 | 
			
		||||
    if (sw->name) {
 | 
			
		||||
        qemu_free (sw->name);
 | 
			
		||||
        sw->name = NULL;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void glue (audio_pcm_hw_add_sw_, TYPE) (HW *hw, SW *sw)
 | 
			
		||||
{
 | 
			
		||||
@@ -191,10 +198,10 @@ static void glue (audio_pcm_hw_gc_, TYPE) (HW **hwp)
 | 
			
		||||
        audio_detach_capture (hw);
 | 
			
		||||
#endif
 | 
			
		||||
        QLIST_REMOVE (hw, entries);
 | 
			
		||||
        glue (hw->pcm_ops->fini_, TYPE) (hw);
 | 
			
		||||
        glue (s->nb_hw_voices_, TYPE) += 1;
 | 
			
		||||
        glue (audio_pcm_hw_free_resources_ ,TYPE) (hw);
 | 
			
		||||
        g_free (hw);
 | 
			
		||||
        glue (hw->pcm_ops->fini_, TYPE) (hw);
 | 
			
		||||
        qemu_free (hw);
 | 
			
		||||
        *hwp = NULL;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -238,17 +245,17 @@ static HW *glue (audio_pcm_hw_add_new_, TYPE) (struct audsettings *as)
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (audio_bug(__func__, !drv)) {
 | 
			
		||||
    if (audio_bug (AUDIO_FUNC, !drv)) {
 | 
			
		||||
        dolog ("No host audio driver\n");
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (audio_bug(__func__, !drv->pcm_ops)) {
 | 
			
		||||
    if (audio_bug (AUDIO_FUNC, !drv->pcm_ops)) {
 | 
			
		||||
        dolog ("Host audio driver without pcm_ops\n");
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    hw = audio_calloc(__func__, 1, glue(drv->voice_size_, TYPE));
 | 
			
		||||
    hw = audio_calloc (AUDIO_FUNC, 1, glue (drv->voice_size_, TYPE));
 | 
			
		||||
    if (!hw) {
 | 
			
		||||
        dolog ("Can not allocate voice `%s' size %d\n",
 | 
			
		||||
               drv->name, glue (drv->voice_size_, TYPE));
 | 
			
		||||
@@ -256,17 +263,15 @@ static HW *glue (audio_pcm_hw_add_new_, TYPE) (struct audsettings *as)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    hw->pcm_ops = drv->pcm_ops;
 | 
			
		||||
    hw->ctl_caps = drv->ctl_caps;
 | 
			
		||||
 | 
			
		||||
    QLIST_INIT (&hw->sw_head);
 | 
			
		||||
#ifdef DAC
 | 
			
		||||
    QLIST_INIT (&hw->cap_head);
 | 
			
		||||
#endif
 | 
			
		||||
    if (glue (hw->pcm_ops->init_, TYPE) (hw, as, s->drv_opaque)) {
 | 
			
		||||
    if (glue (hw->pcm_ops->init_, TYPE) (hw, as)) {
 | 
			
		||||
        goto err0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (audio_bug(__func__, hw->samples <= 0)) {
 | 
			
		||||
    if (audio_bug (AUDIO_FUNC, hw->samples <= 0)) {
 | 
			
		||||
        dolog ("hw->samples=%d\n", hw->samples);
 | 
			
		||||
        goto err1;
 | 
			
		||||
    }
 | 
			
		||||
@@ -295,46 +300,15 @@ static HW *glue (audio_pcm_hw_add_new_, TYPE) (struct audsettings *as)
 | 
			
		||||
 err1:
 | 
			
		||||
    glue (hw->pcm_ops->fini_, TYPE) (hw);
 | 
			
		||||
 err0:
 | 
			
		||||
    g_free (hw);
 | 
			
		||||
    qemu_free (hw);
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
AudiodevPerDirectionOptions *glue(audio_get_pdo_, TYPE)(Audiodev *dev)
 | 
			
		||||
{
 | 
			
		||||
    switch (dev->driver) {
 | 
			
		||||
    case AUDIODEV_DRIVER_NONE:
 | 
			
		||||
        return dev->u.none.TYPE;
 | 
			
		||||
    case AUDIODEV_DRIVER_ALSA:
 | 
			
		||||
        return qapi_AudiodevAlsaPerDirectionOptions_base(dev->u.alsa.TYPE);
 | 
			
		||||
    case AUDIODEV_DRIVER_COREAUDIO:
 | 
			
		||||
        return qapi_AudiodevCoreaudioPerDirectionOptions_base(
 | 
			
		||||
            dev->u.coreaudio.TYPE);
 | 
			
		||||
    case AUDIODEV_DRIVER_DSOUND:
 | 
			
		||||
        return dev->u.dsound.TYPE;
 | 
			
		||||
    case AUDIODEV_DRIVER_OSS:
 | 
			
		||||
        return qapi_AudiodevOssPerDirectionOptions_base(dev->u.oss.TYPE);
 | 
			
		||||
    case AUDIODEV_DRIVER_PA:
 | 
			
		||||
        return qapi_AudiodevPaPerDirectionOptions_base(dev->u.pa.TYPE);
 | 
			
		||||
    case AUDIODEV_DRIVER_SDL:
 | 
			
		||||
        return dev->u.sdl.TYPE;
 | 
			
		||||
    case AUDIODEV_DRIVER_SPICE:
 | 
			
		||||
        return dev->u.spice.TYPE;
 | 
			
		||||
    case AUDIODEV_DRIVER_WAV:
 | 
			
		||||
        return dev->u.wav.TYPE;
 | 
			
		||||
 | 
			
		||||
    case AUDIODEV_DRIVER__MAX:
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    abort();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static HW *glue (audio_pcm_hw_add_, TYPE) (struct audsettings *as)
 | 
			
		||||
{
 | 
			
		||||
    HW *hw;
 | 
			
		||||
    AudioState *s = &glob_audio_state;
 | 
			
		||||
    AudiodevPerDirectionOptions *pdo = glue(audio_get_pdo_, TYPE)(s->dev);
 | 
			
		||||
 | 
			
		||||
    if (pdo->fixed_settings) {
 | 
			
		||||
    if (glue (conf.fixed_, TYPE).enabled && glue (conf.fixed_, TYPE).greedy) {
 | 
			
		||||
        hw = glue (audio_pcm_hw_add_new_, TYPE) (as);
 | 
			
		||||
        if (hw) {
 | 
			
		||||
            return hw;
 | 
			
		||||
@@ -362,17 +336,15 @@ static SW *glue (audio_pcm_create_voice_pair_, TYPE) (
 | 
			
		||||
    SW *sw;
 | 
			
		||||
    HW *hw;
 | 
			
		||||
    struct audsettings hw_as;
 | 
			
		||||
    AudioState *s = &glob_audio_state;
 | 
			
		||||
    AudiodevPerDirectionOptions *pdo = glue(audio_get_pdo_, TYPE)(s->dev);
 | 
			
		||||
 | 
			
		||||
    if (pdo->fixed_settings) {
 | 
			
		||||
        hw_as = audiodev_to_audsettings(pdo);
 | 
			
		||||
    if (glue (conf.fixed_, TYPE).enabled) {
 | 
			
		||||
        hw_as = glue (conf.fixed_, TYPE).settings;
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
        hw_as = *as;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    sw = audio_calloc(__func__, 1, sizeof(*sw));
 | 
			
		||||
    sw = audio_calloc (AUDIO_FUNC, 1, sizeof (*sw));
 | 
			
		||||
    if (!sw) {
 | 
			
		||||
        dolog ("Could not allocate soft voice `%s' (%zu bytes)\n",
 | 
			
		||||
               sw_name ? sw_name : "unknown", sizeof (*sw));
 | 
			
		||||
@@ -396,7 +368,7 @@ err3:
 | 
			
		||||
    glue (audio_pcm_hw_del_sw_, TYPE) (sw);
 | 
			
		||||
    glue (audio_pcm_hw_gc_, TYPE) (&hw);
 | 
			
		||||
err2:
 | 
			
		||||
    g_free (sw);
 | 
			
		||||
    qemu_free (sw);
 | 
			
		||||
err1:
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
@@ -406,13 +378,13 @@ static void glue (audio_close_, TYPE) (SW *sw)
 | 
			
		||||
    glue (audio_pcm_sw_fini_, TYPE) (sw);
 | 
			
		||||
    glue (audio_pcm_hw_del_sw_, TYPE) (sw);
 | 
			
		||||
    glue (audio_pcm_hw_gc_, TYPE) (&sw->hw);
 | 
			
		||||
    g_free (sw);
 | 
			
		||||
    qemu_free (sw);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void glue (AUD_close_, TYPE) (QEMUSoundCard *card, SW *sw)
 | 
			
		||||
{
 | 
			
		||||
    if (sw) {
 | 
			
		||||
        if (audio_bug(__func__, !card)) {
 | 
			
		||||
        if (audio_bug (AUDIO_FUNC, !card)) {
 | 
			
		||||
            dolog ("card=%p\n", card);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
@@ -431,23 +403,26 @@ SW *glue (AUD_open_, TYPE) (
 | 
			
		||||
    )
 | 
			
		||||
{
 | 
			
		||||
    AudioState *s = &glob_audio_state;
 | 
			
		||||
    AudiodevPerDirectionOptions *pdo = glue(audio_get_pdo_, TYPE)(s->dev);
 | 
			
		||||
#ifdef DAC
 | 
			
		||||
    int live = 0;
 | 
			
		||||
    SW *old_sw = NULL;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    if (audio_bug(__func__, !card || !name || !callback_fn || !as)) {
 | 
			
		||||
    ldebug ("open %s, freq %d, nchannels %d, fmt %d\n",
 | 
			
		||||
            name, as->freq, as->nchannels, as->fmt);
 | 
			
		||||
 | 
			
		||||
    if (audio_bug (AUDIO_FUNC, !card || !name || !callback_fn || !as)) {
 | 
			
		||||
        dolog ("card=%p name=%p callback_fn=%p as=%p\n",
 | 
			
		||||
               card, name, callback_fn, as);
 | 
			
		||||
        goto fail;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ldebug ("open %s, freq %d, nchannels %d, fmt %d\n",
 | 
			
		||||
            name, as->freq, as->nchannels, as->fmt);
 | 
			
		||||
 | 
			
		||||
    if (audio_bug(__func__, audio_validate_settings(as))) {
 | 
			
		||||
    if (audio_bug (AUDIO_FUNC, audio_validate_settings (as))) {
 | 
			
		||||
        audio_print_settings (as);
 | 
			
		||||
        goto fail;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (audio_bug(__func__, !s->drv)) {
 | 
			
		||||
    if (audio_bug (AUDIO_FUNC, !s->drv)) {
 | 
			
		||||
        dolog ("Can not open `%s' (no host audio driver)\n", name);
 | 
			
		||||
        goto fail;
 | 
			
		||||
    }
 | 
			
		||||
@@ -456,7 +431,30 @@ SW *glue (AUD_open_, TYPE) (
 | 
			
		||||
        return sw;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!pdo->fixed_settings && sw) {
 | 
			
		||||
#ifdef DAC
 | 
			
		||||
    if (conf.plive && sw && (!sw->active && !sw->empty)) {
 | 
			
		||||
        live = sw->total_hw_samples_mixed;
 | 
			
		||||
 | 
			
		||||
#ifdef DEBUG_PLIVE
 | 
			
		||||
        dolog ("Replacing voice %s with %d live samples\n", SW_NAME (sw), live);
 | 
			
		||||
        dolog ("Old %s freq %d, bits %d, channels %d\n",
 | 
			
		||||
               SW_NAME (sw), sw->info.freq, sw->info.bits, sw->info.nchannels);
 | 
			
		||||
        dolog ("New %s freq %d, bits %d, channels %d\n",
 | 
			
		||||
               name,
 | 
			
		||||
               as->freq,
 | 
			
		||||
               (as->fmt == AUD_FMT_S16 || as->fmt == AUD_FMT_U16) ? 16 : 8,
 | 
			
		||||
               as->nchannels);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
        if (live) {
 | 
			
		||||
            old_sw = sw;
 | 
			
		||||
            old_sw->callback.fn = NULL;
 | 
			
		||||
            sw = NULL;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    if (!glue (conf.fixed_, TYPE).enabled && sw) {
 | 
			
		||||
        glue (AUD_close_, TYPE) (card, sw);
 | 
			
		||||
        sw = NULL;
 | 
			
		||||
    }
 | 
			
		||||
@@ -488,6 +486,20 @@ SW *glue (AUD_open_, TYPE) (
 | 
			
		||||
    sw->callback.fn = callback_fn;
 | 
			
		||||
    sw->callback.opaque = callback_opaque;
 | 
			
		||||
 | 
			
		||||
#ifdef DAC
 | 
			
		||||
    if (live) {
 | 
			
		||||
        int mixed =
 | 
			
		||||
            (live << old_sw->info.shift)
 | 
			
		||||
            * old_sw->info.bytes_per_second
 | 
			
		||||
            / sw->info.bytes_per_second;
 | 
			
		||||
 | 
			
		||||
#ifdef DEBUG_PLIVE
 | 
			
		||||
        dolog ("Silence will be mixed %d\n", mixed);
 | 
			
		||||
#endif
 | 
			
		||||
        sw->total_hw_samples_mixed += mixed;
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef DEBUG_AUDIO
 | 
			
		||||
    dolog ("%s\n", name);
 | 
			
		||||
    audio_pcm_print_info ("hw", &sw->hw->info);
 | 
			
		||||
 
 | 
			
		||||
@@ -1,7 +1,7 @@
 | 
			
		||||
/* public domain */
 | 
			
		||||
 | 
			
		||||
#include "qemu/osdep.h"
 | 
			
		||||
#include "qemu-common.h"
 | 
			
		||||
#include "audio.h"
 | 
			
		||||
 | 
			
		||||
#define AUDIO_CAP "win-int"
 | 
			
		||||
#include <windows.h>
 | 
			
		||||
@@ -24,20 +24,20 @@ int waveformat_from_audio_settings (WAVEFORMATEX *wfx,
 | 
			
		||||
    wfx->cbSize = 0;
 | 
			
		||||
 | 
			
		||||
    switch (as->fmt) {
 | 
			
		||||
    case AUDIO_FORMAT_S8:
 | 
			
		||||
    case AUDIO_FORMAT_U8:
 | 
			
		||||
    case AUD_FMT_S8:
 | 
			
		||||
    case AUD_FMT_U8:
 | 
			
		||||
        wfx->wBitsPerSample = 8;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case AUDIO_FORMAT_S16:
 | 
			
		||||
    case AUDIO_FORMAT_U16:
 | 
			
		||||
    case AUD_FMT_S16:
 | 
			
		||||
    case AUD_FMT_U16:
 | 
			
		||||
        wfx->wBitsPerSample = 16;
 | 
			
		||||
        wfx->nAvgBytesPerSec <<= 1;
 | 
			
		||||
        wfx->nBlockAlign <<= 1;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case AUDIO_FORMAT_S32:
 | 
			
		||||
    case AUDIO_FORMAT_U32:
 | 
			
		||||
    case AUD_FMT_S32:
 | 
			
		||||
    case AUD_FMT_U32:
 | 
			
		||||
        wfx->wBitsPerSample = 32;
 | 
			
		||||
        wfx->nAvgBytesPerSec <<= 2;
 | 
			
		||||
        wfx->nBlockAlign <<= 2;
 | 
			
		||||
@@ -85,15 +85,15 @@ int waveformat_to_audio_settings (WAVEFORMATEX *wfx,
 | 
			
		||||
 | 
			
		||||
    switch (wfx->wBitsPerSample) {
 | 
			
		||||
    case 8:
 | 
			
		||||
        as->fmt = AUDIO_FORMAT_U8;
 | 
			
		||||
        as->fmt = AUD_FMT_U8;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case 16:
 | 
			
		||||
        as->fmt = AUDIO_FORMAT_S16;
 | 
			
		||||
        as->fmt = AUD_FMT_S16;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case 32:
 | 
			
		||||
        as->fmt = AUDIO_FORMAT_S32;
 | 
			
		||||
        as->fmt = AUD_FMT_S32;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    default:
 | 
			
		||||
 
 | 
			
		||||
@@ -22,253 +22,38 @@
 | 
			
		||||
 * THE SOFTWARE.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "qemu/osdep.h"
 | 
			
		||||
#include <CoreAudio/CoreAudio.h>
 | 
			
		||||
#include <string.h>             /* strerror */
 | 
			
		||||
#include <pthread.h>            /* pthread_X */
 | 
			
		||||
 | 
			
		||||
#include "qemu/module.h"
 | 
			
		||||
#include "qemu-common.h"
 | 
			
		||||
#include "audio.h"
 | 
			
		||||
 | 
			
		||||
#define AUDIO_CAP "coreaudio"
 | 
			
		||||
#include "audio_int.h"
 | 
			
		||||
 | 
			
		||||
#ifndef MAC_OS_X_VERSION_10_6
 | 
			
		||||
#define MAC_OS_X_VERSION_10_6 1060
 | 
			
		||||
#endif
 | 
			
		||||
struct {
 | 
			
		||||
    int buffer_frames;
 | 
			
		||||
    int nbuffers;
 | 
			
		||||
    int isAtexit;
 | 
			
		||||
} conf = {
 | 
			
		||||
    .buffer_frames = 512,
 | 
			
		||||
    .nbuffers = 4,
 | 
			
		||||
    .isAtexit = 0
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
typedef struct coreaudioVoiceOut {
 | 
			
		||||
    HWVoiceOut hw;
 | 
			
		||||
    pthread_mutex_t mutex;
 | 
			
		||||
    int isAtexit;
 | 
			
		||||
    AudioDeviceID outputDeviceID;
 | 
			
		||||
    UInt32 audioDevicePropertyBufferFrameSize;
 | 
			
		||||
    AudioStreamBasicDescription outputStreamBasicDescription;
 | 
			
		||||
    AudioDeviceIOProcID ioprocid;
 | 
			
		||||
    int live;
 | 
			
		||||
    int decr;
 | 
			
		||||
    int rpos;
 | 
			
		||||
} coreaudioVoiceOut;
 | 
			
		||||
 | 
			
		||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
 | 
			
		||||
/* The APIs used here only become available from 10.6 */
 | 
			
		||||
 | 
			
		||||
static OSStatus coreaudio_get_voice(AudioDeviceID *id)
 | 
			
		||||
{
 | 
			
		||||
    UInt32 size = sizeof(*id);
 | 
			
		||||
    AudioObjectPropertyAddress addr = {
 | 
			
		||||
        kAudioHardwarePropertyDefaultOutputDevice,
 | 
			
		||||
        kAudioObjectPropertyScopeGlobal,
 | 
			
		||||
        kAudioObjectPropertyElementMaster
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    return AudioObjectGetPropertyData(kAudioObjectSystemObject,
 | 
			
		||||
                                      &addr,
 | 
			
		||||
                                      0,
 | 
			
		||||
                                      NULL,
 | 
			
		||||
                                      &size,
 | 
			
		||||
                                      id);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static OSStatus coreaudio_get_framesizerange(AudioDeviceID id,
 | 
			
		||||
                                             AudioValueRange *framerange)
 | 
			
		||||
{
 | 
			
		||||
    UInt32 size = sizeof(*framerange);
 | 
			
		||||
    AudioObjectPropertyAddress addr = {
 | 
			
		||||
        kAudioDevicePropertyBufferFrameSizeRange,
 | 
			
		||||
        kAudioDevicePropertyScopeOutput,
 | 
			
		||||
        kAudioObjectPropertyElementMaster
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    return AudioObjectGetPropertyData(id,
 | 
			
		||||
                                      &addr,
 | 
			
		||||
                                      0,
 | 
			
		||||
                                      NULL,
 | 
			
		||||
                                      &size,
 | 
			
		||||
                                      framerange);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static OSStatus coreaudio_get_framesize(AudioDeviceID id, UInt32 *framesize)
 | 
			
		||||
{
 | 
			
		||||
    UInt32 size = sizeof(*framesize);
 | 
			
		||||
    AudioObjectPropertyAddress addr = {
 | 
			
		||||
        kAudioDevicePropertyBufferFrameSize,
 | 
			
		||||
        kAudioDevicePropertyScopeOutput,
 | 
			
		||||
        kAudioObjectPropertyElementMaster
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    return AudioObjectGetPropertyData(id,
 | 
			
		||||
                                      &addr,
 | 
			
		||||
                                      0,
 | 
			
		||||
                                      NULL,
 | 
			
		||||
                                      &size,
 | 
			
		||||
                                      framesize);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static OSStatus coreaudio_set_framesize(AudioDeviceID id, UInt32 *framesize)
 | 
			
		||||
{
 | 
			
		||||
    UInt32 size = sizeof(*framesize);
 | 
			
		||||
    AudioObjectPropertyAddress addr = {
 | 
			
		||||
        kAudioDevicePropertyBufferFrameSize,
 | 
			
		||||
        kAudioDevicePropertyScopeOutput,
 | 
			
		||||
        kAudioObjectPropertyElementMaster
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    return AudioObjectSetPropertyData(id,
 | 
			
		||||
                                      &addr,
 | 
			
		||||
                                      0,
 | 
			
		||||
                                      NULL,
 | 
			
		||||
                                      size,
 | 
			
		||||
                                      framesize);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static OSStatus coreaudio_get_streamformat(AudioDeviceID id,
 | 
			
		||||
                                           AudioStreamBasicDescription *d)
 | 
			
		||||
{
 | 
			
		||||
    UInt32 size = sizeof(*d);
 | 
			
		||||
    AudioObjectPropertyAddress addr = {
 | 
			
		||||
        kAudioDevicePropertyStreamFormat,
 | 
			
		||||
        kAudioDevicePropertyScopeOutput,
 | 
			
		||||
        kAudioObjectPropertyElementMaster
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    return AudioObjectGetPropertyData(id,
 | 
			
		||||
                                      &addr,
 | 
			
		||||
                                      0,
 | 
			
		||||
                                      NULL,
 | 
			
		||||
                                      &size,
 | 
			
		||||
                                      d);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static OSStatus coreaudio_set_streamformat(AudioDeviceID id,
 | 
			
		||||
                                           AudioStreamBasicDescription *d)
 | 
			
		||||
{
 | 
			
		||||
    UInt32 size = sizeof(*d);
 | 
			
		||||
    AudioObjectPropertyAddress addr = {
 | 
			
		||||
        kAudioDevicePropertyStreamFormat,
 | 
			
		||||
        kAudioDevicePropertyScopeOutput,
 | 
			
		||||
        kAudioObjectPropertyElementMaster
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    return AudioObjectSetPropertyData(id,
 | 
			
		||||
                                      &addr,
 | 
			
		||||
                                      0,
 | 
			
		||||
                                      NULL,
 | 
			
		||||
                                      size,
 | 
			
		||||
                                      d);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static OSStatus coreaudio_get_isrunning(AudioDeviceID id, UInt32 *result)
 | 
			
		||||
{
 | 
			
		||||
    UInt32 size = sizeof(*result);
 | 
			
		||||
    AudioObjectPropertyAddress addr = {
 | 
			
		||||
        kAudioDevicePropertyDeviceIsRunning,
 | 
			
		||||
        kAudioDevicePropertyScopeOutput,
 | 
			
		||||
        kAudioObjectPropertyElementMaster
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    return AudioObjectGetPropertyData(id,
 | 
			
		||||
                                      &addr,
 | 
			
		||||
                                      0,
 | 
			
		||||
                                      NULL,
 | 
			
		||||
                                      &size,
 | 
			
		||||
                                      result);
 | 
			
		||||
}
 | 
			
		||||
#else
 | 
			
		||||
/* Legacy versions of functions using deprecated APIs */
 | 
			
		||||
 | 
			
		||||
static OSStatus coreaudio_get_voice(AudioDeviceID *id)
 | 
			
		||||
{
 | 
			
		||||
    UInt32 size = sizeof(*id);
 | 
			
		||||
 | 
			
		||||
    return AudioHardwareGetProperty(
 | 
			
		||||
        kAudioHardwarePropertyDefaultOutputDevice,
 | 
			
		||||
        &size,
 | 
			
		||||
        id);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static OSStatus coreaudio_get_framesizerange(AudioDeviceID id,
 | 
			
		||||
                                             AudioValueRange *framerange)
 | 
			
		||||
{
 | 
			
		||||
    UInt32 size = sizeof(*framerange);
 | 
			
		||||
 | 
			
		||||
    return AudioDeviceGetProperty(
 | 
			
		||||
        id,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        kAudioDevicePropertyBufferFrameSizeRange,
 | 
			
		||||
        &size,
 | 
			
		||||
        framerange);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static OSStatus coreaudio_get_framesize(AudioDeviceID id, UInt32 *framesize)
 | 
			
		||||
{
 | 
			
		||||
    UInt32 size = sizeof(*framesize);
 | 
			
		||||
 | 
			
		||||
    return AudioDeviceGetProperty(
 | 
			
		||||
        id,
 | 
			
		||||
        0,
 | 
			
		||||
        false,
 | 
			
		||||
        kAudioDevicePropertyBufferFrameSize,
 | 
			
		||||
        &size,
 | 
			
		||||
        framesize);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static OSStatus coreaudio_set_framesize(AudioDeviceID id, UInt32 *framesize)
 | 
			
		||||
{
 | 
			
		||||
    UInt32 size = sizeof(*framesize);
 | 
			
		||||
 | 
			
		||||
    return AudioDeviceSetProperty(
 | 
			
		||||
        id,
 | 
			
		||||
        NULL,
 | 
			
		||||
        0,
 | 
			
		||||
        false,
 | 
			
		||||
        kAudioDevicePropertyBufferFrameSize,
 | 
			
		||||
        size,
 | 
			
		||||
        framesize);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static OSStatus coreaudio_get_streamformat(AudioDeviceID id,
 | 
			
		||||
                                           AudioStreamBasicDescription *d)
 | 
			
		||||
{
 | 
			
		||||
    UInt32 size = sizeof(*d);
 | 
			
		||||
 | 
			
		||||
    return AudioDeviceGetProperty(
 | 
			
		||||
        id,
 | 
			
		||||
        0,
 | 
			
		||||
        false,
 | 
			
		||||
        kAudioDevicePropertyStreamFormat,
 | 
			
		||||
        &size,
 | 
			
		||||
        d);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static OSStatus coreaudio_set_streamformat(AudioDeviceID id,
 | 
			
		||||
                                           AudioStreamBasicDescription *d)
 | 
			
		||||
{
 | 
			
		||||
    UInt32 size = sizeof(*d);
 | 
			
		||||
 | 
			
		||||
    return AudioDeviceSetProperty(
 | 
			
		||||
        id,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        kAudioDevicePropertyStreamFormat,
 | 
			
		||||
        size,
 | 
			
		||||
        d);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static OSStatus coreaudio_get_isrunning(AudioDeviceID id, UInt32 *result)
 | 
			
		||||
{
 | 
			
		||||
    UInt32 size = sizeof(*result);
 | 
			
		||||
 | 
			
		||||
    return AudioDeviceGetProperty(
 | 
			
		||||
        id,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        kAudioDevicePropertyDeviceIsRunning,
 | 
			
		||||
        &size,
 | 
			
		||||
        result);
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
static void coreaudio_logstatus (OSStatus status)
 | 
			
		||||
{
 | 
			
		||||
    const char *str = "BUG";
 | 
			
		||||
@@ -363,7 +148,10 @@ static inline UInt32 isPlaying (AudioDeviceID outputDeviceID)
 | 
			
		||||
{
 | 
			
		||||
    OSStatus status;
 | 
			
		||||
    UInt32 result = 0;
 | 
			
		||||
    status = coreaudio_get_isrunning(outputDeviceID, &result);
 | 
			
		||||
    UInt32 propertySize = sizeof(outputDeviceID);
 | 
			
		||||
    status = AudioDeviceGetProperty(
 | 
			
		||||
        outputDeviceID, 0, 0,
 | 
			
		||||
        kAudioDevicePropertyDeviceIsRunning, &propertySize, &result);
 | 
			
		||||
    if (status != kAudioHardwareNoError) {
 | 
			
		||||
        coreaudio_logerr(status,
 | 
			
		||||
                         "Could not determine whether Device is playing\n");
 | 
			
		||||
@@ -371,6 +159,11 @@ static inline UInt32 isPlaying (AudioDeviceID outputDeviceID)
 | 
			
		||||
    return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void coreaudio_atexit (void)
 | 
			
		||||
{
 | 
			
		||||
    conf.isAtexit = 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int coreaudio_lock (coreaudioVoiceOut *core, const char *fn_name)
 | 
			
		||||
{
 | 
			
		||||
    int err;
 | 
			
		||||
@@ -494,17 +287,14 @@ static int coreaudio_write (SWVoiceOut *sw, void *buf, int len)
 | 
			
		||||
    return audio_pcm_sw_write (sw, buf, len);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
 | 
			
		||||
                              void *drv_opaque)
 | 
			
		||||
static int coreaudio_init_out (HWVoiceOut *hw, struct audsettings *as)
 | 
			
		||||
{
 | 
			
		||||
    OSStatus status;
 | 
			
		||||
    coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw;
 | 
			
		||||
    UInt32 propertySize;
 | 
			
		||||
    int err;
 | 
			
		||||
    const char *typ = "playback";
 | 
			
		||||
    AudioValueRange frameRange;
 | 
			
		||||
    Audiodev *dev = drv_opaque;
 | 
			
		||||
    AudiodevCoreaudioPerDirectionOptions *cpdo = dev->u.coreaudio.out;
 | 
			
		||||
    int frames;
 | 
			
		||||
 | 
			
		||||
    /* create mutex */
 | 
			
		||||
    err = pthread_mutex_init(&core->mutex, NULL);
 | 
			
		||||
@@ -515,7 +305,12 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
 | 
			
		||||
 | 
			
		||||
    audio_pcm_init_info (&hw->info, as);
 | 
			
		||||
 | 
			
		||||
    status = coreaudio_get_voice(&core->outputDeviceID);
 | 
			
		||||
    /* open default output device */
 | 
			
		||||
    propertySize = sizeof(core->outputDeviceID);
 | 
			
		||||
    status = AudioHardwareGetProperty(
 | 
			
		||||
        kAudioHardwarePropertyDefaultOutputDevice,
 | 
			
		||||
        &propertySize,
 | 
			
		||||
        &core->outputDeviceID);
 | 
			
		||||
    if (status != kAudioHardwareNoError) {
 | 
			
		||||
        coreaudio_logerr2 (status, typ,
 | 
			
		||||
                           "Could not get default output Device\n");
 | 
			
		||||
@@ -527,7 +322,13 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* get minimum and maximum buffer frame sizes */
 | 
			
		||||
    status = coreaudio_get_framesizerange(core->outputDeviceID,
 | 
			
		||||
    propertySize = sizeof(frameRange);
 | 
			
		||||
    status = AudioDeviceGetProperty(
 | 
			
		||||
        core->outputDeviceID,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        kAudioDevicePropertyBufferFrameSizeRange,
 | 
			
		||||
        &propertySize,
 | 
			
		||||
        &frameRange);
 | 
			
		||||
    if (status != kAudioHardwareNoError) {
 | 
			
		||||
        coreaudio_logerr2 (status, typ,
 | 
			
		||||
@@ -535,21 +336,27 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    frames = audio_buffer_frames(
 | 
			
		||||
        qapi_AudiodevCoreaudioPerDirectionOptions_base(cpdo), as, 11610);
 | 
			
		||||
    if (frameRange.mMinimum > frames) {
 | 
			
		||||
    if (frameRange.mMinimum > conf.buffer_frames) {
 | 
			
		||||
        core->audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMinimum;
 | 
			
		||||
        dolog ("warning: Upsizing Buffer Frames to %f\n", frameRange.mMinimum);
 | 
			
		||||
    } else if (frameRange.mMaximum < frames) {
 | 
			
		||||
    }
 | 
			
		||||
    else if (frameRange.mMaximum < conf.buffer_frames) {
 | 
			
		||||
        core->audioDevicePropertyBufferFrameSize = (UInt32) frameRange.mMaximum;
 | 
			
		||||
        dolog ("warning: Downsizing Buffer Frames to %f\n", frameRange.mMaximum);
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
        core->audioDevicePropertyBufferFrameSize = frames;
 | 
			
		||||
        core->audioDevicePropertyBufferFrameSize = conf.buffer_frames;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* set Buffer Frame Size */
 | 
			
		||||
    status = coreaudio_set_framesize(core->outputDeviceID,
 | 
			
		||||
    propertySize = sizeof(core->audioDevicePropertyBufferFrameSize);
 | 
			
		||||
    status = AudioDeviceSetProperty(
 | 
			
		||||
        core->outputDeviceID,
 | 
			
		||||
        NULL,
 | 
			
		||||
        0,
 | 
			
		||||
        false,
 | 
			
		||||
        kAudioDevicePropertyBufferFrameSize,
 | 
			
		||||
        propertySize,
 | 
			
		||||
        &core->audioDevicePropertyBufferFrameSize);
 | 
			
		||||
    if (status != kAudioHardwareNoError) {
 | 
			
		||||
        coreaudio_logerr2 (status, typ,
 | 
			
		||||
@@ -559,18 +366,29 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* get Buffer Frame Size */
 | 
			
		||||
    status = coreaudio_get_framesize(core->outputDeviceID,
 | 
			
		||||
    propertySize = sizeof(core->audioDevicePropertyBufferFrameSize);
 | 
			
		||||
    status = AudioDeviceGetProperty(
 | 
			
		||||
        core->outputDeviceID,
 | 
			
		||||
        0,
 | 
			
		||||
        false,
 | 
			
		||||
        kAudioDevicePropertyBufferFrameSize,
 | 
			
		||||
        &propertySize,
 | 
			
		||||
        &core->audioDevicePropertyBufferFrameSize);
 | 
			
		||||
    if (status != kAudioHardwareNoError) {
 | 
			
		||||
        coreaudio_logerr2 (status, typ,
 | 
			
		||||
                           "Could not get device buffer frame size\n");
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
    hw->samples = (cpdo->has_buffer_count ? cpdo->buffer_count : 4) *
 | 
			
		||||
        core->audioDevicePropertyBufferFrameSize;
 | 
			
		||||
    hw->samples = conf.nbuffers * core->audioDevicePropertyBufferFrameSize;
 | 
			
		||||
 | 
			
		||||
    /* get StreamFormat */
 | 
			
		||||
    status = coreaudio_get_streamformat(core->outputDeviceID,
 | 
			
		||||
    propertySize = sizeof(core->outputStreamBasicDescription);
 | 
			
		||||
    status = AudioDeviceGetProperty(
 | 
			
		||||
        core->outputDeviceID,
 | 
			
		||||
        0,
 | 
			
		||||
        false,
 | 
			
		||||
        kAudioDevicePropertyStreamFormat,
 | 
			
		||||
        &propertySize,
 | 
			
		||||
        &core->outputStreamBasicDescription);
 | 
			
		||||
    if (status != kAudioHardwareNoError) {
 | 
			
		||||
        coreaudio_logerr2 (status, typ,
 | 
			
		||||
@@ -581,7 +399,14 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
 | 
			
		||||
 | 
			
		||||
    /* set Samplerate */
 | 
			
		||||
    core->outputStreamBasicDescription.mSampleRate = (Float64) as->freq;
 | 
			
		||||
    status = coreaudio_set_streamformat(core->outputDeviceID,
 | 
			
		||||
    propertySize = sizeof(core->outputStreamBasicDescription);
 | 
			
		||||
    status = AudioDeviceSetProperty(
 | 
			
		||||
        core->outputDeviceID,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        0,
 | 
			
		||||
        kAudioDevicePropertyStreamFormat,
 | 
			
		||||
        propertySize,
 | 
			
		||||
        &core->outputStreamBasicDescription);
 | 
			
		||||
    if (status != kAudioHardwareNoError) {
 | 
			
		||||
        coreaudio_logerr2 (status, typ, "Could not set samplerate %d\n",
 | 
			
		||||
@@ -591,12 +416,8 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* set Callback */
 | 
			
		||||
    core->ioprocid = NULL;
 | 
			
		||||
    status = AudioDeviceCreateIOProcID(core->outputDeviceID,
 | 
			
		||||
                                       audioDeviceIOProc,
 | 
			
		||||
                                       hw,
 | 
			
		||||
                                       &core->ioprocid);
 | 
			
		||||
    if (status != kAudioHardwareNoError || core->ioprocid == NULL) {
 | 
			
		||||
    status = AudioDeviceAddIOProc(core->outputDeviceID, audioDeviceIOProc, hw);
 | 
			
		||||
    if (status != kAudioHardwareNoError) {
 | 
			
		||||
        coreaudio_logerr2 (status, typ, "Could not set IOProc\n");
 | 
			
		||||
        core->outputDeviceID = kAudioDeviceUnknown;
 | 
			
		||||
        return -1;
 | 
			
		||||
@@ -604,10 +425,10 @@ static int coreaudio_init_out(HWVoiceOut *hw, struct audsettings *as,
 | 
			
		||||
 | 
			
		||||
    /* start Playback */
 | 
			
		||||
    if (!isPlaying(core->outputDeviceID)) {
 | 
			
		||||
        status = AudioDeviceStart(core->outputDeviceID, core->ioprocid);
 | 
			
		||||
        status = AudioDeviceStart(core->outputDeviceID, audioDeviceIOProc);
 | 
			
		||||
        if (status != kAudioHardwareNoError) {
 | 
			
		||||
            coreaudio_logerr2 (status, typ, "Could not start playback\n");
 | 
			
		||||
            AudioDeviceDestroyIOProcID(core->outputDeviceID, core->ioprocid);
 | 
			
		||||
            AudioDeviceRemoveIOProc(core->outputDeviceID, audioDeviceIOProc);
 | 
			
		||||
            core->outputDeviceID = kAudioDeviceUnknown;
 | 
			
		||||
            return -1;
 | 
			
		||||
        }
 | 
			
		||||
@@ -622,18 +443,18 @@ static void coreaudio_fini_out (HWVoiceOut *hw)
 | 
			
		||||
    int err;
 | 
			
		||||
    coreaudioVoiceOut *core = (coreaudioVoiceOut *) hw;
 | 
			
		||||
 | 
			
		||||
    if (!audio_is_cleaning_up()) {
 | 
			
		||||
    if (!conf.isAtexit) {
 | 
			
		||||
        /* stop playback */
 | 
			
		||||
        if (isPlaying(core->outputDeviceID)) {
 | 
			
		||||
            status = AudioDeviceStop(core->outputDeviceID, core->ioprocid);
 | 
			
		||||
            status = AudioDeviceStop(core->outputDeviceID, audioDeviceIOProc);
 | 
			
		||||
            if (status != kAudioHardwareNoError) {
 | 
			
		||||
                coreaudio_logerr (status, "Could not stop playback\n");
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* remove callback */
 | 
			
		||||
        status = AudioDeviceDestroyIOProcID(core->outputDeviceID,
 | 
			
		||||
                                            core->ioprocid);
 | 
			
		||||
        status = AudioDeviceRemoveIOProc(core->outputDeviceID,
 | 
			
		||||
                                         audioDeviceIOProc);
 | 
			
		||||
        if (status != kAudioHardwareNoError) {
 | 
			
		||||
            coreaudio_logerr (status, "Could not remove IOProc\n");
 | 
			
		||||
        }
 | 
			
		||||
@@ -656,7 +477,7 @@ static int coreaudio_ctl_out (HWVoiceOut *hw, int cmd, ...)
 | 
			
		||||
    case VOICE_ENABLE:
 | 
			
		||||
        /* start playback */
 | 
			
		||||
        if (!isPlaying(core->outputDeviceID)) {
 | 
			
		||||
            status = AudioDeviceStart(core->outputDeviceID, core->ioprocid);
 | 
			
		||||
            status = AudioDeviceStart(core->outputDeviceID, audioDeviceIOProc);
 | 
			
		||||
            if (status != kAudioHardwareNoError) {
 | 
			
		||||
                coreaudio_logerr (status, "Could not resume playback\n");
 | 
			
		||||
            }
 | 
			
		||||
@@ -665,10 +486,9 @@ static int coreaudio_ctl_out (HWVoiceOut *hw, int cmd, ...)
 | 
			
		||||
 | 
			
		||||
    case VOICE_DISABLE:
 | 
			
		||||
        /* stop playback */
 | 
			
		||||
        if (!audio_is_cleaning_up()) {
 | 
			
		||||
        if (!conf.isAtexit) {
 | 
			
		||||
            if (isPlaying(core->outputDeviceID)) {
 | 
			
		||||
                status = AudioDeviceStop(core->outputDeviceID,
 | 
			
		||||
                                         core->ioprocid);
 | 
			
		||||
                status = AudioDeviceStop(core->outputDeviceID, audioDeviceIOProc);
 | 
			
		||||
                if (status != kAudioHardwareNoError) {
 | 
			
		||||
                    coreaudio_logerr (status, "Could not pause playback\n");
 | 
			
		||||
                }
 | 
			
		||||
@@ -679,15 +499,33 @@ static int coreaudio_ctl_out (HWVoiceOut *hw, int cmd, ...)
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void *coreaudio_audio_init(Audiodev *dev)
 | 
			
		||||
static void *coreaudio_audio_init (void)
 | 
			
		||||
{
 | 
			
		||||
    return dev;
 | 
			
		||||
    atexit(coreaudio_atexit);
 | 
			
		||||
    return &coreaudio_audio_init;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void coreaudio_audio_fini (void *opaque)
 | 
			
		||||
{
 | 
			
		||||
    (void) opaque;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static struct audio_option coreaudio_options[] = {
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "BUFFER_SIZE",
 | 
			
		||||
        .tag   = AUD_OPT_INT,
 | 
			
		||||
        .valp  = &conf.buffer_frames,
 | 
			
		||||
        .descr = "Size of the buffer in frames"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "BUFFER_COUNT",
 | 
			
		||||
        .tag   = AUD_OPT_INT,
 | 
			
		||||
        .valp  = &conf.nbuffers,
 | 
			
		||||
        .descr = "Number of buffers"
 | 
			
		||||
    },
 | 
			
		||||
    { /* End of list */ }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static struct audio_pcm_ops coreaudio_pcm_ops = {
 | 
			
		||||
    .init_out = coreaudio_init_out,
 | 
			
		||||
    .fini_out = coreaudio_fini_out,
 | 
			
		||||
@@ -696,9 +534,10 @@ static struct audio_pcm_ops coreaudio_pcm_ops = {
 | 
			
		||||
    .ctl_out  = coreaudio_ctl_out
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static struct audio_driver coreaudio_audio_driver = {
 | 
			
		||||
struct audio_driver coreaudio_audio_driver = {
 | 
			
		||||
    .name           = "coreaudio",
 | 
			
		||||
    .descr          = "CoreAudio http://developer.apple.com/audio/coreaudio.html",
 | 
			
		||||
    .options        = coreaudio_options,
 | 
			
		||||
    .init           = coreaudio_audio_init,
 | 
			
		||||
    .fini           = coreaudio_audio_fini,
 | 
			
		||||
    .pcm_ops        = &coreaudio_pcm_ops,
 | 
			
		||||
@@ -708,9 +547,3 @@ static struct audio_driver coreaudio_audio_driver = {
 | 
			
		||||
    .voice_size_out = sizeof (coreaudioVoiceOut),
 | 
			
		||||
    .voice_size_in  = 0
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void register_audio_coreaudio(void)
 | 
			
		||||
{
 | 
			
		||||
    audio_driver_register(&coreaudio_audio_driver);
 | 
			
		||||
}
 | 
			
		||||
type_init(register_audio_coreaudio);
 | 
			
		||||
 
 | 
			
		||||
@@ -67,11 +67,11 @@ static int glue (dsound_lock_, TYPE) (
 | 
			
		||||
    LPVOID *p2p,
 | 
			
		||||
    DWORD *blen1p,
 | 
			
		||||
    DWORD *blen2p,
 | 
			
		||||
    int entire,
 | 
			
		||||
    dsound *s
 | 
			
		||||
    int entire
 | 
			
		||||
    )
 | 
			
		||||
{
 | 
			
		||||
    HRESULT hr;
 | 
			
		||||
    int i;
 | 
			
		||||
    LPVOID p1 = NULL, p2 = NULL;
 | 
			
		||||
    DWORD blen1 = 0, blen2 = 0;
 | 
			
		||||
    DWORD flag;
 | 
			
		||||
@@ -81,21 +81,40 @@ static int glue (dsound_lock_, TYPE) (
 | 
			
		||||
#else
 | 
			
		||||
    flag = entire ? DSBLOCK_ENTIREBUFFER : 0;
 | 
			
		||||
#endif
 | 
			
		||||
    hr = glue(IFACE, _Lock)(buf, pos, len, &p1, &blen1, &p2, &blen2, flag);
 | 
			
		||||
    for (i = 0; i < conf.lock_retries; ++i) {
 | 
			
		||||
        hr = glue (IFACE, _Lock) (
 | 
			
		||||
            buf,
 | 
			
		||||
            pos,
 | 
			
		||||
            len,
 | 
			
		||||
            &p1,
 | 
			
		||||
            &blen1,
 | 
			
		||||
            &p2,
 | 
			
		||||
            &blen2,
 | 
			
		||||
            flag
 | 
			
		||||
            );
 | 
			
		||||
 | 
			
		||||
        if (FAILED (hr)) {
 | 
			
		||||
#ifndef DSBTYPE_IN
 | 
			
		||||
            if (hr == DSERR_BUFFERLOST) {
 | 
			
		||||
            if (glue (dsound_restore_, TYPE) (buf, s)) {
 | 
			
		||||
                if (glue (dsound_restore_, TYPE) (buf)) {
 | 
			
		||||
                    dsound_logerr (hr, "Could not lock " NAME "\n");
 | 
			
		||||
            }
 | 
			
		||||
                    goto fail;
 | 
			
		||||
                }
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
#endif
 | 
			
		||||
            dsound_logerr (hr, "Could not lock " NAME "\n");
 | 
			
		||||
            goto fail;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (i == conf.lock_retries) {
 | 
			
		||||
        dolog ("%d attempts to lock " NAME " failed\n", i);
 | 
			
		||||
        goto fail;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if ((p1 && (blen1 & info->align)) || (p2 && (blen2 & info->align))) {
 | 
			
		||||
        dolog ("DirectSound returned misaligned buffer %ld %ld\n",
 | 
			
		||||
               blen1, blen2);
 | 
			
		||||
@@ -155,16 +174,14 @@ static void dsound_fini_out (HWVoiceOut *hw)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef DSBTYPE_IN
 | 
			
		||||
static int dsound_init_in(HWVoiceIn *hw, struct audsettings *as,
 | 
			
		||||
                          void *drv_opaque)
 | 
			
		||||
static int dsound_init_in (HWVoiceIn *hw, struct audsettings *as)
 | 
			
		||||
#else
 | 
			
		||||
static int dsound_init_out(HWVoiceOut *hw, struct audsettings *as,
 | 
			
		||||
                           void *drv_opaque)
 | 
			
		||||
static int dsound_init_out (HWVoiceOut *hw, struct audsettings *as)
 | 
			
		||||
#endif
 | 
			
		||||
{
 | 
			
		||||
    int err;
 | 
			
		||||
    HRESULT hr;
 | 
			
		||||
    dsound *s = drv_opaque;
 | 
			
		||||
    dsound *s = &glob_dsound;
 | 
			
		||||
    WAVEFORMATEX wfx;
 | 
			
		||||
    struct audsettings obt_as;
 | 
			
		||||
#ifdef DSBTYPE_IN
 | 
			
		||||
@@ -172,13 +189,11 @@ static int dsound_init_out(HWVoiceOut *hw, struct audsettings *as,
 | 
			
		||||
    DSoundVoiceIn *ds = (DSoundVoiceIn *) hw;
 | 
			
		||||
    DSCBUFFERDESC bd;
 | 
			
		||||
    DSCBCAPS bc;
 | 
			
		||||
    AudiodevPerDirectionOptions *pdo = s->dev->u.dsound.in;
 | 
			
		||||
#else
 | 
			
		||||
    const char *typ = "DAC";
 | 
			
		||||
    DSoundVoiceOut *ds = (DSoundVoiceOut *) hw;
 | 
			
		||||
    DSBUFFERDESC bd;
 | 
			
		||||
    DSBCAPS bc;
 | 
			
		||||
    AudiodevPerDirectionOptions *pdo = s->dev->u.dsound.out;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    if (!s->FIELD2) {
 | 
			
		||||
@@ -194,8 +209,8 @@ static int dsound_init_out(HWVoiceOut *hw, struct audsettings *as,
 | 
			
		||||
    memset (&bd, 0, sizeof (bd));
 | 
			
		||||
    bd.dwSize = sizeof (bd);
 | 
			
		||||
    bd.lpwfxFormat = &wfx;
 | 
			
		||||
    bd.dwBufferBytes = audio_buffer_bytes(pdo, as, 92880);
 | 
			
		||||
#ifdef DSBTYPE_IN
 | 
			
		||||
    bd.dwBufferBytes = conf.bufsize_in;
 | 
			
		||||
    hr = IDirectSoundCapture_CreateCaptureBuffer (
 | 
			
		||||
        s->dsound_capture,
 | 
			
		||||
        &bd,
 | 
			
		||||
@@ -204,6 +219,7 @@ static int dsound_init_out(HWVoiceOut *hw, struct audsettings *as,
 | 
			
		||||
        );
 | 
			
		||||
#else
 | 
			
		||||
    bd.dwFlags = DSBCAPS_STICKYFOCUS | DSBCAPS_GETCURRENTPOSITION2;
 | 
			
		||||
    bd.dwBufferBytes = conf.bufsize_out;
 | 
			
		||||
    hr = IDirectSound_CreateSoundBuffer (
 | 
			
		||||
        s->dsound,
 | 
			
		||||
        &bd,
 | 
			
		||||
@@ -253,7 +269,6 @@ static int dsound_init_out(HWVoiceOut *hw, struct audsettings *as,
 | 
			
		||||
            );
 | 
			
		||||
    }
 | 
			
		||||
    hw->samples = bc.dwBufferBytes >> hw->info.shift;
 | 
			
		||||
    ds->s = s;
 | 
			
		||||
 | 
			
		||||
#ifdef DEBUG_DSOUND
 | 
			
		||||
    dolog ("caps %ld, desc %ld\n",
 | 
			
		||||
 
 | 
			
		||||
@@ -26,13 +26,11 @@
 | 
			
		||||
 * SEAL 1.07 by Carlos 'pel' Hasan was used as documentation
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "qemu/osdep.h"
 | 
			
		||||
#include "qemu-common.h"
 | 
			
		||||
#include "audio.h"
 | 
			
		||||
 | 
			
		||||
#define AUDIO_CAP "dsound"
 | 
			
		||||
#include "audio_int.h"
 | 
			
		||||
#include "qemu/host-utils.h"
 | 
			
		||||
#include "qemu/module.h"
 | 
			
		||||
 | 
			
		||||
#include <windows.h>
 | 
			
		||||
#include <mmsystem.h>
 | 
			
		||||
@@ -43,19 +41,42 @@
 | 
			
		||||
 | 
			
		||||
/* #define DEBUG_DSOUND */
 | 
			
		||||
 | 
			
		||||
static struct {
 | 
			
		||||
    int lock_retries;
 | 
			
		||||
    int restore_retries;
 | 
			
		||||
    int getstatus_retries;
 | 
			
		||||
    int set_primary;
 | 
			
		||||
    int bufsize_in;
 | 
			
		||||
    int bufsize_out;
 | 
			
		||||
    struct audsettings settings;
 | 
			
		||||
    int latency_millis;
 | 
			
		||||
} conf = {
 | 
			
		||||
    .lock_retries       = 1,
 | 
			
		||||
    .restore_retries    = 1,
 | 
			
		||||
    .getstatus_retries  = 1,
 | 
			
		||||
    .set_primary        = 0,
 | 
			
		||||
    .bufsize_in         = 16384,
 | 
			
		||||
    .bufsize_out        = 16384,
 | 
			
		||||
    .settings.freq      = 44100,
 | 
			
		||||
    .settings.nchannels = 2,
 | 
			
		||||
    .settings.fmt       = AUD_FMT_S16,
 | 
			
		||||
    .latency_millis     = 10
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
typedef struct {
 | 
			
		||||
    LPDIRECTSOUND dsound;
 | 
			
		||||
    LPDIRECTSOUNDCAPTURE dsound_capture;
 | 
			
		||||
    LPDIRECTSOUNDBUFFER dsound_primary_buffer;
 | 
			
		||||
    struct audsettings settings;
 | 
			
		||||
    Audiodev *dev;
 | 
			
		||||
} dsound;
 | 
			
		||||
 | 
			
		||||
static dsound glob_dsound;
 | 
			
		||||
 | 
			
		||||
typedef struct {
 | 
			
		||||
    HWVoiceOut hw;
 | 
			
		||||
    LPDIRECTSOUNDBUFFER dsound_buffer;
 | 
			
		||||
    DWORD old_pos;
 | 
			
		||||
    int first_time;
 | 
			
		||||
    dsound *s;
 | 
			
		||||
#ifdef DEBUG_DSOUND
 | 
			
		||||
    DWORD old_ppos;
 | 
			
		||||
    DWORD played;
 | 
			
		||||
@@ -67,7 +88,6 @@ typedef struct {
 | 
			
		||||
    HWVoiceIn hw;
 | 
			
		||||
    int first_time;
 | 
			
		||||
    LPDIRECTSOUNDCAPTUREBUFFER dsound_capture_buffer;
 | 
			
		||||
    dsound *s;
 | 
			
		||||
} DSoundVoiceIn;
 | 
			
		||||
 | 
			
		||||
static void dsound_log_hresult (HRESULT hr)
 | 
			
		||||
@@ -243,9 +263,9 @@ static void GCC_FMT_ATTR (3, 4) dsound_logerr2 (
 | 
			
		||||
    dsound_log_hresult (hr);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static uint64_t usecs_to_bytes(struct audio_pcm_info *info, uint32_t usecs)
 | 
			
		||||
static DWORD millis_to_bytes (struct audio_pcm_info *info, DWORD millis)
 | 
			
		||||
{
 | 
			
		||||
    return muldiv64(usecs, info->bytes_per_second, 1000000);
 | 
			
		||||
    return (millis * info->bytes_per_second) / 1000;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef DEBUG_DSOUND
 | 
			
		||||
@@ -261,17 +281,29 @@ static void print_wave_format (WAVEFORMATEX *wfx)
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
static int dsound_restore_out (LPDIRECTSOUNDBUFFER dsb, dsound *s)
 | 
			
		||||
static int dsound_restore_out (LPDIRECTSOUNDBUFFER dsb)
 | 
			
		||||
{
 | 
			
		||||
    HRESULT hr;
 | 
			
		||||
    int i;
 | 
			
		||||
 | 
			
		||||
    for (i = 0; i < conf.restore_retries; ++i) {
 | 
			
		||||
        hr = IDirectSoundBuffer_Restore (dsb);
 | 
			
		||||
 | 
			
		||||
    if (hr != DS_OK) {
 | 
			
		||||
        switch (hr) {
 | 
			
		||||
        case DS_OK:
 | 
			
		||||
            return 0;
 | 
			
		||||
 | 
			
		||||
        case DSERR_BUFFERLOST:
 | 
			
		||||
            continue;
 | 
			
		||||
 | 
			
		||||
        default:
 | 
			
		||||
            dsound_logerr (hr, "Could not restore playback buffer\n");
 | 
			
		||||
            return -1;
 | 
			
		||||
        }
 | 
			
		||||
    return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    dolog ("%d attempts to restore playback buffer failed\n", i);
 | 
			
		||||
    return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#include "dsound_template.h"
 | 
			
		||||
@@ -279,11 +311,12 @@ static int dsound_restore_out (LPDIRECTSOUNDBUFFER dsb, dsound *s)
 | 
			
		||||
#include "dsound_template.h"
 | 
			
		||||
#undef DSBTYPE_IN
 | 
			
		||||
 | 
			
		||||
static int dsound_get_status_out (LPDIRECTSOUNDBUFFER dsb, DWORD *statusp,
 | 
			
		||||
                                  dsound *s)
 | 
			
		||||
static int dsound_get_status_out (LPDIRECTSOUNDBUFFER dsb, DWORD *statusp)
 | 
			
		||||
{
 | 
			
		||||
    HRESULT hr;
 | 
			
		||||
    int i;
 | 
			
		||||
 | 
			
		||||
    for (i = 0; i < conf.getstatus_retries; ++i) {
 | 
			
		||||
        hr = IDirectSoundBuffer_GetStatus (dsb, statusp);
 | 
			
		||||
        if (FAILED (hr)) {
 | 
			
		||||
            dsound_logerr (hr, "Could not get playback buffer status\n");
 | 
			
		||||
@@ -291,9 +324,13 @@ static int dsound_get_status_out (LPDIRECTSOUNDBUFFER dsb, DWORD *statusp,
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (*statusp & DSERR_BUFFERLOST) {
 | 
			
		||||
        dsound_restore_out(dsb, s);
 | 
			
		||||
            if (dsound_restore_out (dsb)) {
 | 
			
		||||
                return -1;
 | 
			
		||||
            }
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
@@ -339,8 +376,7 @@ static void dsound_write_sample (HWVoiceOut *hw, uint8_t *dst, int dst_len)
 | 
			
		||||
    hw->rpos = pos % hw->samples;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void dsound_clear_sample (HWVoiceOut *hw, LPDIRECTSOUNDBUFFER dsb,
 | 
			
		||||
                                 dsound *s)
 | 
			
		||||
static void dsound_clear_sample (HWVoiceOut *hw, LPDIRECTSOUNDBUFFER dsb)
 | 
			
		||||
{
 | 
			
		||||
    int err;
 | 
			
		||||
    LPVOID p1, p2;
 | 
			
		||||
@@ -353,8 +389,7 @@ static void dsound_clear_sample (HWVoiceOut *hw, LPDIRECTSOUNDBUFFER dsb,
 | 
			
		||||
        hw->samples << hw->info.shift,
 | 
			
		||||
        &p1, &p2,
 | 
			
		||||
        &blen1, &blen2,
 | 
			
		||||
        1,
 | 
			
		||||
        s
 | 
			
		||||
        1
 | 
			
		||||
        );
 | 
			
		||||
    if (err) {
 | 
			
		||||
        return;
 | 
			
		||||
@@ -380,9 +415,25 @@ static void dsound_clear_sample (HWVoiceOut *hw, LPDIRECTSOUNDBUFFER dsb,
 | 
			
		||||
    dsound_unlock_out (dsb, p1, p2, blen1, blen2);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int dsound_open (dsound *s)
 | 
			
		||||
static void dsound_close (dsound *s)
 | 
			
		||||
{
 | 
			
		||||
    HRESULT hr;
 | 
			
		||||
 | 
			
		||||
    if (s->dsound_primary_buffer) {
 | 
			
		||||
        hr = IDirectSoundBuffer_Release (s->dsound_primary_buffer);
 | 
			
		||||
        if (FAILED (hr)) {
 | 
			
		||||
            dsound_logerr (hr, "Could not release primary buffer\n");
 | 
			
		||||
        }
 | 
			
		||||
        s->dsound_primary_buffer = NULL;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int dsound_open (dsound *s)
 | 
			
		||||
{
 | 
			
		||||
    int err;
 | 
			
		||||
    HRESULT hr;
 | 
			
		||||
    WAVEFORMATEX wfx;
 | 
			
		||||
    DSBUFFERDESC dsbd;
 | 
			
		||||
    HWND hwnd;
 | 
			
		||||
 | 
			
		||||
    hwnd = GetForegroundWindow ();
 | 
			
		||||
@@ -398,16 +449,71 @@ static int dsound_open (dsound *s)
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!conf.set_primary) {
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    err = waveformat_from_audio_settings (&wfx, &conf.settings);
 | 
			
		||||
    if (err) {
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    memset (&dsbd, 0, sizeof (dsbd));
 | 
			
		||||
    dsbd.dwSize = sizeof (dsbd);
 | 
			
		||||
    dsbd.dwFlags = DSBCAPS_PRIMARYBUFFER;
 | 
			
		||||
    dsbd.dwBufferBytes = 0;
 | 
			
		||||
    dsbd.lpwfxFormat = NULL;
 | 
			
		||||
 | 
			
		||||
    hr = IDirectSound_CreateSoundBuffer (
 | 
			
		||||
        s->dsound,
 | 
			
		||||
        &dsbd,
 | 
			
		||||
        &s->dsound_primary_buffer,
 | 
			
		||||
        NULL
 | 
			
		||||
        );
 | 
			
		||||
    if (FAILED (hr)) {
 | 
			
		||||
        dsound_logerr (hr, "Could not create primary playback buffer\n");
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    hr = IDirectSoundBuffer_SetFormat (s->dsound_primary_buffer, &wfx);
 | 
			
		||||
    if (FAILED (hr)) {
 | 
			
		||||
        dsound_logerr (hr, "Could not set primary playback buffer format\n");
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    hr = IDirectSoundBuffer_GetFormat (
 | 
			
		||||
        s->dsound_primary_buffer,
 | 
			
		||||
        &wfx,
 | 
			
		||||
        sizeof (wfx),
 | 
			
		||||
        NULL
 | 
			
		||||
        );
 | 
			
		||||
    if (FAILED (hr)) {
 | 
			
		||||
        dsound_logerr (hr, "Could not get primary playback buffer format\n");
 | 
			
		||||
        goto fail0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
#ifdef DEBUG_DSOUND
 | 
			
		||||
    dolog ("Primary\n");
 | 
			
		||||
    print_wave_format (&wfx);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    err = waveformat_to_audio_settings (&wfx, &s->settings);
 | 
			
		||||
    if (err) {
 | 
			
		||||
        goto fail0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
 | 
			
		||||
 fail0:
 | 
			
		||||
    dsound_close (s);
 | 
			
		||||
    return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int dsound_ctl_out (HWVoiceOut *hw, int cmd, ...)
 | 
			
		||||
{
 | 
			
		||||
    HRESULT hr;
 | 
			
		||||
    DWORD status;
 | 
			
		||||
    DSoundVoiceOut *ds = (DSoundVoiceOut *) hw;
 | 
			
		||||
    LPDIRECTSOUNDBUFFER dsb = ds->dsound_buffer;
 | 
			
		||||
    dsound *s = ds->s;
 | 
			
		||||
 | 
			
		||||
    if (!dsb) {
 | 
			
		||||
        dolog ("Attempt to control voice without a buffer\n");
 | 
			
		||||
@@ -416,7 +522,7 @@ static int dsound_ctl_out (HWVoiceOut *hw, int cmd, ...)
 | 
			
		||||
 | 
			
		||||
    switch (cmd) {
 | 
			
		||||
    case VOICE_ENABLE:
 | 
			
		||||
        if (dsound_get_status_out (dsb, &status, s)) {
 | 
			
		||||
        if (dsound_get_status_out (dsb, &status)) {
 | 
			
		||||
            return -1;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -425,7 +531,7 @@ static int dsound_ctl_out (HWVoiceOut *hw, int cmd, ...)
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        dsound_clear_sample (hw, dsb, s);
 | 
			
		||||
        dsound_clear_sample (hw, dsb);
 | 
			
		||||
 | 
			
		||||
        hr = IDirectSoundBuffer_Play (dsb, 0, 0, DSBPLAY_LOOPING);
 | 
			
		||||
        if (FAILED (hr)) {
 | 
			
		||||
@@ -435,7 +541,7 @@ static int dsound_ctl_out (HWVoiceOut *hw, int cmd, ...)
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case VOICE_DISABLE:
 | 
			
		||||
        if (dsound_get_status_out (dsb, &status, s)) {
 | 
			
		||||
        if (dsound_get_status_out (dsb, &status)) {
 | 
			
		||||
            return -1;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -472,8 +578,6 @@ static int dsound_run_out (HWVoiceOut *hw, int live)
 | 
			
		||||
    DWORD wpos, ppos, old_pos;
 | 
			
		||||
    LPVOID p1, p2;
 | 
			
		||||
    int bufsize;
 | 
			
		||||
    dsound *s = ds->s;
 | 
			
		||||
    AudiodevDsoundOptions *dso = &s->dev->u.dsound;
 | 
			
		||||
 | 
			
		||||
    if (!dsb) {
 | 
			
		||||
        dolog ("Attempt to run empty with playback buffer\n");
 | 
			
		||||
@@ -496,14 +600,14 @@ static int dsound_run_out (HWVoiceOut *hw, int live)
 | 
			
		||||
    len = live << hwshift;
 | 
			
		||||
 | 
			
		||||
    if (ds->first_time) {
 | 
			
		||||
        if (dso->latency) {
 | 
			
		||||
        if (conf.latency_millis) {
 | 
			
		||||
            DWORD cur_blat;
 | 
			
		||||
 | 
			
		||||
            cur_blat = audio_ring_dist (wpos, ppos, bufsize);
 | 
			
		||||
            ds->first_time = 0;
 | 
			
		||||
            old_pos = wpos;
 | 
			
		||||
            old_pos +=
 | 
			
		||||
                usecs_to_bytes(&hw->info, dso->latency) - cur_blat;
 | 
			
		||||
                millis_to_bytes (&hw->info, conf.latency_millis) - cur_blat;
 | 
			
		||||
            old_pos %= bufsize;
 | 
			
		||||
            old_pos &= ~hw->info.align;
 | 
			
		||||
        }
 | 
			
		||||
@@ -538,7 +642,7 @@ static int dsound_run_out (HWVoiceOut *hw, int live)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (audio_bug(__func__, len < 0 || len > bufsize)) {
 | 
			
		||||
    if (audio_bug (AUDIO_FUNC, len < 0 || len > bufsize)) {
 | 
			
		||||
        dolog ("len=%d bufsize=%d old_pos=%ld ppos=%ld\n",
 | 
			
		||||
               len, bufsize, old_pos, ppos);
 | 
			
		||||
        return 0;
 | 
			
		||||
@@ -559,8 +663,7 @@ static int dsound_run_out (HWVoiceOut *hw, int live)
 | 
			
		||||
        len,
 | 
			
		||||
        &p1, &p2,
 | 
			
		||||
        &blen1, &blen2,
 | 
			
		||||
        0,
 | 
			
		||||
        s
 | 
			
		||||
        0
 | 
			
		||||
        );
 | 
			
		||||
    if (err) {
 | 
			
		||||
        return 0;
 | 
			
		||||
@@ -663,7 +766,6 @@ static int dsound_run_in (HWVoiceIn *hw)
 | 
			
		||||
    DWORD cpos, rpos;
 | 
			
		||||
    LPVOID p1, p2;
 | 
			
		||||
    int hwshift;
 | 
			
		||||
    dsound *s = ds->s;
 | 
			
		||||
 | 
			
		||||
    if (!dscb) {
 | 
			
		||||
        dolog ("Attempt to run without capture buffer\n");
 | 
			
		||||
@@ -718,8 +820,7 @@ static int dsound_run_in (HWVoiceIn *hw)
 | 
			
		||||
        &p2,
 | 
			
		||||
        &blen1,
 | 
			
		||||
        &blen2,
 | 
			
		||||
        0,
 | 
			
		||||
        s
 | 
			
		||||
        0
 | 
			
		||||
        );
 | 
			
		||||
    if (err) {
 | 
			
		||||
        return 0;
 | 
			
		||||
@@ -748,7 +849,6 @@ static void dsound_audio_fini (void *opaque)
 | 
			
		||||
    dsound *s = opaque;
 | 
			
		||||
 | 
			
		||||
    if (!s->dsound) {
 | 
			
		||||
        g_free(s);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -759,7 +859,6 @@ static void dsound_audio_fini (void *opaque)
 | 
			
		||||
    s->dsound = NULL;
 | 
			
		||||
 | 
			
		||||
    if (!s->dsound_capture) {
 | 
			
		||||
        g_free(s);
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -768,30 +867,17 @@ static void dsound_audio_fini (void *opaque)
 | 
			
		||||
        dsound_logerr (hr, "Could not release DirectSoundCapture\n");
 | 
			
		||||
    }
 | 
			
		||||
    s->dsound_capture = NULL;
 | 
			
		||||
 | 
			
		||||
    g_free(s);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void *dsound_audio_init(Audiodev *dev)
 | 
			
		||||
static void *dsound_audio_init (void)
 | 
			
		||||
{
 | 
			
		||||
    int err;
 | 
			
		||||
    HRESULT hr;
 | 
			
		||||
    dsound *s = g_malloc0(sizeof(dsound));
 | 
			
		||||
    AudiodevDsoundOptions *dso;
 | 
			
		||||
 | 
			
		||||
    assert(dev->driver == AUDIODEV_DRIVER_DSOUND);
 | 
			
		||||
    s->dev = dev;
 | 
			
		||||
    dso = &dev->u.dsound;
 | 
			
		||||
 | 
			
		||||
    if (!dso->has_latency) {
 | 
			
		||||
        dso->has_latency = true;
 | 
			
		||||
        dso->latency = 10000; /* 10 ms */
 | 
			
		||||
    }
 | 
			
		||||
    dsound *s = &glob_dsound;
 | 
			
		||||
 | 
			
		||||
    hr = CoInitialize (NULL);
 | 
			
		||||
    if (FAILED (hr)) {
 | 
			
		||||
        dsound_logerr (hr, "Could not initialize COM\n");
 | 
			
		||||
        g_free(s);
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -804,7 +890,6 @@ static void *dsound_audio_init(Audiodev *dev)
 | 
			
		||||
        );
 | 
			
		||||
    if (FAILED (hr)) {
 | 
			
		||||
        dsound_logerr (hr, "Could not create DirectSound instance\n");
 | 
			
		||||
        g_free(s);
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -816,7 +901,7 @@ static void *dsound_audio_init(Audiodev *dev)
 | 
			
		||||
        if (FAILED (hr)) {
 | 
			
		||||
            dsound_logerr (hr, "Could not release DirectSound\n");
 | 
			
		||||
        }
 | 
			
		||||
        g_free(s);
 | 
			
		||||
        s->dsound = NULL;
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -852,6 +937,70 @@ static void *dsound_audio_init(Audiodev *dev)
 | 
			
		||||
    return s;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static struct audio_option dsound_options[] = {
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "LOCK_RETRIES",
 | 
			
		||||
        .tag   = AUD_OPT_INT,
 | 
			
		||||
        .valp  = &conf.lock_retries,
 | 
			
		||||
        .descr = "Number of times to attempt locking the buffer"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "RESTOURE_RETRIES",
 | 
			
		||||
        .tag   = AUD_OPT_INT,
 | 
			
		||||
        .valp  = &conf.restore_retries,
 | 
			
		||||
        .descr = "Number of times to attempt restoring the buffer"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "GETSTATUS_RETRIES",
 | 
			
		||||
        .tag   = AUD_OPT_INT,
 | 
			
		||||
        .valp  = &conf.getstatus_retries,
 | 
			
		||||
        .descr = "Number of times to attempt getting status of the buffer"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "SET_PRIMARY",
 | 
			
		||||
        .tag   = AUD_OPT_BOOL,
 | 
			
		||||
        .valp  = &conf.set_primary,
 | 
			
		||||
        .descr = "Set the parameters of primary buffer"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "LATENCY_MILLIS",
 | 
			
		||||
        .tag   = AUD_OPT_INT,
 | 
			
		||||
        .valp  = &conf.latency_millis,
 | 
			
		||||
        .descr = "(undocumented)"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "PRIMARY_FREQ",
 | 
			
		||||
        .tag   = AUD_OPT_INT,
 | 
			
		||||
        .valp  = &conf.settings.freq,
 | 
			
		||||
        .descr = "Primary buffer frequency"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "PRIMARY_CHANNELS",
 | 
			
		||||
        .tag   = AUD_OPT_INT,
 | 
			
		||||
        .valp  = &conf.settings.nchannels,
 | 
			
		||||
        .descr = "Primary buffer number of channels (1 - mono, 2 - stereo)"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "PRIMARY_FMT",
 | 
			
		||||
        .tag   = AUD_OPT_FMT,
 | 
			
		||||
        .valp  = &conf.settings.fmt,
 | 
			
		||||
        .descr = "Primary buffer format"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "BUFSIZE_OUT",
 | 
			
		||||
        .tag   = AUD_OPT_INT,
 | 
			
		||||
        .valp  = &conf.bufsize_out,
 | 
			
		||||
        .descr = "(undocumented)"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "BUFSIZE_IN",
 | 
			
		||||
        .tag   = AUD_OPT_INT,
 | 
			
		||||
        .valp  = &conf.bufsize_in,
 | 
			
		||||
        .descr = "(undocumented)"
 | 
			
		||||
    },
 | 
			
		||||
    { /* End of list */ }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static struct audio_pcm_ops dsound_pcm_ops = {
 | 
			
		||||
    .init_out = dsound_init_out,
 | 
			
		||||
    .fini_out = dsound_fini_out,
 | 
			
		||||
@@ -866,9 +1015,10 @@ static struct audio_pcm_ops dsound_pcm_ops = {
 | 
			
		||||
    .ctl_in   = dsound_ctl_in
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static struct audio_driver dsound_audio_driver = {
 | 
			
		||||
struct audio_driver dsound_audio_driver = {
 | 
			
		||||
    .name           = "dsound",
 | 
			
		||||
    .descr          = "DirectSound http://wikipedia.org/wiki/DirectSound",
 | 
			
		||||
    .options        = dsound_options,
 | 
			
		||||
    .init           = dsound_audio_init,
 | 
			
		||||
    .fini           = dsound_audio_fini,
 | 
			
		||||
    .pcm_ops        = &dsound_pcm_ops,
 | 
			
		||||
@@ -878,9 +1028,3 @@ static struct audio_driver dsound_audio_driver = {
 | 
			
		||||
    .voice_size_out = sizeof (DSoundVoiceOut),
 | 
			
		||||
    .voice_size_in  = sizeof (DSoundVoiceIn)
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void register_audio_dsound(void)
 | 
			
		||||
{
 | 
			
		||||
    audio_driver_register(&dsound_audio_driver);
 | 
			
		||||
}
 | 
			
		||||
type_init(register_audio_dsound);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										557
									
								
								audio/esdaudio.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										557
									
								
								audio/esdaudio.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,557 @@
 | 
			
		||||
/*
 | 
			
		||||
 * QEMU ESD audio driver
 | 
			
		||||
 *
 | 
			
		||||
 * Copyright (c) 2006 Frederick Reeve (brushed up by malc)
 | 
			
		||||
 *
 | 
			
		||||
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
			
		||||
 * of this software and associated documentation files (the "Software"), to deal
 | 
			
		||||
 * in the Software without restriction, including without limitation the rights
 | 
			
		||||
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
			
		||||
 * copies of the Software, and to permit persons to whom the Software is
 | 
			
		||||
 * furnished to do so, subject to the following conditions:
 | 
			
		||||
 *
 | 
			
		||||
 * The above copyright notice and this permission notice shall be included in
 | 
			
		||||
 * all copies or substantial portions of the Software.
 | 
			
		||||
 *
 | 
			
		||||
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 | 
			
		||||
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
			
		||||
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
			
		||||
 * THE SOFTWARE.
 | 
			
		||||
 */
 | 
			
		||||
#include <esd.h>
 | 
			
		||||
#include "qemu-common.h"
 | 
			
		||||
#include "audio.h"
 | 
			
		||||
 | 
			
		||||
#define AUDIO_CAP "esd"
 | 
			
		||||
#include "audio_int.h"
 | 
			
		||||
#include "audio_pt_int.h"
 | 
			
		||||
 | 
			
		||||
typedef struct {
 | 
			
		||||
    HWVoiceOut hw;
 | 
			
		||||
    int done;
 | 
			
		||||
    int live;
 | 
			
		||||
    int decr;
 | 
			
		||||
    int rpos;
 | 
			
		||||
    void *pcm_buf;
 | 
			
		||||
    int fd;
 | 
			
		||||
    struct audio_pt pt;
 | 
			
		||||
} ESDVoiceOut;
 | 
			
		||||
 | 
			
		||||
typedef struct {
 | 
			
		||||
    HWVoiceIn hw;
 | 
			
		||||
    int done;
 | 
			
		||||
    int dead;
 | 
			
		||||
    int incr;
 | 
			
		||||
    int wpos;
 | 
			
		||||
    void *pcm_buf;
 | 
			
		||||
    int fd;
 | 
			
		||||
    struct audio_pt pt;
 | 
			
		||||
} ESDVoiceIn;
 | 
			
		||||
 | 
			
		||||
static struct {
 | 
			
		||||
    int samples;
 | 
			
		||||
    int divisor;
 | 
			
		||||
    char *dac_host;
 | 
			
		||||
    char *adc_host;
 | 
			
		||||
} conf = {
 | 
			
		||||
    .samples = 1024,
 | 
			
		||||
    .divisor = 2,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void GCC_FMT_ATTR (2, 3) qesd_logerr (int err, const char *fmt, ...)
 | 
			
		||||
{
 | 
			
		||||
    va_list ap;
 | 
			
		||||
 | 
			
		||||
    va_start (ap, fmt);
 | 
			
		||||
    AUD_vlog (AUDIO_CAP, fmt, ap);
 | 
			
		||||
    va_end (ap);
 | 
			
		||||
 | 
			
		||||
    AUD_log (AUDIO_CAP, "Reason: %s\n", strerror (err));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* playback */
 | 
			
		||||
static void *qesd_thread_out (void *arg)
 | 
			
		||||
{
 | 
			
		||||
    ESDVoiceOut *esd = arg;
 | 
			
		||||
    HWVoiceOut *hw = &esd->hw;
 | 
			
		||||
    int threshold;
 | 
			
		||||
 | 
			
		||||
    threshold = conf.divisor ? hw->samples / conf.divisor : 0;
 | 
			
		||||
 | 
			
		||||
    if (audio_pt_lock (&esd->pt, AUDIO_FUNC)) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    for (;;) {
 | 
			
		||||
        int decr, to_mix, rpos;
 | 
			
		||||
 | 
			
		||||
        for (;;) {
 | 
			
		||||
            if (esd->done) {
 | 
			
		||||
                goto exit;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (esd->live > threshold) {
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (audio_pt_wait (&esd->pt, AUDIO_FUNC)) {
 | 
			
		||||
                goto exit;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        decr = to_mix = esd->live;
 | 
			
		||||
        rpos = hw->rpos;
 | 
			
		||||
 | 
			
		||||
        if (audio_pt_unlock (&esd->pt, AUDIO_FUNC)) {
 | 
			
		||||
            return NULL;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        while (to_mix) {
 | 
			
		||||
            ssize_t written;
 | 
			
		||||
            int chunk = audio_MIN (to_mix, hw->samples - rpos);
 | 
			
		||||
            struct st_sample *src = hw->mix_buf + rpos;
 | 
			
		||||
 | 
			
		||||
            hw->clip (esd->pcm_buf, src, chunk);
 | 
			
		||||
 | 
			
		||||
        again:
 | 
			
		||||
            written = write (esd->fd, esd->pcm_buf, chunk << hw->info.shift);
 | 
			
		||||
            if (written == -1) {
 | 
			
		||||
                if (errno == EINTR || errno == EAGAIN) {
 | 
			
		||||
                    goto again;
 | 
			
		||||
                }
 | 
			
		||||
                qesd_logerr (errno, "write failed\n");
 | 
			
		||||
                return NULL;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (written != chunk << hw->info.shift) {
 | 
			
		||||
                int wsamples = written >> hw->info.shift;
 | 
			
		||||
                int wbytes = wsamples << hw->info.shift;
 | 
			
		||||
                if (wbytes != written) {
 | 
			
		||||
                    dolog ("warning: Misaligned write %d (requested %zd), "
 | 
			
		||||
                           "alignment %d\n",
 | 
			
		||||
                           wbytes, written, hw->info.align + 1);
 | 
			
		||||
                }
 | 
			
		||||
                to_mix -= wsamples;
 | 
			
		||||
                rpos = (rpos + wsamples) % hw->samples;
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            rpos = (rpos + chunk) % hw->samples;
 | 
			
		||||
            to_mix -= chunk;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (audio_pt_lock (&esd->pt, AUDIO_FUNC)) {
 | 
			
		||||
            return NULL;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        esd->rpos = rpos;
 | 
			
		||||
        esd->live -= decr;
 | 
			
		||||
        esd->decr += decr;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 exit:
 | 
			
		||||
    audio_pt_unlock (&esd->pt, AUDIO_FUNC);
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int qesd_run_out (HWVoiceOut *hw, int live)
 | 
			
		||||
{
 | 
			
		||||
    int decr;
 | 
			
		||||
    ESDVoiceOut *esd = (ESDVoiceOut *) hw;
 | 
			
		||||
 | 
			
		||||
    if (audio_pt_lock (&esd->pt, AUDIO_FUNC)) {
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    decr = audio_MIN (live, esd->decr);
 | 
			
		||||
    esd->decr -= decr;
 | 
			
		||||
    esd->live = live - decr;
 | 
			
		||||
    hw->rpos = esd->rpos;
 | 
			
		||||
    if (esd->live > 0) {
 | 
			
		||||
        audio_pt_unlock_and_signal (&esd->pt, AUDIO_FUNC);
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
        audio_pt_unlock (&esd->pt, AUDIO_FUNC);
 | 
			
		||||
    }
 | 
			
		||||
    return decr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int qesd_write (SWVoiceOut *sw, void *buf, int len)
 | 
			
		||||
{
 | 
			
		||||
    return audio_pcm_sw_write (sw, buf, len);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int qesd_init_out (HWVoiceOut *hw, struct audsettings *as)
 | 
			
		||||
{
 | 
			
		||||
    ESDVoiceOut *esd = (ESDVoiceOut *) hw;
 | 
			
		||||
    struct audsettings obt_as = *as;
 | 
			
		||||
    int esdfmt = ESD_STREAM | ESD_PLAY;
 | 
			
		||||
 | 
			
		||||
    esdfmt |= (as->nchannels == 2) ? ESD_STEREO : ESD_MONO;
 | 
			
		||||
    switch (as->fmt) {
 | 
			
		||||
    case AUD_FMT_S8:
 | 
			
		||||
    case AUD_FMT_U8:
 | 
			
		||||
        esdfmt |= ESD_BITS8;
 | 
			
		||||
        obt_as.fmt = AUD_FMT_U8;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case AUD_FMT_S32:
 | 
			
		||||
    case AUD_FMT_U32:
 | 
			
		||||
        dolog ("Will use 16 instead of 32 bit samples\n");
 | 
			
		||||
 | 
			
		||||
    case AUD_FMT_S16:
 | 
			
		||||
    case AUD_FMT_U16:
 | 
			
		||||
    deffmt:
 | 
			
		||||
        esdfmt |= ESD_BITS16;
 | 
			
		||||
        obt_as.fmt = AUD_FMT_S16;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    default:
 | 
			
		||||
        dolog ("Internal logic error: Bad audio format %d\n", as->fmt);
 | 
			
		||||
        goto deffmt;
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
    obt_as.endianness = AUDIO_HOST_ENDIANNESS;
 | 
			
		||||
 | 
			
		||||
    audio_pcm_init_info (&hw->info, &obt_as);
 | 
			
		||||
 | 
			
		||||
    hw->samples = conf.samples;
 | 
			
		||||
    esd->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift);
 | 
			
		||||
    if (!esd->pcm_buf) {
 | 
			
		||||
        dolog ("Could not allocate buffer (%d bytes)\n",
 | 
			
		||||
               hw->samples << hw->info.shift);
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    esd->fd = esd_play_stream (esdfmt, as->freq, conf.dac_host, NULL);
 | 
			
		||||
    if (esd->fd < 0) {
 | 
			
		||||
        qesd_logerr (errno, "esd_play_stream failed\n");
 | 
			
		||||
        goto fail1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (audio_pt_init (&esd->pt, qesd_thread_out, esd, AUDIO_CAP, AUDIO_FUNC)) {
 | 
			
		||||
        goto fail2;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
 | 
			
		||||
 fail2:
 | 
			
		||||
    if (close (esd->fd)) {
 | 
			
		||||
        qesd_logerr (errno, "%s: close on esd socket(%d) failed\n",
 | 
			
		||||
                     AUDIO_FUNC, esd->fd);
 | 
			
		||||
    }
 | 
			
		||||
    esd->fd = -1;
 | 
			
		||||
 | 
			
		||||
 fail1:
 | 
			
		||||
    qemu_free (esd->pcm_buf);
 | 
			
		||||
    esd->pcm_buf = NULL;
 | 
			
		||||
    return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void qesd_fini_out (HWVoiceOut *hw)
 | 
			
		||||
{
 | 
			
		||||
    void *ret;
 | 
			
		||||
    ESDVoiceOut *esd = (ESDVoiceOut *) hw;
 | 
			
		||||
 | 
			
		||||
    audio_pt_lock (&esd->pt, AUDIO_FUNC);
 | 
			
		||||
    esd->done = 1;
 | 
			
		||||
    audio_pt_unlock_and_signal (&esd->pt, AUDIO_FUNC);
 | 
			
		||||
    audio_pt_join (&esd->pt, &ret, AUDIO_FUNC);
 | 
			
		||||
 | 
			
		||||
    if (esd->fd >= 0) {
 | 
			
		||||
        if (close (esd->fd)) {
 | 
			
		||||
            qesd_logerr (errno, "failed to close esd socket\n");
 | 
			
		||||
        }
 | 
			
		||||
        esd->fd = -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    audio_pt_fini (&esd->pt, AUDIO_FUNC);
 | 
			
		||||
 | 
			
		||||
    qemu_free (esd->pcm_buf);
 | 
			
		||||
    esd->pcm_buf = NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int qesd_ctl_out (HWVoiceOut *hw, int cmd, ...)
 | 
			
		||||
{
 | 
			
		||||
    (void) hw;
 | 
			
		||||
    (void) cmd;
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* capture */
 | 
			
		||||
static void *qesd_thread_in (void *arg)
 | 
			
		||||
{
 | 
			
		||||
    ESDVoiceIn *esd = arg;
 | 
			
		||||
    HWVoiceIn *hw = &esd->hw;
 | 
			
		||||
    int threshold;
 | 
			
		||||
 | 
			
		||||
    threshold = conf.divisor ? hw->samples / conf.divisor : 0;
 | 
			
		||||
 | 
			
		||||
    if (audio_pt_lock (&esd->pt, AUDIO_FUNC)) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    for (;;) {
 | 
			
		||||
        int incr, to_grab, wpos;
 | 
			
		||||
 | 
			
		||||
        for (;;) {
 | 
			
		||||
            if (esd->done) {
 | 
			
		||||
                goto exit;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (esd->dead > threshold) {
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (audio_pt_wait (&esd->pt, AUDIO_FUNC)) {
 | 
			
		||||
                goto exit;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        incr = to_grab = esd->dead;
 | 
			
		||||
        wpos = hw->wpos;
 | 
			
		||||
 | 
			
		||||
        if (audio_pt_unlock (&esd->pt, AUDIO_FUNC)) {
 | 
			
		||||
            return NULL;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        while (to_grab) {
 | 
			
		||||
            ssize_t nread;
 | 
			
		||||
            int chunk = audio_MIN (to_grab, hw->samples - wpos);
 | 
			
		||||
            void *buf = advance (esd->pcm_buf, wpos);
 | 
			
		||||
 | 
			
		||||
        again:
 | 
			
		||||
            nread = read (esd->fd, buf, chunk << hw->info.shift);
 | 
			
		||||
            if (nread == -1) {
 | 
			
		||||
                if (errno == EINTR || errno == EAGAIN) {
 | 
			
		||||
                    goto again;
 | 
			
		||||
                }
 | 
			
		||||
                qesd_logerr (errno, "read failed\n");
 | 
			
		||||
                return NULL;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (nread != chunk << hw->info.shift) {
 | 
			
		||||
                int rsamples = nread >> hw->info.shift;
 | 
			
		||||
                int rbytes = rsamples << hw->info.shift;
 | 
			
		||||
                if (rbytes != nread) {
 | 
			
		||||
                    dolog ("warning: Misaligned write %d (requested %zd), "
 | 
			
		||||
                           "alignment %d\n",
 | 
			
		||||
                           rbytes, nread, hw->info.align + 1);
 | 
			
		||||
                }
 | 
			
		||||
                to_grab -= rsamples;
 | 
			
		||||
                wpos = (wpos + rsamples) % hw->samples;
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            hw->conv (hw->conv_buf + wpos, buf, nread >> hw->info.shift);
 | 
			
		||||
            wpos = (wpos + chunk) % hw->samples;
 | 
			
		||||
            to_grab -= chunk;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (audio_pt_lock (&esd->pt, AUDIO_FUNC)) {
 | 
			
		||||
            return NULL;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        esd->wpos = wpos;
 | 
			
		||||
        esd->dead -= incr;
 | 
			
		||||
        esd->incr += incr;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 exit:
 | 
			
		||||
    audio_pt_unlock (&esd->pt, AUDIO_FUNC);
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int qesd_run_in (HWVoiceIn *hw)
 | 
			
		||||
{
 | 
			
		||||
    int live, incr, dead;
 | 
			
		||||
    ESDVoiceIn *esd = (ESDVoiceIn *) hw;
 | 
			
		||||
 | 
			
		||||
    if (audio_pt_lock (&esd->pt, AUDIO_FUNC)) {
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    live = audio_pcm_hw_get_live_in (hw);
 | 
			
		||||
    dead = hw->samples - live;
 | 
			
		||||
    incr = audio_MIN (dead, esd->incr);
 | 
			
		||||
    esd->incr -= incr;
 | 
			
		||||
    esd->dead = dead - incr;
 | 
			
		||||
    hw->wpos = esd->wpos;
 | 
			
		||||
    if (esd->dead > 0) {
 | 
			
		||||
        audio_pt_unlock_and_signal (&esd->pt, AUDIO_FUNC);
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
        audio_pt_unlock (&esd->pt, AUDIO_FUNC);
 | 
			
		||||
    }
 | 
			
		||||
    return incr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int qesd_read (SWVoiceIn *sw, void *buf, int len)
 | 
			
		||||
{
 | 
			
		||||
    return audio_pcm_sw_read (sw, buf, len);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int qesd_init_in (HWVoiceIn *hw, struct audsettings *as)
 | 
			
		||||
{
 | 
			
		||||
    ESDVoiceIn *esd = (ESDVoiceIn *) hw;
 | 
			
		||||
    struct audsettings obt_as = *as;
 | 
			
		||||
    int esdfmt = ESD_STREAM | ESD_RECORD;
 | 
			
		||||
 | 
			
		||||
    esdfmt |= (as->nchannels == 2) ? ESD_STEREO : ESD_MONO;
 | 
			
		||||
    switch (as->fmt) {
 | 
			
		||||
    case AUD_FMT_S8:
 | 
			
		||||
    case AUD_FMT_U8:
 | 
			
		||||
        esdfmt |= ESD_BITS8;
 | 
			
		||||
        obt_as.fmt = AUD_FMT_U8;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case AUD_FMT_S16:
 | 
			
		||||
    case AUD_FMT_U16:
 | 
			
		||||
        esdfmt |= ESD_BITS16;
 | 
			
		||||
        obt_as.fmt = AUD_FMT_S16;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case AUD_FMT_S32:
 | 
			
		||||
    case AUD_FMT_U32:
 | 
			
		||||
        dolog ("Will use 16 instead of 32 bit samples\n");
 | 
			
		||||
        esdfmt |= ESD_BITS16;
 | 
			
		||||
        obt_as.fmt = AUD_FMT_S16;
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    obt_as.endianness = AUDIO_HOST_ENDIANNESS;
 | 
			
		||||
 | 
			
		||||
    audio_pcm_init_info (&hw->info, &obt_as);
 | 
			
		||||
 | 
			
		||||
    hw->samples = conf.samples;
 | 
			
		||||
    esd->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift);
 | 
			
		||||
    if (!esd->pcm_buf) {
 | 
			
		||||
        dolog ("Could not allocate buffer (%d bytes)\n",
 | 
			
		||||
               hw->samples << hw->info.shift);
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    esd->fd = esd_record_stream (esdfmt, as->freq, conf.adc_host, NULL);
 | 
			
		||||
    if (esd->fd < 0) {
 | 
			
		||||
        qesd_logerr (errno, "esd_record_stream failed\n");
 | 
			
		||||
        goto fail1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (audio_pt_init (&esd->pt, qesd_thread_in, esd, AUDIO_CAP, AUDIO_FUNC)) {
 | 
			
		||||
        goto fail2;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
 | 
			
		||||
 fail2:
 | 
			
		||||
    if (close (esd->fd)) {
 | 
			
		||||
        qesd_logerr (errno, "%s: close on esd socket(%d) failed\n",
 | 
			
		||||
                     AUDIO_FUNC, esd->fd);
 | 
			
		||||
    }
 | 
			
		||||
    esd->fd = -1;
 | 
			
		||||
 | 
			
		||||
 fail1:
 | 
			
		||||
    qemu_free (esd->pcm_buf);
 | 
			
		||||
    esd->pcm_buf = NULL;
 | 
			
		||||
    return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void qesd_fini_in (HWVoiceIn *hw)
 | 
			
		||||
{
 | 
			
		||||
    void *ret;
 | 
			
		||||
    ESDVoiceIn *esd = (ESDVoiceIn *) hw;
 | 
			
		||||
 | 
			
		||||
    audio_pt_lock (&esd->pt, AUDIO_FUNC);
 | 
			
		||||
    esd->done = 1;
 | 
			
		||||
    audio_pt_unlock_and_signal (&esd->pt, AUDIO_FUNC);
 | 
			
		||||
    audio_pt_join (&esd->pt, &ret, AUDIO_FUNC);
 | 
			
		||||
 | 
			
		||||
    if (esd->fd >= 0) {
 | 
			
		||||
        if (close (esd->fd)) {
 | 
			
		||||
            qesd_logerr (errno, "failed to close esd socket\n");
 | 
			
		||||
        }
 | 
			
		||||
        esd->fd = -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    audio_pt_fini (&esd->pt, AUDIO_FUNC);
 | 
			
		||||
 | 
			
		||||
    qemu_free (esd->pcm_buf);
 | 
			
		||||
    esd->pcm_buf = NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int qesd_ctl_in (HWVoiceIn *hw, int cmd, ...)
 | 
			
		||||
{
 | 
			
		||||
    (void) hw;
 | 
			
		||||
    (void) cmd;
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* common */
 | 
			
		||||
static void *qesd_audio_init (void)
 | 
			
		||||
{
 | 
			
		||||
    return &conf;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void qesd_audio_fini (void *opaque)
 | 
			
		||||
{
 | 
			
		||||
    (void) opaque;
 | 
			
		||||
    ldebug ("esd_fini");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
struct audio_option qesd_options[] = {
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "SAMPLES",
 | 
			
		||||
        .tag   = AUD_OPT_INT,
 | 
			
		||||
        .valp  = &conf.samples,
 | 
			
		||||
        .descr = "buffer size in samples"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "DIVISOR",
 | 
			
		||||
        .tag   = AUD_OPT_INT,
 | 
			
		||||
        .valp  = &conf.divisor,
 | 
			
		||||
        .descr = "threshold divisor"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "DAC_HOST",
 | 
			
		||||
        .tag   = AUD_OPT_STR,
 | 
			
		||||
        .valp  = &conf.dac_host,
 | 
			
		||||
        .descr = "playback host"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "ADC_HOST",
 | 
			
		||||
        .tag   = AUD_OPT_STR,
 | 
			
		||||
        .valp  = &conf.adc_host,
 | 
			
		||||
        .descr = "capture host"
 | 
			
		||||
    },
 | 
			
		||||
    { /* End of list */ }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static struct audio_pcm_ops qesd_pcm_ops = {
 | 
			
		||||
    .init_out = qesd_init_out,
 | 
			
		||||
    .fini_out = qesd_fini_out,
 | 
			
		||||
    .run_out  = qesd_run_out,
 | 
			
		||||
    .write    = qesd_write,
 | 
			
		||||
    .ctl_out  = qesd_ctl_out,
 | 
			
		||||
 | 
			
		||||
    .init_in  = qesd_init_in,
 | 
			
		||||
    .fini_in  = qesd_fini_in,
 | 
			
		||||
    .run_in   = qesd_run_in,
 | 
			
		||||
    .read     = qesd_read,
 | 
			
		||||
    .ctl_in   = qesd_ctl_in,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct audio_driver esd_audio_driver = {
 | 
			
		||||
    .name           = "esd",
 | 
			
		||||
    .descr          = "http://en.wikipedia.org/wiki/Esound",
 | 
			
		||||
    .options        = qesd_options,
 | 
			
		||||
    .init           = qesd_audio_init,
 | 
			
		||||
    .fini           = qesd_audio_fini,
 | 
			
		||||
    .pcm_ops        = &qesd_pcm_ops,
 | 
			
		||||
    .can_be_default = 0,
 | 
			
		||||
    .max_voices_out = INT_MAX,
 | 
			
		||||
    .max_voices_in  = INT_MAX,
 | 
			
		||||
    .voice_size_out = sizeof (ESDVoiceOut),
 | 
			
		||||
    .voice_size_in  = sizeof (ESDVoiceIn)
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										687
									
								
								audio/fmodaudio.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										687
									
								
								audio/fmodaudio.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,687 @@
 | 
			
		||||
/*
 | 
			
		||||
 * QEMU FMOD audio driver
 | 
			
		||||
 *
 | 
			
		||||
 * Copyright (c) 2004-2005 Vassili Karpov (malc)
 | 
			
		||||
 *
 | 
			
		||||
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
			
		||||
 * of this software and associated documentation files (the "Software"), to deal
 | 
			
		||||
 * in the Software without restriction, including without limitation the rights
 | 
			
		||||
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
			
		||||
 * copies of the Software, and to permit persons to whom the Software is
 | 
			
		||||
 * furnished to do so, subject to the following conditions:
 | 
			
		||||
 *
 | 
			
		||||
 * The above copyright notice and this permission notice shall be included in
 | 
			
		||||
 * all copies or substantial portions of the Software.
 | 
			
		||||
 *
 | 
			
		||||
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
			
		||||
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
			
		||||
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 | 
			
		||||
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
			
		||||
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
			
		||||
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
			
		||||
 * THE SOFTWARE.
 | 
			
		||||
 */
 | 
			
		||||
#include <fmod.h>
 | 
			
		||||
#include <fmod_errors.h>
 | 
			
		||||
#include "qemu-common.h"
 | 
			
		||||
#include "audio.h"
 | 
			
		||||
 | 
			
		||||
#define AUDIO_CAP "fmod"
 | 
			
		||||
#include "audio_int.h"
 | 
			
		||||
 | 
			
		||||
typedef struct FMODVoiceOut {
 | 
			
		||||
    HWVoiceOut hw;
 | 
			
		||||
    unsigned int old_pos;
 | 
			
		||||
    FSOUND_SAMPLE *fmod_sample;
 | 
			
		||||
    int channel;
 | 
			
		||||
} FMODVoiceOut;
 | 
			
		||||
 | 
			
		||||
typedef struct FMODVoiceIn {
 | 
			
		||||
    HWVoiceIn hw;
 | 
			
		||||
    FSOUND_SAMPLE *fmod_sample;
 | 
			
		||||
} FMODVoiceIn;
 | 
			
		||||
 | 
			
		||||
static struct {
 | 
			
		||||
    const char *drvname;
 | 
			
		||||
    int nb_samples;
 | 
			
		||||
    int freq;
 | 
			
		||||
    int nb_channels;
 | 
			
		||||
    int bufsize;
 | 
			
		||||
    int broken_adc;
 | 
			
		||||
} conf = {
 | 
			
		||||
    .nb_samples  = 2048 * 2,
 | 
			
		||||
    .freq        = 44100,
 | 
			
		||||
    .nb_channels = 2,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void GCC_FMT_ATTR (1, 2) fmod_logerr (const char *fmt, ...)
 | 
			
		||||
{
 | 
			
		||||
    va_list ap;
 | 
			
		||||
 | 
			
		||||
    va_start (ap, fmt);
 | 
			
		||||
    AUD_vlog (AUDIO_CAP, fmt, ap);
 | 
			
		||||
    va_end (ap);
 | 
			
		||||
 | 
			
		||||
    AUD_log (AUDIO_CAP, "Reason: %s\n",
 | 
			
		||||
             FMOD_ErrorString (FSOUND_GetError ()));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void GCC_FMT_ATTR (2, 3) fmod_logerr2 (
 | 
			
		||||
    const char *typ,
 | 
			
		||||
    const char *fmt,
 | 
			
		||||
    ...
 | 
			
		||||
    )
 | 
			
		||||
{
 | 
			
		||||
    va_list ap;
 | 
			
		||||
 | 
			
		||||
    AUD_log (AUDIO_CAP, "Could not initialize %s\n", typ);
 | 
			
		||||
 | 
			
		||||
    va_start (ap, fmt);
 | 
			
		||||
    AUD_vlog (AUDIO_CAP, fmt, ap);
 | 
			
		||||
    va_end (ap);
 | 
			
		||||
 | 
			
		||||
    AUD_log (AUDIO_CAP, "Reason: %s\n",
 | 
			
		||||
             FMOD_ErrorString (FSOUND_GetError ()));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int fmod_write (SWVoiceOut *sw, void *buf, int len)
 | 
			
		||||
{
 | 
			
		||||
    return audio_pcm_sw_write (sw, buf, len);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void fmod_clear_sample (FMODVoiceOut *fmd)
 | 
			
		||||
{
 | 
			
		||||
    HWVoiceOut *hw = &fmd->hw;
 | 
			
		||||
    int status;
 | 
			
		||||
    void *p1 = 0, *p2 = 0;
 | 
			
		||||
    unsigned int len1 = 0, len2 = 0;
 | 
			
		||||
 | 
			
		||||
    status = FSOUND_Sample_Lock (
 | 
			
		||||
        fmd->fmod_sample,
 | 
			
		||||
        0,
 | 
			
		||||
        hw->samples << hw->info.shift,
 | 
			
		||||
        &p1,
 | 
			
		||||
        &p2,
 | 
			
		||||
        &len1,
 | 
			
		||||
        &len2
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
    if (!status) {
 | 
			
		||||
        fmod_logerr ("Failed to lock sample\n");
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if ((len1 & hw->info.align) || (len2 & hw->info.align)) {
 | 
			
		||||
        dolog ("Lock returned misaligned length %d, %d, alignment %d\n",
 | 
			
		||||
               len1, len2, hw->info.align + 1);
 | 
			
		||||
        goto fail;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if ((len1 + len2) - (hw->samples << hw->info.shift)) {
 | 
			
		||||
        dolog ("Lock returned incomplete length %d, %d\n",
 | 
			
		||||
               len1 + len2, hw->samples << hw->info.shift);
 | 
			
		||||
        goto fail;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    audio_pcm_info_clear_buf (&hw->info, p1, hw->samples);
 | 
			
		||||
 | 
			
		||||
 fail:
 | 
			
		||||
    status = FSOUND_Sample_Unlock (fmd->fmod_sample, p1, p2, len1, len2);
 | 
			
		||||
    if (!status) {
 | 
			
		||||
        fmod_logerr ("Failed to unlock sample\n");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void fmod_write_sample (HWVoiceOut *hw, uint8_t *dst, int dst_len)
 | 
			
		||||
{
 | 
			
		||||
    int src_len1 = dst_len;
 | 
			
		||||
    int src_len2 = 0;
 | 
			
		||||
    int pos = hw->rpos + dst_len;
 | 
			
		||||
    struct st_sample *src1 = hw->mix_buf + hw->rpos;
 | 
			
		||||
    struct st_sample *src2 = NULL;
 | 
			
		||||
 | 
			
		||||
    if (pos > hw->samples) {
 | 
			
		||||
        src_len1 = hw->samples - hw->rpos;
 | 
			
		||||
        src2 = hw->mix_buf;
 | 
			
		||||
        src_len2 = dst_len - src_len1;
 | 
			
		||||
        pos = src_len2;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (src_len1) {
 | 
			
		||||
        hw->clip (dst, src1, src_len1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (src_len2) {
 | 
			
		||||
        dst = advance (dst, src_len1 << hw->info.shift);
 | 
			
		||||
        hw->clip (dst, src2, src_len2);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    hw->rpos = pos % hw->samples;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int fmod_unlock_sample (FSOUND_SAMPLE *sample, void *p1, void *p2,
 | 
			
		||||
                               unsigned int blen1, unsigned int blen2)
 | 
			
		||||
{
 | 
			
		||||
    int status = FSOUND_Sample_Unlock (sample, p1, p2, blen1, blen2);
 | 
			
		||||
    if (!status) {
 | 
			
		||||
        fmod_logerr ("Failed to unlock sample\n");
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int fmod_lock_sample (
 | 
			
		||||
    FSOUND_SAMPLE *sample,
 | 
			
		||||
    struct audio_pcm_info *info,
 | 
			
		||||
    int pos,
 | 
			
		||||
    int len,
 | 
			
		||||
    void **p1,
 | 
			
		||||
    void **p2,
 | 
			
		||||
    unsigned int *blen1,
 | 
			
		||||
    unsigned int *blen2
 | 
			
		||||
    )
 | 
			
		||||
{
 | 
			
		||||
    int status;
 | 
			
		||||
 | 
			
		||||
    status = FSOUND_Sample_Lock (
 | 
			
		||||
        sample,
 | 
			
		||||
        pos << info->shift,
 | 
			
		||||
        len << info->shift,
 | 
			
		||||
        p1,
 | 
			
		||||
        p2,
 | 
			
		||||
        blen1,
 | 
			
		||||
        blen2
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
    if (!status) {
 | 
			
		||||
        fmod_logerr ("Failed to lock sample\n");
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if ((*blen1 & info->align) || (*blen2 & info->align)) {
 | 
			
		||||
        dolog ("Lock returned misaligned length %d, %d, alignment %d\n",
 | 
			
		||||
               *blen1, *blen2, info->align + 1);
 | 
			
		||||
 | 
			
		||||
        fmod_unlock_sample (sample, *p1, *p2, *blen1, *blen2);
 | 
			
		||||
 | 
			
		||||
        *p1 = NULL - 1;
 | 
			
		||||
        *p2 = NULL - 1;
 | 
			
		||||
        *blen1 = ~0U;
 | 
			
		||||
        *blen2 = ~0U;
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!*p1 && *blen1) {
 | 
			
		||||
        dolog ("warning: !p1 && blen1=%d\n", *blen1);
 | 
			
		||||
        *blen1 = 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!p2 && *blen2) {
 | 
			
		||||
        dolog ("warning: !p2 && blen2=%d\n", *blen2);
 | 
			
		||||
        *blen2 = 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int fmod_run_out (HWVoiceOut *hw, int live)
 | 
			
		||||
{
 | 
			
		||||
    FMODVoiceOut *fmd = (FMODVoiceOut *) hw;
 | 
			
		||||
    int decr;
 | 
			
		||||
    void *p1 = 0, *p2 = 0;
 | 
			
		||||
    unsigned int blen1 = 0, blen2 = 0;
 | 
			
		||||
    unsigned int len1 = 0, len2 = 0;
 | 
			
		||||
 | 
			
		||||
    if (!hw->pending_disable) {
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    decr = live;
 | 
			
		||||
 | 
			
		||||
    if (fmd->channel >= 0) {
 | 
			
		||||
        int len = decr;
 | 
			
		||||
        int old_pos = fmd->old_pos;
 | 
			
		||||
        int ppos = FSOUND_GetCurrentPosition (fmd->channel);
 | 
			
		||||
 | 
			
		||||
        if (ppos == old_pos || !ppos) {
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if ((old_pos < ppos) && ((old_pos + len) > ppos)) {
 | 
			
		||||
            len = ppos - old_pos;
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            if ((old_pos > ppos) && ((old_pos + len) > (ppos + hw->samples))) {
 | 
			
		||||
                len = hw->samples - old_pos + ppos;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        decr = len;
 | 
			
		||||
 | 
			
		||||
        if (audio_bug (AUDIO_FUNC, decr < 0)) {
 | 
			
		||||
            dolog ("decr=%d live=%d ppos=%d old_pos=%d len=%d\n",
 | 
			
		||||
                   decr, live, ppos, old_pos, len);
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    if (!decr) {
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (fmod_lock_sample (fmd->fmod_sample, &fmd->hw.info,
 | 
			
		||||
                          fmd->old_pos, decr,
 | 
			
		||||
                          &p1, &p2,
 | 
			
		||||
                          &blen1, &blen2)) {
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    len1 = blen1 >> hw->info.shift;
 | 
			
		||||
    len2 = blen2 >> hw->info.shift;
 | 
			
		||||
    ldebug ("%p %p %d %d %d %d\n", p1, p2, len1, len2, blen1, blen2);
 | 
			
		||||
    decr = len1 + len2;
 | 
			
		||||
 | 
			
		||||
    if (p1 && len1) {
 | 
			
		||||
        fmod_write_sample (hw, p1, len1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (p2 && len2) {
 | 
			
		||||
        fmod_write_sample (hw, p2, len2);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fmod_unlock_sample (fmd->fmod_sample, p1, p2, blen1, blen2);
 | 
			
		||||
 | 
			
		||||
    fmd->old_pos = (fmd->old_pos + decr) % hw->samples;
 | 
			
		||||
    return decr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int aud_to_fmodfmt (audfmt_e fmt, int stereo)
 | 
			
		||||
{
 | 
			
		||||
    int mode = FSOUND_LOOP_NORMAL;
 | 
			
		||||
 | 
			
		||||
    switch (fmt) {
 | 
			
		||||
    case AUD_FMT_S8:
 | 
			
		||||
        mode |= FSOUND_SIGNED | FSOUND_8BITS;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case AUD_FMT_U8:
 | 
			
		||||
        mode |= FSOUND_UNSIGNED | FSOUND_8BITS;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case AUD_FMT_S16:
 | 
			
		||||
        mode |= FSOUND_SIGNED | FSOUND_16BITS;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case AUD_FMT_U16:
 | 
			
		||||
        mode |= FSOUND_UNSIGNED | FSOUND_16BITS;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    default:
 | 
			
		||||
        dolog ("Internal logic error: Bad audio format %d\n", fmt);
 | 
			
		||||
#ifdef DEBUG_FMOD
 | 
			
		||||
        abort ();
 | 
			
		||||
#endif
 | 
			
		||||
        mode |= FSOUND_8BITS;
 | 
			
		||||
    }
 | 
			
		||||
    mode |= stereo ? FSOUND_STEREO : FSOUND_MONO;
 | 
			
		||||
    return mode;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void fmod_fini_out (HWVoiceOut *hw)
 | 
			
		||||
{
 | 
			
		||||
    FMODVoiceOut *fmd = (FMODVoiceOut *) hw;
 | 
			
		||||
 | 
			
		||||
    if (fmd->fmod_sample) {
 | 
			
		||||
        FSOUND_Sample_Free (fmd->fmod_sample);
 | 
			
		||||
        fmd->fmod_sample = 0;
 | 
			
		||||
 | 
			
		||||
        if (fmd->channel >= 0) {
 | 
			
		||||
            FSOUND_StopSound (fmd->channel);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int fmod_init_out (HWVoiceOut *hw, struct audsettings *as)
 | 
			
		||||
{
 | 
			
		||||
    int bits16, mode, channel;
 | 
			
		||||
    FMODVoiceOut *fmd = (FMODVoiceOut *) hw;
 | 
			
		||||
    struct audsettings obt_as = *as;
 | 
			
		||||
 | 
			
		||||
    mode = aud_to_fmodfmt (as->fmt, as->nchannels == 2 ? 1 : 0);
 | 
			
		||||
    fmd->fmod_sample = FSOUND_Sample_Alloc (
 | 
			
		||||
        FSOUND_FREE,            /* index */
 | 
			
		||||
        conf.nb_samples,        /* length */
 | 
			
		||||
        mode,                   /* mode */
 | 
			
		||||
        as->freq,               /* freq */
 | 
			
		||||
        255,                    /* volume */
 | 
			
		||||
        128,                    /* pan */
 | 
			
		||||
        255                     /* priority */
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
    if (!fmd->fmod_sample) {
 | 
			
		||||
        fmod_logerr2 ("DAC", "Failed to allocate FMOD sample\n");
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    channel = FSOUND_PlaySoundEx (FSOUND_FREE, fmd->fmod_sample, 0, 1);
 | 
			
		||||
    if (channel < 0) {
 | 
			
		||||
        fmod_logerr2 ("DAC", "Failed to start playing sound\n");
 | 
			
		||||
        FSOUND_Sample_Free (fmd->fmod_sample);
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
    fmd->channel = channel;
 | 
			
		||||
 | 
			
		||||
    /* FMOD always operates on little endian frames? */
 | 
			
		||||
    obt_as.endianness = 0;
 | 
			
		||||
    audio_pcm_init_info (&hw->info, &obt_as);
 | 
			
		||||
    bits16 = (mode & FSOUND_16BITS) != 0;
 | 
			
		||||
    hw->samples = conf.nb_samples;
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int fmod_ctl_out (HWVoiceOut *hw, int cmd, ...)
 | 
			
		||||
{
 | 
			
		||||
    int status;
 | 
			
		||||
    FMODVoiceOut *fmd = (FMODVoiceOut *) hw;
 | 
			
		||||
 | 
			
		||||
    switch (cmd) {
 | 
			
		||||
    case VOICE_ENABLE:
 | 
			
		||||
        fmod_clear_sample (fmd);
 | 
			
		||||
        status = FSOUND_SetPaused (fmd->channel, 0);
 | 
			
		||||
        if (!status) {
 | 
			
		||||
            fmod_logerr ("Failed to resume channel %d\n", fmd->channel);
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case VOICE_DISABLE:
 | 
			
		||||
        status = FSOUND_SetPaused (fmd->channel, 1);
 | 
			
		||||
        if (!status) {
 | 
			
		||||
            fmod_logerr ("Failed to pause channel %d\n", fmd->channel);
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int fmod_init_in (HWVoiceIn *hw, struct audsettings *as)
 | 
			
		||||
{
 | 
			
		||||
    int bits16, mode;
 | 
			
		||||
    FMODVoiceIn *fmd = (FMODVoiceIn *) hw;
 | 
			
		||||
    struct audsettings obt_as = *as;
 | 
			
		||||
 | 
			
		||||
    if (conf.broken_adc) {
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    mode = aud_to_fmodfmt (as->fmt, as->nchannels == 2 ? 1 : 0);
 | 
			
		||||
    fmd->fmod_sample = FSOUND_Sample_Alloc (
 | 
			
		||||
        FSOUND_FREE,            /* index */
 | 
			
		||||
        conf.nb_samples,        /* length */
 | 
			
		||||
        mode,                   /* mode */
 | 
			
		||||
        as->freq,               /* freq */
 | 
			
		||||
        255,                    /* volume */
 | 
			
		||||
        128,                    /* pan */
 | 
			
		||||
        255                     /* priority */
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
    if (!fmd->fmod_sample) {
 | 
			
		||||
        fmod_logerr2 ("ADC", "Failed to allocate FMOD sample\n");
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* FMOD always operates on little endian frames? */
 | 
			
		||||
    obt_as.endianness = 0;
 | 
			
		||||
    audio_pcm_init_info (&hw->info, &obt_as);
 | 
			
		||||
    bits16 = (mode & FSOUND_16BITS) != 0;
 | 
			
		||||
    hw->samples = conf.nb_samples;
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void fmod_fini_in (HWVoiceIn *hw)
 | 
			
		||||
{
 | 
			
		||||
    FMODVoiceIn *fmd = (FMODVoiceIn *) hw;
 | 
			
		||||
 | 
			
		||||
    if (fmd->fmod_sample) {
 | 
			
		||||
        FSOUND_Record_Stop ();
 | 
			
		||||
        FSOUND_Sample_Free (fmd->fmod_sample);
 | 
			
		||||
        fmd->fmod_sample = 0;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int fmod_run_in (HWVoiceIn *hw)
 | 
			
		||||
{
 | 
			
		||||
    FMODVoiceIn *fmd = (FMODVoiceIn *) hw;
 | 
			
		||||
    int hwshift = hw->info.shift;
 | 
			
		||||
    int live, dead, new_pos, len;
 | 
			
		||||
    unsigned int blen1 = 0, blen2 = 0;
 | 
			
		||||
    unsigned int len1, len2;
 | 
			
		||||
    unsigned int decr;
 | 
			
		||||
    void *p1, *p2;
 | 
			
		||||
 | 
			
		||||
    live = audio_pcm_hw_get_live_in (hw);
 | 
			
		||||
    dead = hw->samples - live;
 | 
			
		||||
    if (!dead) {
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    new_pos = FSOUND_Record_GetPosition ();
 | 
			
		||||
    if (new_pos < 0) {
 | 
			
		||||
        fmod_logerr ("Could not get recording position\n");
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    len = audio_ring_dist (new_pos,  hw->wpos, hw->samples);
 | 
			
		||||
    if (!len) {
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
    len = audio_MIN (len, dead);
 | 
			
		||||
 | 
			
		||||
    if (fmod_lock_sample (fmd->fmod_sample, &fmd->hw.info,
 | 
			
		||||
                          hw->wpos, len,
 | 
			
		||||
                          &p1, &p2,
 | 
			
		||||
                          &blen1, &blen2)) {
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    len1 = blen1 >> hwshift;
 | 
			
		||||
    len2 = blen2 >> hwshift;
 | 
			
		||||
    decr = len1 + len2;
 | 
			
		||||
 | 
			
		||||
    if (p1 && blen1) {
 | 
			
		||||
        hw->conv (hw->conv_buf + hw->wpos, p1, len1);
 | 
			
		||||
    }
 | 
			
		||||
    if (p2 && len2) {
 | 
			
		||||
        hw->conv (hw->conv_buf, p2, len2);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fmod_unlock_sample (fmd->fmod_sample, p1, p2, blen1, blen2);
 | 
			
		||||
    hw->wpos = (hw->wpos + decr) % hw->samples;
 | 
			
		||||
    return decr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static struct {
 | 
			
		||||
    const char *name;
 | 
			
		||||
    int type;
 | 
			
		||||
} drvtab[] = {
 | 
			
		||||
    { .name = "none",   .type = FSOUND_OUTPUT_NOSOUND },
 | 
			
		||||
#ifdef _WIN32
 | 
			
		||||
    { .name = "winmm",  .type = FSOUND_OUTPUT_WINMM   },
 | 
			
		||||
    { .name = "dsound", .type = FSOUND_OUTPUT_DSOUND  },
 | 
			
		||||
    { .name = "a3d",    .type = FSOUND_OUTPUT_A3D     },
 | 
			
		||||
    { .name = "asio",   .type = FSOUND_OUTPUT_ASIO    },
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef __linux__
 | 
			
		||||
    { .name = "oss",    .type = FSOUND_OUTPUT_OSS     },
 | 
			
		||||
    { .name = "alsa",   .type = FSOUND_OUTPUT_ALSA    },
 | 
			
		||||
    { .name = "esd",    .type = FSOUND_OUTPUT_ESD     },
 | 
			
		||||
#endif
 | 
			
		||||
#ifdef __APPLE__
 | 
			
		||||
    { .name = "mac",    .type = FSOUND_OUTPUT_MAC     },
 | 
			
		||||
#endif
 | 
			
		||||
#if 0
 | 
			
		||||
    { .name = "xbox",   .type = FSOUND_OUTPUT_XBOX    },
 | 
			
		||||
    { .name = "ps2",    .type = FSOUND_OUTPUT_PS2     },
 | 
			
		||||
    { .name = "gcube",  .type = FSOUND_OUTPUT_GC      },
 | 
			
		||||
#endif
 | 
			
		||||
    { .name = "none-realtime", .type = FSOUND_OUTPUT_NOSOUND_NONREALTIME }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void *fmod_audio_init (void)
 | 
			
		||||
{
 | 
			
		||||
    size_t i;
 | 
			
		||||
    double ver;
 | 
			
		||||
    int status;
 | 
			
		||||
    int output_type = -1;
 | 
			
		||||
    const char *drv = conf.drvname;
 | 
			
		||||
 | 
			
		||||
    ver = FSOUND_GetVersion ();
 | 
			
		||||
    if (ver < FMOD_VERSION) {
 | 
			
		||||
        dolog ("Wrong FMOD version %f, need at least %f\n", ver, FMOD_VERSION);
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
#ifdef __linux__
 | 
			
		||||
    if (ver < 3.75) {
 | 
			
		||||
        dolog ("FMOD before 3.75 has bug preventing ADC from working\n"
 | 
			
		||||
               "ADC will be disabled.\n");
 | 
			
		||||
        conf.broken_adc = 1;
 | 
			
		||||
    }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    if (drv) {
 | 
			
		||||
        int found = 0;
 | 
			
		||||
        for (i = 0; i < ARRAY_SIZE (drvtab); i++) {
 | 
			
		||||
            if (!strcmp (drv, drvtab[i].name)) {
 | 
			
		||||
                output_type = drvtab[i].type;
 | 
			
		||||
                found = 1;
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        if (!found) {
 | 
			
		||||
            dolog ("Unknown FMOD driver `%s'\n", drv);
 | 
			
		||||
            dolog ("Valid drivers:\n");
 | 
			
		||||
            for (i = 0; i < ARRAY_SIZE (drvtab); i++) {
 | 
			
		||||
                dolog ("  %s\n", drvtab[i].name);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (output_type != -1) {
 | 
			
		||||
        status = FSOUND_SetOutput (output_type);
 | 
			
		||||
        if (!status) {
 | 
			
		||||
            fmod_logerr ("FSOUND_SetOutput(%d) failed\n", output_type);
 | 
			
		||||
            return NULL;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (conf.bufsize) {
 | 
			
		||||
        status = FSOUND_SetBufferSize (conf.bufsize);
 | 
			
		||||
        if (!status) {
 | 
			
		||||
            fmod_logerr ("FSOUND_SetBufferSize (%d) failed\n", conf.bufsize);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    status = FSOUND_Init (conf.freq, conf.nb_channels, 0);
 | 
			
		||||
    if (!status) {
 | 
			
		||||
        fmod_logerr ("FSOUND_Init failed\n");
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return &conf;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int fmod_read (SWVoiceIn *sw, void *buf, int size)
 | 
			
		||||
{
 | 
			
		||||
    return audio_pcm_sw_read (sw, buf, size);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int fmod_ctl_in (HWVoiceIn *hw, int cmd, ...)
 | 
			
		||||
{
 | 
			
		||||
    int status;
 | 
			
		||||
    FMODVoiceIn *fmd = (FMODVoiceIn *) hw;
 | 
			
		||||
 | 
			
		||||
    switch (cmd) {
 | 
			
		||||
    case VOICE_ENABLE:
 | 
			
		||||
        status = FSOUND_Record_StartSample (fmd->fmod_sample, 1);
 | 
			
		||||
        if (!status) {
 | 
			
		||||
            fmod_logerr ("Failed to start recording\n");
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case VOICE_DISABLE:
 | 
			
		||||
        status = FSOUND_Record_Stop ();
 | 
			
		||||
        if (!status) {
 | 
			
		||||
            fmod_logerr ("Failed to stop recording\n");
 | 
			
		||||
        }
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void fmod_audio_fini (void *opaque)
 | 
			
		||||
{
 | 
			
		||||
    (void) opaque;
 | 
			
		||||
    FSOUND_Close ();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static struct audio_option fmod_options[] = {
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "DRV",
 | 
			
		||||
        .tag   = AUD_OPT_STR,
 | 
			
		||||
        .valp  = &conf.drvname,
 | 
			
		||||
        .descr = "FMOD driver"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "FREQ",
 | 
			
		||||
        .tag   = AUD_OPT_INT,
 | 
			
		||||
        .valp  = &conf.freq,
 | 
			
		||||
        .descr = "Default frequency"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "SAMPLES",
 | 
			
		||||
        .tag   = AUD_OPT_INT,
 | 
			
		||||
        .valp  = &conf.nb_samples,
 | 
			
		||||
        .descr = "Buffer size in samples"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "CHANNELS",
 | 
			
		||||
        .tag   = AUD_OPT_INT,
 | 
			
		||||
        .valp  = &conf.nb_channels,
 | 
			
		||||
        .descr = "Number of default channels (1 - mono, 2 - stereo)"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "BUFSIZE",
 | 
			
		||||
        .tag   = AUD_OPT_INT,
 | 
			
		||||
        .valp  = &conf.bufsize,
 | 
			
		||||
        .descr = "(undocumented)"
 | 
			
		||||
    },
 | 
			
		||||
    { /* End of list */ }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static struct audio_pcm_ops fmod_pcm_ops = {
 | 
			
		||||
    .init_out = fmod_init_out,
 | 
			
		||||
    .fini_out = fmod_fini_out,
 | 
			
		||||
    .run_out  = fmod_run_out,
 | 
			
		||||
    .write    = fmod_write,
 | 
			
		||||
    .ctl_out  = fmod_ctl_out,
 | 
			
		||||
 | 
			
		||||
    .init_in  = fmod_init_in,
 | 
			
		||||
    .fini_in  = fmod_fini_in,
 | 
			
		||||
    .run_in   = fmod_run_in,
 | 
			
		||||
    .read     = fmod_read,
 | 
			
		||||
    .ctl_in   = fmod_ctl_in
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct audio_driver fmod_audio_driver = {
 | 
			
		||||
    .name           = "fmod",
 | 
			
		||||
    .descr          = "FMOD 3.xx http://www.fmod.org",
 | 
			
		||||
    .options        = fmod_options,
 | 
			
		||||
    .init           = fmod_audio_init,
 | 
			
		||||
    .fini           = fmod_audio_fini,
 | 
			
		||||
    .pcm_ops        = &fmod_pcm_ops,
 | 
			
		||||
    .can_be_default = 1,
 | 
			
		||||
    .max_voices_out = INT_MAX,
 | 
			
		||||
    .max_voices_in  = INT_MAX,
 | 
			
		||||
    .voice_size_out = sizeof (FMODVoiceOut),
 | 
			
		||||
    .voice_size_in  = sizeof (FMODVoiceIn)
 | 
			
		||||
};
 | 
			
		||||
@@ -22,9 +22,7 @@
 | 
			
		||||
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
			
		||||
 * THE SOFTWARE.
 | 
			
		||||
 */
 | 
			
		||||
#include "qemu/osdep.h"
 | 
			
		||||
#include "qemu/bswap.h"
 | 
			
		||||
#include "qemu/error-report.h"
 | 
			
		||||
#include "qemu-common.h"
 | 
			
		||||
#include "audio.h"
 | 
			
		||||
 | 
			
		||||
#define AUDIO_CAP "mixeng"
 | 
			
		||||
@@ -35,8 +33,7 @@
 | 
			
		||||
#define ENDIAN_CONVERT(v) (v)
 | 
			
		||||
 | 
			
		||||
/* Signed 8 bit */
 | 
			
		||||
#define BSIZE 8
 | 
			
		||||
#define ITYPE int
 | 
			
		||||
#define IN_T int8_t
 | 
			
		||||
#define IN_MIN SCHAR_MIN
 | 
			
		||||
#define IN_MAX SCHAR_MAX
 | 
			
		||||
#define SIGNED
 | 
			
		||||
@@ -45,29 +42,25 @@
 | 
			
		||||
#undef SIGNED
 | 
			
		||||
#undef IN_MAX
 | 
			
		||||
#undef IN_MIN
 | 
			
		||||
#undef BSIZE
 | 
			
		||||
#undef ITYPE
 | 
			
		||||
#undef IN_T
 | 
			
		||||
#undef SHIFT
 | 
			
		||||
 | 
			
		||||
/* Unsigned 8 bit */
 | 
			
		||||
#define BSIZE 8
 | 
			
		||||
#define ITYPE uint
 | 
			
		||||
#define IN_T uint8_t
 | 
			
		||||
#define IN_MIN 0
 | 
			
		||||
#define IN_MAX UCHAR_MAX
 | 
			
		||||
#define SHIFT 8
 | 
			
		||||
#include "mixeng_template.h"
 | 
			
		||||
#undef IN_MAX
 | 
			
		||||
#undef IN_MIN
 | 
			
		||||
#undef BSIZE
 | 
			
		||||
#undef ITYPE
 | 
			
		||||
#undef IN_T
 | 
			
		||||
#undef SHIFT
 | 
			
		||||
 | 
			
		||||
#undef ENDIAN_CONVERT
 | 
			
		||||
#undef ENDIAN_CONVERSION
 | 
			
		||||
 | 
			
		||||
/* Signed 16 bit */
 | 
			
		||||
#define BSIZE 16
 | 
			
		||||
#define ITYPE int
 | 
			
		||||
#define IN_T int16_t
 | 
			
		||||
#define IN_MIN SHRT_MIN
 | 
			
		||||
#define IN_MAX SHRT_MAX
 | 
			
		||||
#define SIGNED
 | 
			
		||||
@@ -85,13 +78,11 @@
 | 
			
		||||
#undef SIGNED
 | 
			
		||||
#undef IN_MAX
 | 
			
		||||
#undef IN_MIN
 | 
			
		||||
#undef BSIZE
 | 
			
		||||
#undef ITYPE
 | 
			
		||||
#undef IN_T
 | 
			
		||||
#undef SHIFT
 | 
			
		||||
 | 
			
		||||
/* Unsigned 16 bit */
 | 
			
		||||
#define BSIZE 16
 | 
			
		||||
#define ITYPE uint
 | 
			
		||||
#define IN_T uint16_t
 | 
			
		||||
#define IN_MIN 0
 | 
			
		||||
#define IN_MAX USHRT_MAX
 | 
			
		||||
#define SHIFT 16
 | 
			
		||||
@@ -107,13 +98,11 @@
 | 
			
		||||
#undef ENDIAN_CONVERSION
 | 
			
		||||
#undef IN_MAX
 | 
			
		||||
#undef IN_MIN
 | 
			
		||||
#undef BSIZE
 | 
			
		||||
#undef ITYPE
 | 
			
		||||
#undef IN_T
 | 
			
		||||
#undef SHIFT
 | 
			
		||||
 | 
			
		||||
/* Signed 32 bit */
 | 
			
		||||
#define BSIZE 32
 | 
			
		||||
#define ITYPE int
 | 
			
		||||
#define IN_T int32_t
 | 
			
		||||
#define IN_MIN INT32_MIN
 | 
			
		||||
#define IN_MAX INT32_MAX
 | 
			
		||||
#define SIGNED
 | 
			
		||||
@@ -131,13 +120,11 @@
 | 
			
		||||
#undef SIGNED
 | 
			
		||||
#undef IN_MAX
 | 
			
		||||
#undef IN_MIN
 | 
			
		||||
#undef BSIZE
 | 
			
		||||
#undef ITYPE
 | 
			
		||||
#undef IN_T
 | 
			
		||||
#undef SHIFT
 | 
			
		||||
 | 
			
		||||
/* Unsigned 32 bit */
 | 
			
		||||
#define BSIZE 32
 | 
			
		||||
#define ITYPE uint
 | 
			
		||||
#define IN_T uint32_t
 | 
			
		||||
#define IN_MIN 0
 | 
			
		||||
#define IN_MAX UINT32_MAX
 | 
			
		||||
#define SHIFT 32
 | 
			
		||||
@@ -153,8 +140,7 @@
 | 
			
		||||
#undef ENDIAN_CONVERSION
 | 
			
		||||
#undef IN_MAX
 | 
			
		||||
#undef IN_MIN
 | 
			
		||||
#undef BSIZE
 | 
			
		||||
#undef ITYPE
 | 
			
		||||
#undef IN_T
 | 
			
		||||
#undef SHIFT
 | 
			
		||||
 | 
			
		||||
t_sample *mixeng_conv[2][2][2][3] = {
 | 
			
		||||
@@ -267,42 +253,11 @@ f_sample *mixeng_clip[2][2][2][3] = {
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void audio_sample_to_uint64(void *samples, int pos,
 | 
			
		||||
                            uint64_t *left, uint64_t *right)
 | 
			
		||||
{
 | 
			
		||||
    struct st_sample *sample = samples;
 | 
			
		||||
    sample += pos;
 | 
			
		||||
#ifdef FLOAT_MIXENG
 | 
			
		||||
    error_report(
 | 
			
		||||
        "Coreaudio and floating point samples are not supported by replay yet");
 | 
			
		||||
    abort();
 | 
			
		||||
#else
 | 
			
		||||
    *left = sample->l;
 | 
			
		||||
    *right = sample->r;
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void audio_sample_from_uint64(void *samples, int pos,
 | 
			
		||||
                            uint64_t left, uint64_t right)
 | 
			
		||||
{
 | 
			
		||||
    struct st_sample *sample = samples;
 | 
			
		||||
    sample += pos;
 | 
			
		||||
#ifdef FLOAT_MIXENG
 | 
			
		||||
    error_report(
 | 
			
		||||
        "Coreaudio and floating point samples are not supported by replay yet");
 | 
			
		||||
    abort();
 | 
			
		||||
#else
 | 
			
		||||
    sample->l = left;
 | 
			
		||||
    sample->r = right;
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * August 21, 1998
 | 
			
		||||
 * Copyright 1998 Fabrice Bellard.
 | 
			
		||||
 *
 | 
			
		||||
 * [Rewrote completely the code of Lance Norskog And Sundry
 | 
			
		||||
 * [Rewrote completly the code of Lance Norskog And Sundry
 | 
			
		||||
 * Contributors with a more efficient algorithm.]
 | 
			
		||||
 *
 | 
			
		||||
 * This source code is freely redistributable and may be used for
 | 
			
		||||
@@ -343,7 +298,7 @@ struct rate {
 | 
			
		||||
 */
 | 
			
		||||
void *st_rate_start (int inrate, int outrate)
 | 
			
		||||
{
 | 
			
		||||
    struct rate *rate = audio_calloc(__func__, 1, sizeof(*rate));
 | 
			
		||||
    struct rate *rate = audio_calloc (AUDIO_FUNC, 1, sizeof (*rate));
 | 
			
		||||
 | 
			
		||||
    if (!rate) {
 | 
			
		||||
        dolog ("Could not allocate resampler (%zu bytes)\n", sizeof (*rate));
 | 
			
		||||
@@ -371,7 +326,7 @@ void *st_rate_start (int inrate, int outrate)
 | 
			
		||||
 | 
			
		||||
void st_rate_stop (void *opaque)
 | 
			
		||||
{
 | 
			
		||||
    g_free (opaque);
 | 
			
		||||
    qemu_free (opaque);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void mixeng_clear (struct st_sample *buf, int len)
 | 
			
		||||
@@ -381,6 +336,7 @@ void mixeng_clear (struct st_sample *buf, int len)
 | 
			
		||||
 | 
			
		||||
void mixeng_volume (struct st_sample *buf, int len, struct mixeng_volume *vol)
 | 
			
		||||
{
 | 
			
		||||
#ifdef CONFIG_MIXEMU
 | 
			
		||||
    if (vol->mute) {
 | 
			
		||||
        mixeng_clear (buf, len);
 | 
			
		||||
        return;
 | 
			
		||||
@@ -396,4 +352,9 @@ void mixeng_volume (struct st_sample *buf, int len, struct mixeng_volume *vol)
 | 
			
		||||
#endif
 | 
			
		||||
        buf += 1;
 | 
			
		||||
    }
 | 
			
		||||
#else
 | 
			
		||||
    (void) buf;
 | 
			
		||||
    (void) len;
 | 
			
		||||
    (void) vol;
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -21,7 +21,6 @@
 | 
			
		||||
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
			
		||||
 * THE SOFTWARE.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#ifndef QEMU_MIXENG_H
 | 
			
		||||
#define QEMU_MIXENG_H
 | 
			
		||||
 | 
			
		||||
@@ -49,4 +48,4 @@ void st_rate_stop (void *opaque);
 | 
			
		||||
void mixeng_clear (struct st_sample *buf, int len);
 | 
			
		||||
void mixeng_volume (struct st_sample *buf, int len, struct mixeng_volume *vol);
 | 
			
		||||
 | 
			
		||||
#endif /* QEMU_MIXENG_H */
 | 
			
		||||
#endif  /* mixeng.h */
 | 
			
		||||
 
 | 
			
		||||
@@ -31,11 +31,10 @@
 | 
			
		||||
#define HALF (IN_MAX >> 1)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#define ET glue (ENDIAN_CONVERSION, glue (glue (glue (_, ITYPE), BSIZE), _t))
 | 
			
		||||
#define IN_T glue (glue (ITYPE, BSIZE), _t)
 | 
			
		||||
#define ET glue (ENDIAN_CONVERSION, glue (_, IN_T))
 | 
			
		||||
 | 
			
		||||
#ifdef FLOAT_MIXENG
 | 
			
		||||
static inline mixeng_real glue (conv_, ET) (IN_T v)
 | 
			
		||||
static mixeng_real inline glue (conv_, ET) (IN_T v)
 | 
			
		||||
{
 | 
			
		||||
    IN_T nv = ENDIAN_CONVERT (v);
 | 
			
		||||
 | 
			
		||||
@@ -54,7 +53,7 @@ static inline mixeng_real glue (conv_, ET) (IN_T v)
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static inline IN_T glue (clip_, ET) (mixeng_real v)
 | 
			
		||||
static IN_T inline glue (clip_, ET) (mixeng_real v)
 | 
			
		||||
{
 | 
			
		||||
    if (v >= 0.5) {
 | 
			
		||||
        return IN_MAX;
 | 
			
		||||
@@ -151,4 +150,3 @@ static void glue (glue (clip_, ET), _from_mono)
 | 
			
		||||
 | 
			
		||||
#undef ET
 | 
			
		||||
#undef HALF
 | 
			
		||||
#undef IN_T
 | 
			
		||||
 
 | 
			
		||||
@@ -21,12 +21,9 @@
 | 
			
		||||
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
			
		||||
 * THE SOFTWARE.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "qemu/osdep.h"
 | 
			
		||||
#include "qemu/host-utils.h"
 | 
			
		||||
#include "qemu/module.h"
 | 
			
		||||
#include "qemu-common.h"
 | 
			
		||||
#include "audio.h"
 | 
			
		||||
#include "qemu/timer.h"
 | 
			
		||||
#include "qemu-timer.h"
 | 
			
		||||
 | 
			
		||||
#define AUDIO_CAP "noaudio"
 | 
			
		||||
#include "audio_int.h"
 | 
			
		||||
@@ -49,9 +46,9 @@ static int no_run_out (HWVoiceOut *hw, int live)
 | 
			
		||||
    int64_t ticks;
 | 
			
		||||
    int64_t bytes;
 | 
			
		||||
 | 
			
		||||
    now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
 | 
			
		||||
    now = qemu_get_clock_ns (vm_clock);
 | 
			
		||||
    ticks = now - no->old_ticks;
 | 
			
		||||
    bytes = muldiv64(ticks, hw->info.bytes_per_second, NANOSECONDS_PER_SECOND);
 | 
			
		||||
    bytes = muldiv64 (ticks, hw->info.bytes_per_second, get_ticks_per_sec ());
 | 
			
		||||
    bytes = audio_MIN (bytes, INT_MAX);
 | 
			
		||||
    samples = bytes >> hw->info.shift;
 | 
			
		||||
 | 
			
		||||
@@ -66,7 +63,7 @@ static int no_write (SWVoiceOut *sw, void *buf, int len)
 | 
			
		||||
    return audio_pcm_sw_write (sw, buf, len);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int no_init_out(HWVoiceOut *hw, struct audsettings *as, void *drv_opaque)
 | 
			
		||||
static int no_init_out (HWVoiceOut *hw, struct audsettings *as)
 | 
			
		||||
{
 | 
			
		||||
    audio_pcm_init_info (&hw->info, as);
 | 
			
		||||
    hw->samples = 1024;
 | 
			
		||||
@@ -85,7 +82,7 @@ static int no_ctl_out (HWVoiceOut *hw, int cmd, ...)
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int no_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
 | 
			
		||||
static int no_init_in (HWVoiceIn *hw, struct audsettings *as)
 | 
			
		||||
{
 | 
			
		||||
    audio_pcm_init_info (&hw->info, as);
 | 
			
		||||
    hw->samples = 1024;
 | 
			
		||||
@@ -105,10 +102,10 @@ static int no_run_in (HWVoiceIn *hw)
 | 
			
		||||
    int samples = 0;
 | 
			
		||||
 | 
			
		||||
    if (dead) {
 | 
			
		||||
        int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
 | 
			
		||||
        int64_t now = qemu_get_clock_ns (vm_clock);
 | 
			
		||||
        int64_t ticks = now - no->old_ticks;
 | 
			
		||||
        int64_t bytes =
 | 
			
		||||
            muldiv64(ticks, hw->info.bytes_per_second, NANOSECONDS_PER_SECOND);
 | 
			
		||||
            muldiv64 (ticks, hw->info.bytes_per_second, get_ticks_per_sec ());
 | 
			
		||||
 | 
			
		||||
        no->old_ticks = now;
 | 
			
		||||
        bytes = audio_MIN (bytes, INT_MAX);
 | 
			
		||||
@@ -137,7 +134,7 @@ static int no_ctl_in (HWVoiceIn *hw, int cmd, ...)
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void *no_audio_init(Audiodev *dev)
 | 
			
		||||
static void *no_audio_init (void)
 | 
			
		||||
{
 | 
			
		||||
    return &no_audio_init;
 | 
			
		||||
}
 | 
			
		||||
@@ -161,9 +158,10 @@ static struct audio_pcm_ops no_pcm_ops = {
 | 
			
		||||
    .ctl_in   = no_ctl_in
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static struct audio_driver no_audio_driver = {
 | 
			
		||||
struct audio_driver no_audio_driver = {
 | 
			
		||||
    .name           = "none",
 | 
			
		||||
    .descr          = "Timer based audio emulation",
 | 
			
		||||
    .options        = NULL,
 | 
			
		||||
    .init           = no_audio_init,
 | 
			
		||||
    .fini           = no_audio_fini,
 | 
			
		||||
    .pcm_ops        = &no_pcm_ops,
 | 
			
		||||
@@ -173,9 +171,3 @@ static struct audio_driver no_audio_driver = {
 | 
			
		||||
    .voice_size_out = sizeof (NoVoiceOut),
 | 
			
		||||
    .voice_size_in  = sizeof (NoVoiceIn)
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void register_audio_none(void)
 | 
			
		||||
{
 | 
			
		||||
    audio_driver_register(&no_audio_driver);
 | 
			
		||||
}
 | 
			
		||||
type_init(register_audio_none);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										263
									
								
								audio/ossaudio.c
									
									
									
									
									
								
							
							
						
						
									
										263
									
								
								audio/ossaudio.c
									
									
									
									
									
								
							@@ -21,15 +21,19 @@
 | 
			
		||||
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
			
		||||
 * THE SOFTWARE.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "qemu/osdep.h"
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <sys/mman.h>
 | 
			
		||||
#include <sys/types.h>
 | 
			
		||||
#include <sys/ioctl.h>
 | 
			
		||||
#ifdef __OpenBSD__
 | 
			
		||||
#include <soundcard.h>
 | 
			
		||||
#else
 | 
			
		||||
#include <sys/soundcard.h>
 | 
			
		||||
#include "qemu/main-loop.h"
 | 
			
		||||
#include "qemu/module.h"
 | 
			
		||||
#include "qemu/host-utils.h"
 | 
			
		||||
#endif
 | 
			
		||||
#include "qemu-common.h"
 | 
			
		||||
#include "host-utils.h"
 | 
			
		||||
#include "qemu-char.h"
 | 
			
		||||
#include "audio.h"
 | 
			
		||||
#include "trace.h"
 | 
			
		||||
 | 
			
		||||
#define AUDIO_CAP "oss"
 | 
			
		||||
#include "audio_int.h"
 | 
			
		||||
@@ -47,7 +51,6 @@ typedef struct OSSVoiceOut {
 | 
			
		||||
    int fragsize;
 | 
			
		||||
    int mmapped;
 | 
			
		||||
    int pending;
 | 
			
		||||
    Audiodev *dev;
 | 
			
		||||
} OSSVoiceOut;
 | 
			
		||||
 | 
			
		||||
typedef struct OSSVoiceIn {
 | 
			
		||||
@@ -56,12 +59,31 @@ typedef struct OSSVoiceIn {
 | 
			
		||||
    int fd;
 | 
			
		||||
    int nfrags;
 | 
			
		||||
    int fragsize;
 | 
			
		||||
    Audiodev *dev;
 | 
			
		||||
} OSSVoiceIn;
 | 
			
		||||
 | 
			
		||||
static struct {
 | 
			
		||||
    int try_mmap;
 | 
			
		||||
    int nfrags;
 | 
			
		||||
    int fragsize;
 | 
			
		||||
    const char *devpath_out;
 | 
			
		||||
    const char *devpath_in;
 | 
			
		||||
    int debug;
 | 
			
		||||
    int exclusive;
 | 
			
		||||
    int policy;
 | 
			
		||||
} conf = {
 | 
			
		||||
    .try_mmap = 0,
 | 
			
		||||
    .nfrags = 4,
 | 
			
		||||
    .fragsize = 4096,
 | 
			
		||||
    .devpath_out = "/dev/dsp",
 | 
			
		||||
    .devpath_in = "/dev/dsp",
 | 
			
		||||
    .debug = 0,
 | 
			
		||||
    .exclusive = 0,
 | 
			
		||||
    .policy = 5
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
struct oss_params {
 | 
			
		||||
    int freq;
 | 
			
		||||
    int fmt;
 | 
			
		||||
    audfmt_e fmt;
 | 
			
		||||
    int nchannels;
 | 
			
		||||
    int nfrags;
 | 
			
		||||
    int fragsize;
 | 
			
		||||
@@ -120,18 +142,18 @@ static void oss_helper_poll_in (void *opaque)
 | 
			
		||||
    audio_run ("oss_poll_in");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void oss_poll_out (HWVoiceOut *hw)
 | 
			
		||||
static int oss_poll_out (HWVoiceOut *hw)
 | 
			
		||||
{
 | 
			
		||||
    OSSVoiceOut *oss = (OSSVoiceOut *) hw;
 | 
			
		||||
 | 
			
		||||
    qemu_set_fd_handler (oss->fd, NULL, oss_helper_poll_out, NULL);
 | 
			
		||||
    return qemu_set_fd_handler (oss->fd, NULL, oss_helper_poll_out, NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void oss_poll_in (HWVoiceIn *hw)
 | 
			
		||||
static int oss_poll_in (HWVoiceIn *hw)
 | 
			
		||||
{
 | 
			
		||||
    OSSVoiceIn *oss = (OSSVoiceIn *) hw;
 | 
			
		||||
 | 
			
		||||
    qemu_set_fd_handler (oss->fd, oss_helper_poll_in, NULL, NULL);
 | 
			
		||||
    return qemu_set_fd_handler (oss->fd, oss_helper_poll_in, NULL, NULL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int oss_write (SWVoiceOut *sw, void *buf, int len)
 | 
			
		||||
@@ -139,16 +161,16 @@ static int oss_write (SWVoiceOut *sw, void *buf, int len)
 | 
			
		||||
    return audio_pcm_sw_write (sw, buf, len);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int aud_to_ossfmt (AudioFormat fmt, int endianness)
 | 
			
		||||
static int aud_to_ossfmt (audfmt_e fmt, int endianness)
 | 
			
		||||
{
 | 
			
		||||
    switch (fmt) {
 | 
			
		||||
    case AUDIO_FORMAT_S8:
 | 
			
		||||
    case AUD_FMT_S8:
 | 
			
		||||
        return AFMT_S8;
 | 
			
		||||
 | 
			
		||||
    case AUDIO_FORMAT_U8:
 | 
			
		||||
    case AUD_FMT_U8:
 | 
			
		||||
        return AFMT_U8;
 | 
			
		||||
 | 
			
		||||
    case AUDIO_FORMAT_S16:
 | 
			
		||||
    case AUD_FMT_S16:
 | 
			
		||||
        if (endianness) {
 | 
			
		||||
            return AFMT_S16_BE;
 | 
			
		||||
        }
 | 
			
		||||
@@ -156,7 +178,7 @@ static int aud_to_ossfmt (AudioFormat fmt, int endianness)
 | 
			
		||||
            return AFMT_S16_LE;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    case AUDIO_FORMAT_U16:
 | 
			
		||||
    case AUD_FMT_U16:
 | 
			
		||||
        if (endianness) {
 | 
			
		||||
            return AFMT_U16_BE;
 | 
			
		||||
        }
 | 
			
		||||
@@ -173,37 +195,37 @@ static int aud_to_ossfmt (AudioFormat fmt, int endianness)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int oss_to_audfmt (int ossfmt, AudioFormat *fmt, int *endianness)
 | 
			
		||||
static int oss_to_audfmt (int ossfmt, audfmt_e *fmt, int *endianness)
 | 
			
		||||
{
 | 
			
		||||
    switch (ossfmt) {
 | 
			
		||||
    case AFMT_S8:
 | 
			
		||||
        *endianness = 0;
 | 
			
		||||
        *fmt = AUDIO_FORMAT_S8;
 | 
			
		||||
        *fmt = AUD_FMT_S8;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case AFMT_U8:
 | 
			
		||||
        *endianness = 0;
 | 
			
		||||
        *fmt = AUDIO_FORMAT_U8;
 | 
			
		||||
        *fmt = AUD_FMT_U8;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case AFMT_S16_LE:
 | 
			
		||||
        *endianness = 0;
 | 
			
		||||
        *fmt = AUDIO_FORMAT_S16;
 | 
			
		||||
        *fmt = AUD_FMT_S16;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case AFMT_U16_LE:
 | 
			
		||||
        *endianness = 0;
 | 
			
		||||
        *fmt = AUDIO_FORMAT_U16;
 | 
			
		||||
        *fmt = AUD_FMT_U16;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case AFMT_S16_BE:
 | 
			
		||||
        *endianness = 1;
 | 
			
		||||
        *fmt = AUDIO_FORMAT_S16;
 | 
			
		||||
        *fmt = AUD_FMT_S16;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case AFMT_U16_BE:
 | 
			
		||||
        *endianness = 1;
 | 
			
		||||
        *fmt = AUDIO_FORMAT_U16;
 | 
			
		||||
        *fmt = AUD_FMT_U16;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    default:
 | 
			
		||||
@@ -253,25 +275,19 @@ static int oss_get_version (int fd, int *version, const char *typ)
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
static int oss_open(int in, struct oss_params *req, audsettings *as,
 | 
			
		||||
                    struct oss_params *obt, int *pfd, Audiodev *dev)
 | 
			
		||||
static int oss_open (int in, struct oss_params *req,
 | 
			
		||||
                     struct oss_params *obt, int *pfd)
 | 
			
		||||
{
 | 
			
		||||
    AudiodevOssOptions *oopts = &dev->u.oss;
 | 
			
		||||
    AudiodevOssPerDirectionOptions *opdo = in ? oopts->in : oopts->out;
 | 
			
		||||
    int fd;
 | 
			
		||||
    int oflags = (oopts->has_exclusive && oopts->exclusive) ? O_EXCL : 0;
 | 
			
		||||
    int oflags = conf.exclusive ? O_EXCL : 0;
 | 
			
		||||
    audio_buf_info abinfo;
 | 
			
		||||
    int fmt, freq, nchannels;
 | 
			
		||||
    int setfragment = 1;
 | 
			
		||||
    const char *dspname = opdo->has_dev ? opdo->dev : "/dev/dsp";
 | 
			
		||||
    const char *dspname = in ? conf.devpath_in : conf.devpath_out;
 | 
			
		||||
    const char *typ = in ? "ADC" : "DAC";
 | 
			
		||||
#ifdef USE_DSP_POLICY
 | 
			
		||||
    int policy = oopts->has_dsp_policy ? oopts->dsp_policy : 5;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    /* Kludge needed to have working mmap on Linux */
 | 
			
		||||
    oflags |= (oopts->has_try_mmap && oopts->try_mmap) ?
 | 
			
		||||
        O_RDWR : (in ? O_RDONLY : O_WRONLY);
 | 
			
		||||
    oflags |= conf.try_mmap ? O_RDWR : (in ? O_RDONLY : O_WRONLY);
 | 
			
		||||
 | 
			
		||||
    fd = open (dspname, oflags | O_NONBLOCK);
 | 
			
		||||
    if (-1 == fd) {
 | 
			
		||||
@@ -282,9 +298,6 @@ static int oss_open(int in, struct oss_params *req, audsettings *as,
 | 
			
		||||
    freq = req->freq;
 | 
			
		||||
    nchannels = req->nchannels;
 | 
			
		||||
    fmt = req->fmt;
 | 
			
		||||
    req->nfrags = opdo->has_buffer_count ? opdo->buffer_count : 4;
 | 
			
		||||
    req->fragsize = audio_buffer_bytes(
 | 
			
		||||
        qapi_AudiodevOssPerDirectionOptions_base(opdo), as, 23220);
 | 
			
		||||
 | 
			
		||||
    if (ioctl (fd, SNDCTL_DSP_SAMPLESIZE, &fmt)) {
 | 
			
		||||
        oss_logerr2 (errno, typ, "Failed to set sample size %d\n", req->fmt);
 | 
			
		||||
@@ -308,18 +321,20 @@ static int oss_open(int in, struct oss_params *req, audsettings *as,
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
#ifdef USE_DSP_POLICY
 | 
			
		||||
    if (policy >= 0) {
 | 
			
		||||
    if (conf.policy >= 0) {
 | 
			
		||||
        int version;
 | 
			
		||||
 | 
			
		||||
        if (!oss_get_version (fd, &version, typ)) {
 | 
			
		||||
            trace_oss_version(version);
 | 
			
		||||
            if (conf.debug) {
 | 
			
		||||
                dolog ("OSS version = %#x\n", version);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (version >= 0x040000) {
 | 
			
		||||
                int policy2 = policy;
 | 
			
		||||
                if (ioctl(fd, SNDCTL_DSP_POLICY, &policy2)) {
 | 
			
		||||
                int policy = conf.policy;
 | 
			
		||||
                if (ioctl (fd, SNDCTL_DSP_POLICY, &policy)) {
 | 
			
		||||
                    oss_logerr2 (errno, typ,
 | 
			
		||||
                                 "Failed to set timing policy to %d\n",
 | 
			
		||||
                                 policy);
 | 
			
		||||
                                 conf.policy);
 | 
			
		||||
                    goto err;
 | 
			
		||||
                }
 | 
			
		||||
                setfragment = 0;
 | 
			
		||||
@@ -447,12 +462,19 @@ static int oss_run_out (HWVoiceOut *hw, int live)
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (abinfo.bytes > bufsize) {
 | 
			
		||||
            trace_oss_invalid_available_size(abinfo.bytes, bufsize);
 | 
			
		||||
            if (conf.debug) {
 | 
			
		||||
                dolog ("warning: Invalid available size, size=%d bufsize=%d\n"
 | 
			
		||||
                       "please report your OS/audio hw to av1474@comtv.ru\n",
 | 
			
		||||
                       abinfo.bytes, bufsize);
 | 
			
		||||
            }
 | 
			
		||||
            abinfo.bytes = bufsize;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (abinfo.bytes < 0) {
 | 
			
		||||
            trace_oss_invalid_available_size(abinfo.bytes, bufsize);
 | 
			
		||||
            if (conf.debug) {
 | 
			
		||||
                dolog ("warning: Invalid available size, size=%d bufsize=%d\n",
 | 
			
		||||
                       abinfo.bytes, bufsize);
 | 
			
		||||
            }
 | 
			
		||||
            return 0;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -486,32 +508,31 @@ static void oss_fini_out (HWVoiceOut *hw)
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            g_free (oss->pcm_buf);
 | 
			
		||||
            qemu_free (oss->pcm_buf);
 | 
			
		||||
        }
 | 
			
		||||
        oss->pcm_buf = NULL;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int oss_init_out(HWVoiceOut *hw, struct audsettings *as,
 | 
			
		||||
                        void *drv_opaque)
 | 
			
		||||
static int oss_init_out (HWVoiceOut *hw, struct audsettings *as)
 | 
			
		||||
{
 | 
			
		||||
    OSSVoiceOut *oss = (OSSVoiceOut *) hw;
 | 
			
		||||
    struct oss_params req, obt;
 | 
			
		||||
    int endianness;
 | 
			
		||||
    int err;
 | 
			
		||||
    int fd;
 | 
			
		||||
    AudioFormat effective_fmt;
 | 
			
		||||
    audfmt_e effective_fmt;
 | 
			
		||||
    struct audsettings obt_as;
 | 
			
		||||
    Audiodev *dev = drv_opaque;
 | 
			
		||||
    AudiodevOssOptions *oopts = &dev->u.oss;
 | 
			
		||||
 | 
			
		||||
    oss->fd = -1;
 | 
			
		||||
 | 
			
		||||
    req.fmt = aud_to_ossfmt (as->fmt, as->endianness);
 | 
			
		||||
    req.freq = as->freq;
 | 
			
		||||
    req.nchannels = as->nchannels;
 | 
			
		||||
    req.fragsize = conf.fragsize;
 | 
			
		||||
    req.nfrags = conf.nfrags;
 | 
			
		||||
 | 
			
		||||
    if (oss_open(0, &req, as, &obt, &fd, dev)) {
 | 
			
		||||
    if (oss_open (0, &req, &obt, &fd)) {
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -538,7 +559,7 @@ static int oss_init_out(HWVoiceOut *hw, struct audsettings *as,
 | 
			
		||||
    hw->samples = (obt.nfrags * obt.fragsize) >> hw->info.shift;
 | 
			
		||||
 | 
			
		||||
    oss->mmapped = 0;
 | 
			
		||||
    if (oopts->has_try_mmap && oopts->try_mmap) {
 | 
			
		||||
    if (conf.try_mmap) {
 | 
			
		||||
        oss->pcm_buf = mmap (
 | 
			
		||||
            NULL,
 | 
			
		||||
            hw->samples << hw->info.shift,
 | 
			
		||||
@@ -581,9 +602,11 @@ static int oss_init_out(HWVoiceOut *hw, struct audsettings *as,
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!oss->mmapped) {
 | 
			
		||||
        oss->pcm_buf = audio_calloc(__func__,
 | 
			
		||||
        oss->pcm_buf = audio_calloc (
 | 
			
		||||
            AUDIO_FUNC,
 | 
			
		||||
            hw->samples,
 | 
			
		||||
                                    1 << hw->info.shift);
 | 
			
		||||
            1 << hw->info.shift
 | 
			
		||||
            );
 | 
			
		||||
        if (!oss->pcm_buf) {
 | 
			
		||||
            dolog (
 | 
			
		||||
                "Could not allocate DAC buffer (%d samples, each %d bytes)\n",
 | 
			
		||||
@@ -596,7 +619,6 @@ static int oss_init_out(HWVoiceOut *hw, struct audsettings *as,
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    oss->fd = fd;
 | 
			
		||||
    oss->dev = dev;
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -604,16 +626,19 @@ static int oss_ctl_out (HWVoiceOut *hw, int cmd, ...)
 | 
			
		||||
{
 | 
			
		||||
    int trig;
 | 
			
		||||
    OSSVoiceOut *oss = (OSSVoiceOut *) hw;
 | 
			
		||||
    AudiodevOssPerDirectionOptions *opdo = oss->dev->u.oss.out;
 | 
			
		||||
 | 
			
		||||
    switch (cmd) {
 | 
			
		||||
    case VOICE_ENABLE:
 | 
			
		||||
        {
 | 
			
		||||
            bool poll_mode = opdo->try_poll;
 | 
			
		||||
            va_list ap;
 | 
			
		||||
            int poll_mode;
 | 
			
		||||
 | 
			
		||||
            va_start (ap, cmd);
 | 
			
		||||
            poll_mode = va_arg (ap, int);
 | 
			
		||||
            va_end (ap);
 | 
			
		||||
 | 
			
		||||
            ldebug ("enabling voice\n");
 | 
			
		||||
            if (poll_mode) {
 | 
			
		||||
                oss_poll_out (hw);
 | 
			
		||||
            if (poll_mode && oss_poll_out (hw)) {
 | 
			
		||||
                poll_mode = 0;
 | 
			
		||||
            }
 | 
			
		||||
            hw->poll_mode = poll_mode;
 | 
			
		||||
@@ -655,23 +680,24 @@ static int oss_ctl_out (HWVoiceOut *hw, int cmd, ...)
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int oss_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
 | 
			
		||||
static int oss_init_in (HWVoiceIn *hw, struct audsettings *as)
 | 
			
		||||
{
 | 
			
		||||
    OSSVoiceIn *oss = (OSSVoiceIn *) hw;
 | 
			
		||||
    struct oss_params req, obt;
 | 
			
		||||
    int endianness;
 | 
			
		||||
    int err;
 | 
			
		||||
    int fd;
 | 
			
		||||
    AudioFormat effective_fmt;
 | 
			
		||||
    audfmt_e effective_fmt;
 | 
			
		||||
    struct audsettings obt_as;
 | 
			
		||||
    Audiodev *dev = drv_opaque;
 | 
			
		||||
 | 
			
		||||
    oss->fd = -1;
 | 
			
		||||
 | 
			
		||||
    req.fmt = aud_to_ossfmt (as->fmt, as->endianness);
 | 
			
		||||
    req.freq = as->freq;
 | 
			
		||||
    req.nchannels = as->nchannels;
 | 
			
		||||
    if (oss_open(1, &req, as, &obt, &fd, dev)) {
 | 
			
		||||
    req.fragsize = conf.fragsize;
 | 
			
		||||
    req.nfrags = conf.nfrags;
 | 
			
		||||
    if (oss_open (1, &req, &obt, &fd)) {
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -696,7 +722,7 @@ static int oss_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    hw->samples = (obt.nfrags * obt.fragsize) >> hw->info.shift;
 | 
			
		||||
    oss->pcm_buf = audio_calloc(__func__, hw->samples, 1 << hw->info.shift);
 | 
			
		||||
    oss->pcm_buf = audio_calloc (AUDIO_FUNC, hw->samples, 1 << hw->info.shift);
 | 
			
		||||
    if (!oss->pcm_buf) {
 | 
			
		||||
        dolog ("Could not allocate ADC buffer (%d samples, each %d bytes)\n",
 | 
			
		||||
               hw->samples, 1 << hw->info.shift);
 | 
			
		||||
@@ -705,7 +731,6 @@ static int oss_init_in(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    oss->fd = fd;
 | 
			
		||||
    oss->dev = dev;
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -715,9 +740,11 @@ static void oss_fini_in (HWVoiceIn *hw)
 | 
			
		||||
 | 
			
		||||
    oss_anal_close (&oss->fd);
 | 
			
		||||
 | 
			
		||||
    g_free(oss->pcm_buf);
 | 
			
		||||
    if (oss->pcm_buf) {
 | 
			
		||||
        qemu_free (oss->pcm_buf);
 | 
			
		||||
        oss->pcm_buf = NULL;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int oss_run_in (HWVoiceIn *hw)
 | 
			
		||||
{
 | 
			
		||||
@@ -796,15 +823,18 @@ static int oss_read (SWVoiceIn *sw, void *buf, int size)
 | 
			
		||||
static int oss_ctl_in (HWVoiceIn *hw, int cmd, ...)
 | 
			
		||||
{
 | 
			
		||||
    OSSVoiceIn *oss = (OSSVoiceIn *) hw;
 | 
			
		||||
    AudiodevOssPerDirectionOptions *opdo = oss->dev->u.oss.out;
 | 
			
		||||
 | 
			
		||||
    switch (cmd) {
 | 
			
		||||
    case VOICE_ENABLE:
 | 
			
		||||
        {
 | 
			
		||||
            bool poll_mode = opdo->try_poll;
 | 
			
		||||
            va_list ap;
 | 
			
		||||
            int poll_mode;
 | 
			
		||||
 | 
			
		||||
            if (poll_mode) {
 | 
			
		||||
                oss_poll_in (hw);
 | 
			
		||||
            va_start (ap, cmd);
 | 
			
		||||
            poll_mode = va_arg (ap, int);
 | 
			
		||||
            va_end (ap);
 | 
			
		||||
 | 
			
		||||
            if (poll_mode && oss_poll_in (hw)) {
 | 
			
		||||
                poll_mode = 0;
 | 
			
		||||
            }
 | 
			
		||||
            hw->poll_mode = poll_mode;
 | 
			
		||||
@@ -821,36 +851,70 @@ static int oss_ctl_in (HWVoiceIn *hw, int cmd, ...)
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void oss_init_per_direction(AudiodevOssPerDirectionOptions *opdo)
 | 
			
		||||
static void *oss_audio_init (void)
 | 
			
		||||
{
 | 
			
		||||
    if (!opdo->has_try_poll) {
 | 
			
		||||
        opdo->try_poll = true;
 | 
			
		||||
        opdo->has_try_poll = true;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void *oss_audio_init(Audiodev *dev)
 | 
			
		||||
{
 | 
			
		||||
    AudiodevOssOptions *oopts;
 | 
			
		||||
    assert(dev->driver == AUDIODEV_DRIVER_OSS);
 | 
			
		||||
 | 
			
		||||
    oopts = &dev->u.oss;
 | 
			
		||||
    oss_init_per_direction(oopts->in);
 | 
			
		||||
    oss_init_per_direction(oopts->out);
 | 
			
		||||
 | 
			
		||||
    if (access(oopts->in->has_dev ? oopts->in->dev : "/dev/dsp",
 | 
			
		||||
               R_OK | W_OK) < 0 ||
 | 
			
		||||
        access(oopts->out->has_dev ? oopts->out->dev : "/dev/dsp",
 | 
			
		||||
               R_OK | W_OK) < 0) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
    return dev;
 | 
			
		||||
    return &conf;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void oss_audio_fini (void *opaque)
 | 
			
		||||
{
 | 
			
		||||
    (void) opaque;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static struct audio_option oss_options[] = {
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "FRAGSIZE",
 | 
			
		||||
        .tag   = AUD_OPT_INT,
 | 
			
		||||
        .valp  = &conf.fragsize,
 | 
			
		||||
        .descr = "Fragment size in bytes"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "NFRAGS",
 | 
			
		||||
        .tag   = AUD_OPT_INT,
 | 
			
		||||
        .valp  = &conf.nfrags,
 | 
			
		||||
        .descr = "Number of fragments"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "MMAP",
 | 
			
		||||
        .tag   = AUD_OPT_BOOL,
 | 
			
		||||
        .valp  = &conf.try_mmap,
 | 
			
		||||
        .descr = "Try using memory mapped access"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "DAC_DEV",
 | 
			
		||||
        .tag   = AUD_OPT_STR,
 | 
			
		||||
        .valp  = &conf.devpath_out,
 | 
			
		||||
        .descr = "Path to DAC device"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "ADC_DEV",
 | 
			
		||||
        .tag   = AUD_OPT_STR,
 | 
			
		||||
        .valp  = &conf.devpath_in,
 | 
			
		||||
        .descr = "Path to ADC device"
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "EXCLUSIVE",
 | 
			
		||||
        .tag   = AUD_OPT_BOOL,
 | 
			
		||||
        .valp  = &conf.exclusive,
 | 
			
		||||
        .descr = "Open device in exclusive mode (vmix wont work)"
 | 
			
		||||
    },
 | 
			
		||||
#ifdef USE_DSP_POLICY
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "POLICY",
 | 
			
		||||
        .tag   = AUD_OPT_INT,
 | 
			
		||||
        .valp  = &conf.policy,
 | 
			
		||||
        .descr = "Set the timing policy of the device, -1 to use fragment mode",
 | 
			
		||||
    },
 | 
			
		||||
#endif
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "DEBUG",
 | 
			
		||||
        .tag   = AUD_OPT_BOOL,
 | 
			
		||||
        .valp  = &conf.debug,
 | 
			
		||||
        .descr = "Turn on some debugging messages"
 | 
			
		||||
    },
 | 
			
		||||
    { /* End of list */ }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static struct audio_pcm_ops oss_pcm_ops = {
 | 
			
		||||
    .init_out = oss_init_out,
 | 
			
		||||
    .fini_out = oss_fini_out,
 | 
			
		||||
@@ -865,9 +929,10 @@ static struct audio_pcm_ops oss_pcm_ops = {
 | 
			
		||||
    .ctl_in   = oss_ctl_in
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static struct audio_driver oss_audio_driver = {
 | 
			
		||||
struct audio_driver oss_audio_driver = {
 | 
			
		||||
    .name           = "oss",
 | 
			
		||||
    .descr          = "OSS http://www.opensound.com",
 | 
			
		||||
    .options        = oss_options,
 | 
			
		||||
    .init           = oss_audio_init,
 | 
			
		||||
    .fini           = oss_audio_fini,
 | 
			
		||||
    .pcm_ops        = &oss_pcm_ops,
 | 
			
		||||
@@ -877,9 +942,3 @@ static struct audio_driver oss_audio_driver = {
 | 
			
		||||
    .voice_size_out = sizeof (OSSVoiceOut),
 | 
			
		||||
    .voice_size_in  = sizeof (OSSVoiceIn)
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void register_audio_oss(void)
 | 
			
		||||
{
 | 
			
		||||
    audio_driver_register(&oss_audio_driver);
 | 
			
		||||
}
 | 
			
		||||
type_init(register_audio_oss);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										721
									
								
								audio/paaudio.c
									
									
									
									
									
								
							
							
						
						
									
										721
									
								
								audio/paaudio.c
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							@@ -71,12 +71,6 @@ void NAME (void *opaque, struct st_sample *ibuf, struct st_sample *obuf,
 | 
			
		||||
        while (rate->ipos <= (rate->opos >> 32)) {
 | 
			
		||||
            ilast = *ibuf++;
 | 
			
		||||
            rate->ipos++;
 | 
			
		||||
 | 
			
		||||
            /* if ipos overflow, there is  a infinite loop */
 | 
			
		||||
            if (rate->ipos == 0xffffffff) {
 | 
			
		||||
                rate->ipos = 1;
 | 
			
		||||
                rate->opos = rate->opos & 0xffffffff;
 | 
			
		||||
            }
 | 
			
		||||
            /* See if we finished the input buffer yet */
 | 
			
		||||
            if (ibuf >= iend) {
 | 
			
		||||
                goto the_end;
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										196
									
								
								audio/sdlaudio.c
									
									
									
									
									
								
							
							
						
						
									
										196
									
								
								audio/sdlaudio.c
									
									
									
									
									
								
							@@ -21,11 +21,9 @@
 | 
			
		||||
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
			
		||||
 * THE SOFTWARE.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "qemu/osdep.h"
 | 
			
		||||
#include <SDL.h>
 | 
			
		||||
#include <SDL_thread.h>
 | 
			
		||||
#include "qemu/module.h"
 | 
			
		||||
#include "qemu-common.h"
 | 
			
		||||
#include "audio.h"
 | 
			
		||||
 | 
			
		||||
#ifndef _WIN32
 | 
			
		||||
@@ -42,14 +40,21 @@
 | 
			
		||||
typedef struct SDLVoiceOut {
 | 
			
		||||
    HWVoiceOut hw;
 | 
			
		||||
    int live;
 | 
			
		||||
    int rpos;
 | 
			
		||||
    int decr;
 | 
			
		||||
} SDLVoiceOut;
 | 
			
		||||
 | 
			
		||||
static struct {
 | 
			
		||||
    int nb_samples;
 | 
			
		||||
} conf = {
 | 
			
		||||
    .nb_samples = 1024
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static struct SDLAudioState {
 | 
			
		||||
    int exit;
 | 
			
		||||
    SDL_mutex *mutex;
 | 
			
		||||
    SDL_sem *sem;
 | 
			
		||||
    int initialized;
 | 
			
		||||
    bool driver_created;
 | 
			
		||||
    Audiodev *dev;
 | 
			
		||||
} glob_sdl;
 | 
			
		||||
typedef struct SDLAudioState SDLAudioState;
 | 
			
		||||
 | 
			
		||||
@@ -64,19 +69,64 @@ static void GCC_FMT_ATTR (1, 2) sdl_logerr (const char *fmt, ...)
 | 
			
		||||
    AUD_log (AUDIO_CAP, "Reason: %s\n", SDL_GetError ());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int aud_to_sdlfmt (AudioFormat fmt)
 | 
			
		||||
static int sdl_lock (SDLAudioState *s, const char *forfn)
 | 
			
		||||
{
 | 
			
		||||
    if (SDL_LockMutex (s->mutex)) {
 | 
			
		||||
        sdl_logerr ("SDL_LockMutex for %s failed\n", forfn);
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int sdl_unlock (SDLAudioState *s, const char *forfn)
 | 
			
		||||
{
 | 
			
		||||
    if (SDL_UnlockMutex (s->mutex)) {
 | 
			
		||||
        sdl_logerr ("SDL_UnlockMutex for %s failed\n", forfn);
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int sdl_post (SDLAudioState *s, const char *forfn)
 | 
			
		||||
{
 | 
			
		||||
    if (SDL_SemPost (s->sem)) {
 | 
			
		||||
        sdl_logerr ("SDL_SemPost for %s failed\n", forfn);
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int sdl_wait (SDLAudioState *s, const char *forfn)
 | 
			
		||||
{
 | 
			
		||||
    if (SDL_SemWait (s->sem)) {
 | 
			
		||||
        sdl_logerr ("SDL_SemWait for %s failed\n", forfn);
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int sdl_unlock_and_post (SDLAudioState *s, const char *forfn)
 | 
			
		||||
{
 | 
			
		||||
    if (sdl_unlock (s, forfn)) {
 | 
			
		||||
        return -1;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return sdl_post (s, forfn);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int aud_to_sdlfmt (audfmt_e fmt)
 | 
			
		||||
{
 | 
			
		||||
    switch (fmt) {
 | 
			
		||||
    case AUDIO_FORMAT_S8:
 | 
			
		||||
    case AUD_FMT_S8:
 | 
			
		||||
        return AUDIO_S8;
 | 
			
		||||
 | 
			
		||||
    case AUDIO_FORMAT_U8:
 | 
			
		||||
    case AUD_FMT_U8:
 | 
			
		||||
        return AUDIO_U8;
 | 
			
		||||
 | 
			
		||||
    case AUDIO_FORMAT_S16:
 | 
			
		||||
    case AUD_FMT_S16:
 | 
			
		||||
        return AUDIO_S16LSB;
 | 
			
		||||
 | 
			
		||||
    case AUDIO_FORMAT_U16:
 | 
			
		||||
    case AUD_FMT_U16:
 | 
			
		||||
        return AUDIO_U16LSB;
 | 
			
		||||
 | 
			
		||||
    default:
 | 
			
		||||
@@ -88,37 +138,37 @@ static int aud_to_sdlfmt (AudioFormat fmt)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int sdl_to_audfmt(int sdlfmt, AudioFormat *fmt, int *endianness)
 | 
			
		||||
static int sdl_to_audfmt(int sdlfmt, audfmt_e *fmt, int *endianness)
 | 
			
		||||
{
 | 
			
		||||
    switch (sdlfmt) {
 | 
			
		||||
    case AUDIO_S8:
 | 
			
		||||
        *endianness = 0;
 | 
			
		||||
        *fmt = AUDIO_FORMAT_S8;
 | 
			
		||||
        *fmt = AUD_FMT_S8;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case AUDIO_U8:
 | 
			
		||||
        *endianness = 0;
 | 
			
		||||
        *fmt = AUDIO_FORMAT_U8;
 | 
			
		||||
        *fmt = AUD_FMT_U8;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case AUDIO_S16LSB:
 | 
			
		||||
        *endianness = 0;
 | 
			
		||||
        *fmt = AUDIO_FORMAT_S16;
 | 
			
		||||
        *fmt = AUD_FMT_S16;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case AUDIO_U16LSB:
 | 
			
		||||
        *endianness = 0;
 | 
			
		||||
        *fmt = AUDIO_FORMAT_U16;
 | 
			
		||||
        *fmt = AUD_FMT_U16;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case AUDIO_S16MSB:
 | 
			
		||||
        *endianness = 1;
 | 
			
		||||
        *fmt = AUDIO_FORMAT_S16;
 | 
			
		||||
        *fmt = AUD_FMT_S16;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    case AUDIO_U16MSB:
 | 
			
		||||
        *endianness = 1;
 | 
			
		||||
        *fmt = AUDIO_FORMAT_U16;
 | 
			
		||||
        *fmt = AUD_FMT_U16;
 | 
			
		||||
        break;
 | 
			
		||||
 | 
			
		||||
    default:
 | 
			
		||||
@@ -170,9 +220,9 @@ static int sdl_open (SDL_AudioSpec *req, SDL_AudioSpec *obt)
 | 
			
		||||
static void sdl_close (SDLAudioState *s)
 | 
			
		||||
{
 | 
			
		||||
    if (s->initialized) {
 | 
			
		||||
        SDL_LockAudio();
 | 
			
		||||
        sdl_lock (s, "sdl_close");
 | 
			
		||||
        s->exit = 1;
 | 
			
		||||
        SDL_UnlockAudio();
 | 
			
		||||
        sdl_unlock_and_post (s, "sdl_close");
 | 
			
		||||
        SDL_PauseAudio (1);
 | 
			
		||||
        SDL_CloseAudio ();
 | 
			
		||||
        s->initialized = 0;
 | 
			
		||||
@@ -185,14 +235,35 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len)
 | 
			
		||||
    SDLAudioState *s = &glob_sdl;
 | 
			
		||||
    HWVoiceOut *hw = &sdl->hw;
 | 
			
		||||
    int samples = len >> hw->info.shift;
 | 
			
		||||
    int to_mix, decr;
 | 
			
		||||
 | 
			
		||||
    if (s->exit || !sdl->live) {
 | 
			
		||||
    if (s->exit) {
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /* dolog ("in callback samples=%d live=%d\n", samples, sdl->live); */
 | 
			
		||||
    while (samples) {
 | 
			
		||||
        int to_mix, decr;
 | 
			
		||||
 | 
			
		||||
        /* dolog ("in callback samples=%d\n", samples); */
 | 
			
		||||
        sdl_wait (s, "sdl_callback");
 | 
			
		||||
        if (s->exit) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (sdl_lock (s, "sdl_callback")) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (audio_bug (AUDIO_FUNC, sdl->live < 0 || sdl->live > hw->samples)) {
 | 
			
		||||
            dolog ("sdl->live=%d hw->samples=%d\n",
 | 
			
		||||
                   sdl->live, hw->samples);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (!sdl->live) {
 | 
			
		||||
            goto again;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        /* dolog ("in callback live=%d\n", live); */
 | 
			
		||||
        to_mix = audio_MIN (samples, sdl->live);
 | 
			
		||||
        decr = to_mix;
 | 
			
		||||
        while (to_mix) {
 | 
			
		||||
@@ -201,7 +272,7 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len)
 | 
			
		||||
 | 
			
		||||
            /* dolog ("in callback to_mix %d, chunk %d\n", to_mix, chunk); */
 | 
			
		||||
            hw->clip (buf, src, chunk);
 | 
			
		||||
        hw->rpos = (hw->rpos + chunk) % hw->samples;
 | 
			
		||||
            sdl->rpos = (sdl->rpos + chunk) % hw->samples;
 | 
			
		||||
            to_mix -= chunk;
 | 
			
		||||
            buf += chunk << hw->info.shift;
 | 
			
		||||
        }
 | 
			
		||||
@@ -209,13 +280,13 @@ static void sdl_callback (void *opaque, Uint8 *buf, int len)
 | 
			
		||||
        sdl->live -= decr;
 | 
			
		||||
        sdl->decr += decr;
 | 
			
		||||
 | 
			
		||||
    /* dolog ("done len=%d\n", len); */
 | 
			
		||||
 | 
			
		||||
    /* SDL2 does not clear the remaining buffer for us, so do it on our own */
 | 
			
		||||
    if (samples) {
 | 
			
		||||
        memset(buf, 0, samples << hw->info.shift);
 | 
			
		||||
    again:
 | 
			
		||||
        if (sdl_unlock (s, "sdl_callback")) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    /* dolog ("done len=%d\n", len); */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int sdl_write_out (SWVoiceOut *sw, void *buf, int len)
 | 
			
		||||
{
 | 
			
		||||
@@ -226,8 +297,11 @@ static int sdl_run_out (HWVoiceOut *hw, int live)
 | 
			
		||||
{
 | 
			
		||||
    int decr;
 | 
			
		||||
    SDLVoiceOut *sdl = (SDLVoiceOut *) hw;
 | 
			
		||||
    SDLAudioState *s = &glob_sdl;
 | 
			
		||||
 | 
			
		||||
    SDL_LockAudio();
 | 
			
		||||
    if (sdl_lock (s, "sdl_run_out")) {
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (sdl->decr > live) {
 | 
			
		||||
        ldebug ("sdl->decr %d live %d sdl->live %d\n",
 | 
			
		||||
@@ -239,10 +313,15 @@ static int sdl_run_out (HWVoiceOut *hw, int live)
 | 
			
		||||
    decr = audio_MIN (sdl->decr, live);
 | 
			
		||||
    sdl->decr -= decr;
 | 
			
		||||
 | 
			
		||||
    sdl->live = live;
 | 
			
		||||
 | 
			
		||||
    SDL_UnlockAudio();
 | 
			
		||||
    sdl->live = live - decr;
 | 
			
		||||
    hw->rpos = sdl->rpos;
 | 
			
		||||
 | 
			
		||||
    if (sdl->live > 0) {
 | 
			
		||||
        sdl_unlock_and_post (s, "sdl_run_out");
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
        sdl_unlock (s, "sdl_run_out");
 | 
			
		||||
    }
 | 
			
		||||
    return decr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -253,21 +332,20 @@ static void sdl_fini_out (HWVoiceOut *hw)
 | 
			
		||||
    sdl_close (&glob_sdl);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int sdl_init_out(HWVoiceOut *hw, struct audsettings *as,
 | 
			
		||||
                        void *drv_opaque)
 | 
			
		||||
static int sdl_init_out (HWVoiceOut *hw, struct audsettings *as)
 | 
			
		||||
{
 | 
			
		||||
    SDLVoiceOut *sdl = (SDLVoiceOut *) hw;
 | 
			
		||||
    SDLAudioState *s = &glob_sdl;
 | 
			
		||||
    SDL_AudioSpec req, obt;
 | 
			
		||||
    int endianness;
 | 
			
		||||
    int err;
 | 
			
		||||
    AudioFormat effective_fmt;
 | 
			
		||||
    audfmt_e effective_fmt;
 | 
			
		||||
    struct audsettings obt_as;
 | 
			
		||||
 | 
			
		||||
    req.freq = as->freq;
 | 
			
		||||
    req.format = aud_to_sdlfmt (as->fmt);
 | 
			
		||||
    req.channels = as->nchannels;
 | 
			
		||||
    req.samples = audio_buffer_samples(s->dev->u.sdl.out, as, 11610);
 | 
			
		||||
    req.samples = conf.nb_samples;
 | 
			
		||||
    req.callback = sdl_callback;
 | 
			
		||||
    req.userdata = sdl;
 | 
			
		||||
 | 
			
		||||
@@ -311,21 +389,30 @@ static int sdl_ctl_out (HWVoiceOut *hw, int cmd, ...)
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void *sdl_audio_init(Audiodev *dev)
 | 
			
		||||
static void *sdl_audio_init (void)
 | 
			
		||||
{
 | 
			
		||||
    SDLAudioState *s = &glob_sdl;
 | 
			
		||||
    if (s->driver_created) {
 | 
			
		||||
        sdl_logerr("Can't create multiple sdl backends\n");
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (SDL_InitSubSystem (SDL_INIT_AUDIO)) {
 | 
			
		||||
        sdl_logerr ("SDL failed to initialize audio subsystem\n");
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    s->driver_created = true;
 | 
			
		||||
    s->dev = dev;
 | 
			
		||||
    s->mutex = SDL_CreateMutex ();
 | 
			
		||||
    if (!s->mutex) {
 | 
			
		||||
        sdl_logerr ("Failed to create SDL mutex\n");
 | 
			
		||||
        SDL_QuitSubSystem (SDL_INIT_AUDIO);
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    s->sem = SDL_CreateSemaphore (0);
 | 
			
		||||
    if (!s->sem) {
 | 
			
		||||
        sdl_logerr ("Failed to create SDL semaphore\n");
 | 
			
		||||
        SDL_DestroyMutex (s->mutex);
 | 
			
		||||
        SDL_QuitSubSystem (SDL_INIT_AUDIO);
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return s;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -333,11 +420,21 @@ static void sdl_audio_fini (void *opaque)
 | 
			
		||||
{
 | 
			
		||||
    SDLAudioState *s = opaque;
 | 
			
		||||
    sdl_close (s);
 | 
			
		||||
    SDL_DestroySemaphore (s->sem);
 | 
			
		||||
    SDL_DestroyMutex (s->mutex);
 | 
			
		||||
    SDL_QuitSubSystem (SDL_INIT_AUDIO);
 | 
			
		||||
    s->driver_created = false;
 | 
			
		||||
    s->dev = NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static struct audio_option sdl_options[] = {
 | 
			
		||||
    {
 | 
			
		||||
        .name  = "SAMPLES",
 | 
			
		||||
        .tag   = AUD_OPT_INT,
 | 
			
		||||
        .valp  = &conf.nb_samples,
 | 
			
		||||
        .descr = "Size of SDL buffer in samples"
 | 
			
		||||
    },
 | 
			
		||||
    { /* End of list */ }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static struct audio_pcm_ops sdl_pcm_ops = {
 | 
			
		||||
    .init_out = sdl_init_out,
 | 
			
		||||
    .fini_out = sdl_fini_out,
 | 
			
		||||
@@ -346,9 +443,10 @@ static struct audio_pcm_ops sdl_pcm_ops = {
 | 
			
		||||
    .ctl_out  = sdl_ctl_out,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static struct audio_driver sdl_audio_driver = {
 | 
			
		||||
struct audio_driver sdl_audio_driver = {
 | 
			
		||||
    .name           = "sdl",
 | 
			
		||||
    .descr          = "SDL http://www.libsdl.org",
 | 
			
		||||
    .options        = sdl_options,
 | 
			
		||||
    .init           = sdl_audio_init,
 | 
			
		||||
    .fini           = sdl_audio_fini,
 | 
			
		||||
    .pcm_ops        = &sdl_pcm_ops,
 | 
			
		||||
@@ -358,9 +456,3 @@ static struct audio_driver sdl_audio_driver = {
 | 
			
		||||
    .voice_size_out = sizeof (SDLVoiceOut),
 | 
			
		||||
    .voice_size_in  = 0
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void register_audio_sdl(void)
 | 
			
		||||
{
 | 
			
		||||
    audio_driver_register(&sdl_audio_driver);
 | 
			
		||||
}
 | 
			
		||||
type_init(register_audio_sdl);
 | 
			
		||||
 
 | 
			
		||||
@@ -17,29 +17,16 @@
 | 
			
		||||
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#include "qemu/osdep.h"
 | 
			
		||||
#include "hw/hw.h"
 | 
			
		||||
#include "qemu/host-utils.h"
 | 
			
		||||
#include "qemu/module.h"
 | 
			
		||||
#include "qemu/error-report.h"
 | 
			
		||||
#include "qemu/timer.h"
 | 
			
		||||
#include "qemu-timer.h"
 | 
			
		||||
#include "ui/qemu-spice.h"
 | 
			
		||||
 | 
			
		||||
#define AUDIO_CAP "spice"
 | 
			
		||||
#include "audio.h"
 | 
			
		||||
#include "audio_int.h"
 | 
			
		||||
 | 
			
		||||
#if SPICE_INTERFACE_PLAYBACK_MAJOR > 1 || SPICE_INTERFACE_PLAYBACK_MINOR >= 3
 | 
			
		||||
#define LINE_OUT_SAMPLES (480 * 4)
 | 
			
		||||
#else
 | 
			
		||||
#define LINE_OUT_SAMPLES (256 * 4)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#if SPICE_INTERFACE_RECORD_MAJOR > 2 || SPICE_INTERFACE_RECORD_MINOR >= 3
 | 
			
		||||
#define LINE_IN_SAMPLES (480 * 4)
 | 
			
		||||
#else
 | 
			
		||||
#define LINE_IN_SAMPLES (256 * 4)
 | 
			
		||||
#endif
 | 
			
		||||
#define LINE_IN_SAMPLES 1024
 | 
			
		||||
#define LINE_OUT_SAMPLES 1024
 | 
			
		||||
 | 
			
		||||
typedef struct SpiceRateCtl {
 | 
			
		||||
    int64_t               start_ticks;
 | 
			
		||||
@@ -78,7 +65,7 @@ static const SpiceRecordInterface record_sif = {
 | 
			
		||||
    .base.minor_version = SPICE_INTERFACE_RECORD_MINOR,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static void *spice_audio_init(Audiodev *dev)
 | 
			
		||||
static void *spice_audio_init (void)
 | 
			
		||||
{
 | 
			
		||||
    if (!using_spice) {
 | 
			
		||||
        return NULL;
 | 
			
		||||
@@ -94,7 +81,7 @@ static void spice_audio_fini (void *opaque)
 | 
			
		||||
static void rate_start (SpiceRateCtl *rate)
 | 
			
		||||
{
 | 
			
		||||
    memset (rate, 0, sizeof (*rate));
 | 
			
		||||
    rate->start_ticks = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
 | 
			
		||||
    rate->start_ticks = qemu_get_clock_ns (vm_clock);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static int rate_get_samples (struct audio_pcm_info *info, SpiceRateCtl *rate)
 | 
			
		||||
@@ -104,12 +91,12 @@ static int rate_get_samples (struct audio_pcm_info *info, SpiceRateCtl *rate)
 | 
			
		||||
    int64_t bytes;
 | 
			
		||||
    int64_t samples;
 | 
			
		||||
 | 
			
		||||
    now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
 | 
			
		||||
    now = qemu_get_clock_ns (vm_clock);
 | 
			
		||||
    ticks = now - rate->start_ticks;
 | 
			
		||||
    bytes = muldiv64(ticks, info->bytes_per_second, NANOSECONDS_PER_SECOND);
 | 
			
		||||
    bytes = muldiv64 (ticks, info->bytes_per_second, get_ticks_per_sec ());
 | 
			
		||||
    samples = (bytes - rate->bytes_sent) >> info->shift;
 | 
			
		||||
    if (samples < 0 || samples > 65536) {
 | 
			
		||||
        error_report("Resetting rate control (%" PRId64 " samples)", samples);
 | 
			
		||||
        fprintf (stderr, "Resetting rate control (%" PRId64 " samples)\n", samples);
 | 
			
		||||
        rate_start (rate);
 | 
			
		||||
        samples = 0;
 | 
			
		||||
    }
 | 
			
		||||
@@ -119,19 +106,14 @@ static int rate_get_samples (struct audio_pcm_info *info, SpiceRateCtl *rate)
 | 
			
		||||
 | 
			
		||||
/* playback */
 | 
			
		||||
 | 
			
		||||
static int line_out_init(HWVoiceOut *hw, struct audsettings *as,
 | 
			
		||||
                         void *drv_opaque)
 | 
			
		||||
static int line_out_init (HWVoiceOut *hw, struct audsettings *as)
 | 
			
		||||
{
 | 
			
		||||
    SpiceVoiceOut *out = container_of (hw, SpiceVoiceOut, hw);
 | 
			
		||||
    struct audsettings settings;
 | 
			
		||||
 | 
			
		||||
#if SPICE_INTERFACE_PLAYBACK_MAJOR > 1 || SPICE_INTERFACE_PLAYBACK_MINOR >= 3
 | 
			
		||||
    settings.freq       = spice_server_get_best_playback_rate(NULL);
 | 
			
		||||
#else
 | 
			
		||||
    settings.freq       = SPICE_INTERFACE_PLAYBACK_FREQ;
 | 
			
		||||
#endif
 | 
			
		||||
    settings.nchannels  = SPICE_INTERFACE_PLAYBACK_CHAN;
 | 
			
		||||
    settings.fmt        = AUDIO_FORMAT_S16;
 | 
			
		||||
    settings.fmt        = AUD_FMT_S16;
 | 
			
		||||
    settings.endianness = AUDIO_HOST_ENDIANNESS;
 | 
			
		||||
 | 
			
		||||
    audio_pcm_init_info (&hw->info, &settings);
 | 
			
		||||
@@ -140,9 +122,6 @@ static int line_out_init(HWVoiceOut *hw, struct audsettings *as,
 | 
			
		||||
 | 
			
		||||
    out->sin.base.sif = &playback_sif.base;
 | 
			
		||||
    qemu_spice_add_interface (&out->sin.base);
 | 
			
		||||
#if SPICE_INTERFACE_PLAYBACK_MAJOR > 1 || SPICE_INTERFACE_PLAYBACK_MINOR >= 3
 | 
			
		||||
    spice_server_set_playback_rate(&out->sin, settings.freq);
 | 
			
		||||
#endif
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -223,43 +202,20 @@ static int line_out_ctl (HWVoiceOut *hw, int cmd, ...)
 | 
			
		||||
        }
 | 
			
		||||
        spice_server_playback_stop (&out->sin);
 | 
			
		||||
        break;
 | 
			
		||||
    case VOICE_VOLUME:
 | 
			
		||||
        {
 | 
			
		||||
#if ((SPICE_INTERFACE_PLAYBACK_MAJOR >= 1) && (SPICE_INTERFACE_PLAYBACK_MINOR >= 2))
 | 
			
		||||
            SWVoiceOut *sw;
 | 
			
		||||
            va_list ap;
 | 
			
		||||
            uint16_t vol[2];
 | 
			
		||||
 | 
			
		||||
            va_start (ap, cmd);
 | 
			
		||||
            sw = va_arg (ap, SWVoiceOut *);
 | 
			
		||||
            va_end (ap);
 | 
			
		||||
 | 
			
		||||
            vol[0] = sw->vol.l / ((1ULL << 16) + 1);
 | 
			
		||||
            vol[1] = sw->vol.r / ((1ULL << 16) + 1);
 | 
			
		||||
            spice_server_playback_set_volume (&out->sin, 2, vol);
 | 
			
		||||
            spice_server_playback_set_mute (&out->sin, sw->vol.mute);
 | 
			
		||||
#endif
 | 
			
		||||
            break;
 | 
			
		||||
    }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/* record */
 | 
			
		||||
 | 
			
		||||
static int line_in_init(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
 | 
			
		||||
static int line_in_init (HWVoiceIn *hw, struct audsettings *as)
 | 
			
		||||
{
 | 
			
		||||
    SpiceVoiceIn *in = container_of (hw, SpiceVoiceIn, hw);
 | 
			
		||||
    struct audsettings settings;
 | 
			
		||||
 | 
			
		||||
#if SPICE_INTERFACE_RECORD_MAJOR > 2 || SPICE_INTERFACE_RECORD_MINOR >= 3
 | 
			
		||||
    settings.freq       = spice_server_get_best_record_rate(NULL);
 | 
			
		||||
#else
 | 
			
		||||
    settings.freq       = SPICE_INTERFACE_RECORD_FREQ;
 | 
			
		||||
#endif
 | 
			
		||||
    settings.nchannels  = SPICE_INTERFACE_RECORD_CHAN;
 | 
			
		||||
    settings.fmt        = AUDIO_FORMAT_S16;
 | 
			
		||||
    settings.fmt        = AUD_FMT_S16;
 | 
			
		||||
    settings.endianness = AUDIO_HOST_ENDIANNESS;
 | 
			
		||||
 | 
			
		||||
    audio_pcm_init_info (&hw->info, &settings);
 | 
			
		||||
@@ -268,9 +224,6 @@ static int line_in_init(HWVoiceIn *hw, struct audsettings *as, void *drv_opaque)
 | 
			
		||||
 | 
			
		||||
    in->sin.base.sif = &record_sif.base;
 | 
			
		||||
    qemu_spice_add_interface (&in->sin.base);
 | 
			
		||||
#if SPICE_INTERFACE_RECORD_MAJOR > 2 || SPICE_INTERFACE_RECORD_MINOR >= 3
 | 
			
		||||
    spice_server_set_record_rate(&in->sin, settings.freq);
 | 
			
		||||
#endif
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -351,29 +304,14 @@ static int line_in_ctl (HWVoiceIn *hw, int cmd, ...)
 | 
			
		||||
        in->active = 0;
 | 
			
		||||
        spice_server_record_stop (&in->sin);
 | 
			
		||||
        break;
 | 
			
		||||
    case VOICE_VOLUME:
 | 
			
		||||
        {
 | 
			
		||||
#if ((SPICE_INTERFACE_RECORD_MAJOR >= 2) && (SPICE_INTERFACE_RECORD_MINOR >= 2))
 | 
			
		||||
            SWVoiceIn *sw;
 | 
			
		||||
            va_list ap;
 | 
			
		||||
            uint16_t vol[2];
 | 
			
		||||
 | 
			
		||||
            va_start (ap, cmd);
 | 
			
		||||
            sw = va_arg (ap, SWVoiceIn *);
 | 
			
		||||
            va_end (ap);
 | 
			
		||||
 | 
			
		||||
            vol[0] = sw->vol.l / ((1ULL << 16) + 1);
 | 
			
		||||
            vol[1] = sw->vol.r / ((1ULL << 16) + 1);
 | 
			
		||||
            spice_server_record_set_volume (&in->sin, 2, vol);
 | 
			
		||||
            spice_server_record_set_mute (&in->sin, sw->vol.mute);
 | 
			
		||||
#endif
 | 
			
		||||
            break;
 | 
			
		||||
    }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static struct audio_option audio_options[] = {
 | 
			
		||||
    { /* end of list */ },
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static struct audio_pcm_ops audio_callbacks = {
 | 
			
		||||
    .init_out = line_out_init,
 | 
			
		||||
    .fini_out = line_out_fini,
 | 
			
		||||
@@ -388,9 +326,10 @@ static struct audio_pcm_ops audio_callbacks = {
 | 
			
		||||
    .ctl_in   = line_in_ctl,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
static struct audio_driver spice_audio_driver = {
 | 
			
		||||
struct audio_driver spice_audio_driver = {
 | 
			
		||||
    .name           = "spice",
 | 
			
		||||
    .descr          = "spice audio driver",
 | 
			
		||||
    .options        = audio_options,
 | 
			
		||||
    .init           = spice_audio_init,
 | 
			
		||||
    .fini           = spice_audio_fini,
 | 
			
		||||
    .pcm_ops        = &audio_callbacks,
 | 
			
		||||
@@ -398,18 +337,9 @@ static struct audio_driver spice_audio_driver = {
 | 
			
		||||
    .max_voices_in  = 1,
 | 
			
		||||
    .voice_size_out = sizeof (SpiceVoiceOut),
 | 
			
		||||
    .voice_size_in  = sizeof (SpiceVoiceIn),
 | 
			
		||||
#if ((SPICE_INTERFACE_PLAYBACK_MAJOR >= 1) && (SPICE_INTERFACE_PLAYBACK_MINOR >= 2))
 | 
			
		||||
    .ctl_caps       = VOICE_VOLUME_CAP
 | 
			
		||||
#endif
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
void qemu_spice_audio_init (void)
 | 
			
		||||
{
 | 
			
		||||
    spice_audio_driver.can_be_default = 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void register_audio_spice(void)
 | 
			
		||||
{
 | 
			
		||||
    audio_driver_register(&spice_audio_driver);
 | 
			
		||||
}
 | 
			
		||||
type_init(register_audio_spice);
 | 
			
		||||
 
 | 
			
		||||
Some files were not shown because too many files have changed in this diff Show More
		Reference in New Issue
	
	Block a user