10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
51253Slq150181 * Common Development and Distribution License (the "License").
61253Slq150181 * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
211253Slq150181
220Sstevel@tonic-gate /*
23*7688SAaron.Zang@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate #include <sys/types.h>
280Sstevel@tonic-gate #include <sys/varargs.h>
290Sstevel@tonic-gate #include <sys/modctl.h>
300Sstevel@tonic-gate #include <sys/cmn_err.h>
310Sstevel@tonic-gate #include <sys/console.h>
320Sstevel@tonic-gate #include <sys/consdev.h>
330Sstevel@tonic-gate #include <sys/promif.h>
341253Slq150181 #include <sys/note.h>
351253Slq150181 #include <sys/polled_io.h>
360Sstevel@tonic-gate #include <sys/systm.h>
370Sstevel@tonic-gate #include <sys/file.h>
380Sstevel@tonic-gate #include <sys/conf.h>
390Sstevel@tonic-gate #include <sys/kmem.h>
400Sstevel@tonic-gate #include <sys/taskq.h>
410Sstevel@tonic-gate #include <sys/log.h>
420Sstevel@tonic-gate #include <sys/ddi.h>
430Sstevel@tonic-gate #include <sys/sunddi.h>
440Sstevel@tonic-gate #include <sys/esunddi.h>
450Sstevel@tonic-gate #include <sys/fs/snode.h>
460Sstevel@tonic-gate #include <sys/termios.h>
471253Slq150181 #include <sys/tem_impl.h>
480Sstevel@tonic-gate
490Sstevel@tonic-gate #define MINLINES 10
500Sstevel@tonic-gate #define MAXLINES 48
510Sstevel@tonic-gate #define LOSCREENLINES 34
520Sstevel@tonic-gate #define HISCREENLINES 48
530Sstevel@tonic-gate
540Sstevel@tonic-gate #define MINCOLS 10
550Sstevel@tonic-gate #define MAXCOLS 120
560Sstevel@tonic-gate #define LOSCREENCOLS 80
570Sstevel@tonic-gate #define HISCREENCOLS 120
580Sstevel@tonic-gate
590Sstevel@tonic-gate vnode_t *console_vnode;
600Sstevel@tonic-gate taskq_t *console_taskq;
610Sstevel@tonic-gate
620Sstevel@tonic-gate /*
630Sstevel@tonic-gate * The current set of polled I/O routines (if any)
640Sstevel@tonic-gate */
650Sstevel@tonic-gate struct cons_polledio *cons_polledio;
660Sstevel@tonic-gate
670Sstevel@tonic-gate /*
680Sstevel@tonic-gate * Console I/O Routines
690Sstevel@tonic-gate *
700Sstevel@tonic-gate * In the event that kernel messages are generated with cmn_err(9F) or printf()
710Sstevel@tonic-gate * early in boot, after a panic, in resource-constrained situations, or sent
720Sstevel@tonic-gate * through /dev/console to the wscons driver, we may be called upon to render
730Sstevel@tonic-gate * characters directly to the frame buffer using the underlying prom_*()
740Sstevel@tonic-gate * routines. These in turn may attempt to use PROM services directly, or may
750Sstevel@tonic-gate * use a kernel console emulator if one is available. Unfortunately, if PROM
760Sstevel@tonic-gate * services are being used by the kernel on a multi-CPU system, these routines
770Sstevel@tonic-gate * might be called while another CPU is simultaneously accessing a frame buffer
780Sstevel@tonic-gate * memory mapping (perhaps through the X server). This situation may not be
790Sstevel@tonic-gate * supported by the frame buffer hardware.
800Sstevel@tonic-gate *
810Sstevel@tonic-gate * To handle this situation, we implement a two-phase locking scheme which we
820Sstevel@tonic-gate * use to protect accesses to the underlying prom_*() rendering routines. The
830Sstevel@tonic-gate * common-code functions console_hold() and console_rele() are used to gain
840Sstevel@tonic-gate * exclusive access to the console from within the kernel. We use a standard
850Sstevel@tonic-gate * r/w lock in writer-mode only to implement the kernel lock. We use an r/w
860Sstevel@tonic-gate * lock instead of a mutex here because character rendering is slow and hold
870Sstevel@tonic-gate * times will be relatively long, and there is no point in adaptively spinning.
880Sstevel@tonic-gate * These routines may be called recursively, in which case subsequent calls
890Sstevel@tonic-gate * just increment the console_depth hold count. Once exclusive access is
900Sstevel@tonic-gate * gained, we grab the frame buffer device node and block further mappings to
910Sstevel@tonic-gate * it by holding the specfs node lock and the device node's lock. We then
920Sstevel@tonic-gate * observe if any mappings are present by examining the specfs node's s_mapcnt
930Sstevel@tonic-gate * (non-clone mmaps) and the devinfo node's devi_ref count (clone opens).
940Sstevel@tonic-gate *
950Sstevel@tonic-gate * Then, around each character rendering call, the routines console_enter()
960Sstevel@tonic-gate * and console_exit() are used to inform the platform code that we are
970Sstevel@tonic-gate * accessing the character rendering routines. These platform routines can
980Sstevel@tonic-gate * then examine the "busy" flag returned by console_enter() and briefly stop
990Sstevel@tonic-gate * the other CPUs so that they cannot access the frame buffer hardware while
1000Sstevel@tonic-gate * we are busy rendering characters. This mess can all be removed when the
1010Sstevel@tonic-gate * impossible dream of a unified kernel console emulator is someday realized.
1020Sstevel@tonic-gate */
1030Sstevel@tonic-gate
1040Sstevel@tonic-gate static krwlock_t console_lock;
1050Sstevel@tonic-gate static uint_t console_depth;
1060Sstevel@tonic-gate static int console_busy;
1070Sstevel@tonic-gate
1080Sstevel@tonic-gate extern void pm_cfb_check_and_powerup(void);
1090Sstevel@tonic-gate extern void pm_cfb_rele(void);
1100Sstevel@tonic-gate
1110Sstevel@tonic-gate static int
console_hold(void)1120Sstevel@tonic-gate console_hold(void)
1130Sstevel@tonic-gate {
1140Sstevel@tonic-gate if (panicstr != NULL)
1150Sstevel@tonic-gate return (console_busy); /* assume exclusive access in panic */
1160Sstevel@tonic-gate
1170Sstevel@tonic-gate if (rw_owner(&console_lock) != curthread)
1180Sstevel@tonic-gate rw_enter(&console_lock, RW_WRITER);
1190Sstevel@tonic-gate
1200Sstevel@tonic-gate if (console_depth++ != 0)
1210Sstevel@tonic-gate return (console_busy); /* lock is being entered recursively */
1220Sstevel@tonic-gate
1230Sstevel@tonic-gate pm_cfb_check_and_powerup();
1240Sstevel@tonic-gate
1251253Slq150181 #ifdef _HAVE_TEM_FIRMWARE
1261253Slq150181 if (consmode == CONS_FW && ncpus > 1 && fbvp != NULL) {
1270Sstevel@tonic-gate struct snode *csp = VTOS(VTOS(fbvp)->s_commonvp);
1280Sstevel@tonic-gate
1290Sstevel@tonic-gate mutex_enter(&csp->s_lock);
1300Sstevel@tonic-gate console_busy = csp->s_mapcnt != 0;
1310Sstevel@tonic-gate
1320Sstevel@tonic-gate if (csp->s_mapcnt == 0 && fbdip != NULL) {
1330Sstevel@tonic-gate mutex_enter(&DEVI(fbdip)->devi_lock);
1340Sstevel@tonic-gate console_busy = DEVI(fbdip)->devi_ref != 0;
1350Sstevel@tonic-gate }
1360Sstevel@tonic-gate }
1371253Slq150181 #endif /* _HAVE_TEM_FIRMWARE */
1380Sstevel@tonic-gate return (console_busy);
1390Sstevel@tonic-gate }
1400Sstevel@tonic-gate
1410Sstevel@tonic-gate static void
console_rele(void)1420Sstevel@tonic-gate console_rele(void)
1430Sstevel@tonic-gate {
1440Sstevel@tonic-gate if (panicstr != NULL)
1450Sstevel@tonic-gate return; /* do not modify lock states if we are panicking */
1460Sstevel@tonic-gate
1470Sstevel@tonic-gate ASSERT(RW_WRITE_HELD(&console_lock));
1480Sstevel@tonic-gate ASSERT(console_depth != 0);
1490Sstevel@tonic-gate
1500Sstevel@tonic-gate if (--console_depth != 0)
1510Sstevel@tonic-gate return; /* lock is being dropped recursively */
1520Sstevel@tonic-gate
1531253Slq150181 #ifdef _HAVE_TEM_FIRMWARE
1541253Slq150181 if (consmode == CONS_FW && ncpus > 1 && fbvp != NULL) {
1550Sstevel@tonic-gate struct snode *csp = VTOS(VTOS(fbvp)->s_commonvp);
1560Sstevel@tonic-gate
1570Sstevel@tonic-gate ASSERT(MUTEX_HELD(&csp->s_lock));
1580Sstevel@tonic-gate if (csp->s_mapcnt == 0 && fbdip != NULL)
1590Sstevel@tonic-gate mutex_exit(&DEVI(fbdip)->devi_lock);
1600Sstevel@tonic-gate
1610Sstevel@tonic-gate mutex_exit(&csp->s_lock);
1620Sstevel@tonic-gate }
1631253Slq150181 #endif /* _HAVE_TEM_FIRMWARE */
1640Sstevel@tonic-gate pm_cfb_rele();
1650Sstevel@tonic-gate console_busy = 0;
1660Sstevel@tonic-gate rw_exit(&console_lock);
1670Sstevel@tonic-gate }
1680Sstevel@tonic-gate
1690Sstevel@tonic-gate static void
console_getprop(dev_t dev,dev_info_t * dip,char * name,ushort_t * sp)1700Sstevel@tonic-gate console_getprop(dev_t dev, dev_info_t *dip, char *name, ushort_t *sp)
1710Sstevel@tonic-gate {
1720Sstevel@tonic-gate uchar_t *data;
1730Sstevel@tonic-gate uint_t len;
1740Sstevel@tonic-gate uint_t i;
1750Sstevel@tonic-gate
1760Sstevel@tonic-gate *sp = 0;
1770Sstevel@tonic-gate if (ddi_prop_lookup_byte_array(dev, dip, 0, name, &data, &len) ==
1780Sstevel@tonic-gate DDI_PROP_SUCCESS) {
1790Sstevel@tonic-gate for (i = 0; i < len; i++) {
1800Sstevel@tonic-gate if (data[i] < '0' || data[i] > '9')
1810Sstevel@tonic-gate break;
1820Sstevel@tonic-gate *sp = *sp * 10 + data[i] - '0';
1830Sstevel@tonic-gate }
1840Sstevel@tonic-gate ddi_prop_free(data);
1850Sstevel@tonic-gate }
1860Sstevel@tonic-gate }
1870Sstevel@tonic-gate
1880Sstevel@tonic-gate /*
1890Sstevel@tonic-gate * Gets the number of rows and columns (in char's) and the
1900Sstevel@tonic-gate * width and height (in pixels) of the console.
1910Sstevel@tonic-gate */
1920Sstevel@tonic-gate void
console_get_size(ushort_t * r,ushort_t * c,ushort_t * x,ushort_t * y)1930Sstevel@tonic-gate console_get_size(ushort_t *r, ushort_t *c, ushort_t *x, ushort_t *y)
1940Sstevel@tonic-gate {
1950Sstevel@tonic-gate int rel_needed = 0;
1960Sstevel@tonic-gate dev_info_t *dip;
1970Sstevel@tonic-gate dev_t dev;
1980Sstevel@tonic-gate
1990Sstevel@tonic-gate /*
2000Sstevel@tonic-gate * If we have loaded the console IO stuff, then ask for the screen
2010Sstevel@tonic-gate * size properties from the layered terminal emulator. Else ask for
2020Sstevel@tonic-gate * them from the root node, which will eventually fall through to the
2030Sstevel@tonic-gate * options node and get them from the prom.
2040Sstevel@tonic-gate */
2051253Slq150181 if (rwsconsvp == NULL || consmode == CONS_FW) {
2060Sstevel@tonic-gate dip = ddi_root_node();
2070Sstevel@tonic-gate dev = DDI_DEV_T_ANY;
2080Sstevel@tonic-gate } else {
2091253Slq150181 dev = rwsconsvp->v_rdev; /* layering is wc -> tem */
2101253Slq150181 dip = e_ddi_hold_devi_by_dev(dev, 0);
2110Sstevel@tonic-gate rel_needed = 1;
2120Sstevel@tonic-gate }
2130Sstevel@tonic-gate
2140Sstevel@tonic-gate /*
2150Sstevel@tonic-gate * If we have not initialized a console yet and don't have a root
2160Sstevel@tonic-gate * node (ie. we have not initialized the DDI yet) return our default
2170Sstevel@tonic-gate * size for the screen.
2180Sstevel@tonic-gate */
2190Sstevel@tonic-gate if (dip == NULL) {
2200Sstevel@tonic-gate *r = LOSCREENLINES;
2210Sstevel@tonic-gate *c = LOSCREENCOLS;
2220Sstevel@tonic-gate *x = *y = 0;
2230Sstevel@tonic-gate return;
2240Sstevel@tonic-gate }
2250Sstevel@tonic-gate
2261253Slq150181 console_getprop(DDI_DEV_T_ANY, dip, "screen-#columns", c);
2271253Slq150181 console_getprop(DDI_DEV_T_ANY, dip, "screen-#rows", r);
2281253Slq150181 console_getprop(DDI_DEV_T_ANY, dip, "screen-width", x);
2291253Slq150181 console_getprop(DDI_DEV_T_ANY, dip, "screen-height", y);
2300Sstevel@tonic-gate
2310Sstevel@tonic-gate if (*c < MINCOLS)
2320Sstevel@tonic-gate *c = LOSCREENCOLS;
2330Sstevel@tonic-gate else if (*c > MAXCOLS)
2340Sstevel@tonic-gate *c = HISCREENCOLS;
2350Sstevel@tonic-gate
2360Sstevel@tonic-gate if (*r < MINLINES)
2370Sstevel@tonic-gate *r = LOSCREENLINES;
2380Sstevel@tonic-gate else if (*r > MAXLINES)
2390Sstevel@tonic-gate *r = HISCREENLINES;
2400Sstevel@tonic-gate
2410Sstevel@tonic-gate if (rel_needed)
2420Sstevel@tonic-gate ddi_release_devi(dip);
2430Sstevel@tonic-gate }
2440Sstevel@tonic-gate
2450Sstevel@tonic-gate typedef struct console_msg {
2460Sstevel@tonic-gate size_t cm_size;
2470Sstevel@tonic-gate char cm_text[1];
2480Sstevel@tonic-gate } console_msg_t;
2490Sstevel@tonic-gate
2501253Slq150181 /*
2511253Slq150181 * If we can't access the console stream, fall through to PROM, which redirects
2521253Slq150181 * it back into to terminal emulator as appropriate. The console stream should
2531253Slq150181 * be available after consconfig runs.
2541253Slq150181 */
2550Sstevel@tonic-gate static void
console_putmsg(console_msg_t * cm)2560Sstevel@tonic-gate console_putmsg(console_msg_t *cm)
2570Sstevel@tonic-gate {
2580Sstevel@tonic-gate int busy, spl;
2590Sstevel@tonic-gate ssize_t res;
2600Sstevel@tonic-gate
2610Sstevel@tonic-gate ASSERT(taskq_member(console_taskq, curthread));
2620Sstevel@tonic-gate
2630Sstevel@tonic-gate if (rconsvp == NULL || panicstr ||
2640Sstevel@tonic-gate vn_rdwr(UIO_WRITE, console_vnode, cm->cm_text, strlen(cm->cm_text),
2650Sstevel@tonic-gate 0, UIO_SYSSPACE, FAPPEND, (rlim64_t)LOG_HIWAT, kcred, &res) != 0) {
2660Sstevel@tonic-gate
2670Sstevel@tonic-gate busy = console_hold();
2680Sstevel@tonic-gate spl = console_enter(busy);
2690Sstevel@tonic-gate
2700Sstevel@tonic-gate prom_printf("%s", cm->cm_text);
2710Sstevel@tonic-gate
2720Sstevel@tonic-gate console_exit(busy, spl);
2730Sstevel@tonic-gate console_rele();
2740Sstevel@tonic-gate }
2750Sstevel@tonic-gate
2760Sstevel@tonic-gate kmem_free(cm, cm->cm_size);
2770Sstevel@tonic-gate }
2780Sstevel@tonic-gate
2790Sstevel@tonic-gate void
console_vprintf(const char * fmt,va_list adx)2800Sstevel@tonic-gate console_vprintf(const char *fmt, va_list adx)
2810Sstevel@tonic-gate {
2820Sstevel@tonic-gate console_msg_t *cm;
2830Sstevel@tonic-gate size_t len = vsnprintf(NULL, 0, fmt, adx);
2840Sstevel@tonic-gate int busy, spl;
2850Sstevel@tonic-gate
2860Sstevel@tonic-gate if (console_taskq != NULL && rconsvp != NULL && panicstr == NULL &&
2870Sstevel@tonic-gate (cm = kmem_alloc(sizeof (*cm) + len, KM_NOSLEEP)) != NULL) {
2880Sstevel@tonic-gate cm->cm_size = sizeof (*cm) + len;
2890Sstevel@tonic-gate (void) vsnprintf(cm->cm_text, len + 1, fmt, adx);
2900Sstevel@tonic-gate if (taskq_dispatch(console_taskq, (task_func_t *)console_putmsg,
2910Sstevel@tonic-gate cm, TQ_NOSLEEP) != 0)
2920Sstevel@tonic-gate return;
2930Sstevel@tonic-gate kmem_free(cm, cm->cm_size);
2940Sstevel@tonic-gate }
2950Sstevel@tonic-gate
2960Sstevel@tonic-gate busy = console_hold();
2970Sstevel@tonic-gate spl = console_enter(busy);
2980Sstevel@tonic-gate
2990Sstevel@tonic-gate prom_vprintf(fmt, adx);
3000Sstevel@tonic-gate
3010Sstevel@tonic-gate console_exit(busy, spl);
3020Sstevel@tonic-gate console_rele();
3030Sstevel@tonic-gate }
3040Sstevel@tonic-gate
3050Sstevel@tonic-gate /*PRINTFLIKE1*/
3060Sstevel@tonic-gate void
console_printf(const char * fmt,...)3070Sstevel@tonic-gate console_printf(const char *fmt, ...)
3080Sstevel@tonic-gate {
3090Sstevel@tonic-gate va_list adx;
3100Sstevel@tonic-gate
3110Sstevel@tonic-gate va_start(adx, fmt);
3120Sstevel@tonic-gate console_vprintf(fmt, adx);
3130Sstevel@tonic-gate va_end(adx);
3140Sstevel@tonic-gate }
3150Sstevel@tonic-gate
3160Sstevel@tonic-gate /*
3171253Slq150181 * Avoid calling this function.
3181253Slq150181 *
3191253Slq150181 * Nothing in the kernel besides the wscons driver (wc) uses this
3201253Slq150181 * function. It may hopefully one day be removed altogether.
3211253Slq150181 * If a wayward module calls this they will pass through to PROM,
3221253Slq150181 * get redirected into the kernel emulator as appropriate.
3230Sstevel@tonic-gate */
3240Sstevel@tonic-gate void
console_puts(const char * s,size_t n)3250Sstevel@tonic-gate console_puts(const char *s, size_t n)
3260Sstevel@tonic-gate {
3270Sstevel@tonic-gate int busy, spl;
3280Sstevel@tonic-gate
3290Sstevel@tonic-gate busy = console_hold();
3300Sstevel@tonic-gate spl = console_enter(busy);
3310Sstevel@tonic-gate
3320Sstevel@tonic-gate prom_writestr(s, n);
3330Sstevel@tonic-gate
3340Sstevel@tonic-gate console_exit(busy, spl);
3350Sstevel@tonic-gate console_rele();
3360Sstevel@tonic-gate }
3370Sstevel@tonic-gate
3381253Slq150181 /*
3391253Slq150181 * Let this function just go straight through to the PROM, since
3401253Slq150181 * we are called in early boot prior to the kernel terminal
3411253Slq150181 * emulator being available, and prior to the PROM stdout redirect
3421253Slq150181 * vector being set.
3431253Slq150181 */
3441253Slq150181 static void
console_putc(int c)3450Sstevel@tonic-gate console_putc(int c)
3460Sstevel@tonic-gate {
3470Sstevel@tonic-gate int busy = console_hold();
3480Sstevel@tonic-gate int spl = console_enter(busy);
3490Sstevel@tonic-gate
3500Sstevel@tonic-gate if (c == '\n')
3510Sstevel@tonic-gate prom_putchar('\r');
3520Sstevel@tonic-gate prom_putchar(c);
3530Sstevel@tonic-gate
3540Sstevel@tonic-gate console_exit(busy, spl);
3550Sstevel@tonic-gate console_rele();
3560Sstevel@tonic-gate }
3570Sstevel@tonic-gate
3580Sstevel@tonic-gate /*
3590Sstevel@tonic-gate * Read a string from the console device. We only permit synchronous
3600Sstevel@tonic-gate * conversation between the kernel and a console user early in boot prior to
3610Sstevel@tonic-gate * the initialization of rconsvp.
3620Sstevel@tonic-gate */
3630Sstevel@tonic-gate void
console_gets(char * s,size_t len)3640Sstevel@tonic-gate console_gets(char *s, size_t len)
3650Sstevel@tonic-gate {
3660Sstevel@tonic-gate char *p = s;
3670Sstevel@tonic-gate char *q = s + len - 1;
3680Sstevel@tonic-gate int c;
3690Sstevel@tonic-gate
3700Sstevel@tonic-gate ASSERT(rconsvp == NULL);
3710Sstevel@tonic-gate (void) console_hold();
3720Sstevel@tonic-gate
3730Sstevel@tonic-gate for (;;) {
3740Sstevel@tonic-gate switch (c = (prom_getchar() & 0x7f)) {
3750Sstevel@tonic-gate case 0x7f: /* DEL */
3760Sstevel@tonic-gate if (p == s)
3770Sstevel@tonic-gate break;
3780Sstevel@tonic-gate console_putc(c);
3790Sstevel@tonic-gate c = '\b';
3800Sstevel@tonic-gate /*FALLTHRU*/
3810Sstevel@tonic-gate
3820Sstevel@tonic-gate case '\b':
3830Sstevel@tonic-gate if (p == s)
3840Sstevel@tonic-gate break;
3850Sstevel@tonic-gate console_putc('\b');
3860Sstevel@tonic-gate console_putc(' ');
3870Sstevel@tonic-gate /*FALLTHRU*/
3880Sstevel@tonic-gate
3890Sstevel@tonic-gate case '#': /* historical backspace alias */
3900Sstevel@tonic-gate console_putc(c);
3910Sstevel@tonic-gate if (p > s)
3920Sstevel@tonic-gate p--;
3930Sstevel@tonic-gate break;
3940Sstevel@tonic-gate
3950Sstevel@tonic-gate case CTRL('u'):
3960Sstevel@tonic-gate console_putc(c);
3970Sstevel@tonic-gate console_putc('\n');
3980Sstevel@tonic-gate p = s;
3990Sstevel@tonic-gate break;
4000Sstevel@tonic-gate
4010Sstevel@tonic-gate case '\r':
4020Sstevel@tonic-gate case '\n':
4030Sstevel@tonic-gate console_putc('\n');
4040Sstevel@tonic-gate goto done;
4050Sstevel@tonic-gate
4060Sstevel@tonic-gate default:
4070Sstevel@tonic-gate if (p < q) {
4080Sstevel@tonic-gate console_putc(c);
4090Sstevel@tonic-gate *p++ = c;
4100Sstevel@tonic-gate } else
4110Sstevel@tonic-gate console_putc('\a');
4120Sstevel@tonic-gate }
4130Sstevel@tonic-gate }
4140Sstevel@tonic-gate done:
4150Sstevel@tonic-gate console_rele();
4160Sstevel@tonic-gate *p = '\0';
4170Sstevel@tonic-gate }
4180Sstevel@tonic-gate
4190Sstevel@tonic-gate /*
4200Sstevel@tonic-gate * Read a character from the console device. Synchronous conversation between
4210Sstevel@tonic-gate * the kernel and a console user is only permitted early in boot prior to the
4220Sstevel@tonic-gate * initialization of rconsvp.
4230Sstevel@tonic-gate */
4240Sstevel@tonic-gate int
console_getc(void)4250Sstevel@tonic-gate console_getc(void)
4260Sstevel@tonic-gate {
4270Sstevel@tonic-gate int c;
4280Sstevel@tonic-gate
4290Sstevel@tonic-gate ASSERT(rconsvp == NULL);
4300Sstevel@tonic-gate c = prom_getchar();
4310Sstevel@tonic-gate
4320Sstevel@tonic-gate if (c == '\r')
4330Sstevel@tonic-gate c = '\n';
4340Sstevel@tonic-gate
4350Sstevel@tonic-gate console_putc(c);
4360Sstevel@tonic-gate return (c);
4370Sstevel@tonic-gate }
438