PREFIX only used in main.c
[unix-history] / usr / src / usr.sbin / config / mkglue.c
CommitLineData
6eca41a6
SL
1/*
2 * Copyright (c) 1980 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
6
7#ifndef lint
19ed21d5 8static char sccsid[] = "@(#)mkglue.c 5.4 (Berkeley) %G%";
6eca41a6
SL
9#endif not lint
10
11/*
12 * Make the bus adaptor interrupt glue files.
13 */
14#include <stdio.h>
15#include "config.h"
16#include "y.tab.h"
17#include <ctype.h>
18
19/*
20 * Create the UNIBUS interrupt vector glue file.
21 */
22ubglue()
23{
24 register FILE *fp, *gp;
25 register struct device *dp, *mp;
26
27 fp = fopen(path("ubglue.s"), "w");
28 if (fp == 0) {
29 perror(path("ubglue.s"));
30 exit(1);
31 }
32 gp = fopen(path("ubvec.s"), "w");
33 if (gp == 0) {
34 perror(path("ubvec.s"));
35 exit(1);
36 }
37 for (dp = dtab; dp != 0; dp = dp->d_next) {
38 mp = dp->d_conn;
39 if (mp != 0 && mp != (struct device *)-1 &&
40 !eq(mp->d_name, "mba")) {
41 struct idlst *id, *id2;
42
43 for (id = dp->d_vec; id; id = id->id_next) {
44 for (id2 = dp->d_vec; id2; id2 = id2->id_next) {
45 if (id2 == id) {
46 dump_ubavec(fp, id->id,
47 dp->d_unit);
48 break;
49 }
50 if (!strcmp(id->id, id2->id))
51 break;
52 }
53 }
54 }
55 }
56 dump_std(fp, gp);
57 for (dp = dtab; dp != 0; dp = dp->d_next) {
58 mp = dp->d_conn;
59 if (mp != 0 && mp != (struct device *)-1 &&
60 !eq(mp->d_name, "mba")) {
61 struct idlst *id, *id2;
62
63 for (id = dp->d_vec; id; id = id->id_next) {
64 for (id2 = dp->d_vec; id2; id2 = id2->id_next) {
65 if (id2 == id) {
66 dump_intname(fp, id->id,
67 dp->d_unit);
68 break;
69 }
70 if (!strcmp(id->id, id2->id))
71 break;
72 }
73 }
74 }
75 }
76 dump_ctrs(fp);
77 (void) fclose(fp);
78 (void) fclose(gp);
79}
80
81static int cntcnt = 0; /* number of interrupt counters allocated */
82
83/*
84 * Print a UNIBUS interrupt vector.
85 */
86dump_ubavec(fp, vector, number)
87 register FILE *fp;
88 char *vector;
89 int number;
90{
91 char nbuf[80];
92 register char *v = nbuf;
93
94 (void) sprintf(v, "%s%d", vector, number);
95 fprintf(fp, "\t.globl\t_X%s\n\t.align\t2\n_X%s:\n\tpushr\t$0x3f\n",
96 v, v);
97 fprintf(fp, "\tincl\t_fltintrcnt+(4*%d)\n", cntcnt++);
98 if (strncmp(vector, "dzx", 3) == 0)
99 fprintf(fp, "\tmovl\t$%d,r0\n\tjmp\tdzdma\n\n", number);
100 else {
101 if (strncmp(vector, "uur", 3) == 0) {
102 fprintf(fp, "#ifdef UUDMA\n");
103 fprintf(fp, "\tmovl\t$%d,r0\n\tjsb\tuudma\n", number);
104 fprintf(fp, "#endif\n");
105 }
106 fprintf(fp, "\tpushl\t$%d\n", number);
107 fprintf(fp, "\tcalls\t$1,_%s\n\tpopr\t$0x3f\n", vector);
108 fprintf(fp, "\tincl\t_cnt+V_INTR\n\trei\n\n");
109 }
110}
111
a0105456
SL
112/*
113 * Create the VERSAbus interrupt vector glue file.
114 */
115vbglue()
116{
117 register FILE *fp, *gp;
118 register struct device *dp, *mp;
119
120 fp = fopen(path("vbglue.s"), "w");
121 if (fp == 0) {
122 perror(path("vbglue.s"));
123 exit(1);
124 }
125 gp = fopen(path("vbvec.s"), "w");
126 if (gp == 0) {
127 perror(path("vbvec.s"));
128 exit(1);
129 }
130 for (dp = dtab; dp != 0; dp = dp->d_next) {
131 struct idlst *id, *id2;
132
133 mp = dp->d_conn;
134 if (mp == 0 || mp == (struct device *)-1 ||
135 eq(mp->d_name, "mba"))
136 continue;
137 for (id = dp->d_vec; id; id = id->id_next)
138 for (id2 = dp->d_vec; id2; id2 = id2->id_next) {
139 if (id == id2) {
140 dump_vbavec(fp, id->id, dp->d_unit);
141 break;
142 }
143 if (eq(id->id, id2->id))
144 break;
145 }
146 }
147 dump_std(fp, gp);
148 for (dp = dtab; dp != 0; dp = dp->d_next) {
149 mp = dp->d_conn;
150 if (mp != 0 && mp != (struct device *)-1 &&
151 !eq(mp->d_name, "mba")) {
152 struct idlst *id, *id2;
153
154 for (id = dp->d_vec; id; id = id->id_next) {
155 for (id2 = dp->d_vec; id2; id2 = id2->id_next) {
156 if (id2 == id) {
157 dump_intname(fp, id->id,
158 dp->d_unit);
159 break;
160 }
161 if (eq(id->id, id2->id))
162 break;
163 }
164 }
165 }
166 }
167 dump_ctrs(fp);
168 (void) fclose(fp);
169 (void) fclose(gp);
170}
171
172/*
173 * Print a VERSAbus interrupt vector
174 */
175dump_vbavec(fp, vector, number)
176 register FILE *fp;
177 char *vector;
178 int number;
179{
180 char nbuf[80];
181 register char *v = nbuf;
182
183 (void) sprintf(v, "%s%d", vector, number);
184 fprintf(fp, "SCBVEC(%s):\n", v);
185 fprintf(fp, "\tCHECK_SFE(4)\n");
186 fprintf(fp, "\tSAVE_FPSTAT(4)\n");
187 fprintf(fp, "\tPUSHR\n");
188 fprintf(fp, "\tincl\t_fltintrcnt+(4*%d)\n", cntcnt++);
189 fprintf(fp, "\tpushl\t$%d\n", number);
190 fprintf(fp, "\tcallf\t$8,_%s\n", vector);
191 fprintf(fp, "\tincl\t_cnt+V_INTR\n");
192 fprintf(fp, "\tPOPR\n");
193 fprintf(fp, "\tREST_FPSTAT\n");
194 fprintf(fp, "\trei\n\n");
195}
196
6eca41a6
SL
197static char *vaxinames[] = {
198 "clock", "cnr", "cnx", "tur", "tux",
199 "mba0", "mba1", "mba2", "mba3",
200 "uba0", "uba1", "uba2", "uba3"
201};
a0105456
SL
202static char *tahoeinames[] = {
203 "clock", "cnr", "cnx", "rmtr", "rmtx", "buserr",
204};
6eca41a6
SL
205static struct stdintrs {
206 char **si_names; /* list of standard interrupt names */
207 int si_n; /* number of such names */
208} stdintrs[] = {
209 { vaxinames, sizeof (vaxinames) / sizeof (vaxinames[0]) },
a0105456 210 { tahoeinames, (sizeof (tahoeinames) / sizeof (tahoeinames[0])) }
6eca41a6
SL
211};
212/*
213 * Start the interrupt name table with the names
214 * of the standard vectors not directly associated
215 * with a bus. Also, dump the defines needed to
216 * reference the associated counters into a separate
217 * file which is prepended to locore.s.
218 */
219dump_std(fp, gp)
220 register FILE *fp, *gp;
221{
222 register struct stdintrs *si = &stdintrs[machine-1];
223 register char **cpp;
224 register int i;
225
226 fprintf(fp, "\n\t.globl\t_intrnames\n");
227 fprintf(fp, "\n\t.globl\t_eintrnames\n");
228 fprintf(fp, "\t.data\n");
229 fprintf(fp, "_intrnames:\n");
230 cpp = si->si_names;
231 for (i = 0; i < si->si_n; i++) {
232 register char *cp, *tp;
233 char buf[80];
234
235 cp = *cpp;
236 if (cp[0] == 'i' && cp[1] == 'n' && cp[2] == 't') {
237 cp += 3;
238 if (*cp == 'r')
239 cp++;
240 }
241 for (tp = buf; *cp; cp++)
242 if (islower(*cp))
243 *tp++ = toupper(*cp);
244 else
245 *tp++ = *cp;
246 *tp = '\0';
247 fprintf(gp, "#define\tI_%s\t%d\n", buf, i*sizeof (long));
248 fprintf(fp, "\t.asciz\t\"%s\"\n", *cpp);
249 cpp++;
250 }
251}
252
253dump_intname(fp, vector, number)
254 register FILE *fp;
255 char *vector;
256 int number;
257{
258 register char *cp = vector;
259
260 fprintf(fp, "\t.asciz\t\"");
261 /*
262 * Skip any "int" or "intr" in the name.
263 */
264 while (*cp)
265 if (cp[0] == 'i' && cp[1] == 'n' && cp[2] == 't') {
266 cp += 3;
267 if (*cp == 'r')
268 cp++;
269 } else {
270 putc(*cp, fp);
271 cp++;
272 }
273 fprintf(fp, "%d\"\n", number);
274}
275
276/*
277 * Reserve space for the interrupt counters.
278 */
279dump_ctrs(fp)
280 register FILE *fp;
281{
282 struct stdintrs *si = &stdintrs[machine-1];
283
284 fprintf(fp, "_eintrnames:\n");
285 fprintf(fp, "\n\t.globl\t_intrcnt\n");
286 fprintf(fp, "\n\t.globl\t_eintrcnt\n");
287 fprintf(fp, "\t.align 2\n");
288 fprintf(fp, "_intrcnt:\n");
289 fprintf(fp, "\t.space\t4 * %d\n", si->si_n);
19ed21d5 290 fprintf(fp, "_fltintrcnt:\n");
6eca41a6
SL
291 fprintf(fp, "\t.space\t4 * %d\n", cntcnt);
292 fprintf(fp, "_eintrcnt:\n\n");
293 fprintf(fp, "\t.text\n");
294}