2009-06-17 17:31:02 -06:00
|
|
|
#!/bin/sh
|
|
|
|
# Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style
|
|
|
|
# license that can be found in the LICENSE file.
|
|
|
|
|
2012-01-30 21:17:11 -07:00
|
|
|
trap "rm -f arch_GOARCH.h defs_GOOS_GOARCH.h os_GOOS.h signals_GOOS.h" EXIT INT TERM
|
2009-06-17 17:31:02 -06:00
|
|
|
set -e
|
|
|
|
|
2011-12-19 13:51:13 -07:00
|
|
|
SYS=$1
|
|
|
|
export GOOS=$(echo $SYS | sed 's/_.*//')
|
|
|
|
export GOARCH=$(echo $SYS | sed 's/.*_//')
|
|
|
|
shift
|
|
|
|
|
|
|
|
case "$GOARCH" in
|
|
|
|
386) CC=8c;;
|
|
|
|
amd64) CC=6c;;
|
|
|
|
arm) CC=5c;;
|
|
|
|
esac
|
2012-02-02 21:32:41 -07:00
|
|
|
CC="$GOROOT/bin/tool/$CC"
|
2011-12-19 13:51:13 -07:00
|
|
|
export CC
|
|
|
|
|
|
|
|
export CFLAGS="-Dos_$GOOS -Darch_$GOARCH"
|
|
|
|
|
|
|
|
cp arch_$GOARCH.h arch_GOARCH.h
|
|
|
|
cp defs_${GOOS}_$GOARCH.h defs_GOOS_GOARCH.h
|
|
|
|
cp os_$GOOS.h os_GOOS.h
|
|
|
|
cp signals_$GOOS.h signals_GOOS.h
|
|
|
|
|
2009-06-17 17:31:02 -06:00
|
|
|
cat <<'EOF'
|
|
|
|
// Assembly constants.
|
2011-12-19 13:51:13 -07:00
|
|
|
// AUTO-GENERATED by autogen.sh; DO NOT EDIT
|
2009-06-17 17:31:02 -06:00
|
|
|
|
|
|
|
EOF
|
2012-01-30 15:46:31 -07:00
|
|
|
if [ ! -x "$CC" ]; then
|
2012-01-24 13:03:41 -07:00
|
|
|
echo "// dummy file for cmd/go to correctly generate buildscript"
|
|
|
|
exit
|
|
|
|
fi
|
2009-06-17 17:31:02 -06:00
|
|
|
|
|
|
|
case "$GOARCH" in
|
|
|
|
386)
|
2009-10-03 11:37:12 -06:00
|
|
|
# The offsets 0 and 4 are also known to:
|
|
|
|
# ../../cmd/8l/pass.c:/D_GS
|
2012-01-19 15:13:33 -07:00
|
|
|
# cgo/gcc_linux_386.c:/^threadentry
|
|
|
|
# cgo/gcc_darwin_386.c:/^threadentry
|
2010-01-06 18:58:55 -07:00
|
|
|
case "$GOOS" in
|
2010-04-30 00:45:14 -06:00
|
|
|
windows)
|
2012-01-08 17:23:07 -07:00
|
|
|
echo '#define get_tls(r) MOVL 0x14(FS), r'
|
2010-01-06 18:58:55 -07:00
|
|
|
echo '#define g(r) 0(r)'
|
|
|
|
echo '#define m(r) 4(r)'
|
|
|
|
;;
|
2010-10-18 10:32:55 -06:00
|
|
|
plan9)
|
2011-02-11 11:39:05 -07:00
|
|
|
echo '#define get_tls(r) MOVL _tos(SB), r '
|
|
|
|
echo '#define g(r) -8(r)'
|
|
|
|
echo '#define m(r) -4(r)'
|
2010-10-18 10:32:55 -06:00
|
|
|
;;
|
2010-07-17 17:54:03 -06:00
|
|
|
linux)
|
|
|
|
# On Linux systems, what we call 0(GS) and 4(GS) for g and m
|
|
|
|
# turn into %gs:-8 and %gs:-4 (using gcc syntax to denote
|
|
|
|
# what the machine sees as opposed to 8l input).
|
|
|
|
# 8l rewrites 0(GS) and 4(GS) into these.
|
|
|
|
#
|
|
|
|
# On Linux Xen, it is not allowed to use %gs:-8 and %gs:-4
|
|
|
|
# directly. Instead, we have to store %gs:0 into a temporary
|
|
|
|
# register and then use -8(%reg) and -4(%reg). This kind
|
|
|
|
# of addressing is correct even when not running Xen.
|
|
|
|
#
|
|
|
|
# 8l can rewrite MOVL 0(GS), CX into the appropriate pair
|
|
|
|
# of mov instructions, using CX as the intermediate register
|
|
|
|
# (safe because CX is about to be written to anyway).
|
|
|
|
# But 8l cannot handle other instructions, like storing into 0(GS),
|
|
|
|
# which is where these macros come into play.
|
|
|
|
# get_tls sets up the temporary and then g and r use it.
|
|
|
|
#
|
|
|
|
# The final wrinkle is that get_tls needs to read from %gs:0,
|
|
|
|
# but in 8l input it's called 8(GS), because 8l is going to
|
|
|
|
# subtract 8 from all the offsets, as described above.
|
|
|
|
echo '#define get_tls(r) MOVL 8(GS), r'
|
|
|
|
echo '#define g(r) -8(r)'
|
|
|
|
echo '#define m(r) -4(r)'
|
|
|
|
;;
|
2010-01-06 18:58:55 -07:00
|
|
|
*)
|
|
|
|
echo '#define get_tls(r)'
|
|
|
|
echo '#define g(r) 0(GS)'
|
|
|
|
echo '#define m(r) 4(GS)'
|
|
|
|
;;
|
|
|
|
esac
|
2009-06-17 17:31:02 -06:00
|
|
|
;;
|
|
|
|
amd64)
|
2011-06-29 01:37:56 -06:00
|
|
|
case "$GOOS" in
|
|
|
|
windows)
|
2012-01-08 17:23:07 -07:00
|
|
|
echo '#define get_tls(r) MOVQ 0x28(GS), r'
|
2011-06-29 01:37:56 -06:00
|
|
|
echo '#define g(r) 0(r)'
|
|
|
|
echo '#define m(r) 8(r)'
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
# The offsets 0 and 8 are known to:
|
|
|
|
# ../../cmd/6l/pass.c:/D_GS
|
2012-01-19 15:13:33 -07:00
|
|
|
# cgo/gcc_linux_amd64.c:/^threadentry
|
|
|
|
# cgo/gcc_darwin_amd64.c:/^threadentry
|
2011-06-29 01:37:56 -06:00
|
|
|
#
|
|
|
|
echo '#define get_tls(r)'
|
|
|
|
echo '#define g(r) 0(GS)'
|
|
|
|
echo '#define m(r) 8(GS)'
|
|
|
|
;;
|
|
|
|
esac
|
2009-06-17 17:31:02 -06:00
|
|
|
;;
|
2009-06-22 15:08:00 -06:00
|
|
|
arm)
|
|
|
|
echo '#define g R10'
|
|
|
|
echo '#define m R9'
|
|
|
|
echo '#define LR R14'
|
|
|
|
;;
|
2009-06-17 17:31:02 -06:00
|
|
|
*)
|
|
|
|
echo 'unknown $GOARCH: '$GOARCH 1>&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
echo
|
|
|
|
|
2012-01-30 15:46:31 -07:00
|
|
|
"$CC" $CFLAGS -a proc.c |
|
2009-06-17 17:31:02 -06:00
|
|
|
awk '
|
2011-02-04 12:32:59 -07:00
|
|
|
{ gsub(/\r/, ""); }
|
2009-06-17 17:31:02 -06:00
|
|
|
/^aggr G$/ { aggr="g" }
|
|
|
|
/^aggr M$/ { aggr = "m" }
|
|
|
|
/^aggr Gobuf$/ { aggr = "gobuf" }
|
2011-08-27 07:17:00 -06:00
|
|
|
/^aggr WinCall$/ { aggr = "wincall" }
|
2009-06-17 17:31:02 -06:00
|
|
|
/^}/ { aggr = "" }
|
|
|
|
|
|
|
|
# Gobuf 24 sched;
|
|
|
|
# 'Y' 48 stack0;
|
|
|
|
# 'Y' 56 entry;
|
|
|
|
# 'A' G 64 alllink;
|
|
|
|
aggr != "" && /^ / {
|
|
|
|
name=$NF;
|
|
|
|
sub(/;/, "", name);
|
|
|
|
offset=$(NF-1);
|
|
|
|
printf("#define %s_%s %s\n", aggr, name, offset);
|
|
|
|
}
|
2011-12-19 13:51:13 -07:00
|
|
|
'
|