1 /* $NetBSD: putdriver.c,v 1.8 2005/12/11 12:25:16 christos Exp $ */
4 * This code is such a kludge that I don't want to put my name on it.
5 * It was a ridiculously fast hack and needs rewriting.
6 * However it does work...
9 /* The original idea was to put all the driver code
10 * in one place so it would be easy to modify
11 * but as hacks got thrown in it got worse and worse...
12 * It's to the point where a user would be better off
13 * writing his own driver and xebec should JUST produce
17 #include <sys/cdefs.h>
18 __KERNEL_RCSID(0, "$NetBSD: putdriver.c,v 1.8 2005/12/11 12:25:16 christos Exp $");
24 extern char protocol
[];
25 char Eventshiftstring
[10];
26 static char statename
[] = {'_', 's', 't', 'a', 't', 'e', 0 };
28 static char *strings
[] = {
43 #define PART12 { 10,12 }
44 "\n\nstatic struct act_ent {\n",
45 "\tint a_newstate;\n\tint a_action;\n",
46 "} statetable[] = { {0,0},\n",
55 #define PART2 { 20,20 }
67 #define PART3 { 30,41 }
70 "_driver(p, e)\nregister ",
73 " *p;\nregister struct ",
77 "\tregister int index, error=0;\n",
78 "\tstruct act_ent *a;\n",
79 "\tstatic struct act_ent erroraction = {0,-1};\n",
89 #define PART4 { 50,54 }
93 "_debug;\n\textern FILE *",
102 #define PART6 { 60, 65 }
103 "\n\tindex = inx[1 + e->ev_number][p->",
106 "];\n\tif(index<0) index=_Xebec_index(e, p);\n",
107 "\tif (index==0) {\n\t\ta = &erroraction;\n",
108 "\t} else\n\t\ta = &statetable[index];\n\n",
114 #define PART7 {70, 77 }
119 "_astringfile, \"%15s <-- %15s [%15s] \\n\\t%s\\n\",\n",
120 "\t\tsstring[a->a_newstate], sstring[p->",
122 "_state], estring[e->ev_number], astring[a->a_action]);\n\n",
126 #define PART8 { 80, 84 }
127 "\tif(a->a_action)\n",
128 "\t\terror = _Xebec_action( a->a_action, e, p );\n",
129 "\tif(error==0)\n\tp->",
131 "_state = a->a_newstate;\n\treturn error;\n}\n",
138 #define PART9 { 90, 99 }
139 "\n_XEBEC_PG int _Xebec_action(a,e,p)\nint a;\nstruct ",
148 "_protocol_error(e,p);\n",
151 #define PART10 { 101, 105 }
156 "_astringfile, \"index 0x%5x\\n\", index);\n",
162 #define PART5 { 110, 121 }
163 "\n_XEBEC_PG int\n_Xebec_index( e,p )\n",
169 " *p;\n{\nswitch( (e->ev_number<<",
184 #define PART11 {130, 137 }
185 "\tIFTRACE(D_DRIVER)\n",
188 "trace(DRIVERTRACE,",
189 "\t\ta->a_newstate, p->",
191 "_state, e->ev_number, a->a_action, 0);\n\n",
196 #define PART13 {140, 147 }
201 "_astringfile, \"%15s <-- %15s [%15s] \\n\",\n",
202 "\t\tsstring[a->a_newstate], sstring[p->",
204 "_state], estring[e->ev_number]);\n\n",
208 #define PART14 { 150,150 }
209 "#define _XEBEC_PG static\n",
211 #define PART15 { 151,151 }
212 "#define _XEBEC_PG \n",
216 static struct { int start
; int finish
; } parts
[] = {
236 putdriver(FILE *f
, int x
)
240 for( i
= parts
[x
].start
; i
<= parts
[x
].finish
; i
++)
241 fprintf(f
, "%s", strings
[i
]);