138 lines
7.0 KiB
Plaintext
138 lines
7.0 KiB
Plaintext
#!/sbin/runscript
|
|
# Copyright 1999-2006 Gentoo Foundation
|
|
# Distributed under the terms of the GNU General Public License v2
|
|
# $Header: $
|
|
|
|
# enable automatic i386/ARM/M68K/MIPS/SPARC/PPC/s390 program execution by the kernel
|
|
|
|
depend() {
|
|
after procfs
|
|
}
|
|
|
|
start() {
|
|
ebegin "Registering qemu-user binaries"
|
|
|
|
if [[ ! -d /proc/sys/fs/binfmt_misc ]] ; then
|
|
eerror "You need support for \"misc binaries\" in your kernel!"
|
|
eend 1
|
|
fi
|
|
|
|
if [[ $(mount | grep -c binfmt_misc) -eq 0 ]] ; then
|
|
mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc &> /dev/null
|
|
local result=$?
|
|
|
|
if [[ $result -ne 0 ]] ; then
|
|
eend $result
|
|
fi
|
|
fi
|
|
|
|
# probe cpu type
|
|
cpu=`uname -m`
|
|
case "$cpu" in
|
|
i386|i486|i586|i686|i86pc|BePC|x86_64)
|
|
cpu="i386"
|
|
;;
|
|
m68k)
|
|
cpu="m68k"
|
|
;;
|
|
mips*)
|
|
cpu="mips"
|
|
;;
|
|
"Power Macintosh"|ppc|ppc64)
|
|
cpu="ppc"
|
|
;;
|
|
armv[4-9]*)
|
|
cpu="arm"
|
|
;;
|
|
sparc*)
|
|
cpu="sparc"
|
|
;;
|
|
esac
|
|
|
|
# register the interpreter for each cpu except for the native one
|
|
if [ $cpu != "i386" ] ; then
|
|
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-binfmt:P' > /proc/sys/fs/binfmt_misc/register
|
|
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-binfmt:P' > /proc/sys/fs/binfmt_misc/register
|
|
fi
|
|
if [ $cpu != "alpha" ] ; then
|
|
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-binfmt:P' > /proc/sys/fs/binfmt_misc/register
|
|
fi
|
|
if [ $cpu != "arm" ] ; then
|
|
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\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-arm-binfmt:P' > /proc/sys/fs/binfmt_misc/register
|
|
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-binfmt:P' > /proc/sys/fs/binfmt_misc/register
|
|
fi
|
|
if [ $cpu != "sparc" ] ; then
|
|
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-binfmt:P' > /proc/sys/fs/binfmt_misc/register
|
|
fi
|
|
if [ $cpu != "ppc" ] ; then
|
|
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-binfmt:P' > /proc/sys/fs/binfmt_misc/register
|
|
fi
|
|
if [ $cpu != "m68k" ] ; then
|
|
echo 'Please check cpu value and header information for m68k!'
|
|
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-binfmt:P' > /proc/sys/fs/binfmt_misc/register
|
|
fi
|
|
if [ $cpu != "mips" ] ; then
|
|
# FIXME: We could use the other endianness on a MIPS host.
|
|
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-binfmt:P' > /proc/sys/fs/binfmt_misc/register
|
|
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-binfmt:P' > /proc/sys/fs/binfmt_misc/register
|
|
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-binfmt:P' > /proc/sys/fs/binfmt_misc/register
|
|
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-binfmt:P' > /proc/sys/fs/binfmt_misc/register
|
|
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-binfmt:P' > /proc/sys/fs/binfmt_misc/register
|
|
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-binfmt:P' > /proc/sys/fs/binfmt_misc/register
|
|
fi
|
|
if [ $cpu != "sh" ] ; then
|
|
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-binfmt:P' > /proc/sys/fs/binfmt_misc/register
|
|
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-binfmt:P' > /proc/sys/fs/binfmt_misc/register
|
|
fi
|
|
if [ $cpu != "s390x" ] ; then
|
|
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-binfmt:P' > /proc/sys/fs/binfmt_misc/register
|
|
fi
|
|
eend $?
|
|
}
|
|
|
|
stop() {
|
|
ebegin "Unregistering qemu-user binaries"
|
|
|
|
if [[ -f /proc/sys/fs/binfmt_misc/i386 ]] ; then
|
|
echo '-1' > /proc/sys/fs/binfmt_misc/i386
|
|
echo '-1' > /proc/sys/fs/binfmt_misc/i486
|
|
fi
|
|
if [[ -f /proc/sys/fs/binfmt_misc/alpha ]] ; then
|
|
echo '-1' > /proc/sys/fs/binfmt_misc/alpha
|
|
fi
|
|
if [[ -f /proc/sys/fs/binfmt_misc/arm ]] ; then
|
|
echo '-1' > /proc/sys/fs/binfmt_misc/arm
|
|
echo '-1' > /proc/sys/fs/binfmt_misc/armeb
|
|
fi
|
|
if [[ -f /proc/sys/fs/binfmt_misc/sparc ]] ; then
|
|
echo '-1' > /proc/sys/fs/binfmt_misc/sparc
|
|
fi
|
|
if [[ -f /proc/sys/fs/binfmt_misc/ppc ]] ; then
|
|
echo '-1' > /proc/sys/fs/binfmt_misc/ppc
|
|
fi
|
|
if [[ -f /proc/sys/fs/binfmt_misc/m68k ]] ; then
|
|
echo '-1' > /proc/sys/fs/binfmt_misc/m68k
|
|
fi
|
|
if [[ -f /proc/sys/fs/binfmt_misc/misp ]] ; then
|
|
echo '-1' > /proc/sys/fs/binfmt_misc/mips
|
|
echo '-1' > /proc/sys/fs/binfmt_misc/mipsel
|
|
echo '-1' > /proc/sys/fs/binfmt_misc/mipsn32
|
|
echo '-1' > /proc/sys/fs/binfmt_misc/mipsn32el
|
|
echo '-1' > /proc/sys/fs/binfmt_misc/mips64
|
|
echo '-1' > /proc/sys/fs/binfmt_misc/mips64el
|
|
fi
|
|
if [[ -f /proc/sys/fs/binfmt_misc/sh4 ]] ; then
|
|
echo '-1' > /proc/sys/fs/binfmt_misc/sh4
|
|
echo '-1' > /proc/sys/fs/binfmt_misc/sh4eb
|
|
fi
|
|
if [[ -f /proc/sys/fs/binfmt_misc/s390x ]] ; then
|
|
echo '-1' > /proc/sys/fs/binfmt_misc/s390x
|
|
fi
|
|
|
|
eend $?
|
|
}
|
|
|
|
# vim: ts=4 :
|
|
|
|
|