blob: d0383f54a83eba1367688afb38c88269a8d886fa [file] [log] [blame]
Russ Cox602a4462009-06-01 22:14:57 -07001#!/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 Coxfd1add22009-11-01 11:13:27 -080013# This script runs or (given -n) prints suggested commands to generate z files
Russ Cox602a4462009-06-01 22:14:57 -070014# 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 Cox602a4462009-06-01 22:14:57 -070057# * zerror_${GOOS}_${GOARCH}.go
58#
59# This machine-generated file defines the system's error numbers,
Rob Pikecd324982009-08-13 13:22:37 -070060# error strings, and signal numbers. The generator is "mkerrors.sh".
61# Usually no arguments are needed, but mkerrors.sh will pass its
Russ Cox602a4462009-06-01 22:14:57 -070062# arguments on to godefs.
63#
64# * zsyscall_${GOOS}_${GOARCH}.go
65#
Rob Pikecd324982009-08-13 13:22:37 -070066# Generated by mksyscall.sh; see syscall_${GOOS}.go above.
Russ Cox602a4462009-06-01 22:14:57 -070067#
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
76GOOSARCH="${GOOS}_${GOARCH}"
77
78# defaults
Rob Pikecd324982009-08-13 13:22:37 -070079mksyscall="mksyscall.sh"
80mkerrors="mkerrors.sh"
Russ Coxfd1add22009-11-01 11:13:27 -080081run="sh"
82
83case "$1" in
84-n)
85 run="cat"
86 shift
87esac
88
89case "$#" in
900)
91 ;;
92*)
93 echo 'usage: mkall.sh [-n]' 1>&2
94 exit 2
95esac
Russ Cox602a4462009-06-01 22:14:57 -070096
97case "$GOOSARCH" in
98_* | *_ | _)
99 echo 'undefined $GOOS_$GOARCH:' "$GOOSARCH" 1>&2
100 exit 1
101 ;;
102darwin_386)
Rob Pikecd324982009-08-13 13:22:37 -0700103 mksyscall="mksyscall.sh -l32"
104 mksysnum="mksysnum_darwin.sh /home/rsc/pub/xnu-1228/bsd/kern/syscalls.master"
Russ Cox602a4462009-06-01 22:14:57 -0700105 mktypes="godefs -gsyscall -f-m32"
106 ;;
107darwin_amd64)
Rob Pikecd324982009-08-13 13:22:37 -0700108 mksysnum="mksysnum_darwin.sh /home/rsc/pub/xnu-1228/bsd/kern/syscalls.master"
Russ Cox602a4462009-06-01 22:14:57 -0700109 mktypes="godefs -gsyscall -f-m64"
Rob Pikecd324982009-08-13 13:22:37 -0700110 mkerrors="mkerrors.sh"
Russ Cox602a4462009-06-01 22:14:57 -0700111 ;;
Russ Cox802d6d42009-06-04 13:33:40 -0700112linux_386)
Rob Pikecd324982009-08-13 13:22:37 -0700113 mksyscall="mksyscall.sh -l32"
114 mksysnum="mksysnum_linux.sh /usr/include/asm/unistd_32.h"
Russ Cox802d6d42009-06-04 13:33:40 -0700115 mktypes="godefs -gsyscall -f-m32"
116 ;;
Russ Cox602a4462009-06-01 22:14:57 -0700117linux_amd64)
Rob Pikecd324982009-08-13 13:22:37 -0700118 mksysnum="mksysnum_linux.sh /usr/include/asm/unistd_64.h"
Russ Cox602a4462009-06-01 22:14:57 -0700119 mktypes="godefs -gsyscall -f-m64"
120 ;;
Russ Coxb4284562009-09-22 07:49:31 -0700121nacl_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 Backmane5c884f2009-10-01 06:55:01 -0700130linux_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 Cox602a4462009-06-01 22:14:57 -0700138*)
139 echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2
140 exit 1
141 ;;
142esac
143
Russ Coxfd1add22009-11-01 11:13:27 -0800144(
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