2009-10-14 21:17:00 +04:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
2016-01-27 02:21:18 +03:00
|
|
|
# $NetBSD: makerumpif.sh,v 1.10 2016/01/26 23:21:18 pooka Exp $
|
2009-10-14 21:17:00 +04:00
|
|
|
#
|
2015-04-23 13:50:00 +03:00
|
|
|
# Copyright (c) 2009, 2015 Antti Kantee. All rights reserved.
|
2009-10-14 21:17:00 +04:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
|
|
|
|
#
|
|
|
|
# This reads a rump component interface description and creates:
|
|
|
|
# 1: rump private prototypes for internal calls
|
|
|
|
# 2: public prototypes for calls outside of rump
|
|
|
|
# 3: public interface implementations which run the rump scheduler
|
|
|
|
# and call the private interface
|
|
|
|
#
|
|
|
|
|
|
|
|
usage ()
|
|
|
|
{
|
|
|
|
|
|
|
|
echo "usage: $0 spec"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
boom ()
|
|
|
|
{
|
|
|
|
|
|
|
|
echo $*
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2013-02-14 14:54:54 +04:00
|
|
|
unset TOPDIR
|
|
|
|
if [ $# -eq 3 ]; then
|
|
|
|
if [ $1 = '-R' ]; then
|
|
|
|
TOPDIR=$2
|
|
|
|
else
|
|
|
|
usage
|
|
|
|
fi
|
|
|
|
shift; shift
|
|
|
|
fi
|
|
|
|
[ $# -ne 1 ] && usage
|
2009-10-14 21:17:00 +04:00
|
|
|
|
|
|
|
MYDIR=`pwd`
|
2013-02-14 14:54:54 +04:00
|
|
|
if [ -z "${TOPDIR}" ]; then
|
|
|
|
while [ ! -f Makefile.rump ]; do
|
|
|
|
[ `pwd` = '/' ] && boom Could not find rump topdir.
|
|
|
|
cd ..
|
|
|
|
done
|
|
|
|
TOPDIR="`pwd`"
|
|
|
|
fi
|
2009-10-14 21:17:00 +04:00
|
|
|
cd ${MYDIR}
|
|
|
|
|
|
|
|
sed -e '
|
|
|
|
:again
|
|
|
|
/\\$/{
|
|
|
|
N
|
|
|
|
s/[ ]*\\\n[ ]*/ /
|
|
|
|
b again
|
|
|
|
}
|
2013-02-14 14:54:54 +04:00
|
|
|
' ${1} | awk -F\| -v topdir=${TOPDIR} '
|
2009-10-14 21:17:00 +04:00
|
|
|
function fileheaders(file, srcstr)
|
|
|
|
{
|
2016-01-27 02:21:18 +03:00
|
|
|
printf("/*\t$NetBSD: makerumpif.sh,v 1.10 2016/01/26 23:21:18 pooka Exp $\t*/\n\n") > file
|
2009-10-14 21:17:00 +04:00
|
|
|
printf("/*\n * Automatically generated. DO NOT EDIT.\n") > file
|
2016-01-27 02:21:18 +03:00
|
|
|
genstr = "$NetBSD: makerumpif.sh,v 1.10 2016/01/26 23:21:18 pooka Exp $"
|
2009-10-14 21:17:00 +04:00
|
|
|
gsub("\\$", "", genstr)
|
|
|
|
printf(" * from: %s\n", srcstr) > file
|
|
|
|
printf(" * by: %s\n", genstr) > file
|
|
|
|
printf(" */\n") > file
|
|
|
|
}
|
|
|
|
|
|
|
|
function die(str)
|
|
|
|
{
|
|
|
|
|
|
|
|
print str
|
|
|
|
exit(1)
|
|
|
|
}
|
|
|
|
|
|
|
|
NR == 1 {
|
|
|
|
sub(";[^\\$]*\\$", "")
|
|
|
|
sub("\\$", "")
|
|
|
|
fromstr = $0
|
|
|
|
next
|
|
|
|
}
|
|
|
|
|
|
|
|
$1 == "NAME"{myname = $2;next}
|
2013-02-14 14:54:54 +04:00
|
|
|
$1 == "PUBHDR"{pubhdr = topdir "/" $2;print pubhdr;next}
|
|
|
|
$1 == "PRIVHDR"{privhdr = topdir "/" $2;print privhdr;next}
|
|
|
|
$1 == "WRAPPERS"{gencalls = topdir "/" $2;print gencalls;next}
|
2009-10-14 21:17:00 +04:00
|
|
|
|
|
|
|
/^;/{next}
|
|
|
|
/\\$/{sub("\\\n", "");getline nextline;$0 = $0 nextline}
|
|
|
|
/^[ \t]*$/{next}
|
|
|
|
{
|
|
|
|
if (NF != 3 && NF != 4) {
|
|
|
|
die("error: unexpected number of fields\n")
|
|
|
|
}
|
2015-04-23 13:50:00 +03:00
|
|
|
isweak = 0
|
|
|
|
iscompat = 0
|
2009-10-14 21:17:00 +04:00
|
|
|
if (NF == 4) {
|
2015-04-23 13:50:00 +03:00
|
|
|
if ($4 == "WEAK") {
|
2009-10-14 21:17:00 +04:00
|
|
|
isweak = 1
|
2015-04-23 13:50:00 +03:00
|
|
|
} else if (match($4, "COMPAT_")) {
|
|
|
|
iscompat = 1
|
|
|
|
compat = $4
|
|
|
|
} else {
|
2009-10-14 21:17:00 +04:00
|
|
|
die("error: unexpected fourth field");
|
2015-04-23 13:50:00 +03:00
|
|
|
}
|
2009-10-14 21:17:00 +04:00
|
|
|
}
|
|
|
|
if (!myname)
|
|
|
|
die("name not specified");
|
|
|
|
if (!pubhdr)
|
|
|
|
die("public header not specified");
|
|
|
|
if (!privhdr)
|
|
|
|
die("private header not specified");
|
|
|
|
if (!gencalls)
|
|
|
|
die("wrapper file not specified");
|
|
|
|
|
|
|
|
if (!once) {
|
|
|
|
fileheaders(pubhdr, fromstr)
|
|
|
|
fileheaders(privhdr, fromstr)
|
|
|
|
fileheaders(gencalls, fromstr)
|
|
|
|
once = 1
|
|
|
|
|
|
|
|
pubfile = pubhdr
|
|
|
|
sub(".*/", "", pubfile)
|
|
|
|
|
|
|
|
privfile = privhdr
|
|
|
|
sub(".*/", "", privfile)
|
|
|
|
|
|
|
|
printf("\n") > pubhdr
|
|
|
|
printf("\n") > privhdr
|
|
|
|
|
2014-04-25 21:50:01 +04:00
|
|
|
printf("#ifndef _RUMP_PRIF_%s_H_\n", toupper(myname)) > privhdr
|
|
|
|
printf("#define _RUMP_PRIF_%s_H_\n", toupper(myname)) > privhdr
|
|
|
|
printf("\n") > privhdr
|
|
|
|
|
2009-10-14 21:17:00 +04:00
|
|
|
printf("\n#include <sys/cdefs.h>\n") > gencalls
|
2016-01-27 02:21:18 +03:00
|
|
|
printf("#include <sys/systm.h>\n\n") > gencalls
|
|
|
|
printf("#include <rump-sys/kern.h>\n", privfile) > gencalls
|
|
|
|
printf("#include <rump-sys/%s>\n\n", privfile) > gencalls
|
|
|
|
printf("#include <rump/rump.h>\n") > gencalls
|
2009-10-14 21:17:00 +04:00
|
|
|
printf("#include <rump/%s>\n\n", pubfile) > gencalls
|
2009-10-14 21:26:09 +04:00
|
|
|
printf("void __dead rump_%s_unavailable(void);\n", \
|
2009-10-14 21:17:00 +04:00
|
|
|
myname) > gencalls
|
|
|
|
printf("void __dead\nrump_%s_unavailable(void)\n{\n", \
|
|
|
|
myname) > gencalls
|
|
|
|
printf("\n\tpanic(\"%s interface unavailable\");\n}\n", \
|
|
|
|
myname) > gencalls
|
|
|
|
}
|
|
|
|
|
|
|
|
funtype = $1
|
|
|
|
sub("[ \t]*$", "", funtype)
|
|
|
|
funname = $2
|
|
|
|
sub("[ \t]*$", "", funname)
|
|
|
|
funargs = $3
|
2009-10-14 21:26:09 +04:00
|
|
|
sub("[ \t]*$", "", funargs)
|
|
|
|
|
2009-10-14 22:14:48 +04:00
|
|
|
printf("%s rump_pub_%s(%s);\n", funtype, funname, funargs) > pubhdr
|
|
|
|
printf("%s rump_%s(%s);\n", funtype, funname, funargs) > privhdr
|
2014-04-25 17:07:31 +04:00
|
|
|
printf("typedef %s (*rump_%s_fn)(%s);\n", \
|
|
|
|
funtype, funname, funargs) > privhdr
|
2009-10-14 21:17:00 +04:00
|
|
|
|
|
|
|
if (funtype == "void")
|
|
|
|
voidret = 1
|
|
|
|
else
|
|
|
|
voidret = 0
|
|
|
|
if (funargs == "void")
|
|
|
|
voidarg = 1
|
|
|
|
else
|
|
|
|
voidarg = 0
|
|
|
|
|
2015-04-23 13:50:00 +03:00
|
|
|
printf("\n") > gencalls
|
|
|
|
if (iscompat) {
|
|
|
|
printf("#ifdef %s\n", compat) > gencalls
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("%s\nrump_pub_%s(", funtype, funname) > gencalls
|
2009-10-14 21:17:00 +04:00
|
|
|
if (!voidarg) {
|
|
|
|
narg = split(funargs, argv, ",")
|
|
|
|
for (i = 1; i <= narg; i++) {
|
|
|
|
sub(" *", "", argv[i])
|
|
|
|
if (match(argv[i], "\\*$") != 0)
|
|
|
|
printf("%sarg%d", argv[i], i) > gencalls
|
|
|
|
else
|
|
|
|
printf("%s arg%d", argv[i], i) > gencalls
|
|
|
|
if (i != narg)
|
|
|
|
printf(", ") > gencalls
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
narg = 0
|
|
|
|
printf("void") > gencalls
|
|
|
|
}
|
|
|
|
printf(")\n{\n") > gencalls
|
|
|
|
|
|
|
|
if (!voidret) {
|
2009-10-14 21:26:09 +04:00
|
|
|
printf("\t%s rv;\n", funtype) > gencalls
|
2009-10-14 21:17:00 +04:00
|
|
|
}
|
2009-10-15 04:29:19 +04:00
|
|
|
printf("\n\trump_schedule();\n\t") > gencalls
|
2009-10-14 21:17:00 +04:00
|
|
|
if (!voidret)
|
|
|
|
printf("rv = ") > gencalls
|
2009-10-14 22:14:48 +04:00
|
|
|
printf("rump_%s(", funname) > gencalls
|
2009-10-14 21:17:00 +04:00
|
|
|
for (i = 1; i <= narg; i++) {
|
|
|
|
printf("arg%i", i) > gencalls
|
|
|
|
if (i < narg)
|
|
|
|
printf(", ") > gencalls
|
|
|
|
}
|
2009-10-15 04:29:19 +04:00
|
|
|
printf(");\n\trump_unschedule();\n") > gencalls
|
2009-10-14 21:17:00 +04:00
|
|
|
if (!voidret)
|
|
|
|
printf("\n\treturn rv;\n") > gencalls
|
|
|
|
printf("}\n") > gencalls
|
2015-04-23 13:50:00 +03:00
|
|
|
if (iscompat) {
|
|
|
|
printf("#else\n") > gencalls
|
|
|
|
printf("__strong_alias(rump_pub_%s,rump_%s_unavailable);\n", \
|
|
|
|
funname, myname) > gencalls
|
|
|
|
printf("#endif /* %s */\n", compat) > gencalls
|
|
|
|
}
|
2009-10-14 21:17:00 +04:00
|
|
|
if (isweak)
|
2009-10-14 22:14:48 +04:00
|
|
|
printf("__weak_alias(rump_%s,rump_%s_unavailable);\n", \
|
2009-10-14 21:17:00 +04:00
|
|
|
funname, myname) > gencalls
|
2014-04-25 21:50:01 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
END { printf("\n#endif /* _RUMP_PRIF_%s_H_ */\n", toupper(myname)) > privhdr }'
|