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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
|
/* $OpenBSD: procs.c,v 1.2 1996/03/04 10:37:16 mickey Exp $ */
/* $NetBSD: procs.c,v 1.4 1994/06/29 06:41:12 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...
*/
#include <stdio.h>
#include <strings.h>
#include "malloc.h"
#include "main.h"
#include "debug.h"
#include "sets.h"
#include "procs.h"
struct Predicate {
int p_index;
int p_transno;
char *p_str;
struct Predicate *p_next;
};
struct Stateent {
int s_index;
int s_newstate;
int s_action;
struct Stateent *s_next;
};
struct Object *SameState = (struct Object *)-1;
int Index = 0;
int Nstates = 0;
int Nevents = 0;
struct Predicate **Predlist;
struct Stateent **Statelist;
extern FILE *astringfile;
end_events() {
int size, part;
char *addr;
IFDEBUG(X)
/* finish estring[], start astring[] */
if(debug['X'] < 2 )
fprintf(astringfile, "};\n\nchar *%s_astring[] = {\n\"NULLACTION\",\n",
protocol);
ENDDEBUG
/* NOSTRICT */
Statelist =
(struct Stateent **) Malloc((Nstates+1) * sizeof(struct Statent *));
/* NOSTRICT */
Predlist =
(struct Predicate **)
Malloc ( (((Nevents)<<Eventshift)+Nstates)*sizeof(struct Predicate *) );
size = (((Nevents)<<Eventshift)+Nstates)*sizeof(struct Predicate *) ;
addr = (char *)Predlist;
IFDEBUG(N)
fprintf(OUT, "Predlist at 0x%x, sbrk 0x%x bzero size %d at addr 0x%x\n",
Predlist, sbrk(0), size, addr);
ENDDEBUG
#define BZSIZE 8192
while(size) {
part = size>BZSIZE?BZSIZE:size;
IFDEBUG(N)
fprintf(OUT, "bzero addr 0x%x part %d size %d\n",addr, part, size);
ENDDEBUG
bzero(addr, part);
IFDEBUG(N)
fprintf(OUT, "after bzero addr 0x%x part %d size %d\n",addr, part, size);
ENDDEBUG
addr += part;
size -= part;
}
IFDEBUG(N)
fprintf(OUT, "endevents..done \n");
ENDDEBUG
}
int acttable(f,actstring)
char *actstring;
FILE *f;
{
static Actindex = 0;
extern FILE *astringfile;
extern int pgoption;
IFDEBUG(a)
fprintf(OUT,"acttable()\n");
ENDDEBUG
fprintf(f, "case 0x%x: \n", ++Actindex);
if(pgoption) {
fprintf(f, "asm(\" # dummy statement\");\n");
fprintf(f, "asm(\"_Xebec_action_%x: \");\n", Actindex );
fprintf(f, "asm(\".data\");\n");
fprintf(f, "asm(\".globl _Xebec_action_%x# X profiling\");\n",
Actindex );
fprintf(f, "asm(\".long 0 # X profiling\");\n");
fprintf(f, "asm(\".text # X profiling\");\n");
fprintf(f, "asm(\"cas r0,r15,r0 # X profiling\");\n");
fprintf(f, "asm(\"bali r15,mcount # X profiling\");\n");
}
fprintf(f, "\t\t%s\n\t\t break;\n", actstring);
IFDEBUG(X)
if(debug['X']<2) {
register int len = 0;
fputc('"',astringfile);
while(*actstring) {
if( *actstring == '\n' ) {
fputc('\\', astringfile);
len++;
fputc('n', astringfile);
} else if (*actstring == '\\') {
fputc('\\', astringfile);
len ++;
fputc('\\', astringfile);
} else if (*actstring == '\"') {
fputc('\\', astringfile);
len ++;
fputc('\"', astringfile);
} else fputc(*actstring, astringfile);
actstring++;
len++;
}
fprintf(astringfile,"\",\n");
if (len > LINELEN) {
fprintf(stderr, "Action too long: %d\n",len); Exit(-1);
}
}
ENDDEBUG
return(Actindex);
}
static int Npred=0, Ndefpred=0, Ntrans=0, Ndefevent=0, Nnulla=0;
statetable(string, oldstate, newstate, action, event)
char *string;
int action;
struct Object *oldstate, *newstate, *event;
{
register int different;
IFDEBUG(a)
fprintf(OUT,"statetable(0x%x, 0x%x,0x%x, 0x%x)\n",
string, oldstate, newstate, action);
fprintf(OUT,"statetable(%s, %s,%s, 0x%x)\n",
string, oldstate->obj_name, newstate->obj_name, action);
ENDDEBUG
if( !action) Nnulla++;
if( newstate->obj_kind == OBJ_SET) {
fprintf(stderr, "Newstate cannot be a set\n");
Exit(-1);
}
different = (newstate != SameState);
(void) predtable( oldstate, event, string,
action, (newstate->obj_number) * different );
IFDEBUG(a)
fprintf(OUT,"EXIT statetable\n");
ENDDEBUG
}
stateentry(index, oldstate, newstate, action)
int index, action;
int oldstate, newstate;
{
extern FILE *statevalfile;
IFDEBUG(a)
fprintf(OUT,"stateentry(0x%x,0x%x,0x%x,0x%x) Statelist@0x%x, val 0x%x\n",
index, oldstate, newstate,action, &Statelist, Statelist);
ENDDEBUG
fprintf(statevalfile, "{0x%x,0x%x},\n", newstate, action);
}
int predtable(os, oe, str, action, newstate)
struct Object *os, *oe;
char *str;
int action, newstate;
{
register struct Predicate *p, **q;
register int event, state;
register struct Object *e, *s;
struct Object *firste;
if (oe == (struct Object *)0 ) {
Ndefevent ++;
fprintf(stderr, "DEFAULT EVENTS aren't implemented; trans ignored\n");
return;
}
Ntrans++;
IFDEBUG(g)
fprintf(stdout,
"PREDTAB: s %5s; e %5s\n", os->obj_kind==OBJ_SET?"SET":"item",
oe->obj_kind==OBJ_SET?"SET":"item");
ENDDEBUG
if (os->obj_kind == OBJ_SET) s = os->obj_members;
else s = os;
if (oe->obj_kind == OBJ_SET) firste = oe->obj_members;
else firste = oe;
if(newstate) {
fprintf(statevalfile, "{0x%x,0x%x},\n",newstate, action);
Index++;
}
while (s) {
if( !newstate ) { /* !newstate --> SAME */
/* i.e., use old obj_number */
fprintf(statevalfile, "{0x%x,0x%x},\n",s->obj_number, action);
Index++;
}
e = firste;
while (e) {
event = e->obj_number; state = s->obj_number;
IFDEBUG(g)
fprintf(stdout,"pred table event=0x%x, state 0x%x\n",
event, state);
fflush(stdout);
ENDDEBUG
if( !str /* DEFAULT PREDICATE */) {
Ndefpred++;
IFDEBUG(g)
fprintf(stdout,
"DEFAULT pred state 0x%x, event 0x%x, Index 0x%x\n",
state, event, Index);
fflush(stdout);
ENDDEBUG
} else
Npred++;
/* put at END of list */
#ifndef LINT
IFDEBUG(g)
fprintf(stdout,
"predicate for event 0x%x, state 0x%x is 0x%x, %s\n",
event, state, Index, str);
fflush(stdout);
ENDDEBUG
#endif LINT
for( ((q = &Predlist[(event<<Eventshift)+state]),
(p = Predlist[(event<<Eventshift)+state]));
p ; p = p->p_next ) {
q = &p->p_next;
}
p = (struct Predicate *)Malloc(sizeof(struct Predicate));
p->p_next = (struct Predicate *)0;
p->p_str = str;
p->p_index = Index;
p->p_transno = transno;
*q = p;
IFDEBUG(g)
fprintf(stdout,
"predtable index 0x%x, transno %d, E 0x%x, S 0x%x\n",
Index, transno, e, s);
ENDDEBUG
e = e->obj_members;
}
s = s->obj_members;
}
return Index ;
}
printprotoerrs()
{
register int e,s;
fprintf(stderr, "[ Event, State ] without any transitions :\n");
for(e = 0; e < Nevents; e++) {
fprintf(stderr, "Event 0x%x: states ", e);
for(s = 0; s < Nstates; s++) {
if( Predlist[(e<<Eventshift)+s] == 0 )
fprintf(stderr, "0x%x ", s);
}
fprintf(stderr, "\n");
}
}
#ifndef LINT
dump_predtable(f)
FILE *f;
{
struct Predicate *p;
register int e,s, hadapred;
int defaultindex;
int defaultItrans;
extern int bytesmalloced;
extern int byteswasted;
#ifdef notdef
fprintf(stdout,
" Xebec used %8d bytes of storage, wasted %8d bytes\n",
bytesmalloced, byteswasted);
#endif notdef
fprintf(stdout,
" %8d states\n %8d events\n %8d transitions\n",
Nstates, Nevents, Ntrans);
fprintf(stdout,
" %8d predicates\n %8d default predicates used\n",
Npred, Ndefpred);
fprintf(stdout,
" %8d null actions\n",
Nnulla);
putdriver(f, 5);
for(e = 0; e < Nevents; e++) { for(s = 0; s < Nstates; s++) {
p = Predlist[(e<<Eventshift)+s];
hadapred=0;
defaultindex=0;
defaultItrans=0;
if(p) {
IFDEBUG(d)
fflush(f);
ENDDEBUG
while(p) {
if(p->p_str) {
if(!hadapred)
fprintf(f, "case 0x%x:\n\t", (e<<Eventshift) + s);
hadapred = 1;
fprintf(f, "if %s return 0x%x;\n\t else ",
p->p_str, p->p_index);
} else {
if(defaultindex) {
fprintf(stderr,
"\nConflict between transitions %d and %d: duplicate default \n",
p->p_transno, defaultItrans);
Exit(-1);
}
defaultindex = p->p_index;
defaultItrans = p->p_transno;
}
p = p->p_next;
}
if( hadapred) {
fprintf(f, "return 0x%x;\n", defaultindex);
}
IFDEBUG(d)
fflush(f);
ENDDEBUG
}
IFDEBUG(g)
fprintf(stdout,
"loop: e 0x%x s 0x%x hadapred 0x%x dindex 0x%x for trans 0x%x\n",
e, s, hadapred, defaultindex, defaultItrans);
ENDDEBUG
if ( hadapred ) {
/* put a -1 in the array - Predlist is temporary storage */
Predlist[(e<<Eventshift)+s] = (struct Predicate *)(-1);
} else {
/* put defaultindex in the array */
/* if defaultindex is zero, then the driver will
* cause an erroraction (same as if no default
* were given and none of the predicates were true;
* also same as if no preds or defaults were given
* for this combo)
*/
Predlist[(e<<Eventshift)+s] = (struct Predicate *)(defaultindex);
}
} }
fprintf(f, "default: return 0;\n} /* end switch */\n");
#ifdef notdef
fprintf(f, "/*NOTREACHED*/return 0;\n} /* _Xebec_index() */\n");
#else notdef
fprintf(f, "} /* _Xebec_index() */\n");
#endif notdef
fprintf(f, "static int inx[%d][%d] = { {", Nevents+1,Nstates);
for(s = 0; s< Nstates; s++) fprintf(f, "0,"); /* event 0 */
fprintf(f, "},\n");
for(e = 0; e < Nevents; e++) {
fprintf(f, " {");
for(s = 0; s < Nstates; s++) {
register struct Predicate *xyz = Predlist[(e<<Eventshift)+s];
/* this kludge is to avoid a lint msg. concerning
* loss of bits
*/
if (xyz == (struct Predicate *)(-1))
fprintf(f, "-1,");
else
fprintf(f, "0x%x,", Predlist[(e<<Eventshift)+s]);
}
fprintf(f, " },\n");
}
fprintf(f, "};");
}
#endif LINT
char *
stash(buf)
char *buf;
{
register int len;
register char *c;
/* grot */
len = strlen(buf);
c = Malloc(len+1);
#ifdef LINT
c =
#endif LINT
strcpy(c, buf);
IFDEBUG(z)
fprintf(stdout,"stash %s at 0x%x\n", c,c);
ENDDEBUG
return(c);
}
#ifdef notdef
dump_pentry(event,state)
int event,state;
{
register struct Predicate *p, **q;
for(
((q = &Predlist[(event<<Eventshift) +state]),
(p = Predlist[(event<<Eventshift) + state]));
p!= (struct Predicate *)0 ; p = p->p_next ) {
#ifndef LINT
IFDEBUG(a)
fprintf(OUT,
"dump_pentry for event 0x%x, state 0x%x is 0x%x\n",
event, state, p);
ENDDEBUG
#endif LINT
q = &p->p_next;
}
}
#endif notdef
|