1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039 |
- if [ ! -d ../startup ]; then
- echo "$0: Run me from src/kern/conf"
- exit 1
- fi
- CONFNAME=$1
- if [ "x$CONFNAME" = x ]; then
- echo "Usage: $0 CONFIG-NAME"
- exit 1
- fi
- FOO=`echo $CONFNAME | tr -d 'a-zA-Z0-9_-'`
- if [ "x$FOO" != x ]; then
- echo "Illegal configuration name $CONFNAME"
- exit 1
- fi
- if [ ! -f $CONFNAME ]; then
- echo "$0: $CONFNAME not found"
- exit 1
- fi
- echo "Configuration $CONFNAME"
- COMPILEDIR="../compile/$CONFNAME"
- CONFTMP=.conftmp
- rm -f $CONFTMP
- echo "$CONFNAME" $CONFTMP | awk '
- BEGIN {
- nfields["include"] = 2;
- nfields["file"] = 2;
- nfields["debug"] = 1;
- nfields["defoption"] = 2;
- nfields["optfile"] = 3;
- nfields["optofffile"] = 3;
- nfields["defdevice"] = 3;
- nfields["defattach"] = 4;
- nfields["pseudoattach"] = 2;
- nfields["options"] = 2;
- nfields["device"] = 4
- okmd["file"] = 1;
- okmd["optfile"] = 1;
- okmd["optofffile"] = 1;
- }
- function doinclude(file, lineno) {
- lineno = 1;
- while (getline < file) {
- if (ERRNO) {
- printf "%s: %s\n", file, ERRNO;
- exit(1);
- }
- processline(file, lineno);
- lineno++;
- }
- }
- function processline(filename, lineno) {
- sub("#.*", "", $0);
- if (NF==0) return;
- direct = $1;
- foundfields = NF;
- if (direct == "machine" && NF > 2 && okmd[$3]) {
- direct = $3;
- foundfields -= 2;
- }
- else if (direct == "platform" && NF > 2 && okmd[$3]) {
- direct = $3;
- foundfields -= 2;
- }
- if (!nfields[direct]) {
- printf "%s: %d: Unknown directive %s\n", filename, lineno, direct;
- exit(1);
- }
- if (direct=="device") {
- if ((NF!=2 && NF!=4) || (NF==4 && $3!="at")) {
- msg = sprintf("%s: Invalid arguments", direct);
- printf "%s: %d: %s\n", filename, lineno, msg;
- exit(1);
- }
- }
- else if (nfields[direct]!=foundfields) {
- printf "%s: %d: %s: Invalid arguments\n", filename, lineno, direct;
- exit(1);
- }
- if (direct == "include") {
- doinclude("../" $2);
- }
- else {
- print >> outfile;
- }
- }
- {
- outfile = $2;
- doinclude($1);
- }
- ' || exit 1
- if [ ! -d "$COMPILEDIR" ]; then
- mkdir $COMPILEDIR
- fi
- echo -n 'Generating files...'
- rm -f $CONFTMP.files
- rm -f $CONFTMP.attach
- awk < $CONFTMP '
- function getunit(invalmsg, d, u, tmp) {
- u = d;
- sub("^[a-zA-Z_]*", "", u);
- if (u!="*") {
- tmp = u;
- sub("[0-9]*", "", tmp);
- if (tmp!="") {
- printf "\n%s: Invalid device/unit specification\n", invalmsg;
- exit(1);
- }
- }
- return u;
- }
- function getbase(invalmsg, d, base) {
- base = d;
- sub("[\\*0-9]*$", "", base);
- if (!use[base]) {
- printf "\n%s: No such device\n", invalmsg;
- exit(1);
- }
- return base;
- }
- $1=="defdevice" {
- dev = $2;
- file = $3;
- tmp = dev;
- sub("[a-zA-Z_]*", "", tmp);
- if (tmp!="") {
- printf "\ndefdevice %s: Illegal device name\n", dev;
- exit(1);
- }
- if (use[dev]) {
- printf "\ndefdevice %s: %s already exists\n", dev, dev;
- exit(1);
- }
- use[dev] = "no";
- files[dev] = file;
- }
- $1=="defattach" {
- dev = $2;
- bus = $3;
- file = $4;
- devmsg = "defattach: device " dev;
- devunit = getunit(devmsg, dev);
- basedev = getbase(devmsg, dev);
- busmsg = "defattach: bus " bus;
- busunit = getunit(busmsg, bus);
- basebus = getbase(busmsg, bus);
- if (pseudo[basedev]) {
- printf "\n%s: Already declared pseudoattach\n", devmsg;
- exit(1);
- }
- attachment = bus "." dev;
- attach[attachment] = "no";
- files[attachment] = file;
- attachable[basedev] = 1;
- }
- $1=="pseudoattach" {
- dev = $2;
- devmsg = "pseudoattach: device " dev;
- devunit = getunit(devmsg, dev);
- basedev = getbase(devmsg, dev);
- if (attachable[basedev]) {
- printf "\n%s: Attachments already declared\n", devmsg;
- exit(1);
- }
- pseudo[basedev] = 1;
- }
- function tryattach(combo) {
- if (!attachok && attach[combo]) {
- attach[combo] = "yes";
- attachok = 1;
- }
- }
- $1=="device" {
- dev = $2;
- if (NF==4) {
- devmsg = "device: " dev " at " $4;
- }
- else {
- devmsg = "device: device " dev;
- }
- devunit = getunit(devmsg, dev);
- basedev = getbase(devmsg, dev);
- gendev = basedev "*";
- if (NF==4) {
- bus = $4;
- busmsg = "device: " dev " at " bus ": " bus;
- busunit = getunit(busmsg, bus);
- basebus = getbase(busmsg, bus);
- genbus = basebus "*";
- if (use[basebus]!="yes") {
- printf "\ndevice: bus %s: Bus device is not enabled\n", bus;
- exit(1);
- }
- attachok = 0;
- tryattach(bus "." dev);
- tryattach(bus "." gendev);
- tryattach(genbus "." dev);
- tryattach(genbus "." gendev);
- if (!attachok) {
- printf "\ndevice: %s at %s: Undefined attachment\n", dev, bus;
- exit(1);
- }
- devattach = sprintf("%s %s", basedev, devunit);
- baseattach = sprintf("%s %s", basebus, busunit);
- printf "attach %s at %s\n", devattach, baseattach >> attachfile;
- }
- else {
- if (attachable[basedev]) {
- printf "\ndevice %s: attachment required\n", dev;
- exit(1);
- }
- if (pseudo[basedev]) {
- if (devunit=="*") {
- printf "\n%s: May not use wildcard units here\n", devmsg;
- exit(1);
- }
- printf "pseudo %s %s\n", basedev, devunit >> attachfile;
- }
- else {
- printf "noattach %s\n", basedev >> attachfile;
- }
- }
- use[basedev] = "yes";
- }
- END {
- for (dev in use) {
- if (use[dev]=="yes") {
- printf "* * %s\n", files[dev] >> filelistfile;
- }
- }
- for (att in attach) {
- if (attach[att]=="yes") {
- printf "* * %s\n", files[att] >> filelistfile;
- }
- }
- }
- ' "attachfile=$CONFTMP.attach" "filelistfile=$CONFTMP.files" || exit 1
- awk < $CONFTMP '
- $1=="defoption" {
- opt = $2;
- options[opt] = "no";
- }
- $1=="optfile" || (($1=="machine" || $1=="platform") && $3=="optfile") {
- if ($1 == "optfile") {
- opt = $2;
- file = $3;
- platform = "*";
- machine = "*";
- }
- else {
- if ($1=="machine") {
- platform = "*";
- machine = $2;
- }
- else {
- platform = $2;
- machine = "*";
- }
- opt = $4;
- file = $5;
- }
- if (!options[opt]) {
- printf "\noptfile %s %s: No such option %s\n", opt, file, opt;
- exit(1);
- }
- controllers[file] = opt;
- platforms[file] = platform;
- machines[file] = machine;
- }
- $1=="optofffile" || (($1=="machine" || $1=="platform") &&$3=="optofffile"){
- if ($1 == "optofffile") {
- opt = $2;
- file = $3;
- platform = "*";
- machine = "*";
- }
- else {
- if ($1=="machine") {
- platform = "*";
- machine = $2;
- }
- else {
- platform = $2;
- machine = "*";
- }
- opt = $4;
- file = $5;
- }
- if (!options[opt]) {
- printf "\noptofffile %s %s: No such option %s\n", opt, file, opt;
- exit(1);
- }
- offcontrollers[file] = opt;
- platforms[file] = platform;
- machines[file] = machine;
- }
- $1=="options" {
- opt = $2;
- if (!options[$2]) {
- printf "\noptions %s: No such option\n", opt;
- exit(1);
- }
- options[$2] = "yes";
- }
- END {
- for (file in controllers) {
- if (options[controllers[file]]=="yes") {
- line = sprintf("%s %s %s",
- platforms[file], machines[file], file);
- printf "%s\n", line >> filelistfile;
- }
- }
- for (file in offcontrollers) {
- if (options[offcontrollers[file]]=="no") {
- line = sprintf("%s %s %s",
- platforms[file], machines[file], file);
- printf "%s\n", line >> filelistfile;
- }
- }
- close(filelistfile);
- for (opt in options) {
- realfile = compiledir "/opt-" opt ".h";
- file = realfile ".new";
- sym = toupper(opt);
- printf "/* Automatically generated; do not edit */\n" > file;
- printf "#ifndef _OPT_%s_H_\n", sym >> file;
- printf "#define _OPT_%s_H_\n", sym >> file;
- val = options[opt]=="yes" ? 1 : 0;
- printf "#define OPT_%s %d\n", sym, val >> file;
- printf "#endif /* _OPT_%s_H_ */\n", sym >> file;
- close(file);
- }
- }
- ' "compiledir=$COMPILEDIR" "filelistfile=$CONFTMP.files" || exit 1
- (
- cd $COMPILEDIR
- for NF in opt-*.h.new; do
- OF=`echo $NF | sed 's/\.new$//'`
- if diff $OF $NF >/dev/null 2>&1; then
- rm -f $NF # unchanged
- else
- mv -f $NF $OF # it changed
- fi
- echo -n " $OF"
- done
- )
- awk < $CONFTMP '
- $1=="file" {
- printf "* * %s\n", $2 >> filelistfile;
- }
- $1=="machine" && $3=="file" {
- printf "* %s %s\n", $2, $4 >> filelistfile;
- }
- $1=="platform" && $3=="file" {
- printf "%s * %s\n", $2, $4 >> filelistfile;
- }
-
- ' "filelistfile=$CONFTMP.files" || exit 1
- echo "* * compile/$CONFNAME/autoconf.c" >> $CONFTMP.files
- awk < $CONFTMP.files '
- /\.cc$/ { next; }
- /\.cpp$/ { next; }
- /\.C$/ { next; }
- /\.c$/ { next; }
- /\.S$/ { next; }
- /\.o$/ { next; }
- {
- printf "\n%s: Unrecognized source file type\n", $1;
- exit(1);
- }
- ' || exit 1;
- sort < $CONFTMP.files | awk '
- BEGIN {
- printf "# Automatically generated by config; do not edit\n";
- }
- {
- platform = $1;
- machine = $2;
- file = $3;
- basename = file;
- sub(".*/", "", basename);
- ext = basename;
- sub(".*\\.", "", ext);
- sub("\\.[^\\.]*$", "", basename);
- if (file ~ "^\\.\\./") {
- sub("^...", "", file);
- path = "$(TOP)/" file;
- }
- else {
- path = "$(KTOP)/" file;
- }
- if (platform != "*") {
- printf "SRCS.PLATFORM.%s+=%s\n", platform, path;
- }
- else if (machine != "*") {
- printf "SRCS.MACHINE.%s+=%s\n", machine, path;
- }
- else {
- printf "SRCS+=%s\n", path;
- }
- }
- ' > $COMPILEDIR/files.mk
- rm -f $CONFTMP.files
- echo -n ' files.mk'
- (
- echo "# Automatically generated by config; do not edit."
- echo "#"
- echo
- echo '# Top of the kernel tree'
- echo 'KTOP=../..'
- echo '# Top of the whole tree'
- echo 'TOP=$(KTOP)/..'
- echo '# Debug vs. optimize'
- awk < $CONFTMP '
- BEGIN { debugflags="-O2"; }
- $1=="debug" {
- debugflags="-g";
- }
- END {
- printf "KDEBUG=%s\n", debugflags;
- }
- '
- echo '# Name of the kernel config file'
- echo "CONFNAME=$CONFNAME"
- echo
- echo '.include "$(TOP)/mk/os161.config.mk"'
- echo '.include "files.mk"'
- echo '.include "$(TOP)/mk/os161.kernel.mk"'
- ) > $COMPILEDIR/Makefile || exit 1
- echo -n ' Makefile'
- ACHREAL=$COMPILEDIR/autoconf.h
- ACH=$COMPILEDIR/autoconf.h.new
- ACC=$COMPILEDIR/autoconf.c
- echo '/* Automatically generated; do not edit */' > $ACH
- echo '/* Automatically generated; do not edit */' > $ACC
- echo '#ifndef _AUTOCONF_H_' >> $ACH
- echo '#define _AUTOCONF_H_' >> $ACH
- echo >> $ACH
- awk < $CONFTMP.attach '{ printf "struct %s_softc;\n", $2 }' >> $ACH
- echo >> $ACH
- awk < $CONFTMP.attach '$1=="noattach" { print $2 }' | sort -u | awk '
- {
- printf "void autoconf_%s(struct %s_softc *dev, int unit);\n", $1, $1;
- }
- ' >> $ACH
- echo >> $ACH
- awk < $CONFTMP.attach '
- $1=="attach" {
- dev = $2;
- bus = $5;
- f = sprintf("struct %s_softc *attach_%s_to_%s", dev, dev, bus);
- printf "%s(int devunit, struct %s_softc *bus);\n", f, bus;
- }
- $1=="pseudo" {
- dev = $2;
- printf "struct %s_softc *pseudoattach_%s(int devunit);\n", dev, dev;
- }
- ' >> $ACH
- echo >> $ACH
- awk < $CONFTMP.attach '
- $1=="attach" {
- dev = $2;
- printf "int config_%s(struct %s_softc *dev, int unit);\n", dev, dev;
- }
- ' >> $ACH
- echo >> $ACH
- echo 'void pseudoconfig(void);' >> $ACH
- echo >> $ACH
- echo '#endif /* _AUTOCONF_H_ */' >> $ACH
- if diff $ACHREAL $ACH >/dev/null 2>&1; then
- rm -f $ACH # unchanged
- else
- mv -f $ACH $ACHREAL # it changed
- fi
- echo -n ' autoconf.h'
- echo '#include <types.h>' >> $ACC
- echo '#include <lib.h>' >> $ACC
- echo '#include "autoconf.h"' >> $ACC
- echo >> $ACC
- awk < $CONFTMP.attach '$1=="attach" || $1=="pseudo" { print $2 }' | sort -u |\
- awk '
- {
- printf "static void autoconf_%s(struct %s_softc *, int);\n", $1, $1;
- }
- ' >> $ACC
- awk < $CONFTMP.attach '$1=="attach" { print $2 }' | sort -u | awk '
- {
- printf "static int nextunit_%s;\n", $1;
- }
- ' >> $ACC
- echo >> $ACC
- awk < $CONFTMP.attach '
- $1=="attach" {
- dev = $2;
- bus = $5;
- printf "static\n";
- printf "int\n";
- printf "tryattach_%s_to_%s", dev, bus;
- printf "(int devunit, struct %s_softc *bus, int busunit)\n", bus;
- printf "{\n";
- printf "\tstruct %s_softc *dev;\n", dev;
- printf "\tint result;\n", dev;
- printf "\n";
- printf "\tdev = attach_%s_to_%s(devunit, bus);\n", dev, bus;
- printf "\tif (dev==NULL) {\n";
- printf "\t\treturn -1;\n";
- printf "\t}\n";
- printf "\tkprintf(\"%s%%d at %s%%d\", devunit, busunit);\n", dev, bus;
- printf "\tresult = config_%s(dev, devunit);\n", dev;
- printf "\tif (result != 0) {\n";
- printf "\t\tkprintf(\": %%s\\n\", strerror(result));\n";
- printf "\t\t/* should really clean up dev */\n";
- printf "\t\treturn result;\n";
- printf "\t}\n";
- printf "\tkprintf(\"\\n\");\n";
- printf "\tnextunit_%s = devunit+1;\n", dev;
- printf "\tautoconf_%s(dev, devunit);\n", dev;
- printf "\treturn 0;\n";
- printf "}\n";
- printf "\n";
- }
- ' >> $ACC
- echo >> $ACC
- awk < $CONFTMP.attach '
- BEGIN { nlines=0; npseudo=0; }
- $1=="attach" {
- devs[nlines] = $2;
- devunits[nlines] = $3;
- buses[nlines] = $5;
- busunits[nlines] = $6;
- alldevs[$2] = 1;
- nlines++;
- }
- $1=="noattach" {
- alldevs[$2] = 0;
- }
- $1=="pseudo" {
- alldevs[$2] = 0;
- pseudodevs[npseudo] = $2;
- pseudounits[npseudo] = $3;
- npseudo++;
- }
- function genprobe(dev, devunit, bus, busunit) {
- tryfunc = sprintf("tryattach_%s_to_%s", dev, bus);
-
- if (busunit!="*") {
- printf "\tif (busunit==%d) {\n", busunit;
- }
- else {
- printf "\t{\n";
- }
- if (devunit!="*") {
- printf "\t\tif (nextunit_%s <= %d) {\n", dev, devunit;
- printf "\t\t\t%s(%d, bus, busunit);\n", tryfunc, devunit;
- printf "\t\t}\n";
- }
- else {
- printf "\t\tint result, devunit=nextunit_%s;\n", dev;
- printf "\t\tdo {\n";
- printf "\t\t\tresult = %s(devunit, bus, busunit);\n", tryfunc;
- printf "\t\t\tdevunit++;\n";
- printf "\t\t} while (result==0);\n";
- }
- printf "\t}\n";
- }
- END {
- for (bus in alldevs) {
- softc = sprintf("struct %s_softc", bus);
- if (alldevs[bus]) printf "static\n";
- printf "void\n";
- printf "autoconf_%s(%s *bus, int busunit)\n", bus, softc;
- printf "{\n";
- printf "\t(void)bus; (void)busunit;\n";
- for (i=0; i<nlines; i++) {
- if (buses[i]==bus) {
- genprobe(devs[i], devunits[i], buses[i], busunits[i]);
- }
- }
- printf "}\n\n";
- }
- printf "void\n";
- printf "pseudoconfig(void)\n";
- printf "{\n";
- for (i=0; i<npseudo; i++) {
- dev = pseudodevs[i];
- unit = pseudounits[i];
- printf "\t{\n";
- printf "\t\tstruct %s_softc *s;\n", dev;
- printf "\t\t\n";
- printf "\t\ts = pseudoattach_%s(%s);\n", dev, unit;
- printf "\t\tif (s!=NULL) {\n";
- printf "\t\t\tkprintf(\"%s%d (virtual)\\n\");\n", dev, unit;
- printf "\t\t\tautoconf_%s(s, %s);\n", dev, unit;
- printf "\t\t}\n";
- printf "\t}\n";
- }
- printf "}\n\n";
- }
- ' >> $ACC
- echo -n ' autoconf.c'
- rm -f $CONFTMP $CONFTMP.attach
- echo
- echo "Configuration in ../compile/$CONFNAME done"
- echo "Remember to bmake depend"
|