1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
|
/* $NetBSD: putdriver.c,v 1.4 1994/06/29 06:41:15 cgd Exp $ */
/*
* This code is such a kludge that I don't want to put my name on it.
* It was a ridiculously fast hack and needs rewriting.
* However it does work...
*/
/* The original idea was to put all the driver code
* in one place so it would be easy to modify
* but as hacks got thrown in it got worse and worse...
* It's to the point where a user would be better off
* writing his own driver and xebec should JUST produce
* the tables.
*/
#include <stdio.h>
#include "main.h"
#include "debug.h"
extern char protocol[];
char Eventshiftstring[10];
static char statename[] = {'_', 's', 't', 'a', 't', 'e', 0 };
static char *strings[] = {
#define PART1 { 0,3 }
"\n#include \"",
kerneldirname,
protocol,
"_states.h\"",
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
#define PART12 { 10,12 }
"\n\nstatic struct act_ent {\n",
"\tint a_newstate;\n\tint a_action;\n",
"} statetable[] = { {0,0},\n",
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
#define PART2 { 20,20 }
"};\n",
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
#define PART3 { 30,41 }
"\n",
protocol,
"_driver(p, e)\nregister ",
protocol,
PCBNAME,
" *p;\nregister struct ",
protocol,
"_event *e;\n",
"{\n",
"\tregister int index, error=0;\n",
"\tstruct act_ent *a;\n",
"\tstatic struct act_ent erroraction = {0,-1};\n",
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
#define PART4 { 50,54 }
"\textern int ",
protocol,
"_debug;\n\textern FILE *",
protocol,
"_astringfile;\n",
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
#define PART6 { 60, 65 }
"\n\tindex = inx[1 + e->ev_number][p->",
protocol,
statename,
"];\n\tif(index<0) index=_Xebec_index(e, p);\n",
"\tif (index==0) {\n\t\ta = &erroraction;\n",
"\t} else\n\t\ta = &statetable[index];\n\n",
(char *)0,
(char *)0,
(char *)0,
(char *)0,
#define PART7 {70, 77 }
"\tif(",
protocol,
"_debug) fprintf(",
protocol,
"_astringfile, \"%15s <-- %15s [%15s] \\n\\t%s\\n\",\n",
"\t\tsstring[a->a_newstate], sstring[p->",
protocol,
"_state], estring[e->ev_number], astring[a->a_action]);\n\n",
(char *)0,
(char *)0,
#define PART8 { 80, 84 }
"\tif(a->a_action)\n",
"\t\terror = _Xebec_action( a->a_action, e, p );\n",
"\tif(error==0)\n\tp->",
protocol,
"_state = a->a_newstate;\n\treturn error;\n}\n",
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
#define PART9 { 90, 99 }
"\n_XEBEC_PG int _Xebec_action(a,e,p)\nint a;\nstruct ",
protocol,
"_event *e;\n",
protocol,
PCBNAME,
" *p;\n{\n",
"switch(a) {\n",
"case -1: return ",
protocol,
"_protocol_error(e,p);\n",
(char *)0,
#define PART10 { 101, 105 }
"\tif(",
protocol,
"_debug) fprintf(",
protocol,
"_astringfile, \"index 0x%5x\\n\", index);\n",
(char *)0,
(char *)0,
(char *)0,
(char *)0,
#define PART5 { 110, 121 }
"\n_XEBEC_PG int\n_Xebec_index( e,p )\n",
"\tstruct ",
protocol,
"_event *e;\n\t",
protocol,
PCBNAME,
" *p;\n{\nswitch( (e->ev_number<<",
Eventshiftstring,
")+(p->",
protocol,
statename,
") ) {\n",
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
(char *)0,
#define PART11 {130, 137 }
"\tIFTRACE(D_DRIVER)\n",
"\t",
protocol,
"trace(DRIVERTRACE,",
"\t\ta->a_newstate, p->",
protocol,
"_state, e->ev_number, a->a_action, 0);\n\n",
"\tENDTRACE\n",
(char *)0,
(char *)0,
#define PART13 {140, 147 }
"\tif(",
protocol,
"_debug) fprintf(",
protocol,
"_astringfile, \"%15s <-- %15s [%15s] \\n\",\n",
"\t\tsstring[a->a_newstate], sstring[p->",
protocol,
"_state], estring[e->ev_number]);\n\n",
(char *)0,
(char *)0,
#define PART14 { 150,150 }
"#define _XEBEC_PG static\n",
#define PART15 { 151,151 }
"#define _XEBEC_PG \n",
};
static struct { int start; int finish; } parts[] = {
{ 0,0 },
PART1,
PART2,
PART3,
PART4,
PART5,
PART6,
PART7,
PART8,
PART9,
PART10,
PART11,
PART12,
PART13,
PART14,
PART15,
};
putdriver(f, x)
FILE *f;
int x;
{
register int i;
for( i = parts[x].start; i<= parts[x].finish; i++)
fprintf(f, "%s", strings[i]);
IFDEBUG(d)
fflush(f);
ENDDEBUG
}
|