--- xinu/sys/kprintf.c 2018/04/24 17:39:04 1.1 +++ xinu/sys/kprintf.c 2018/04/24 17:40:13 1.1.1.2 @@ -1,88 +1,69 @@ -/* kprintf.c - kprintf, kputc, savestate, rststate */ +/* kprintf.c - kprintf, kputc--slightly edited from original Xinu */ #include #include #include -#include #include -#include + +/* set up macros for appropriate SLU as spec. by SLUCHIP: + if SLUCHIP==6850, #include slu6850.h, #define TTYWRITE ttywrite6850, etc. + if SLUCHIP==7201, #include slu7201.h, #define TTYWRITE ttywrite7201, etc. + if SLUCHIP undef.,#include slu.h, #define TTYWRITE ttywrite (orig. case) + similarly sluaccess.h, other TTY fns */ +#include +#ifdef ATT7300 +int slowtime = 500; +/* Xinu console is the serial port on the back, assumed already + initialized by the downloading support */ +#else +int slowtime = 200; +/* MECB console is the console MC6850, init'd by TUTOR */ +#endif /*------------------------------------------------------------------------ * kprintf -- kernel printf: formatted, unbuffered output to CONSOLE *------------------------------------------------------------------------ */ + +/* kprintf is the routine to use for polling output, even in the case that */ +/* the calling program also uses SLU interrupts. It shuts out interrupts */ +/* by going high-CPU-priority, saving the old CPU priority locally and */ +/* reestablishing it on return. It varies from the original Vol I. Xinu */ +/* sources by not changing the device control register, but rather just */ +/* relying on high CPU priority to hold the console (did the original SLU */ +/* fail to post a transmit ready bit with interrupts enabled??) */ + kprintf(fmt, args) /* Derived by Bob Brown, Purdue U. */ - char *fmt; /* Flow control added by Steve Munson */ + char *fmt; { - int kputc(); - savestate(); - _doprnt(fmt, &args, kputc, CONSOLE); - rststate(); - return(OK); + static unsigned short savesr; + int kputc(); + + _disable(&savesr); /* orig. Xinu had "savestate()" */ + _doprnt(fmt, &args, kputc, CONSOLE); + _restore(&savesr); /* orig. Xinu had "rststate()" */ + return(OK); } /*------------------------------------------------------------------------ - * kputc -- write a character on the non memory-mapped console device - * using polled I/O + * kputc -- write a character on the console (or other SLU) + * using polled I/O *------------------------------------------------------------------------ */ -LOCAL kputc(device ,c) - int device; - register char c; /* character to print from _doprnt */ +kputc(device,c) +int device; +register char c; /* character to print from _doprnt */ { - register int crstat, crbuf, ctstat; - register struct tty *ttyptr; - - if ( device != CONSOLE || c == 0 ) + struct csr *csrptr; +/*T*/ int slowdown; /* added to delay output because host */ +/*T*/ /* can't take it at 9600 baud */ + if ( c == 0 ) return; if ( c == NEWLINE ) - kputc( device, RETURN ); - ttyptr = (struct tty *)devtab[device].dvioblk; /* control block*/ - if (ttyptr) { - crstat = mfpr(RXCS); /* get recv. stat */ - crbuf = mfpr(RXDB); /* get content of receiver buffer */ - if ((crstat&SLUREADY) && - (ttyptr->oheld || (ttyptr->oflow && - (crbuf & SLUCHMASK) == ttyptr->ostop))) - do { - crstat = mfpr(RXCS); /* get recv stat */ - while (!(crstat&SLUREADY)) /* wait til ready */ - crstat = mfpr(RXCS);/* get recv stat */ - crbuf = mfpr(RXDB); /* get rec buffer */ - } while ((crbuf&SLUCHMASK) == ttyptr->ostop); - ttyptr->oheld = FALSE; - } - ctstat = mfpr(TXCS); /* get transmit status */ - while (!(ctstat & SLUREADY)) /* not ready to transmit yet */ - ctstat = mfpr(TXCS); /* poll for idle*/ - mtpr(c & SLUCHMASK, TXDB); /* transmit character */ - ctstat = mfpr(TXCS); /* get transmit status */ - while (!(ctstat & SLUREADY)) - ctstat = mfpr(TXCS); /* get transmit status */ -} - -LOCAL int savecrstat, savectstat; -LOCAL PStype ps; -/*------------------------------------------------------------------------------ - * savestate -- save the state of the non-memory mapped CONSOLE device - *------------------------------------------------------------------------------ - */ -LOCAL savestate() -{ - disable(ps); - savecrstat = mfpr(RXCS) & SLUENABLE; - savectstat = mfpr(TXCS) & SLUENABLE; - mtpr(SLUDISABLE, RXCS); /* disable receive intpts */ - mtpr(SLUDISABLE, TXCS); /* disable transmit intpts */ -} - -/*-------------------------------------------------------------------------- - * rststate -- restore the state of the non-memory mapped CONSOLE device - *-------------------------------------------------------------------------- - */ -LOCAL rststate() -{ - mtpr(savecrstat, RXCS); - mtpr(savectstat, TXCS); - restore(ps); + kputc(device, RETURN ); + csrptr = (struct csr *)devtab[device].dvcsr; + while ( (csrptr->cstat & SLUTRANSREADY) == 0 ) ; /* poll for idle*/ + csrptr->cbuf = c; +/*T*/ for(slowdown=0;slowdowncstat & SLUTRANSREADY) == 0 ) ; /* poll for idle*/ }