Commit | Line | Data |
---|---|---|
3c79e4ff | 1 | /* subr_prf.c 4.10 %G% */ |
8cbb423c BJ |
2 | |
3 | #include "../h/param.h" | |
4 | #include "../h/systm.h" | |
5 | #include "../h/seg.h" | |
6 | #include "../h/buf.h" | |
7 | #include "../h/conf.h" | |
96d38f03 | 8 | #include "../h/mtpr.h" |
0dc06be8 | 9 | #include "../h/reboot.h" |
90f8d91f BJ |
10 | #include "../h/vm.h" |
11 | #include "../h/msgbuf.h" | |
d11b28dc RE |
12 | #include "../h/dir.h" |
13 | #include "../h/user.h" | |
14 | #include "../h/tty.h" | |
96d38f03 | 15 | |
8cbb423c BJ |
16 | /* |
17 | * In case console is off, | |
18 | * panicstr contains argument to last | |
19 | * call to panic. | |
20 | */ | |
21 | ||
22 | char *panicstr; | |
23 | ||
24 | /* | |
25 | * Scaled down version of C Library printf. | |
26 | * Only %s %u %d (==%u) %o %x %D are recognized. | |
27 | * Used to print diagnostic information | |
28 | * directly on console tty. | |
29 | * Since it is not interrupt driven, | |
30 | * all system activities are pretty much | |
31 | * suspended. | |
32 | * Printf should not be used for chit-chat. | |
33 | */ | |
34 | /*VARARGS1*/ | |
35 | printf(fmt, x1) | |
36 | register char *fmt; | |
37 | unsigned x1; | |
96d38f03 BJ |
38 | { |
39 | ||
40 | prf(fmt, &x1, 0); | |
41 | } | |
42 | ||
843267b1 BJ |
43 | /* |
44 | * print to the current users terminal, | |
45 | * guarantee not to sleep (so can be called by intr routine) | |
46 | * no watermark checking - so no verbose messages | |
47 | */ | |
48 | /*VARARGS1*/ | |
49 | uprintf(fmt, x1) | |
50 | char *fmt; | |
51 | unsigned x1; | |
96d38f03 BJ |
52 | { |
53 | ||
843267b1 | 54 | prf(fmt, &x1, 2); |
96d38f03 BJ |
55 | } |
56 | ||
843267b1 BJ |
57 | /* THIS CODE IS VAX DEPENDENT */ |
58 | prf(fmt, adx, touser) | |
96d38f03 | 59 | register char *fmt; |
843267b1 | 60 | register u_int *adx; |
8cbb423c | 61 | { |
d5726689 | 62 | register int b, c, i; |
8cbb423c | 63 | char *s; |
3c79e4ff | 64 | int any; |
8cbb423c | 65 | |
8cbb423c | 66 | loop: |
843267b1 | 67 | while ((c = *fmt++) != '%') { |
8cbb423c BJ |
68 | if(c == '\0') |
69 | return; | |
843267b1 | 70 | putchar(c, touser); |
8cbb423c | 71 | } |
843267b1 | 72 | again: |
8cbb423c | 73 | c = *fmt++; |
843267b1 BJ |
74 | switch (c) { |
75 | ||
76 | case 'l': | |
77 | goto again; | |
78 | case 'x': case 'X': | |
79 | b = 16; | |
80 | goto number; | |
81 | case 'd': case 'D': | |
82 | case 'u': /* what a joke */ | |
83 | b = 10; | |
84 | goto number; | |
85 | case 'o': case 'O': | |
86 | b = 8; | |
87 | number: | |
88 | printn(*adx, b, touser); | |
89 | break; | |
90 | case 'c': | |
d5726689 BJ |
91 | b = *adx; |
92 | for (i = 24; i >= 0; i -= 8) | |
93 | if (c = (b >> i) & 0x7f) | |
94 | putchar(c, touser); | |
843267b1 | 95 | break; |
3c79e4ff BJ |
96 | case 'b': |
97 | b = *adx++; | |
98 | s = (char *)*adx; | |
99 | printn(b, *s++, touser); | |
100 | any = 0; | |
101 | if (b) { | |
102 | putchar('<', touser); | |
103 | while (i = *s++) { | |
104 | if (b & (1 << (i-1))) { | |
105 | if (any) | |
106 | putchar(',', touser); | |
107 | any = 1; | |
108 | for (; (c = *s) > 32; s++) | |
109 | putchar(c, touser); | |
110 | } else | |
111 | for (; *s > 32; s++) | |
112 | ; | |
113 | } | |
114 | putchar('>', touser); | |
115 | } | |
116 | break; | |
117 | ||
843267b1 | 118 | case 's': |
8cbb423c | 119 | s = (char *)*adx; |
96d38f03 | 120 | while (c = *s++) |
843267b1 BJ |
121 | putchar(c, touser); |
122 | break; | |
8cbb423c BJ |
123 | } |
124 | adx++; | |
125 | goto loop; | |
126 | } | |
843267b1 | 127 | /* END VAX DEPENDENT CODE */ |
8cbb423c | 128 | |
843267b1 BJ |
129 | printn(n, b, touser) |
130 | unsigned long n; | |
8cbb423c | 131 | { |
d5726689 | 132 | char prbuf[11]; |
843267b1 | 133 | register char *cp; |
8cbb423c | 134 | |
843267b1 BJ |
135 | if (b == 10 && (int)n < 0) { |
136 | putchar('-', touser); | |
137 | n = (unsigned)(-(int)n); | |
8cbb423c | 138 | } |
d5726689 | 139 | cp = prbuf; |
843267b1 BJ |
140 | do { |
141 | *cp++ = "0123456789abcdef"[n%b]; | |
142 | n /= b; | |
143 | } while (n); | |
144 | do | |
145 | putchar(*--cp, touser); | |
d5726689 | 146 | while (cp > prbuf); |
8cbb423c BJ |
147 | } |
148 | ||
149 | /* | |
0dc06be8 BJ |
150 | * Panic is called on unresolvable fatal errors. |
151 | * It syncs, prints "panic: mesg", and then reboots. | |
8cbb423c BJ |
152 | */ |
153 | panic(s) | |
154 | char *s; | |
155 | { | |
843267b1 | 156 | |
8cbb423c | 157 | panicstr = s; |
8cbb423c | 158 | printf("panic: %s\n", s); |
934e4ecf | 159 | (void) spl0(); |
8cbb423c | 160 | for(;;) |
9bd7e93d | 161 | boot(RB_PANIC, RB_AUTOBOOT); |
8cbb423c BJ |
162 | } |
163 | ||
164 | /* | |
165 | * prdev prints a warning message of the | |
166 | * form "mesg on dev x/y". | |
167 | * x and y are the major and minor parts of | |
168 | * the device argument. | |
169 | */ | |
170 | prdev(str, dev) | |
843267b1 BJ |
171 | char *str; |
172 | dev_t dev; | |
8cbb423c BJ |
173 | { |
174 | ||
843267b1 | 175 | printf("%s on dev %d/%d\n", str, major(dev), minor(dev)); |
8cbb423c BJ |
176 | } |
177 | ||
3c79e4ff BJ |
178 | harderr(bp) |
179 | struct buf *bp; | |
8cbb423c BJ |
180 | { |
181 | ||
3c79e4ff | 182 | printf("hard err bn %d ", bp->b_blkno); |
8cbb423c | 183 | } |
96d38f03 | 184 | /* |
843267b1 | 185 | * Print a character on console or users terminal. |
96d38f03 BJ |
186 | * If destination is console then the last MSGBUFS characters |
187 | * are saved in msgbuf for inspection later. | |
188 | */ | |
49c84d3f | 189 | /*ARGSUSED*/ |
843267b1 BJ |
190 | putchar(c, touser) |
191 | register int c; | |
96d38f03 | 192 | { |
96d38f03 | 193 | |
843267b1 BJ |
194 | if (touser) { |
195 | register struct tty *tp = u.u_ttyp; | |
d11b28dc | 196 | |
843267b1 BJ |
197 | if (tp && (tp->t_state&CARR_ON)) { |
198 | register s = spl6(); | |
199 | if (c == '\n') | |
200 | ttyoutput('\r', tp); | |
d11b28dc RE |
201 | ttyoutput(c, tp); |
202 | ttstart(tp); | |
203 | splx(s); | |
204 | } | |
205 | return; | |
206 | } | |
cf19cacc | 207 | if (c != '\0' && c != '\r' && c != 0177 && mfpr(MAPEN)) { |
90f8d91f BJ |
208 | if (msgbuf.msg_magic != MSG_MAGIC) { |
209 | msgbuf.msg_bufx = 0; | |
210 | msgbuf.msg_magic = MSG_MAGIC; | |
211 | } | |
212 | if (msgbuf.msg_bufx < 0 || msgbuf.msg_bufx >= MSG_BSIZE) | |
213 | msgbuf.msg_bufx = 0; | |
214 | msgbuf.msg_bufc[msgbuf.msg_bufx++] = c; | |
96d38f03 BJ |
215 | } |
216 | if (c == 0) | |
217 | return; | |
218 | cnputc(c); | |
219 | } |