1993-04-06 14:37:09 +04:00
|
|
|
#! /bin/sh -
|
1996-03-15 04:25:12 +03:00
|
|
|
# $NetBSD: makesyscalls.sh,v 1.18 1996/03/15 01:25:12 cgd Exp $
|
1994-06-29 10:29:24 +04:00
|
|
|
#
|
1994-10-20 07:37:09 +03:00
|
|
|
# Copyright (c) 1994 Christopher G. Demetriou
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Redistribution and use in source and binary forms, with or without
|
|
|
|
# modification, are permitted provided that the following conditions
|
|
|
|
# are met:
|
|
|
|
# 1. Redistributions of source code must retain the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer.
|
|
|
|
# 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
# notice, this list of conditions and the following disclaimer in the
|
|
|
|
# documentation and/or other materials provided with the distribution.
|
|
|
|
# 3. All advertising materials mentioning features or use of this software
|
|
|
|
# must display the following acknowledgement:
|
|
|
|
# This product includes software developed for the NetBSD Project
|
|
|
|
# by Christopher G. Demetriou.
|
|
|
|
# 4. The name of the author may not be used to endorse or promote products
|
|
|
|
# derived from this software without specific prior written permission
|
|
|
|
#
|
|
|
|
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1994-10-29 02:14:46 +03:00
|
|
|
|
|
|
|
# @(#)makesyscalls.sh 8.1 (Berkeley) 6/10/93
|
1993-04-06 14:37:09 +04:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
1994-10-20 07:22:35 +03:00
|
|
|
case $# in
|
|
|
|
2) ;;
|
|
|
|
*) echo "Usage: $0 config-file input-file" 1>&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# source the config file.
|
|
|
|
. $1
|
1993-04-06 14:37:09 +04:00
|
|
|
|
1994-10-20 07:22:35 +03:00
|
|
|
# the config file sets the following variables:
|
|
|
|
# sysnames the syscall names file
|
|
|
|
# sysnumhdr the syscall numbers file
|
|
|
|
# syssw the syscall switch file
|
|
|
|
# sysarghdr the syscall argument struct definitions
|
|
|
|
# compatopts those syscall types that are for 'compat' syscalls
|
|
|
|
# switchname the name for the 'struct sysent' we define
|
|
|
|
# namesname the name for the 'char *[]' we define
|
|
|
|
# constprefix the prefix for the system call constants
|
|
|
|
#
|
|
|
|
# NOTE THAT THIS makesyscalls.sh DOES NOT SUPPORT 'LIBCOMPAT'.
|
1993-04-06 14:37:09 +04:00
|
|
|
|
|
|
|
# tmp files:
|
|
|
|
sysdcl="sysent.dcl"
|
1995-09-20 01:28:56 +04:00
|
|
|
sysprotos="sys.protos"
|
1994-10-20 07:22:35 +03:00
|
|
|
syscompat_pref="sysent."
|
1993-04-06 14:37:09 +04:00
|
|
|
sysent="sysent.switch"
|
|
|
|
|
1995-10-07 09:25:19 +03:00
|
|
|
trap "rm $sysdcl $sysprotos $sysent" 0
|
1993-04-06 14:37:09 +04:00
|
|
|
|
1994-10-20 07:22:35 +03:00
|
|
|
# Awk program (must support nawk extensions)
|
|
|
|
# Use "awk" at Berkeley, "nawk" or "gawk" elsewhere.
|
|
|
|
awk=${AWK:-awk}
|
1993-04-06 14:37:09 +04:00
|
|
|
|
1994-10-20 07:22:35 +03:00
|
|
|
# Does this awk have a "toupper" function? (i.e. is it GNU awk)
|
|
|
|
isgawk=`$awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null`
|
1993-04-06 14:37:09 +04:00
|
|
|
|
1994-10-20 07:22:35 +03:00
|
|
|
# If this awk does not define "toupper" then define our own.
|
|
|
|
if [ "$isgawk" = TRUE ] ; then
|
|
|
|
# GNU awk provides it.
|
|
|
|
toupper=
|
|
|
|
else
|
|
|
|
# Provide our own toupper()
|
|
|
|
toupper='
|
|
|
|
function toupper(str) {
|
|
|
|
_toupper_cmd = "echo "str" |tr a-z A-Z"
|
|
|
|
_toupper_cmd | getline _toupper_str;
|
|
|
|
close(_toupper_cmd);
|
|
|
|
return _toupper_str;
|
|
|
|
}'
|
|
|
|
fi
|
1993-04-06 14:37:09 +04:00
|
|
|
|
1994-10-20 07:22:35 +03:00
|
|
|
# before handing it off to awk, make a few adjustments:
|
|
|
|
# (1) insert spaces around {, }, (, ), *, and commas.
|
|
|
|
# (2) get rid of any and all dollar signs (so that rcs id use safe)
|
|
|
|
#
|
|
|
|
# The awk script will deal with blank lines and lines that
|
|
|
|
# start with the comment character (';').
|
|
|
|
|
|
|
|
sed -e '
|
|
|
|
s/\$//g
|
|
|
|
:join
|
|
|
|
/\\$/{a\
|
|
|
|
|
|
|
|
N
|
|
|
|
s/\\\n//
|
|
|
|
b join
|
1993-04-06 14:37:09 +04:00
|
|
|
}
|
1994-10-20 07:22:35 +03:00
|
|
|
2,${
|
|
|
|
/^#/!s/\([{}()*,]\)/ \1 /g
|
|
|
|
}
|
|
|
|
' < $2 | $awk "
|
|
|
|
$toupper
|
|
|
|
BEGIN {
|
1996-03-15 04:25:12 +03:00
|
|
|
# to allow nested #if/#else/#endif sets
|
|
|
|
savedepth = 0
|
|
|
|
|
1994-10-20 07:22:35 +03:00
|
|
|
sysnames = \"$sysnames\"
|
1995-09-20 01:28:56 +04:00
|
|
|
sysprotos = \"$sysprotos\"
|
1994-10-20 07:22:35 +03:00
|
|
|
sysnumhdr = \"$sysnumhdr\"
|
|
|
|
sysarghdr = \"$sysarghdr\"
|
|
|
|
switchname = \"$switchname\"
|
|
|
|
namesname = \"$namesname\"
|
|
|
|
constprefix = \"$constprefix\"
|
|
|
|
|
|
|
|
sysdcl = \"$sysdcl\"
|
|
|
|
syscompat_pref = \"$syscompat_pref\"
|
|
|
|
sysent = \"$sysent\"
|
|
|
|
infile = \"$2\"
|
|
|
|
|
|
|
|
compatopts = \"$compatopts\"
|
|
|
|
"'
|
|
|
|
|
|
|
|
printf "/*\n * System call switch table.\n *\n" > sysdcl
|
|
|
|
printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysdcl
|
|
|
|
|
|
|
|
ncompat = split(compatopts,compat)
|
|
|
|
for (i = 1; i <= ncompat; i++) {
|
|
|
|
compat_upper[i] = toupper(compat[i])
|
|
|
|
|
1995-10-07 09:25:19 +03:00
|
|
|
printf "\n#ifdef %s\n", compat_upper[i] > sysent
|
|
|
|
printf "#define %s(func) __CONCAT(%s_,func)\n", compat[i], \
|
|
|
|
compat[i] > sysent
|
|
|
|
printf "#else\n" > sysent
|
|
|
|
printf "#define %s(func) sys_nosys\n", compat[i] > sysent
|
|
|
|
printf "#endif\n" > sysent
|
1993-04-06 14:37:09 +04:00
|
|
|
}
|
1994-10-20 07:22:35 +03:00
|
|
|
|
1995-10-07 09:25:19 +03:00
|
|
|
printf "\n#define\ts(type)\tsizeof(type)\n\n" > sysent
|
|
|
|
printf "struct sysent %s[] = {\n",switchname > sysent
|
|
|
|
|
1994-10-20 07:22:35 +03:00
|
|
|
printf "/*\n * System call names.\n *\n" > sysnames
|
|
|
|
printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnames
|
|
|
|
|
1995-09-20 01:28:56 +04:00
|
|
|
printf "\n/*\n * System call prototypes.\n */\n\n" > sysprotos
|
|
|
|
|
1994-10-20 07:22:35 +03:00
|
|
|
printf "/*\n * System call numbers.\n *\n" > sysnumhdr
|
|
|
|
printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnumhdr
|
|
|
|
|
1994-10-21 02:22:38 +03:00
|
|
|
printf "/*\n * System call argument lists.\n *\n" > sysarghdr
|
1994-10-20 07:22:35 +03:00
|
|
|
printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysarghdr
|
|
|
|
}
|
|
|
|
NR == 1 {
|
|
|
|
printf " * created from%s\n */\n\n", $0 > sysdcl
|
|
|
|
|
|
|
|
printf " * created from%s\n */\n\n", $0 > sysnames
|
|
|
|
printf "char *%s[] = {\n",namesname > sysnames
|
|
|
|
|
|
|
|
printf " * created from%s\n */\n\n", $0 > sysnumhdr
|
|
|
|
|
|
|
|
printf " * created from%s\n */\n\n", $0 > sysarghdr
|
|
|
|
printf "#define\tsyscallarg(x)\tunion { x datum; register_t pad; }\n" \
|
|
|
|
> sysarghdr
|
|
|
|
next
|
|
|
|
}
|
|
|
|
NF == 0 || $1 ~ /^;/ {
|
|
|
|
next
|
|
|
|
}
|
|
|
|
$1 ~ /^#[ ]*include/ {
|
|
|
|
print > sysdcl
|
|
|
|
next
|
|
|
|
}
|
|
|
|
$1 ~ /^#[ ]*if/ {
|
|
|
|
print > sysent
|
1995-09-20 01:28:56 +04:00
|
|
|
print > sysprotos
|
1994-10-20 07:22:35 +03:00
|
|
|
print > sysnames
|
1996-03-15 04:25:12 +03:00
|
|
|
savesyscall[++savedepth] = syscall
|
1994-10-20 07:22:35 +03:00
|
|
|
next
|
|
|
|
}
|
|
|
|
$1 ~ /^#[ ]*else/ {
|
|
|
|
print > sysent
|
1995-09-20 01:28:56 +04:00
|
|
|
print > sysprotos
|
1994-10-20 07:22:35 +03:00
|
|
|
print > sysnames
|
1996-03-15 04:25:12 +03:00
|
|
|
if (savedepth <= 0) {
|
|
|
|
printf "%s: line %d: unbalenced #else\n", \
|
|
|
|
infile, NR
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
syscall = savesyscall[savedepth]
|
1994-10-20 07:22:35 +03:00
|
|
|
next
|
|
|
|
}
|
|
|
|
$1 ~ /^#/ {
|
1996-03-15 04:25:12 +03:00
|
|
|
if ($1 ~ /^#[ ]*endif/) {
|
|
|
|
if (savedepth <= 0) {
|
|
|
|
printf "%s: line %d: unbalenced #endif\n", \
|
|
|
|
infile, NR
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
savedepth--;
|
|
|
|
}
|
1994-10-20 07:22:35 +03:00
|
|
|
print > sysent
|
1995-09-20 01:28:56 +04:00
|
|
|
print > sysprotos
|
1994-10-20 07:22:35 +03:00
|
|
|
print > sysnames
|
|
|
|
next
|
|
|
|
}
|
|
|
|
syscall != $1 {
|
|
|
|
printf "%s: line %d: syscall number out of sync at %d\n", \
|
|
|
|
infile, NR, syscall
|
|
|
|
printf "line is:\n"
|
|
|
|
print
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
function parserr(was, wanted) {
|
|
|
|
printf "%s: line %d: unexpected %s (expected %s)\n", \
|
|
|
|
infile, NR, was, wanted
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
function parseline() {
|
|
|
|
f=3 # toss number and type
|
|
|
|
if ($NF != "}") {
|
|
|
|
funcalias=$NF
|
|
|
|
end=NF-1
|
|
|
|
} else {
|
|
|
|
funcalias=""
|
|
|
|
end=NF
|
1994-05-17 04:00:46 +04:00
|
|
|
}
|
1994-10-20 07:22:35 +03:00
|
|
|
if ($f != "{")
|
|
|
|
parserr($f, "{")
|
|
|
|
f++
|
|
|
|
if ($end != "}")
|
|
|
|
parserr($end, "}")
|
|
|
|
end--
|
|
|
|
if ($end != ";")
|
|
|
|
parserr($end, ";")
|
|
|
|
end--
|
|
|
|
if ($end != ")")
|
|
|
|
parserr($end, ")")
|
|
|
|
end--
|
|
|
|
|
|
|
|
f++ # toss return type
|
|
|
|
|
|
|
|
funcname=$f
|
1995-10-07 09:25:19 +03:00
|
|
|
if (funcalias == "") {
|
1994-10-20 07:22:35 +03:00
|
|
|
funcalias=funcname
|
1995-10-07 09:25:19 +03:00
|
|
|
sub(/^([^_]+_)*sys_/, "", funcalias)
|
|
|
|
}
|
1994-10-20 07:22:35 +03:00
|
|
|
f++
|
|
|
|
|
|
|
|
if ($f != "(")
|
|
|
|
parserr($f, ")")
|
|
|
|
f++
|
|
|
|
|
|
|
|
argc= 0;
|
|
|
|
if (f == end) {
|
|
|
|
if ($f != "void")
|
|
|
|
parserr($f, "argument definition")
|
|
|
|
return
|
1993-04-06 14:37:09 +04:00
|
|
|
}
|
1994-10-20 07:22:35 +03:00
|
|
|
|
|
|
|
while (f <= end) {
|
|
|
|
argc++
|
|
|
|
argtype[argc]=""
|
1994-10-29 02:14:46 +03:00
|
|
|
oldf=""
|
1994-10-20 07:22:35 +03:00
|
|
|
while (f < end && $(f+1) != ",") {
|
1994-10-29 02:14:46 +03:00
|
|
|
if (argtype[argc] != "" && oldf != "*")
|
1994-10-20 07:22:35 +03:00
|
|
|
argtype[argc] = argtype[argc]" ";
|
|
|
|
argtype[argc] = argtype[argc]$f;
|
1994-10-29 02:14:46 +03:00
|
|
|
oldf = $f;
|
1994-10-20 07:22:35 +03:00
|
|
|
f++
|
|
|
|
}
|
|
|
|
if (argtype[argc] == "")
|
|
|
|
parserr($f, "argument definition")
|
|
|
|
argname[argc]=$f;
|
|
|
|
f += 2; # skip name, and any comma
|
1993-04-06 14:37:09 +04:00
|
|
|
}
|
1994-10-20 07:22:35 +03:00
|
|
|
}
|
1995-10-07 09:25:19 +03:00
|
|
|
function putent(nodefs, compatwrap) {
|
1994-10-20 07:22:35 +03:00
|
|
|
# output syscall declaration for switch table
|
1995-09-20 01:28:56 +04:00
|
|
|
prototype = "__P((struct proc *, void *, register_t *))"
|
1994-10-20 07:22:35 +03:00
|
|
|
if (compatwrap == "")
|
1995-10-07 09:25:19 +03:00
|
|
|
printf("int\t%s\t%s;\n", funcname, prototype) > sysprotos
|
1994-10-20 07:22:35 +03:00
|
|
|
else
|
1995-10-07 09:25:19 +03:00
|
|
|
printf("int\t%s_%s\t%s;\n", compatwrap, funcname, prototype) > sysprotos
|
1994-10-20 07:22:35 +03:00
|
|
|
|
|
|
|
# output syscall switch entry
|
|
|
|
# printf("\t{ { %d", argc) > sysent
|
|
|
|
# for (i = 1; i <= argc; i++) {
|
|
|
|
# if (i == 5) # wrap the line
|
|
|
|
# printf(",\n\t ") > sysent
|
|
|
|
# else
|
|
|
|
# printf(", ") > sysent
|
|
|
|
# printf("s(%s)", argtypenospc[i]) > sysent
|
|
|
|
# }
|
|
|
|
printf("\t{ %d, ", argc) > sysent
|
|
|
|
if (argc == 0)
|
|
|
|
printf("0") > sysent
|
|
|
|
else if (compatwrap == "")
|
|
|
|
printf("s(struct %s_args)", funcname) > sysent
|
|
|
|
else
|
|
|
|
printf("s(struct %s_%s_args)", compatwrap, funcname) > sysent
|
|
|
|
if (compatwrap == "")
|
|
|
|
wfn = sprintf("%s", funcname);
|
|
|
|
else
|
|
|
|
wfn = sprintf("%s(%s)", compatwrap, funcname);
|
|
|
|
printf(",\n\t %s },", wfn) > sysent
|
|
|
|
for (i = 0; i < (33 - length(wfn)) / 8; i++)
|
|
|
|
printf("\t") > sysent
|
|
|
|
if (compatwrap == "")
|
|
|
|
printf("/* %d = %s */\n", syscall, funcalias) > sysent
|
|
|
|
else
|
|
|
|
printf("/* %d = %s %s */\n", syscall, compatwrap,
|
|
|
|
funcalias) > sysent
|
|
|
|
|
|
|
|
# output syscall name for names table
|
|
|
|
if (compatwrap == "")
|
|
|
|
printf("\t\"%s\",\t\t\t/* %d = %s */\n", funcalias, syscall,
|
|
|
|
funcalias) > sysnames
|
|
|
|
else
|
|
|
|
printf("\t\"%s_%s\",\t/* %d = %s %s */\n", compatwrap,
|
|
|
|
funcalias, syscall, compatwrap, funcalias) > sysnames
|
|
|
|
|
|
|
|
# output syscall number of header, if appropriate
|
|
|
|
if (nodefs == "" || nodefs == "NOARGS")
|
|
|
|
printf("#define\t%s%s\t%d\n", constprefix, funcalias,
|
|
|
|
syscall) > sysnumhdr
|
|
|
|
else if (nodefs != "NODEF")
|
|
|
|
printf("\t\t\t\t/* %d is %s %s */\n", syscall,
|
|
|
|
compatwrap, funcalias) > sysnumhdr
|
|
|
|
|
|
|
|
# output syscall argument structure, if it has arguments
|
|
|
|
if (argc != 0 && nodefs != "NOARGS") {
|
|
|
|
if (compatwrap == "")
|
|
|
|
printf("\nstruct %s_args {\n", funcname) > sysarghdr
|
|
|
|
else
|
|
|
|
printf("\nstruct %s_%s_args {\n", compatwrap,
|
|
|
|
funcname) > sysarghdr
|
|
|
|
for (i = 1; i <= argc; i++)
|
|
|
|
printf("\tsyscallarg(%s) %s;\n", argtype[i],
|
|
|
|
argname[i]) > sysarghdr
|
|
|
|
printf("};\n") > sysarghdr
|
1993-04-06 14:37:09 +04:00
|
|
|
}
|
1994-10-20 07:22:35 +03:00
|
|
|
}
|
|
|
|
$2 == "STD" {
|
|
|
|
parseline()
|
1995-10-07 09:25:19 +03:00
|
|
|
putent("", "");
|
1994-10-20 07:22:35 +03:00
|
|
|
syscall++
|
|
|
|
next
|
|
|
|
}
|
|
|
|
$2 == "NODEF" || $2 == "NOARGS" {
|
|
|
|
parseline()
|
1995-10-07 09:25:19 +03:00
|
|
|
putent($2, "")
|
1994-10-20 07:22:35 +03:00
|
|
|
syscall++
|
|
|
|
next
|
|
|
|
}
|
|
|
|
$2 == "OBSOL" || $2 == "UNIMPL" {
|
|
|
|
if ($2 == "OBSOL")
|
|
|
|
comment="obsolete"
|
|
|
|
else
|
|
|
|
comment="unimplemented"
|
|
|
|
for (i = 3; i <= NF; i++)
|
|
|
|
comment=comment " " $i
|
|
|
|
|
1995-10-07 09:25:19 +03:00
|
|
|
printf("\t{ 0, 0,\n\t sys_nosys },\t\t\t/* %d = %s */\n", \
|
1994-10-20 07:22:35 +03:00
|
|
|
syscall, comment) > sysent
|
|
|
|
printf("\t\"#%d (%s)\",\t\t/* %d = %s */\n", \
|
|
|
|
syscall, comment, syscall, comment) > sysnames
|
|
|
|
if ($2 != "UNIMPL")
|
|
|
|
printf("\t\t\t\t/* %d is %s */\n", syscall, comment) > sysnumhdr
|
|
|
|
syscall++
|
|
|
|
next
|
|
|
|
}
|
|
|
|
{
|
|
|
|
for (i = 1; i <= ncompat; i++) {
|
|
|
|
if ($2 == compat_upper[i]) {
|
|
|
|
parseline();
|
1995-10-07 09:25:19 +03:00
|
|
|
putent("COMMENT", compat[i])
|
1994-10-20 07:22:35 +03:00
|
|
|
syscall++
|
|
|
|
next
|
|
|
|
}
|
1993-04-06 14:37:09 +04:00
|
|
|
}
|
1994-10-20 07:22:35 +03:00
|
|
|
printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
END {
|
|
|
|
printf("};\n\n") > sysent
|
|
|
|
printf("};\n") > sysnames
|
1995-04-22 23:42:47 +04:00
|
|
|
printf("#define\t%sMAXSYSCALL\t%d\n", constprefix, syscall) > sysnumhdr
|
1994-10-20 07:22:35 +03:00
|
|
|
} '
|
1993-04-06 14:37:09 +04:00
|
|
|
|
1995-10-07 09:25:19 +03:00
|
|
|
cat $sysprotos >> $sysarghdr
|
1995-09-20 01:28:56 +04:00
|
|
|
cat $sysdcl $sysent > $syssw
|
1993-04-06 14:37:09 +04:00
|
|
|
|
1995-04-22 23:42:47 +04:00
|
|
|
#chmod 444 $sysnames $sysnumhdr $syssw
|