123236Smckusick /* 229305Smckusick * Copyright (c) 1982, 1986 Regents of the University of California. 323236Smckusick * All rights reserved. The Berkeley software License Agreement 423236Smckusick * specifies the terms and conditions for redistribution. 523236Smckusick * 6*35402Stef * @(#)prf.c 7.6 (Berkeley) 08/27/88 723236Smckusick */ 8324Sbill 933408Skarels #include "param.h" 10324Sbill 119186Ssam #include "../vax/mtpr.h" 129186Ssam #include "../vax/cons.h" 139186Ssam 14324Sbill /* 15324Sbill * Scaled down version of C Library printf. 163262Swnj * Used to print diagnostic information directly on console tty. 173262Swnj * Since it is not interrupt driven, all system activities are 183262Swnj * suspended. Printf should not be used for chit-chat. 193262Swnj * 203262Swnj * One additional format: %b is supported to decode error registers. 213262Swnj * Usage is: 223262Swnj * printf("reg=%b\n", regval, "<base><arg>*"); 233262Swnj * Where <base> is the output base expressed as a control character, 243262Swnj * e.g. \10 gives octal; \20 gives hex. Each arg is a sequence of 253262Swnj * characters, the first of which gives the bit number to be inspected 263262Swnj * (origin 1), and the next characters (up to a control character, i.e. 273262Swnj * a character <= 32), give the name of the register. Thus 283262Swnj * printf("reg=%b\n", 3, "\10\2BITTWO\1BITONE\n"); 293262Swnj * would produce output: 303262Swnj * reg=2<BITTWO,BITONE> 31324Sbill */ 32324Sbill /*VARARGS1*/ 33324Sbill printf(fmt, x1) 343262Swnj char *fmt; 353262Swnj unsigned x1; 36324Sbill { 373262Swnj 383262Swnj prf(fmt, &x1); 393262Swnj } 403262Swnj 413262Swnj prf(fmt, adx) 423262Swnj register char *fmt; 433262Swnj register u_int *adx; 443262Swnj { 453262Swnj register int b, c, i; 46324Sbill char *s; 473262Swnj int any; 48324Sbill 49324Sbill loop: 503262Swnj while ((c = *fmt++) != '%') { 51324Sbill if(c == '\0') 52324Sbill return; 53324Sbill putchar(c); 54324Sbill } 553262Swnj again: 56324Sbill c = *fmt++; 573262Swnj /* THIS CODE IS VAX DEPENDENT IN HANDLING %l? AND %c */ 583262Swnj switch (c) { 593262Swnj 603262Swnj case 'l': 613262Swnj goto again; 623262Swnj case 'x': case 'X': 633262Swnj b = 16; 643262Swnj goto number; 653262Swnj case 'd': case 'D': 663262Swnj case 'u': /* what a joke */ 673262Swnj b = 10; 683262Swnj goto number; 693262Swnj case 'o': case 'O': 703262Swnj b = 8; 713262Swnj number: 723262Swnj printn((u_long)*adx, b); 733262Swnj break; 743262Swnj case 'c': 753262Swnj b = *adx; 763262Swnj for (i = 24; i >= 0; i -= 8) 773262Swnj if (c = (b >> i) & 0x7f) 783262Swnj putchar(c); 793262Swnj break; 803262Swnj case 'b': 813262Swnj b = *adx++; 82324Sbill s = (char *)*adx; 833262Swnj printn((u_long)b, *s++); 843262Swnj any = 0; 853262Swnj if (b) { 863262Swnj while (i = *s++) { 873262Swnj if (b & (1 << (i-1))) { 8826507Skarels putchar(any? ',' : '<'); 893262Swnj any = 1; 903262Swnj for (; (c = *s) > 32; s++) 913262Swnj putchar(c); 923262Swnj } else 933262Swnj for (; *s > 32; s++) 943262Swnj ; 953262Swnj } 9626507Skarels if (any) 9726507Skarels putchar('>'); 983262Swnj } 993262Swnj break; 1003262Swnj 1013262Swnj case 's': 1023262Swnj s = (char *)*adx; 1033262Swnj while (c = *s++) 104324Sbill putchar(c); 1053262Swnj break; 106324Sbill } 107324Sbill adx++; 108324Sbill goto loop; 109324Sbill } 110324Sbill 111324Sbill /* 112324Sbill * Print a character on console. 113324Sbill */ 114324Sbill putchar(c) 1153262Swnj register c; 116324Sbill { 117324Sbill register s, timo; 118*35402Stef #if VAX630 || VAX650 11934659Smarc extern (*v_putc)(); 120324Sbill 12134659Smarc if (v_putc) { 12234659Smarc (*v_putc)(c); 12334659Smarc if (c == '\n') 12434659Smarc (*v_putc)('\r'); 12534659Smarc return; 12634659Smarc } 12734659Smarc #endif 128324Sbill timo = 30000; 129324Sbill /* 130324Sbill * Try waiting for the console tty to come ready, 131324Sbill * otherwise give up after a reasonable time. 132324Sbill */ 133324Sbill while((mfpr(TXCS)&TXCS_RDY) == 0) 134324Sbill if(--timo == 0) 135324Sbill break; 136324Sbill if(c == 0) 137324Sbill return; 138324Sbill s = mfpr(TXCS); 139324Sbill mtpr(TXCS,0); 140324Sbill mtpr(TXDB, c&0xff); 141324Sbill if(c == '\n') 142324Sbill putchar('\r'); 143324Sbill putchar(0); 144324Sbill mtpr(TXCS, s); 145324Sbill } 146324Sbill 147324Sbill getchar() 148324Sbill { 149324Sbill register c; 150*35402Stef #if VAX630 || VAX650 15134659Smarc extern (*v_getc)(); 152324Sbill 15334659Smarc if (v_getc) { 15434659Smarc c = (*v_getc)(); 15534659Smarc } else { 15634659Smarc #endif 157324Sbill while((mfpr(RXCS)&RXCS_DONE) == 0) 158324Sbill ; 159324Sbill c = mfpr(RXDB)&0177; 160*35402Stef #if VAX630 || VAX650 16134659Smarc } 16234659Smarc #endif 163324Sbill if (c=='\r') 164324Sbill c = '\n'; 16529978Skarels if (c != '\b' && c != '\177') 16629978Skarels putchar(c); 167324Sbill return(c); 168324Sbill } 169