2 # Copyright 2009 The Go Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style
4 # license that can be found in the LICENSE file.
6 # The unix package provides access to the raw system call
7 # interface of the underlying operating system. Porting Go to
8 # a new architecture/operating system combination requires
9 # some manual effort, though there are tools that automate
10 # much of the process. The auto-generated files have names
13 # This script runs or (given -n) prints suggested commands to generate z files
14 # for the current system. Running those commands is not automatic.
15 # This script is documentation more than anything else.
17 # * asm_${GOOS}_${GOARCH}.s
19 # This hand-written assembly file implements system call dispatch.
20 # There are three entry points:
22 # func Syscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr);
23 # func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr);
24 # func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr);
26 # The first and second are the standard ones; they differ only in
27 # how many arguments can be passed to the kernel.
28 # The third is for low-level use by the ForkExec wrapper;
29 # unlike the first two, it does not call into the scheduler to
30 # let it know that a system call is running.
32 # * syscall_${GOOS}.go
34 # This hand-written Go file implements system calls that need
35 # special handling and lists "//sys" comments giving prototypes
36 # for ones that can be auto-generated. Mksyscall reads those
37 # comments to generate the stubs.
39 # * syscall_${GOOS}_${GOARCH}.go
41 # Same as syscall_${GOOS}.go except that it contains code specific
42 # to ${GOOS} on one particular architecture.
46 # This hand-written C file includes standard C headers and then
47 # creates typedef or enum names beginning with a dollar sign
48 # (use of $ in variable names is a gcc extension). The hardest
49 # part about preparing this file is figuring out which headers to
50 # include and which symbols need to be #defined to get the
51 # actual data structures that pass through to the kernel system calls.
52 # Some C libraries present alternate versions for binary compatibility
53 # and translate them on the way in and out of system calls, but
54 # there is almost always a #define that can get the real ones.
55 # See types_darwin.c and types_linux.c for examples.
57 # * zerror_${GOOS}_${GOARCH}.go
59 # This machine-generated file defines the system's error numbers,
60 # error strings, and signal numbers. The generator is "mkerrors.sh".
61 # Usually no arguments are needed, but mkerrors.sh will pass its
62 # arguments on to godefs.
64 # * zsyscall_${GOOS}_${GOARCH}.go
66 # Generated by mksyscall.pl; see syscall_${GOOS}.go above.
68 # * zsysnum_${GOOS}_${GOARCH}.go
70 # Generated by mksysnum_${GOOS}.
72 # * ztypes_${GOOS}_${GOARCH}.go
74 # Generated by godefs; see types_${GOOS}.c above.
76 GOOSARCH="${GOOS}_${GOARCH}"
79 mksyscall="./mksyscall.pl"
80 mkerrors="./mkerrors.sh"
81 zerrors="zerrors_$GOOSARCH.go"
83 zsysctl="zsysctl_$GOOSARCH.go"
92 # Run the command line that appears in the first line
93 # of the generated file to regenerate it.
94 sed 1q $i | sed 's;^// ;;' | sh > _$i && gofmt < _$i > $i
108 echo 'usage: mkall.sh [-n]' 1>&2
112 GOOSARCH_in=syscall_$GOOSARCH.go
115 echo 'undefined $GOOS_$GOARCH:' "$GOOSARCH" 1>&2
119 mkerrors="$mkerrors -m32"
120 mksyscall="./mksyscall.pl -l32"
121 mksysnum="./mksysnum_darwin.pl $(xcrun --show-sdk-path --sdk macosx)/usr/include/sys/syscall.h"
122 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
125 mkerrors="$mkerrors -m64"
126 mksysnum="./mksysnum_darwin.pl $(xcrun --show-sdk-path --sdk macosx)/usr/include/sys/syscall.h"
127 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
131 mksysnum="./mksysnum_darwin.pl /usr/include/sys/syscall.h"
132 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
135 mkerrors="$mkerrors -m64"
136 mksysnum="./mksysnum_darwin.pl $(xcrun --show-sdk-path --sdk iphoneos)/usr/include/sys/syscall.h"
137 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
140 mkerrors="$mkerrors -m32"
141 mksyscall="./mksyscall.pl -l32 -dragonfly"
142 mksysnum="curl -s 'http://gitweb.dragonflybsd.org/dragonfly.git/blob_plain/HEAD:/sys/kern/syscalls.master' | ./mksysnum_dragonfly.pl"
143 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
146 mkerrors="$mkerrors -m64"
147 mksyscall="./mksyscall.pl -dragonfly"
148 mksysnum="curl -s 'http://gitweb.dragonflybsd.org/dragonfly.git/blob_plain/HEAD:/sys/kern/syscalls.master' | ./mksysnum_dragonfly.pl"
149 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
152 mkerrors="$mkerrors -m32"
153 mksyscall="./mksyscall.pl -l32"
154 mksysnum="curl -s 'http://svn.freebsd.org/base/stable/10/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl"
155 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
158 mkerrors="$mkerrors -m64"
159 mksysnum="curl -s 'http://svn.freebsd.org/base/stable/10/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl"
160 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
164 mksyscall="./mksyscall.pl -l32 -arm"
165 mksysnum="curl -s 'http://svn.freebsd.org/base/stable/10/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl"
166 # Let the type of C char be signed for making the bare syscall
167 # API consistent across over platforms.
168 mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
171 mkerrors="$mkerrors -m32"
172 mksyscall="./mksyscall.pl -l32"
173 mksysnum="./mksysnum_linux.pl /usr/include/asm/unistd_32.h"
174 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
177 unistd_h=$(ls -1 /usr/include/asm/unistd_64.h /usr/include/x86_64-linux-gnu/asm/unistd_64.h 2>/dev/null | head -1)
178 if [ "$unistd_h" = "" ]; then
179 echo >&2 cannot find unistd_64.h
182 mkerrors="$mkerrors -m64"
183 mksysnum="./mksysnum_linux.pl $unistd_h"
184 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
188 mksyscall="./mksyscall.pl -l32 -arm"
189 mksysnum="curl -s 'http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/plain/arch/arm/include/uapi/asm/unistd.h' | ./mksysnum_linux.pl -"
190 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
193 unistd_h=$(ls -1 /usr/include/asm/unistd.h /usr/include/asm-generic/unistd.h 2>/dev/null | head -1)
194 if [ "$unistd_h" = "" ]; then
195 echo >&2 cannot find unistd_64.h
198 mksysnum="./mksysnum_linux.pl $unistd_h"
199 # Let the type of C char be signed for making the bare syscall
200 # API consistent across over platforms.
201 mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
204 GOOSARCH_in=syscall_linux_ppc64x.go
205 unistd_h=/usr/include/asm/unistd.h
206 mkerrors="$mkerrors -m64"
207 mksysnum="./mksysnum_linux.pl $unistd_h"
208 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
211 GOOSARCH_in=syscall_linux_ppc64x.go
212 unistd_h=/usr/include/powerpc64le-linux-gnu/asm/unistd.h
213 mkerrors="$mkerrors -m64"
214 mksysnum="./mksysnum_linux.pl $unistd_h"
215 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
218 GOOSARCH_in=syscall_linux_s390x.go
219 unistd_h=/usr/include/asm/unistd.h
220 mkerrors="$mkerrors -m64"
221 mksysnum="./mksysnum_linux.pl $unistd_h"
222 # Let the type of C char be signed to make the bare sys
223 # API more consistent between platforms.
224 # This is a deliberate departure from the way the syscall
225 # package generates its version of the types file.
226 mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
229 GOOSARCH_in=syscall_linux_sparc64.go
230 unistd_h=/usr/include/sparc64-linux-gnu/asm/unistd.h
231 mkerrors="$mkerrors -m64"
232 mksysnum="./mksysnum_linux.pl $unistd_h"
233 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
236 mkerrors="$mkerrors -m32"
237 mksyscall="./mksyscall.pl -l32 -netbsd"
238 mksysnum="curl -s 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_netbsd.pl"
239 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
242 mkerrors="$mkerrors -m64"
243 mksyscall="./mksyscall.pl -netbsd"
244 mksysnum="curl -s 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_netbsd.pl"
245 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
248 mkerrors="$mkerrors -m32"
249 mksyscall="./mksyscall.pl -l32 -openbsd"
250 mksysctl="./mksysctl_openbsd.pl"
251 zsysctl="zsysctl_openbsd.go"
252 mksysnum="curl -s 'http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_openbsd.pl"
253 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
256 mkerrors="$mkerrors -m64"
257 mksyscall="./mksyscall.pl -openbsd"
258 mksysctl="./mksysctl_openbsd.pl"
259 zsysctl="zsysctl_openbsd.go"
260 mksysnum="curl -s 'http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_openbsd.pl"
261 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
264 mksyscall="./mksyscall_solaris.pl"
265 mkerrors="$mkerrors -m64"
267 mktypes="GOARCH=$GOARCH go tool cgo -godefs"
270 echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2
276 if [ -n "$mkerrors" ]; then echo "$mkerrors |gofmt >$zerrors"; fi
279 syscall_goos="syscall_$GOOS.go"
281 darwin | dragonfly | freebsd | netbsd | openbsd)
282 syscall_goos="syscall_bsd.go $syscall_goos"
285 if [ -n "$mksyscall" ]; then echo "$mksyscall -tags $GOOS,$GOARCH $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go"; fi
288 if [ -n "$mksysctl" ]; then echo "$mksysctl |gofmt >$zsysctl"; fi
289 if [ -n "$mksysnum" ]; then echo "$mksysnum |gofmt >zsysnum_$GOOSARCH.go"; fi
290 if [ -n "$mktypes" ]; then
291 echo "echo // +build $GOARCH,$GOOS > ztypes_$GOOSARCH.go";
292 echo "$mktypes types_$GOOS.go | go run mkpost.go >>ztypes_$GOOSARCH.go";