You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

295 lines
9.7 KiB

  1. #!/usr/bin/env bash
  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.
  5. # The unix package provides access to the raw system call
  6. # interface of the underlying operating system. Porting Go to
  7. # a new architecture/operating system combination requires
  8. # some manual effort, though there are tools that automate
  9. # much of the process. The auto-generated files have names
  10. # beginning with z.
  11. #
  12. # This script runs or (given -n) prints suggested commands to generate z files
  13. # for the current system. Running those commands is not automatic.
  14. # This script is documentation more than anything else.
  15. #
  16. # * asm_${GOOS}_${GOARCH}.s
  17. #
  18. # This hand-written assembly file implements system call dispatch.
  19. # There are three entry points:
  20. #
  21. # func Syscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr);
  22. # func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr);
  23. # func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr);
  24. #
  25. # The first and second are the standard ones; they differ only in
  26. # how many arguments can be passed to the kernel.
  27. # The third is for low-level use by the ForkExec wrapper;
  28. # unlike the first two, it does not call into the scheduler to
  29. # let it know that a system call is running.
  30. #
  31. # * syscall_${GOOS}.go
  32. #
  33. # This hand-written Go file implements system calls that need
  34. # special handling and lists "//sys" comments giving prototypes
  35. # for ones that can be auto-generated. Mksyscall reads those
  36. # comments to generate the stubs.
  37. #
  38. # * syscall_${GOOS}_${GOARCH}.go
  39. #
  40. # Same as syscall_${GOOS}.go except that it contains code specific
  41. # to ${GOOS} on one particular architecture.
  42. #
  43. # * types_${GOOS}.c
  44. #
  45. # This hand-written C file includes standard C headers and then
  46. # creates typedef or enum names beginning with a dollar sign
  47. # (use of $ in variable names is a gcc extension). The hardest
  48. # part about preparing this file is figuring out which headers to
  49. # include and which symbols need to be #defined to get the
  50. # actual data structures that pass through to the kernel system calls.
  51. # Some C libraries present alternate versions for binary compatibility
  52. # and translate them on the way in and out of system calls, but
  53. # there is almost always a #define that can get the real ones.
  54. # See types_darwin.c and types_linux.c for examples.
  55. #
  56. # * zerror_${GOOS}_${GOARCH}.go
  57. #
  58. # This machine-generated file defines the system's error numbers,
  59. # error strings, and signal numbers. The generator is "mkerrors.sh".
  60. # Usually no arguments are needed, but mkerrors.sh will pass its
  61. # arguments on to godefs.
  62. #
  63. # * zsyscall_${GOOS}_${GOARCH}.go
  64. #
  65. # Generated by mksyscall.pl; see syscall_${GOOS}.go above.
  66. #
  67. # * zsysnum_${GOOS}_${GOARCH}.go
  68. #
  69. # Generated by mksysnum_${GOOS}.
  70. #
  71. # * ztypes_${GOOS}_${GOARCH}.go
  72. #
  73. # Generated by godefs; see types_${GOOS}.c above.
  74. GOOSARCH="${GOOS}_${GOARCH}"
  75. # defaults
  76. mksyscall="./mksyscall.pl"
  77. mkerrors="./mkerrors.sh"
  78. zerrors="zerrors_$GOOSARCH.go"
  79. mksysctl=""
  80. zsysctl="zsysctl_$GOOSARCH.go"
  81. mksysnum=
  82. mktypes=
  83. run="sh"
  84. case "$1" in
  85. -syscalls)
  86. for i in zsyscall*go
  87. do
  88. # Run the command line that appears in the first line
  89. # of the generated file to regenerate it.
  90. sed 1q $i | sed 's;^// ;;' | sh > _$i && gofmt < _$i > $i
  91. rm _$i
  92. done
  93. exit 0
  94. ;;
  95. -n)
  96. run="cat"
  97. shift
  98. esac
  99. case "$#" in
  100. 0)
  101. ;;
  102. *)
  103. echo 'usage: mkall.sh [-n]' 1>&2
  104. exit 2
  105. esac
  106. GOOSARCH_in=syscall_$GOOSARCH.go
  107. case "$GOOSARCH" in
  108. _* | *_ | _)
  109. echo 'undefined $GOOS_$GOARCH:' "$GOOSARCH" 1>&2
  110. exit 1
  111. ;;
  112. darwin_386)
  113. mkerrors="$mkerrors -m32"
  114. mksyscall="./mksyscall.pl -l32"
  115. mksysnum="./mksysnum_darwin.pl $(xcrun --show-sdk-path --sdk macosx)/usr/include/sys/syscall.h"
  116. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  117. ;;
  118. darwin_amd64)
  119. mkerrors="$mkerrors -m64"
  120. mksysnum="./mksysnum_darwin.pl $(xcrun --show-sdk-path --sdk macosx)/usr/include/sys/syscall.h"
  121. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  122. ;;
  123. darwin_arm)
  124. mkerrors="$mkerrors"
  125. mksysnum="./mksysnum_darwin.pl /usr/include/sys/syscall.h"
  126. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  127. ;;
  128. darwin_arm64)
  129. mkerrors="$mkerrors -m64"
  130. mksysnum="./mksysnum_darwin.pl $(xcrun --show-sdk-path --sdk iphoneos)/usr/include/sys/syscall.h"
  131. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  132. ;;
  133. dragonfly_386)
  134. mkerrors="$mkerrors -m32"
  135. mksyscall="./mksyscall.pl -l32 -dragonfly"
  136. mksysnum="curl -s 'http://gitweb.dragonflybsd.org/dragonfly.git/blob_plain/HEAD:/sys/kern/syscalls.master' | ./mksysnum_dragonfly.pl"
  137. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  138. ;;
  139. dragonfly_amd64)
  140. mkerrors="$mkerrors -m64"
  141. mksyscall="./mksyscall.pl -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"
  144. ;;
  145. freebsd_386)
  146. mkerrors="$mkerrors -m32"
  147. mksyscall="./mksyscall.pl -l32"
  148. mksysnum="curl -s 'http://svn.freebsd.org/base/stable/10/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl"
  149. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  150. ;;
  151. freebsd_amd64)
  152. mkerrors="$mkerrors -m64"
  153. mksysnum="curl -s 'http://svn.freebsd.org/base/stable/10/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl"
  154. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  155. ;;
  156. freebsd_arm)
  157. mkerrors="$mkerrors"
  158. mksyscall="./mksyscall.pl -l32 -arm"
  159. mksysnum="curl -s 'http://svn.freebsd.org/base/stable/10/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl"
  160. # Let the type of C char be signed for making the bare syscall
  161. # API consistent across over platforms.
  162. mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
  163. ;;
  164. linux_386)
  165. mkerrors="$mkerrors -m32"
  166. mksyscall="./mksyscall.pl -l32"
  167. mksysnum="./mksysnum_linux.pl /usr/include/asm/unistd_32.h"
  168. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  169. ;;
  170. linux_amd64)
  171. 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)
  172. if [ "$unistd_h" = "" ]; then
  173. echo >&2 cannot find unistd_64.h
  174. exit 1
  175. fi
  176. mkerrors="$mkerrors -m64"
  177. mksysnum="./mksysnum_linux.pl $unistd_h"
  178. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  179. ;;
  180. linux_arm)
  181. mkerrors="$mkerrors"
  182. mksyscall="./mksyscall.pl -l32 -arm"
  183. 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 -"
  184. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  185. ;;
  186. linux_arm64)
  187. unistd_h=$(ls -1 /usr/include/asm/unistd.h /usr/include/asm-generic/unistd.h 2>/dev/null | head -1)
  188. if [ "$unistd_h" = "" ]; then
  189. echo >&2 cannot find unistd_64.h
  190. exit 1
  191. fi
  192. mksysnum="./mksysnum_linux.pl $unistd_h"
  193. # Let the type of C char be signed for making the bare syscall
  194. # API consistent across over platforms.
  195. mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
  196. ;;
  197. linux_ppc64)
  198. GOOSARCH_in=syscall_linux_ppc64x.go
  199. unistd_h=/usr/include/asm/unistd.h
  200. mkerrors="$mkerrors -m64"
  201. mksysnum="./mksysnum_linux.pl $unistd_h"
  202. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  203. ;;
  204. linux_ppc64le)
  205. GOOSARCH_in=syscall_linux_ppc64x.go
  206. unistd_h=/usr/include/powerpc64le-linux-gnu/asm/unistd.h
  207. mkerrors="$mkerrors -m64"
  208. mksysnum="./mksysnum_linux.pl $unistd_h"
  209. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  210. ;;
  211. linux_s390x)
  212. GOOSARCH_in=syscall_linux_s390x.go
  213. unistd_h=/usr/include/asm/unistd.h
  214. mkerrors="$mkerrors -m64"
  215. mksysnum="./mksysnum_linux.pl $unistd_h"
  216. # Let the type of C char be signed to make the bare sys
  217. # API more consistent between platforms.
  218. # This is a deliberate departure from the way the syscall
  219. # package generates its version of the types file.
  220. mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
  221. ;;
  222. linux_sparc64)
  223. GOOSARCH_in=syscall_linux_sparc64.go
  224. unistd_h=/usr/include/sparc64-linux-gnu/asm/unistd.h
  225. mkerrors="$mkerrors -m64"
  226. mksysnum="./mksysnum_linux.pl $unistd_h"
  227. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  228. ;;
  229. netbsd_386)
  230. mkerrors="$mkerrors -m32"
  231. mksyscall="./mksyscall.pl -l32 -netbsd"
  232. mksysnum="curl -s 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_netbsd.pl"
  233. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  234. ;;
  235. netbsd_amd64)
  236. mkerrors="$mkerrors -m64"
  237. mksyscall="./mksyscall.pl -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"
  240. ;;
  241. openbsd_386)
  242. mkerrors="$mkerrors -m32"
  243. mksyscall="./mksyscall.pl -l32 -openbsd"
  244. mksysctl="./mksysctl_openbsd.pl"
  245. zsysctl="zsysctl_openbsd.go"
  246. mksysnum="curl -s 'http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_openbsd.pl"
  247. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  248. ;;
  249. openbsd_amd64)
  250. mkerrors="$mkerrors -m64"
  251. mksyscall="./mksyscall.pl -openbsd"
  252. mksysctl="./mksysctl_openbsd.pl"
  253. zsysctl="zsysctl_openbsd.go"
  254. mksysnum="curl -s 'http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_openbsd.pl"
  255. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  256. ;;
  257. solaris_amd64)
  258. mksyscall="./mksyscall_solaris.pl"
  259. mkerrors="$mkerrors -m64"
  260. mksysnum=
  261. mktypes="GOARCH=$GOARCH go tool cgo -godefs"
  262. ;;
  263. *)
  264. echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2
  265. exit 1
  266. ;;
  267. esac
  268. (
  269. if [ -n "$mkerrors" ]; then echo "$mkerrors |gofmt >$zerrors"; fi
  270. case "$GOOS" in
  271. *)
  272. syscall_goos="syscall_$GOOS.go"
  273. case "$GOOS" in
  274. darwin | dragonfly | freebsd | netbsd | openbsd)
  275. syscall_goos="syscall_bsd.go $syscall_goos"
  276. ;;
  277. esac
  278. if [ -n "$mksyscall" ]; then echo "$mksyscall -tags $GOOS,$GOARCH $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go"; fi
  279. ;;
  280. esac
  281. if [ -n "$mksysctl" ]; then echo "$mksysctl |gofmt >$zsysctl"; fi
  282. if [ -n "$mksysnum" ]; then echo "$mksysnum |gofmt >zsysnum_$GOOSARCH.go"; fi
  283. if [ -n "$mktypes" ]; then
  284. echo "echo // +build $GOARCH,$GOOS > ztypes_$GOOSARCH.go";
  285. echo "$mktypes types_$GOOS.go | go run mkpost.go >>ztypes_$GOOSARCH.go";
  286. fi
  287. ) | $run