xref: /original-bsd/usr.sbin/config/mkubglue.c (revision 82cc5172)
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
8 static char sccsid[] = "@(#)mkubglue.c	5.2 (Berkeley) 12/02/90";
9 #endif not lint
10 
11 /*
12  * Make the uba interrupt file ubglue.s
13  */
14 #include <stdio.h>
15 #include "config.h"
16 #include "y.tab.h"
17 
18 ubglue()
19 {
20 	register FILE *fp;
21 	register struct device *dp, *mp;
22 
23 	fp = fopen(path("ubglue.s"), "w");
24 	if (fp == 0) {
25 		perror(path("ubglue.s"));
26 		exit(1);
27 	}
28 	for (dp = dtab; dp != 0; dp = dp->d_next) {
29 		mp = dp->d_conn;
30 		if (mp != 0 && mp != (struct device *)-1 &&
31 		    !eq(mp->d_name, "mba")) {
32 			struct idlst *id, *id2;
33 
34 			for (id = dp->d_vec; id; id = id->id_next) {
35 				for (id2 = dp->d_vec; id2; id2 = id2->id_next) {
36 					if (id2 == id) {
37 						dump_vec(fp, id->id, dp->d_unit);
38 						break;
39 					}
40 					if (!strcmp(id->id, id2->id))
41 						break;
42 				}
43 			}
44 		}
45 	}
46 	dump_std(fp);
47 	for (dp = dtab; dp != 0; dp = dp->d_next) {
48 		mp = dp->d_conn;
49 		if (mp != 0 && mp != (struct device *)-1 &&
50 		    !eq(mp->d_name, "mba")) {
51 			struct idlst *id, *id2;
52 
53 			for (id = dp->d_vec; id; id = id->id_next) {
54 				for (id2 = dp->d_vec; id2; id2 = id2->id_next) {
55 					if (id2 == id) {
56 						dump_intname(fp, id->id,
57 							dp->d_unit);
58 						break;
59 					}
60 					if (!strcmp(id->id, id2->id))
61 						break;
62 				}
63 			}
64 		}
65 	}
66 	dump_ctrs(fp);
67 	(void) fclose(fp);
68 }
69 
70 static int cntcnt = 0;		/* number of interrupt counters allocated */
71 
72 /*
73  * print an interrupt vector
74  */
75 dump_vec(fp, vector, number)
76 	register FILE *fp;
77 	char *vector;
78 	int number;
79 {
80 	char nbuf[80];
81 	register char *v = nbuf;
82 
83 	(void) sprintf(v, "%s%d", vector, number);
84 	fprintf(fp, "\t.globl\t_X%s\n\t.align\t2\n_X%s:\n\tpushr\t$0x3f\n",
85 	    v, v);
86 	fprintf(fp, "\tincl\t_fltintrcnt+(4*%d)\n", cntcnt++);
87 	if (strncmp(vector, "dzx", 3) == 0)
88 		fprintf(fp, "\tmovl\t$%d,r0\n\tjmp\tdzdma\n\n", number);
89 	else if (strncmp(vector, "dpx", 3) == 0)
90 		fprintf(fp, "\tmovl\t$%d,r0\n\tjmp\tdpxdma\n\n", number);
91 	else if (strncmp(vector, "dpr", 3) == 0)
92 		fprintf(fp, "\tmovl\t$%d,r0\n\tjmp\tdprdma\n\n", number);
93 	else {
94 		if (strncmp(vector, "uur", 3) == 0) {
95 			fprintf(fp, "#ifdef UUDMA\n");
96 			fprintf(fp, "\tmovl\t$%d,r0\n\tjsb\tuudma\n", number);
97 			fprintf(fp, "#endif\n");
98 		}
99 		fprintf(fp, "\tpushl\t$%d\n", number);
100 		fprintf(fp, "\tcalls\t$1,_%s\n\tpopr\t$0x3f\n", vector);
101 		fprintf(fp, "\tincl\t_cnt+V_INTR\n\trei\n\n");
102 	}
103 }
104 
105 /*
106  * Start the interrupt name table with the names
107  * of the standard vectors not on the unibus.
108  * The number and order of these names should correspond
109  * with the definitions in scb.s.
110  */
111 dump_std(fp)
112 	register FILE *fp;
113 {
114 	fprintf(fp, "\n\t.globl\t_intrnames\n");
115 	fprintf(fp, "\n\t.globl\t_eintrnames\n");
116 	fprintf(fp, "\t.data\n");
117 	fprintf(fp, "_intrnames:\n");
118 	fprintf(fp, "\t.asciz\t\"clock\"\n");
119 	fprintf(fp, "\t.asciz\t\"cnr\"\n");
120 	fprintf(fp, "\t.asciz\t\"cnx\"\n");
121 	fprintf(fp, "\t.asciz\t\"tur\"\n");
122 	fprintf(fp, "\t.asciz\t\"tux\"\n");
123 	fprintf(fp, "\t.asciz\t\"mba0\"\n");
124 	fprintf(fp, "\t.asciz\t\"mba1\"\n");
125 	fprintf(fp, "\t.asciz\t\"mba2\"\n");
126 	fprintf(fp, "\t.asciz\t\"mba3\"\n");
127 	fprintf(fp, "\t.asciz\t\"uba0\"\n");
128 	fprintf(fp, "\t.asciz\t\"uba1\"\n");
129 	fprintf(fp, "\t.asciz\t\"uba2\"\n");
130 	fprintf(fp, "\t.asciz\t\"uba3\"\n");
131 #define	I_FIXED		13			/* number of names above */
132 }
133 
134 dump_intname(fp, vector, number)
135 	register FILE *fp;
136 	char *vector;
137 	int number;
138 {
139 	register char *cp = vector;
140 
141 	fprintf(fp, "\t.asciz\t\"");
142 	/*
143 	 * Skip any "int" or "intr" in the name.
144 	 */
145 	while (*cp)
146 		if (cp[0] == 'i' && cp[1] == 'n' &&  cp[2] == 't') {
147 			cp += 3;
148 			if (*cp == 'r')
149 				cp++;
150 		} else {
151 			putc(*cp, fp);
152 			cp++;
153 		}
154 	fprintf(fp, "%d\"\n", number);
155 }
156 
157 dump_ctrs(fp)
158 	register FILE *fp;
159 {
160 	fprintf(fp, "_eintrnames:\n");
161 	fprintf(fp, "\n\t.globl\t_intrcnt\n");
162 	fprintf(fp, "\n\t.globl\t_eintrcnt\n");
163 	fprintf(fp, "_intrcnt:\n", I_FIXED);
164 	fprintf(fp, "\t.space\t4 * %d\n", I_FIXED);
165 	fprintf(fp, "_fltintrcnt:\n", cntcnt);
166 	fprintf(fp, "\t.space\t4 * %d\n", cntcnt);
167 	fprintf(fp, "_eintrcnt:\n\n");
168 	fprintf(fp, "\t.text\n");
169 }
170