2 # Copyright 1999-2013 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 # $Header: /var/cvsroot/gentoo-x86/app-emulation/qemu/files/qemu-binfmt.initd-r1,v 1.1 2013/01/19 03:42:06 cardoe Exp $
6 # enable automatic i386/ARM/M68K/MIPS/SPARC/PPC/s390 program execution by the kernel
13 ebegin "Registering qemu-user binaries"
15 if [[ ! -d /proc/sys/fs/binfmt_misc ]] ; then
16 /sbin/modprobe binfmt_misc
19 if [[ ! -d /proc/sys/fs/binfmt_misc ]] ; then
20 eerror "You need \"binfmt_misc\" support in your kernel."
25 if [[ ! -f /proc/sys/fs/binfmt_misc/register ]] ; then
26 mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc &> /dev/null
29 if [[ $result -ne 0 ]] ; then
38 i386|i486|i586|i686|i86pc|BePC|x86_64)
47 "Power Macintosh"|ppc|ppc64)
58 # register the interpreter for each cpu except for the native one
59 if [ $cpu != "i386" -a -x "/usr/bin/qemu-i386" ] ; then
60 echo ':i386:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x03\x00:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-i386:P' > /proc/sys/fs/binfmt_misc/register
61 echo ':i486:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x06\x00:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-i386:P' > /proc/sys/fs/binfmt_misc/register
63 if [ $cpu != "alpha" -a -x "/usr/bin/qemu-alpha" ] ; then
64 echo ':alpha:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x26\x90:\xff\xff\xff\xff\xff\xfe\xfe\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-alpha:P' > /proc/sys/fs/binfmt_misc/register
66 if [ $cpu != "arm" -a -x "/usr/bin/qemu-arm" ] ; then
67 echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\x00\xff\xfe\xff\xff\xff:/usr/bin/qemu-arm:P' > /proc/sys/fs/binfmt_misc/register
69 if [ $cpu != "arm" -a -x "/usr/bin/qemu-armeb" ] ; then
70 echo ':armeb:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-armeb:P' > /proc/sys/fs/binfmt_misc/register
72 if [ $cpu != "sparc" -a -x "/usr/bin/qemu-sparc" ] ; then
73 echo ':sparc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x02:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-sparc:P' > /proc/sys/fs/binfmt_misc/register
75 if [ $cpu != "ppc" -a -x "/usr/bin/qemu-ppc" ] ; then
76 echo ':ppc:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x14:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-ppc:P' > /proc/sys/fs/binfmt_misc/register
78 if [ $cpu != "m68k" -a -x "/usr/bin/qemu-m68k" ] ; then
79 echo 'Please check cpu value and header information for m68k!'
80 echo ':m68k:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x04\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-m68k:P' > /proc/sys/fs/binfmt_misc/register
82 if [ $cpu != "mips" -a -x "/usr/bin/qemu-mips" ] ; then
83 # FIXME: We could use the other endianness on a MIPS host.
84 echo ':mips:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-mips:P' > /proc/sys/fs/binfmt_misc/register
86 if [ $cpu != "mips" -a -x "/usr/bin/qemu-mipsel" ] ; then
87 echo ':mipsel:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-mipsel:P' > /proc/sys/fs/binfmt_misc/register
89 if [ $cpu != "mips" -a -x "/usr/bin/qemu-mipsn32" ] ; then
90 echo ':mipsn32:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-mipsn32:P' > /proc/sys/fs/binfmt_misc/register
92 if [ $cpu != "mips" -a -x "/usr/bin/qemu-mipsn32el" ] ; then
93 echo ':mipsn32el:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-mipsn32el:P' > /proc/sys/fs/binfmt_misc/register
95 if [ $cpu != "mips" -a -x "/usr/bin/qemu-mips64" ] ; then
96 echo ':mips64:M::\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-mips64:P' > /proc/sys/fs/binfmt_misc/register
98 if [ $cpu != "mips" -a -x "/usr/bin/qemu-mips64el" ] ; then
99 echo ':mips64el:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x08\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-mips64el:P' > /proc/sys/fs/binfmt_misc/register
101 if [ $cpu != "sh" -a -x "/usr/bin/qemu-sh4" ] ; then
102 echo ':sh4:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a\x00:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-sh4:P' > /proc/sys/fs/binfmt_misc/register
104 if [ $cpu != "sh" -a -x "/usr/bin/qemu-sh4eb" ] ; then
105 echo ':sh4eb:M::\x7fELF\x01\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x2a:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-sh4eb:P' > /proc/sys/fs/binfmt_misc/register
107 if [ $cpu != "s390x" -a -x "/usr/local/bin/qemu-s390x" ] ; then
108 echo ':s390x:M::\x7fELF\x02\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x16:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/local/bin/qemu-s390x:P' > /proc/sys/fs/binfmt_misc/register
114 ebegin "Unregistering qemu-user binaries"
117 arches="${arches} i386 i486"
118 arches="${arches} alpha"
119 arches="${arches} arm armeb"
120 arches="${arches} sparc"
121 arches="${arches} ppc"
122 arches="${arches} m68k"
123 arches="${arches} mips mipsel mipsn32 mipsn32el mips64 mips64el"
124 arches="${arches} sh4 sh4eb"
125 arches="${arches} s390x"
127 for a in ${arches}; do
128 if [[ -f /proc/sys/fs/binfmt_misc/$a ]] ; then
129 echo '-1' > /proc/sys/fs/binfmt_misc/$a