From 6b0deb65c6504ae967b47c7e35e1ff6687fe2971 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Thu, 13 Aug 2009 13:22:37 -0700 Subject: change the names to have .sh suffixes. also fix the comments in the generated files. R=rsc DELTA=949 (470 added, 465 deleted, 14 changed) OCL=33197 CL=33201 --- src/pkg/syscall/PORT | 125 --------------------- src/pkg/syscall/PORT.sh | 125 +++++++++++++++++++++ src/pkg/syscall/mkerrors | 94 ---------------- src/pkg/syscall/mkerrors.sh | 93 ++++++++++++++++ src/pkg/syscall/mksyscall | 182 ------------------------------- src/pkg/syscall/mksyscall.sh | 182 +++++++++++++++++++++++++++++++ src/pkg/syscall/mksysnum_darwin | 38 ------- src/pkg/syscall/mksysnum_darwin.sh | 38 +++++++ src/pkg/syscall/mksysnum_linux | 31 ------ src/pkg/syscall/mksysnum_linux.sh | 31 ++++++ src/pkg/syscall/zerrors_darwin_386.go | 2 +- src/pkg/syscall/zerrors_darwin_amd64.go | 2 +- src/pkg/syscall/zerrors_linux_386.go | 2 +- src/pkg/syscall/zerrors_linux_amd64.go | 2 +- src/pkg/syscall/zsyscall_darwin_386.go | 2 +- src/pkg/syscall/zsyscall_darwin_amd64.go | 2 +- src/pkg/syscall/zsyscall_linux_386.go | 2 +- src/pkg/syscall/zsyscall_linux_amd64.go | 2 +- src/pkg/syscall/zsysnum_darwin_386.go | 2 +- src/pkg/syscall/zsysnum_darwin_amd64.go | 2 +- src/pkg/syscall/zsysnum_linux_386.go | 4 +- src/pkg/syscall/zsysnum_linux_amd64.go | 4 +- 22 files changed, 483 insertions(+), 484 deletions(-) delete mode 100755 src/pkg/syscall/PORT create mode 100755 src/pkg/syscall/PORT.sh delete mode 100755 src/pkg/syscall/mkerrors create mode 100755 src/pkg/syscall/mkerrors.sh delete mode 100755 src/pkg/syscall/mksyscall create mode 100755 src/pkg/syscall/mksyscall.sh delete mode 100755 src/pkg/syscall/mksysnum_darwin create mode 100755 src/pkg/syscall/mksysnum_darwin.sh delete mode 100755 src/pkg/syscall/mksysnum_linux create mode 100755 src/pkg/syscall/mksysnum_linux.sh (limited to 'src') diff --git a/src/pkg/syscall/PORT b/src/pkg/syscall/PORT deleted file mode 100755 index 2eb05920c..000000000 --- a/src/pkg/syscall/PORT +++ /dev/null @@ -1,125 +0,0 @@ -#!/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. - -# The syscall package provides access to the raw system call -# interface of the underlying operating system. Porting Go to -# a new architecture/operating system combination requires -# some manual effort, though there are tools that automate -# much of the process. The auto-generated files have names -# beginning with z. -# -# This script prints suggested commands to generate z files -# for the current system. Running those commands is not automatic. -# This script is documentation more than anything else. -# -# * asm_${GOOS}_${GOARCH}.s -# -# This hand-written assembly file implements system call dispatch. -# There are three entry points: -# -# func Syscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr); -# func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr); -# func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr); -# -# The first and second are the standard ones; they differ only in -# how many arguments can be passed to the kernel. -# The third is for low-level use by the ForkExec wrapper; -# unlike the first two, it does not call into the scheduler to -# let it know that a system call is running. -# -# * syscall_${GOOS}.go -# -# This hand-written Go file implements system calls that need -# special handling and lists "//sys" comments giving prototypes -# for ones that can be auto-generated. Mksyscall reads those -# comments to generate the stubs. -# -# * syscall_${GOOS}_${GOARCH}.go -# -# Same as syscall_${GOOS}.go except that it contains code specific -# to ${GOOS} on one particular architecture. -# -# * types_${GOOS}.c -# -# This hand-written C file includes standard C headers and then -# creates typedef or enum names beginning with a dollar sign -# (use of $ in variable names is a gcc extension). The hardest -# part about preparing this file is figuring out which headers to -# include and which symbols need to be #defined to get the -# actual data structures that pass through to the kernel system calls. -# Some C libraries present alternate versions for binary compatibility -# and translate them on the way in and out of system calls, but -# there is almost always a #define that can get the real ones. -# See types_darwin.c and types_linux.c for examples. -# -# * types_${GOOS}_${GOARCH}.c -# -# Same as types_${GOOS}_${GOARCH}.go except that it contains -# definitions specific to ${GOOS} one one particular architecture. -# -# * zerror_${GOOS}_${GOARCH}.go -# -# This machine-generated file defines the system's error numbers, -# error strings, and signal numbers. The generator is "mkerrors". -# Usually no arguments are needed, but mkerrors will pass its -# arguments on to godefs. -# -# * zsyscall_${GOOS}_${GOARCH}.go -# -# Generated by mksyscall; see syscall_${GOOS}.go above. -# -# * zsysnum_${GOOS}_${GOARCH}.go -# -# Generated by mksysnum_${GOOS}. -# -# * ztypes_${GOOS}_${GOARCH}.go -# -# Generated by godefs; see types_${GOOS}.c above. - -GOOSARCH="${GOOS}_${GOARCH}" - -# defaults -mksyscall="mksyscall" -mkerrors="mkerrors" - -case "$GOOSARCH" in -_* | *_ | _) - echo 'undefined $GOOS_$GOARCH:' "$GOOSARCH" 1>&2 - exit 1 - ;; -darwin_386) - mksyscall="mksyscall -l32" - mksysnum="mksysnum_darwin /home/rsc/pub/xnu-1228/bsd/kern/syscalls.master" - mktypes="godefs -gsyscall -f-m32" - ;; -darwin_amd64) - mksysnum="mksysnum_darwin /home/rsc/pub/xnu-1228/bsd/kern/syscalls.master" - mktypes="godefs -gsyscall -f-m64" - mkerrors="mkerrors" - ;; -linux_386) - mksyscall="mksyscall -l32" - mksysnum="mksysnum_linux /usr/include/asm/unistd_32.h" - mktypes="godefs -gsyscall -f-m32" - ;; -linux_amd64) - mksysnum="mksysnum_linux /usr/include/asm/unistd_64.h" - mktypes="godefs -gsyscall -f-m64" - ;; -*) - echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2 - exit 1 - ;; -esac - -echo "$mkerrors >zerrors_$GOOSARCH.go" -echo "$mksyscall syscall_$GOOS.go syscall_$GOOSARCH.go >zsyscall_$GOOSARCH.go" -echo "$mksysnum >zsysnum_$GOOSARCH.go" -echo "$mktypes types_$GOOS.c types_$GOOSARCH.c >ztypes_$GOOSARCH.go" - -port=$(ls *.go | grep -v _) -arch=$(ls *_$GOOSARCH.s *_$GOOSARCH.go *_$GOOS.go) -all=$(ls $port $arch) # sort them -echo gobuild $all diff --git a/src/pkg/syscall/PORT.sh b/src/pkg/syscall/PORT.sh new file mode 100755 index 000000000..e7121c45b --- /dev/null +++ b/src/pkg/syscall/PORT.sh @@ -0,0 +1,125 @@ +#!/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. + +# The syscall package provides access to the raw system call +# interface of the underlying operating system. Porting Go to +# a new architecture/operating system combination requires +# some manual effort, though there are tools that automate +# much of the process. The auto-generated files have names +# beginning with z. +# +# This script prints suggested commands to generate z files +# for the current system. Running those commands is not automatic. +# This script is documentation more than anything else. +# +# * asm_${GOOS}_${GOARCH}.s +# +# This hand-written assembly file implements system call dispatch. +# There are three entry points: +# +# func Syscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr); +# func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr); +# func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr); +# +# The first and second are the standard ones; they differ only in +# how many arguments can be passed to the kernel. +# The third is for low-level use by the ForkExec wrapper; +# unlike the first two, it does not call into the scheduler to +# let it know that a system call is running. +# +# * syscall_${GOOS}.go +# +# This hand-written Go file implements system calls that need +# special handling and lists "//sys" comments giving prototypes +# for ones that can be auto-generated. Mksyscall reads those +# comments to generate the stubs. +# +# * syscall_${GOOS}_${GOARCH}.go +# +# Same as syscall_${GOOS}.go except that it contains code specific +# to ${GOOS} on one particular architecture. +# +# * types_${GOOS}.c +# +# This hand-written C file includes standard C headers and then +# creates typedef or enum names beginning with a dollar sign +# (use of $ in variable names is a gcc extension). The hardest +# part about preparing this file is figuring out which headers to +# include and which symbols need to be #defined to get the +# actual data structures that pass through to the kernel system calls. +# Some C libraries present alternate versions for binary compatibility +# and translate them on the way in and out of system calls, but +# there is almost always a #define that can get the real ones. +# See types_darwin.c and types_linux.c for examples. +# +# * types_${GOOS}_${GOARCH}.c +# +# Same as types_${GOOS}_${GOARCH}.go except that it contains +# definitions specific to ${GOOS} one one particular architecture. +# +# * zerror_${GOOS}_${GOARCH}.go +# +# This machine-generated file defines the system's error numbers, +# error strings, and signal numbers. The generator is "mkerrors.sh". +# Usually no arguments are needed, but mkerrors.sh will pass its +# arguments on to godefs. +# +# * zsyscall_${GOOS}_${GOARCH}.go +# +# Generated by mksyscall.sh; see syscall_${GOOS}.go above. +# +# * zsysnum_${GOOS}_${GOARCH}.go +# +# Generated by mksysnum_${GOOS}. +# +# * ztypes_${GOOS}_${GOARCH}.go +# +# Generated by godefs; see types_${GOOS}.c above. + +GOOSARCH="${GOOS}_${GOARCH}" + +# defaults +mksyscall="mksyscall.sh" +mkerrors="mkerrors.sh" + +case "$GOOSARCH" in +_* | *_ | _) + echo 'undefined $GOOS_$GOARCH:' "$GOOSARCH" 1>&2 + exit 1 + ;; +darwin_386) + mksyscall="mksyscall.sh -l32" + mksysnum="mksysnum_darwin.sh /home/rsc/pub/xnu-1228/bsd/kern/syscalls.master" + mktypes="godefs -gsyscall -f-m32" + ;; +darwin_amd64) + mksysnum="mksysnum_darwin.sh /home/rsc/pub/xnu-1228/bsd/kern/syscalls.master" + mktypes="godefs -gsyscall -f-m64" + mkerrors="mkerrors.sh" + ;; +linux_386) + mksyscall="mksyscall.sh -l32" + mksysnum="mksysnum_linux.sh /usr/include/asm/unistd_32.h" + mktypes="godefs -gsyscall -f-m32" + ;; +linux_amd64) + mksysnum="mksysnum_linux.sh /usr/include/asm/unistd_64.h" + mktypes="godefs -gsyscall -f-m64" + ;; +*) + echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2 + exit 1 + ;; +esac + +echo "$mkerrors >zerrors_$GOOSARCH.go" +echo "$mksyscall syscall_$GOOS.go syscall_$GOOSARCH.go >zsyscall_$GOOSARCH.go" +echo "$mksysnum >zsysnum_$GOOSARCH.go" +echo "$mktypes types_$GOOS.c types_$GOOSARCH.c >ztypes_$GOOSARCH.go" + +port=$(ls *.go | grep -v _) +arch=$(ls *_$GOOSARCH.s *_$GOOSARCH.go *_$GOOS.go) +all=$(ls $port $arch) # sort them +echo gobuild $all diff --git a/src/pkg/syscall/mkerrors b/src/pkg/syscall/mkerrors deleted file mode 100755 index 015f02145..000000000 --- a/src/pkg/syscall/mkerrors +++ /dev/null @@ -1,94 +0,0 @@ -#!/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. - - -# Generate Go code listing error values (ENAMETOOLONG etc) -# and signal values (SIGALRM etc). They're unrelated except -# that we use the same method for finding them. - -errors=$( - echo '#include ' | - # The gcc command line prints all the #defines - # it encounters while processing the input - gcc -x c - -E -dM | - egrep -h '#define E[A-Z0-9_]+ ' $files | - sed 's/#define //; s/ .*//' -) - -signals=$( - echo '#include ' | - gcc -x c - -E -dM | - egrep -h '#define SIG[^_]' | - egrep -v '#define (SIGEV_|SIGSTKSZ|SIGRT(MIN|MAX))' | - sed 's/#define //; s/ .*//' -) - -# Write godefs input. -( - echo '#include ' - echo '#include ' - echo 'enum {' - for i in $errors $signals - do - echo '$'"$i = $i," - done - echo '};' -) >_errors.c - -echo '// mkerrors' "$@" -echo '// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT' -echo -godefs -gsyscall "$@" _errors.c - -# Run C program to print error strings. -( - echo " -#include -#include -#include -#include - -#define nelem(x) (sizeof(x)/sizeof((x)[0])) - -enum { A = 'A', Z = 'Z', a = 'a', z = 'z' }; // avoid need for single quotes below - -int errors[] = { -" - for i in $errors - do - echo ' '$i, - done - - echo ' -}; - -int -main(void) -{ - int i, j, e; - char buf[1024]; - - printf("\n\n// Error table\n"); - printf("var errors = [...]string {\n"); - for(i=0; i bad, but STREAM -> STREAM. - if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z) - buf[0] += a - A; - printf("\t%d: \"%s\",\n", e, buf); - next:; - } - printf("}\n\n"); -} - -' -) >_errors.c - -gcc -o _errors _errors.c && ./_errors -rm -f _errors.c _errors diff --git a/src/pkg/syscall/mkerrors.sh b/src/pkg/syscall/mkerrors.sh new file mode 100755 index 000000000..15835bdd6 --- /dev/null +++ b/src/pkg/syscall/mkerrors.sh @@ -0,0 +1,93 @@ +#!/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. + +# Generate Go code listing error values (ENAMETOOLONG etc) +# and signal values (SIGALRM etc). They're unrelated except +# that we use the same method for finding them. + +errors=$( + echo '#include ' | + # The gcc command line prints all the #defines + # it encounters while processing the input + gcc -x c - -E -dM | + egrep -h '#define E[A-Z0-9_]+ ' $files | + sed 's/#define //; s/ .*//' +) + +signals=$( + echo '#include ' | + gcc -x c - -E -dM | + egrep -h '#define SIG[^_]' | + egrep -v '#define (SIGEV_|SIGSTKSZ|SIGRT(MIN|MAX))' | + sed 's/#define //; s/ .*//' +) + +# Write godefs input. +( + echo '#include ' + echo '#include ' + echo 'enum {' + for i in $errors $signals + do + echo '$'"$i = $i," + done + echo '};' +) >_errors.c + +echo '// mkerrors.sh' "$@" +echo '// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT' +echo +godefs -gsyscall "$@" _errors.c + +# Run C program to print error strings. +( + echo " +#include +#include +#include +#include + +#define nelem(x) (sizeof(x)/sizeof((x)[0])) + +enum { A = 'A', Z = 'Z', a = 'a', z = 'z' }; // avoid need for single quotes below + +int errors[] = { +" + for i in $errors + do + echo ' '$i, + done + + echo ' +}; + +int +main(void) +{ + int i, j, e; + char buf[1024]; + + printf("\n\n// Error table\n"); + printf("var errors = [...]string {\n"); + for(i=0; i bad, but STREAM -> STREAM. + if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z) + buf[0] += a - A; + printf("\t%d: \"%s\",\n", e, buf); + next:; + } + printf("}\n\n"); +} + +' +) >_errors.c + +gcc -o _errors _errors.c && ./_errors +rm -f _errors.c _errors diff --git a/src/pkg/syscall/mksyscall b/src/pkg/syscall/mksyscall deleted file mode 100755 index 6a2c916cf..000000000 --- a/src/pkg/syscall/mksyscall +++ /dev/null @@ -1,182 +0,0 @@ -#!/usr/bin/perl -# 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. - -# This program reads a file containing function prototypes -# (like syscall_darwin.go) and generates system call bodies. -# The prototypes are marked by lines beginning with "//sys" -# and read like func declarations if //sys is replaced by func, but: -# * The parameter lists must give a name for each argument. -# This includes return parameters. -# * The parameter lists must give a type for each argument: -# the (x, y, z int) shorthand is not allowed. -# * If the return parameter is an error number, it must be named errno. - -$cmdline = "mksyscall " . join(' ', @ARGV); -$errors = 0; -$_32bit = ""; - -if($ARGV[0] eq "-b32") { - $_32bit = "big-endian"; - shift; -} elsif($ARGV[0] eq "-l32") { - $_32bit = "little-endian"; - shift; -} - -if($ARGV[0] =~ /^-/) { - print STDERR "usage: mksyscall [-b32 | -l32] [file ...]\n"; - exit 1; -} - -sub parseparamlist($) { - my ($list) = @_; - $list =~ s/^\s*//; - $list =~ s/\s*$//; - if($list eq "") { - return (); - } - return split(/\s*,\s*/, $list); -} - -sub parseparam($) { - my ($p) = @_; - if($p !~ /^(\S*) (\S*)$/) { - print STDERR "$ARGV:$.: malformed parameter: $p\n"; - $errors = 1; - return ("xx", "int"); - } - return ($1, $2); -} - -$text = ""; -while(<>) { - chomp; - s/\s+/ /g; - s/^\s+//; - s/\s+$//; - next if !/^\/\/sys /; - - # Line must be of the form - # func Open(path string, mode int, perm int) (fd int, errno int) - # Split into name, in params, out params. - if(!/^\/\/sys (\w+)\(([^()]*)\)\s*(?:\(([^()]+)\))?\s*(?:=\s*(SYS_[A-Z0-9_]+))?$/) { - print STDERR "$ARGV:$.: malformed //sys declaration\n"; - $errors = 1; - next; - } - my ($func, $in, $out, $sysname) = ($1, $2, $3, $4); - - # Split argument lists on comma. - my @in = parseparamlist($in); - my @out = parseparamlist($out); - - # Go function header. - $text .= sprintf "func %s(%s) (%s) {\n", $func, join(', ', @in), join(', ', @out); - - # Prepare arguments to Syscall. - my @args = (); - my $n = 0; - foreach my $p (@in) { - my ($name, $type) = parseparam($p); - if($type =~ /^\*/) { - push @args, "uintptr(unsafe.Pointer($name))"; - } elsif($type eq "string") { - push @args, "uintptr(unsafe.Pointer(StringBytePtr($name)))"; - } elsif($type =~ /^\[\](.*)/) { - # Convert slice into pointer, length. - # Have to be careful not to take address of &a[0] if len == 0: - # pass nil in that case. - $text .= "\tvar _p$n *$1;\n"; - $text .= "\tif len($name) > 0 { _p$n = \&${name}[0]; }\n"; - push @args, "uintptr(unsafe.Pointer(_p$n))", "uintptr(len($name))"; - $n++; - } elsif($type eq "int64" && $_32bit ne "") { - if($_32bit eq "big-endian") { - push @args, "uintptr($name >> 32)", "uintptr($name)"; - } else { - push @args, "uintptr($name)", "uintptr($name >> 32)"; - } - } else { - push @args, "uintptr($name)"; - } - } - - # Determine which form to use; pad args with zeros. - my $asm = "Syscall"; - if(@args <= 3) { - while(@args < 3) { - push @args, "0"; - } - } elsif(@args <= 6) { - $asm = "Syscall6"; - while(@args < 6) { - push @args, "0"; - } - } else { - print STDERR "$ARGV:$.: too many arguments to system call\n"; - } - - # System call number. - if($sysname eq "") { - $sysname = "SYS_$func"; - $sysname =~ s/([a-z])([A-Z])/${1}_$2/g; # turn FooBar into Foo_Bar - $sysname =~ y/a-z/A-Z/; - } - - # Actual call. - my $args = join(', ', @args); - $text .= "\tr0, r1, e1 := $asm($sysname, $args);\n"; - - # Assign return values. - for(my $i=0; $i<@out; $i++) { - my $p = $out[$i]; - my ($name, $type) = parseparam($p); - my $reg = ""; - if($name eq "errno") { - $reg = "e1"; - } else { - $reg = sprintf("r%d", $i); - } - if($type eq "bool") { - $reg = "$reg != 0"; - } - if($type eq "int64" && $_32bit ne "") { - # 64-bit number in r1:r0 or r0:r1. - if($i+2 > @out) { - print STDERR "$ARGV:$.: not enough registers for int64 return\n"; - } - if($_32bit eq "big-endian") { - $reg = sprintf("int64(r%d)<<32 | int64(r%d)", $i, $i+1); - } else { - $reg = sprintf("int64(r%d)<<32 | int64(r%d)", $i+1, $i); - } - $i++; # loop will do another $i++ - } - $text .= "\t$name = $type($reg);\n"; - } - - $text .= "\treturn;\n"; - $text .= "}\n\n"; -} - -if($errors) { - exit 1; -} - -print <) { + chomp; + s/\s+/ /g; + s/^\s+//; + s/\s+$//; + next if !/^\/\/sys /; + + # Line must be of the form + # func Open(path string, mode int, perm int) (fd int, errno int) + # Split into name, in params, out params. + if(!/^\/\/sys (\w+)\(([^()]*)\)\s*(?:\(([^()]+)\))?\s*(?:=\s*(SYS_[A-Z0-9_]+))?$/) { + print STDERR "$ARGV:$.: malformed //sys declaration\n"; + $errors = 1; + next; + } + my ($func, $in, $out, $sysname) = ($1, $2, $3, $4); + + # Split argument lists on comma. + my @in = parseparamlist($in); + my @out = parseparamlist($out); + + # Go function header. + $text .= sprintf "func %s(%s) (%s) {\n", $func, join(', ', @in), join(', ', @out); + + # Prepare arguments to Syscall. + my @args = (); + my $n = 0; + foreach my $p (@in) { + my ($name, $type) = parseparam($p); + if($type =~ /^\*/) { + push @args, "uintptr(unsafe.Pointer($name))"; + } elsif($type eq "string") { + push @args, "uintptr(unsafe.Pointer(StringBytePtr($name)))"; + } elsif($type =~ /^\[\](.*)/) { + # Convert slice into pointer, length. + # Have to be careful not to take address of &a[0] if len == 0: + # pass nil in that case. + $text .= "\tvar _p$n *$1;\n"; + $text .= "\tif len($name) > 0 { _p$n = \&${name}[0]; }\n"; + push @args, "uintptr(unsafe.Pointer(_p$n))", "uintptr(len($name))"; + $n++; + } elsif($type eq "int64" && $_32bit ne "") { + if($_32bit eq "big-endian") { + push @args, "uintptr($name >> 32)", "uintptr($name)"; + } else { + push @args, "uintptr($name)", "uintptr($name >> 32)"; + } + } else { + push @args, "uintptr($name)"; + } + } + + # Determine which form to use; pad args with zeros. + my $asm = "Syscall"; + if(@args <= 3) { + while(@args < 3) { + push @args, "0"; + } + } elsif(@args <= 6) { + $asm = "Syscall6"; + while(@args < 6) { + push @args, "0"; + } + } else { + print STDERR "$ARGV:$.: too many arguments to system call\n"; + } + + # System call number. + if($sysname eq "") { + $sysname = "SYS_$func"; + $sysname =~ s/([a-z])([A-Z])/${1}_$2/g; # turn FooBar into Foo_Bar + $sysname =~ y/a-z/A-Z/; + } + + # Actual call. + my $args = join(', ', @args); + $text .= "\tr0, r1, e1 := $asm($sysname, $args);\n"; + + # Assign return values. + for(my $i=0; $i<@out; $i++) { + my $p = $out[$i]; + my ($name, $type) = parseparam($p); + my $reg = ""; + if($name eq "errno") { + $reg = "e1"; + } else { + $reg = sprintf("r%d", $i); + } + if($type eq "bool") { + $reg = "$reg != 0"; + } + if($type eq "int64" && $_32bit ne "") { + # 64-bit number in r1:r0 or r0:r1. + if($i+2 > @out) { + print STDERR "$ARGV:$.: not enough registers for int64 return\n"; + } + if($_32bit eq "big-endian") { + $reg = sprintf("int64(r%d)<<32 | int64(r%d)", $i, $i+1); + } else { + $reg = sprintf("int64(r%d)<<32 | int64(r%d)", $i+1, $i); + } + $i++; # loop will do another $i++ + } + $text .= "\t$name = $type($reg);\n"; + } + + $text .= "\treturn;\n"; + $text .= "}\n\n"; +} + +if($errors) { + exit 1; +} + +print <){ - if(/^([0-9]+)\s+ALL\s+({ \S+\s+(\w+).*})/){ - my $num = $1; - my $proto = $2; - my $name = "SYS_$3"; - $name =~ y/a-z/A-Z/; - - # There are multiple entries for enosys and nosys, so comment them out. - if($name =~ /^SYS_E?NOSYS$/){ - $name = "// $name"; - } - - print " $name = $num; // $proto\n"; - } -} - -print <){ + if(/^([0-9]+)\s+ALL\s+({ \S+\s+(\w+).*})/){ + my $num = $1; + my $proto = $2; + my $name = "SYS_$3"; + $name =~ y/a-z/A-Z/; + + # There are multiple entries for enosys and nosys, so comment them out. + if($name =~ /^SYS_E?NOSYS$/){ + $name = "// $name"; + } + + print " $name = $num; // $proto\n"; + } +} + +print <){ - if(/^#define __NR_(\w+)\s+([0-9]+)/){ - my $name = "SYS_$1"; - my $num = $2; - $name =~ y/a-z/A-Z/; - print " $name = $num;\n"; - } -} - -print <){ + if(/^#define __NR_(\w+)\s+([0-9]+)/){ + my $name = "SYS_$1"; + my $num = $2; + $name =~ y/a-z/A-Z/; + print " $name = $num;\n"; + } +} + +print <