2300: #
2301: /*
2302:  */
2303: 
2304: #include "../param.h"
2305: #include "../seg.h"
2306: #include "../buf.h"
2307: #include "../conf.h"
2308: 
2309: /*
2310:  * Address and structure of the
2311:  * KL-11 console device registers.
2312:  */
2313: struct
2314: {
2315:         int     rsr;
2316:         int     rbr;
2317:         int     xsr;
2318:         int     xbr;
2319: };
2320: /* ---------------------------       */
2321: 
2322: /*
2323:  * In case console is off,
2324:  * panicstr contains argument to last
2325:  * call to panic.
2326:  */
2327: 
2328: char    *panicstr;
2329: 
2330: /*
2331:  * Scaled down version of C Library printf.
2332:  * Only %s %l %d (==%l) %o are recognized.
2333:  * Used to print diagnostic information
2334:  * directly on console tty.
2335:  * Since it is not interrupt driven,
2336:  * all system activities are pretty much
2337:  * suspended.
2338:  * Printf should not be used for chit-chat.
2339:  */
2340: printf(fmt,x1,x2,x3,x4,x5,x6,x7,x8,x9,xa,xb,xc)
2341: char fmt[];
2342: {
2343:         register char *s;
2344:         register *adx, c;
2345: 
2346:         adx = &x1;
2347: loop:
2348:         while((c = *fmt++) != '%') {
2349:                 if(c == '\0')
2350:                         return;
2351:                 putchar(c);
2352:         }
2353:         c = *fmt++;
2354:         if(c == 'd' || c == 'l' || c == 'o')
2355:                 printn(*adx, c=='o'? 8: 10);
2356:         if(c == 's') {
2357:                 s = *adx;
2358:                 while(c = *s++)
2359:                         putchar(c);
2360:         }
2361:         adx++;
2362:         goto loop;
2363: }
2364: /* ---------------------------       */
2365: 
2366: /*
2367:  * Print an unsigned integer in base b.
2368:  */
2369: printn(n, b)
2370: {
2371:         register a;
2372: 
2373:         if(a = ldiv(n, b))
2374:                 printn(a, b);
2375:         putchar(lrem(n, b) + '0');
2376: }
2377: /* ---------------------------       */
2378: 
2379: /*
2380:  * Print a character on console.
2381:  * Attempts to save and restore device
2382:  * status.
2383:  * If the switches are 0, all
2384:  * printing is inhibited.
2385:  */
2386: putchar(c)
2387: {
2388:         register rc, s;
2389: 
2390:         rc = c;
2391:         if(SW->integ == 0)
2392:                 return;
2393:         while((KL->xsr&0200) == 0)
2394:                 ;
2395:         if(rc == 0)
2396:                 return;
2397:         s = KL->xsr;
2398:         KL->xsr = 0;
2399:         KL->xbr = rc;
2400:         if(rc == '\n') {
2401:                 putchar('\r');
2402:                 putchar(0177);
2403:                 putchar(0177);
2404:         }
2405:         putchar(0);
2406:         KL->xsr = s;
2407: }
2408: /* ---------------------------       */
2409: 
2410: /*
2411:  * Panic is called on unresolvable
2412:  * fatal errors.
2413:  * It syncs, prints "panic: mesg" and
2414:  * then loops.
2415:  */
2416: panic(s)
2417: char *s;
2418: {
2419:         panicstr = s;
2420:         update();
2421:         printf("panic: %s\n", s);
2422:         for(;;)
2423:                 idle();
2424: }
2425: /* ---------------------------       */
2426: 
2427: /*
2428:  * prdev prints a warning message of the
2429:  * form "mesg on dev x/y".
2430:  * x and y are the major and minor parts of
2431:  * the device argument.
2432:  */
2433: prdev(str, dev)
2434: {
2435: 
2436:         printf("%s on dev %l/%l\n", str, dev.d_major, dev.d_minor);
2437: }
2438: /* ---------------------------       */
2439: 
2440: /*
2441:  * deverr prints a diagnostic from
2442:  * a device driver.
2443:  * It prints the device, block number,
2444:  * and an octal word (usually some error
2445:  * status register) passed as argument.
2446:  */
2447: deverror(bp, o1, o2)
2448: int *bp;
2449: {
2450:         register *rbp;
2451: 
2452:         rbp = bp;
2453:         prdev("err", rbp->b_dev);
2454:         printf("bn%l er%o %o\n", rbp->b_blkno, o1, o2);
2455: }
2456: /* ---------------------------       */