...
Run Format

Text file src/syscall/mkall.sh

Documentation: syscall

     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	
     6	# The syscall 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
    11	# beginning with z.
    12	#
    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.
    16	#
    17	# * asm_${GOOS}_${GOARCH}.s
    18	#
    19	# This hand-written assembly file implements system call dispatch.
    20	# There are three entry points:
    21	#
    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);
    25	#
    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.
    31	#
    32	# * syscall_${GOOS}.go
    33	#
    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.
    38	#
    39	# * syscall_${GOOS}_${GOARCH}.go
    40	#
    41	# Same as syscall_${GOOS}.go except that it contains code specific
    42	# to ${GOOS} on one particular architecture.
    43	#
    44	# * types_${GOOS}.c
    45	#
    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.
    56	#
    57	# * zerror_${GOOS}_${GOARCH}.go
    58	#
    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.
    63	#
    64	# * zsyscall_${GOOS}_${GOARCH}.go
    65	#
    66	# Generated by mksyscall.pl; see syscall_${GOOS}.go above.
    67	#
    68	# * zsysnum_${GOOS}_${GOARCH}.go
    69	#
    70	# Generated by mksysnum_${GOOS}.
    71	#
    72	# * ztypes_${GOOS}_${GOARCH}.go
    73	#
    74	# Generated by godefs; see types_${GOOS}.c above.
    75	
    76	GOOSARCH="${GOOS}_${GOARCH}"
    77	
    78	# defaults
    79	mksyscall="./mksyscall.pl"
    80	mkerrors="./mkerrors.sh"
    81	zerrors="zerrors_$GOOSARCH.go"
    82	mksysctl=""
    83	zsysctl="zsysctl_$GOOSARCH.go"
    84	mksysnum=
    85	mktypes=
    86	run="sh"
    87	
    88	case "$1" in
    89	-syscalls)
    90		for i in zsyscall*go
    91		do
    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
    95			rm _$i
    96		done
    97		exit 0
    98		;;
    99	-n)
   100		run="cat"
   101		shift
   102	esac
   103	
   104	case "$#" in
   105	0)
   106		;;
   107	*)
   108		echo 'usage: mkall.sh [-n]' 1>&2
   109		exit 2
   110	esac
   111	
   112	GOOSARCH_in=syscall_$GOOSARCH.go
   113	case "$GOOSARCH" in
   114	_* | *_ | _)
   115		echo 'undefined $GOOS_$GOARCH:' "$GOOSARCH" 1>&2
   116		exit 1
   117		;;
   118	darwin_386)
   119		mkerrors="$mkerrors -m32"
   120		mksyscall="./mksyscall.pl -l32"
   121		mksysnum="./mksysnum_darwin.pl /usr/include/sys/syscall.h"
   122		mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   123		;;
   124	darwin_amd64)
   125		mkerrors="$mkerrors -m64"
   126		mksysnum="./mksysnum_darwin.pl /usr/include/sys/syscall.h"
   127		mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   128		;;
   129	darwin_arm64)
   130		mkerrors="$mkerrors -m64"
   131		mksysnum="./mksysnum_darwin.pl /usr/include/sys/syscall.h"
   132		mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   133		;;
   134	dragonfly_amd64)
   135		mkerrors="$mkerrors -m64"
   136		mksyscall="./mksyscall.pl -dragonfly"
   137		mksysnum="curl -s 'http://gitweb.dragonflybsd.org/dragonfly.git/blob_plain/HEAD:/sys/kern/syscalls.master' | ./mksysnum_dragonfly.pl"
   138		mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   139		;;
   140	freebsd_386)
   141		mkerrors="$mkerrors -m32"
   142		mksyscall="./mksyscall.pl -l32"
   143		mksysnum="curl -s 'http://svn.freebsd.org/base/stable/10/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl"
   144		mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   145		;;
   146	freebsd_amd64)
   147		mkerrors="$mkerrors -m64"
   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_arm)
   152		mkerrors="$mkerrors"
   153		mksyscall="./mksyscall.pl -l32 -arm"
   154		mksysnum="curl -s 'http://svn.freebsd.org/base/stable/10/sys/kern/syscalls.master' | ./mksysnum_freebsd.pl"
   155		# Let the type of C char be signed to make the bare syscall
   156		# API consistent between platforms.
   157		mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
   158		;;
   159	linux_386)
   160		mkerrors="$mkerrors -m32"
   161		mksyscall="./mksyscall.pl -l32"
   162		mksysnum="./mksysnum_linux.pl /usr/include/asm/unistd_32.h"
   163		mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   164		;;
   165	linux_amd64)
   166		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)
   167		if [ "$unistd_h" = "" ]; then
   168			echo >&2 cannot find unistd_64.h
   169			exit 1
   170		fi
   171		mkerrors="$mkerrors -m64"
   172		mksysnum="./mksysnum_linux.pl $unistd_h"
   173		mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   174		;;
   175	linux_arm)
   176		mkerrors="$mkerrors"
   177		mksyscall="./mksyscall.pl -l32 -arm"
   178		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 -"
   179		mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   180		;;
   181	linux_arm64)
   182		unistd_h=$(ls -1 /usr/include/asm/unistd.h /usr/include/asm-generic/unistd.h 2>/dev/null | head -1)
   183		if [ "$unistd_h" = "" ]; then
   184			echo >&2 cannot find unistd_64.h
   185			exit 1
   186		fi
   187		mksysnum="./mksysnum_linux.pl $unistd_h"
   188		# Let the type of C char be signed to make the bare syscall
   189		# API consistent between platforms.
   190		mktypes="GOARCH=$GOARCH go tool cgo -godefs -- -fsigned-char"
   191		;;
   192	linux_mips)
   193		GOOSARCH_in=syscall_linux_mipsx.go
   194		unistd_h=/usr/include/asm/unistd.h
   195		mksyscall="./mksyscall.pl -b32 -arm"
   196		mkerrors="$mkerrors"
   197		mksysnum="./mksysnum_linux.pl $unistd_h"
   198		mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   199		;;
   200	linux_mipsle)
   201		GOOSARCH_in=syscall_linux_mipsx.go
   202		unistd_h=/usr/include/asm/unistd.h
   203		mksyscall="./mksyscall.pl -l32 -arm"
   204		mkerrors="$mkerrors"
   205		mksysnum="./mksysnum_linux.pl $unistd_h"
   206		mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   207		;;
   208	linux_mips64)
   209		GOOSARCH_in=syscall_linux_mips64x.go
   210		unistd_h=/usr/include/asm/unistd.h
   211		mkerrors="$mkerrors -m64"
   212		mksysnum="./mksysnum_linux.pl $unistd_h"
   213		mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   214		;;
   215	linux_mips64le)
   216		GOOSARCH_in=syscall_linux_mips64x.go
   217		unistd_h=/usr/include/asm/unistd.h
   218		mkerrors="$mkerrors -m64"
   219		mksysnum="./mksysnum_linux.pl $unistd_h"
   220		mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   221		;;
   222	linux_ppc64)
   223		GOOSARCH_in=syscall_linux_ppc64x.go
   224		unistd_h=/usr/include/asm/unistd.h
   225		mkerrors="$mkerrors -m64"
   226		mksysnum="./mksysnum_linux.pl $unistd_h"
   227		mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   228		;;
   229	linux_ppc64le)
   230		GOOSARCH_in=syscall_linux_ppc64x.go
   231		unistd_h=/usr/include/powerpc64le-linux-gnu/asm/unistd.h
   232		mkerrors="$mkerrors -m64"
   233		mksysnum="./mksysnum_linux.pl $unistd_h"
   234		mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   235		;;
   236	linux_s390x)
   237		GOOSARCH_in=syscall_linux_s390x.go
   238		unistd_h=/usr/include/asm/unistd.h
   239		mkerrors="$mkerrors -m64"
   240		mksysnum="./mksysnum_linux.pl $unistd_h"
   241		mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   242		;;
   243	nacl_386)
   244		mkerrors=""
   245		mksyscall="./mksyscall.pl -l32 -nacl"
   246		mksysnum=""
   247		mktypes=""
   248		;;
   249	nacl_amd64p32)
   250		mkerrors=""
   251		mksyscall="./mksyscall.pl -nacl"
   252		mksysnum=""
   253		mktypes=""
   254		;;
   255	netbsd_386)
   256		mkerrors="$mkerrors -m32"
   257		mksyscall="./mksyscall.pl -l32 -netbsd"
   258		mksysnum="curl -s 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_netbsd.pl"
   259		mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   260		;;
   261	netbsd_amd64)
   262		mkerrors="$mkerrors -m64"
   263		mksyscall="./mksyscall.pl -netbsd"
   264		mksysnum="curl -s 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_netbsd.pl"
   265		mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   266		;;
   267	netbsd_arm)
   268		mkerrors="$mkerrors -m32"
   269		mksyscall="./mksyscall.pl -l32 -netbsd -arm"
   270		mksysnum="curl -s 'http://cvsweb.netbsd.org/bsdweb.cgi/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_netbsd.pl"
   271		mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   272		;;
   273	openbsd_386)
   274		mkerrors="$mkerrors -m32"
   275		mksyscall="./mksyscall.pl -l32 -openbsd"
   276		mksysctl="./mksysctl_openbsd.pl"
   277		zsysctl="zsysctl_openbsd.go"
   278		mksysnum="curl -s 'http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_openbsd.pl"
   279		mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   280		;;
   281	openbsd_amd64)
   282		mkerrors="$mkerrors -m64"
   283		mksyscall="./mksyscall.pl -openbsd"
   284		mksysctl="./mksysctl_openbsd.pl"
   285		zsysctl="zsysctl_openbsd.go"
   286		mksysnum="curl -s 'http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_openbsd.pl"
   287		mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   288		;;
   289	openbsd_arm)
   290		mkerrors="$mkerrors"
   291		mksyscall="./mksyscall.pl -l32 -openbsd -arm"
   292		mksysctl="./mksysctl_openbsd.pl"
   293		zsysctl="zsysctl_openbsd.go"
   294		mksysnum="curl -s 'http://cvsweb.openbsd.org/cgi-bin/cvsweb/~checkout~/src/sys/kern/syscalls.master' | ./mksysnum_openbsd.pl"
   295		mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   296		;;
   297	plan9_386)
   298		mkerrors=
   299		mksyscall="./mksyscall.pl -l32 -plan9"
   300		mksysnum="./mksysnum_plan9.sh /n/sources/plan9/sys/src/libc/9syscall/sys.h"
   301		mktypes="XXX"
   302		;;
   303	solaris_amd64)
   304		mksyscall="./mksyscall_solaris.pl"
   305		mkerrors="$mkerrors -m64"
   306		mksysnum=
   307		mktypes="GOARCH=$GOARCH go tool cgo -godefs"
   308		;;
   309	windows_*)
   310		echo 'run "go generate" instead' 1>&2
   311		exit 1
   312		;;
   313	*)
   314		echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2
   315		exit 1
   316		;;
   317	esac
   318	
   319	(
   320		if [ -n "$mkerrors" ]; then echo "$mkerrors |gofmt >$zerrors"; fi
   321		syscall_goos="syscall_$GOOS.go"
   322	 	case "$GOOS" in
   323		darwin | dragonfly | freebsd | netbsd | openbsd)
   324			syscall_goos="syscall_bsd.go $syscall_goos"
   325	 		;;
   326	 	esac
   327		if [ -n "$mksyscall" ]; then echo "$mksyscall -tags $GOOS,$GOARCH $syscall_goos $GOOSARCH_in |gofmt >zsyscall_$GOOSARCH.go"; fi
   328		if [ -n "$mksysctl" ]; then echo "$mksysctl |gofmt >$zsysctl"; fi
   329		if [ -n "$mksysnum" ]; then echo "$mksysnum |gofmt >zsysnum_$GOOSARCH.go"; fi
   330		if [ -n "$mktypes" ]; then echo "$mktypes types_$GOOS.go |go run mkpost.go >ztypes_$GOOSARCH.go"; fi
   331	) | $run

View as plain text