]> git.draconx.ca Git - gentoo-draconx.git/blob - app-emulation/qemu/files/qemu-binfmt.initd-r1
Merge branch 'amythaon'
[gentoo-draconx.git] / app-emulation / qemu / files / qemu-binfmt.initd-r1
1 #!/sbin/runscript
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 $
5
6 # enable automatic i386/ARM/M68K/MIPS/SPARC/PPC/s390 program execution by the kernel
7
8 depend() {
9     after procfs
10 }
11
12 start() {
13    ebegin "Registering qemu-user binaries"
14
15    if [[ ! -d /proc/sys/fs/binfmt_misc ]] ; then
16       /sbin/modprobe binfmt_misc   
17    fi
18
19    if [[ ! -d /proc/sys/fs/binfmt_misc ]] ; then
20        eerror "You need \"binfmt_misc\" support in your kernel."
21        eend 1
22        return 1
23    fi
24
25    if [[ ! -f /proc/sys/fs/binfmt_misc/register ]] ; then
26       mount -t binfmt_misc binfmt_misc /proc/sys/fs/binfmt_misc &> /dev/null
27       local result=$?
28
29       if [[ $result -ne 0 ]] ; then
30          eend $result
31          return $result
32       fi
33    fi
34
35    # probe cpu type
36    cpu=`uname -m`
37    case "$cpu" in
38       i386|i486|i586|i686|i86pc|BePC|x86_64)
39          cpu="i386"
40          ;;
41       m68k)
42          cpu="m68k"
43          ;;
44       mips*)
45          cpu="mips"
46       ;;
47       "Power Macintosh"|ppc|ppc64)
48          cpu="ppc"
49       ;;
50       armv[4-9]*)
51          cpu="arm"
52       ;;
53       sparc*)
54          cpu="sparc"
55       ;;
56    esac
57
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
62    fi
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
65    fi
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
68    fi
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
71    fi
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
74    fi
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
77    fi
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
81    fi
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
85    fi
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
88    fi
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
91    fi
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
94    fi
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
97    fi
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
100    fi
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
103    fi
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
106    fi
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
109    fi
110    eend $?
111 }
112
113 stop() {
114    ebegin "Unregistering qemu-user binaries"
115    local arches
116
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"
126
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
130       fi
131    done
132
133    eend $?
134 }
135
136 # vim: ts=4 :