Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 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 | # |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame^] | 13 | # This script runs or (given -n) prints suggested commands to generate z files |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 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 | # |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 57 | # * zerror_${GOOS}_${GOARCH}.go |
| 58 | # |
| 59 | # This machine-generated file defines the system's error numbers, |
Rob Pike | cd32498 | 2009-08-13 13:22:37 -0700 | [diff] [blame] | 60 | # error strings, and signal numbers. The generator is "mkerrors.sh". |
| 61 | # Usually no arguments are needed, but mkerrors.sh will pass its |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 62 | # arguments on to godefs. |
| 63 | # |
| 64 | # * zsyscall_${GOOS}_${GOARCH}.go |
| 65 | # |
Rob Pike | cd32498 | 2009-08-13 13:22:37 -0700 | [diff] [blame] | 66 | # Generated by mksyscall.sh; see syscall_${GOOS}.go above. |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 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 |
Rob Pike | cd32498 | 2009-08-13 13:22:37 -0700 | [diff] [blame] | 79 | mksyscall="mksyscall.sh" |
| 80 | mkerrors="mkerrors.sh" |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame^] | 81 | run="sh" |
| 82 | |
| 83 | case "$1" in |
| 84 | -n) |
| 85 | run="cat" |
| 86 | shift |
| 87 | esac |
| 88 | |
| 89 | case "$#" in |
| 90 | 0) |
| 91 | ;; |
| 92 | *) |
| 93 | echo 'usage: mkall.sh [-n]' 1>&2 |
| 94 | exit 2 |
| 95 | esac |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 96 | |
| 97 | case "$GOOSARCH" in |
| 98 | _* | *_ | _) |
| 99 | echo 'undefined $GOOS_$GOARCH:' "$GOOSARCH" 1>&2 |
| 100 | exit 1 |
| 101 | ;; |
| 102 | darwin_386) |
Rob Pike | cd32498 | 2009-08-13 13:22:37 -0700 | [diff] [blame] | 103 | mksyscall="mksyscall.sh -l32" |
| 104 | mksysnum="mksysnum_darwin.sh /home/rsc/pub/xnu-1228/bsd/kern/syscalls.master" |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 105 | mktypes="godefs -gsyscall -f-m32" |
| 106 | ;; |
| 107 | darwin_amd64) |
Rob Pike | cd32498 | 2009-08-13 13:22:37 -0700 | [diff] [blame] | 108 | mksysnum="mksysnum_darwin.sh /home/rsc/pub/xnu-1228/bsd/kern/syscalls.master" |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 109 | mktypes="godefs -gsyscall -f-m64" |
Rob Pike | cd32498 | 2009-08-13 13:22:37 -0700 | [diff] [blame] | 110 | mkerrors="mkerrors.sh" |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 111 | ;; |
Russ Cox | 802d6d4 | 2009-06-04 13:33:40 -0700 | [diff] [blame] | 112 | linux_386) |
Rob Pike | cd32498 | 2009-08-13 13:22:37 -0700 | [diff] [blame] | 113 | mksyscall="mksyscall.sh -l32" |
| 114 | mksysnum="mksysnum_linux.sh /usr/include/asm/unistd_32.h" |
Russ Cox | 802d6d4 | 2009-06-04 13:33:40 -0700 | [diff] [blame] | 115 | mktypes="godefs -gsyscall -f-m32" |
| 116 | ;; |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 117 | linux_amd64) |
Rob Pike | cd32498 | 2009-08-13 13:22:37 -0700 | [diff] [blame] | 118 | mksysnum="mksysnum_linux.sh /usr/include/asm/unistd_64.h" |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 119 | mktypes="godefs -gsyscall -f-m64" |
| 120 | ;; |
Russ Cox | b428456 | 2009-09-22 07:49:31 -0700 | [diff] [blame] | 121 | nacl_386) |
| 122 | NACL="/home/rsc/pub/nacl/native_client" |
| 123 | NACLRUN="$NACL/src/trusted/service_runtime" |
| 124 | NACLSDK="$NACL/src/third_party/nacl_sdk/linux/sdk/nacl-sdk/nacl" |
| 125 | mksyscall="mksyscall.sh -l32" |
| 126 | mksysnum="mksysnum_nacl.sh $NACLRUN/include/bits/nacl_syscalls.h" |
| 127 | mktypes="godefs -gsyscall -f-m32 -f-I$NACLSDK/include -f-I$NACL" |
| 128 | mkerrors="mkerrors_nacl.sh $NACLRUN/include/sys/errno.h" |
| 129 | ;; |
Kai Backman | e5c884f | 2009-10-01 06:55:01 -0700 | [diff] [blame] | 130 | linux_arm) |
| 131 | ARM="/home/kaib/public/linux-2.6.28" |
| 132 | mksyscall="mksyscall.sh -l32" |
| 133 | mksysnum="mksysnum_linux.sh $ARM/arch/arm/include/asm/unistd.h" |
| 134 | // mktypes="godefs -gsyscall -carm-gcc -f-I$ARM/arch/arm/include -f-I$ARM/include -f-D__deprecated='' -f-I$ARM/arch/arm/mach-at91/include -f-DCONFIG_ARCH_AT91SAM9260 " |
| 135 | mktypes="godefs -gsyscall -carm-gcc" |
| 136 | mkerrors="mkerrors.sh" |
| 137 | ;; |
Russ Cox | 602a446 | 2009-06-01 22:14:57 -0700 | [diff] [blame] | 138 | *) |
| 139 | echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2 |
| 140 | exit 1 |
| 141 | ;; |
| 142 | esac |
| 143 | |
Russ Cox | fd1add2 | 2009-11-01 11:13:27 -0800 | [diff] [blame^] | 144 | ( |
| 145 | echo "$mkerrors |gofmt >zerrors_$GOOSARCH.go" |
| 146 | echo "$mksyscall syscall_$GOOS.go syscall_$GOOSARCH.go |gofmt >zsyscall_$GOOSARCH.go" |
| 147 | echo "$mksysnum |gofmt >zsysnum_$GOOSARCH.go" |
| 148 | echo "$mktypes types_$GOOS.c |gofmt >ztypes_$GOOSARCH.go" |
| 149 | ) | $run |