Subject: Re: how facilitate custom driver development: the cdevsw/conf.c problem
To: None <tech-kern@NetBSD.ORG>
From: Chris Torek <torek@BSDI.COM>
List: current-users
Date: 09/07/1997 18:59:51
>... [I realize that most of arch/foo/foo/conf.c could be generated,
>but I don't think we are ready for that yet]
Hm... did I ever describe the config code in BSD/OS that does this?
Here are a few lines from my sparc/conf/ioconf.c.sparc file, for
an example:
/*
* Template ioconf.c for sparc.
*/
#include <sys/param.h>
#include <sys/conf.h>
#include <sys/device.h>
#include <sys/vnode.h>
%CONFIG
extern struct devsw cnsw, cttysw, mmsw, swapsw, logsw, devfdsw;
extern struct devsw ptssw, ptcsw;
extern struct devsw mssw, fbsw, kbdsw, openpromsw;
%DECLSW
/*
* The table here is derived from Sun's /dev/MAKEDEV. I am not sure
* what all of these are, but if we stick to Sun's numbering, we should
* be pretty well off.
*/
struct devsw *devsw[] = {
&cnsw, /* 0 = virtual console */
NULL, /* 1 = "oct" tty */
&cttysw, /* 2 = controlling terminal */
[...]
%DEVSW(pty, &ptssw), /* 20 = pseudo-tty slave */
%DEVSW(pty, &ptcsw), /* 21 = pseudo-tty master */
[...]
%DEVSW(fd), /* 54 = floppy */
%DEVSW(cgthree), /* 55 = /dev/cgthree */
There are four %-keywords that are decoded here:
%CONFIG emits the configuration (cfdata, locators, etc.).
%DECLSW emits "extern struct devsw XXsw" for all
configured devices.
%DEVSW(x) emits &xxsw if device x is configured, else NULL
%DEVSW(x,y) emits y if device x is configured, else NULL
%IFSEL(x,y) emits y if option x is selected, else NULL
%IFSEL(x,y,z) emits y if option x is selected, else z
This is pretty simple yet flexible -- for instance, you can do:
int dougs_special_weird_mode = %IFSEL(dougsmode,1,0);
which will set `dougs_special_weird_mode' under `options DOUGSMODE'.
Note that y and z may not contain commas (and, in my current
implementation, spaces are dropped too, mainly as a side effect).
There are, of course, a bunch of related changes (no more separate
bdevsw and cdevsw, the devsw array is a table of pointers, and each
driver defines its own XXsw structure).
Chris