*/
/*
* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved.
- *
+ *
* km.m - kernel keyboard/monitor module, procedural interface.
- *
+ *
* HISTORY
*/
#include <sys/param.h>
#include <sys/conf.h>
#include <sys/systm.h>
#include <sys/uio.h>
-#include <sys/fcntl.h> /* for kmopen */
+#include <sys/fcntl.h> /* for kmopen */
#include <sys/errno.h>
-#include <sys/proc.h> /* for kmopen */
+#include <sys/proc.h> /* for kmopen */
#include <sys/msgbuf.h>
#include <sys/time.h>
#include <dev/kmreg_com.h>
extern int cngetc(void);
-void kminit(void);
-void cons_cinput(char ch);
+void kminit(void);
+void cons_cinput(char ch);
/*
* 'Global' variables, shared only by this file and conf.c.
kminit(void)
{
km_tty[0] = ttymalloc();
- km_tty[0]->t_dev = makedev(12, 0);
+ km_tty[0]->t_dev = makedev(12, 0);
initialized = 1;
}
* cdevsw interface to km driver.
*/
int
-kmopen(dev_t dev, int flag, __unused int devtype, proc_t pp)
+kmopen(dev_t dev, __unused int flag, __unused int devtype, proc_t pp)
{
int unit;
struct tty *tp;
int ret;
unit = minor(dev);
- if (unit >= 1)
- return (ENXIO);
+ if (unit >= 1) {
+ return ENXIO;
+ }
tp = km_tty[unit];
goto out;
}
- tp->t_state |= TS_CARR_ON; /* lie and say carrier exists and is
- * on. */
- ret = ((*linesw[tp->t_line].l_open) (dev, tp));
+ tp->t_state |= TS_CARR_ON; /* lie and say carrier exists and is
+ * on. */
+ ret = ((*linesw[tp->t_line].l_open)(dev, tp));
{
PE_Video video;
wp = &tp->t_winsize;
wp->ws_xpixel = 8;
wp->ws_ypixel = 16;
- tty_unlock(tp); /* XXX race window */
-
- if (flag & O_POPUP)
- PE_initialize_console(0, kPETextScreen);
+ tty_unlock(tp); /* XXX race window */
bzero(&video, sizeof(video));
PE_current_console(&video);
wp->ws_col = 80;
wp->ws_row = 24;
} else if (video.v_width != 0 && video.v_height != 0) {
- wp->ws_col = video.v_width / wp->ws_xpixel;
- wp->ws_row = video.v_height / wp->ws_ypixel;
+ unsigned long ws_col = video.v_width / wp->ws_xpixel;
+ unsigned long ws_row = video.v_height / wp->ws_ypixel;
+
+ assert((ws_col <= USHRT_MAX) && (ws_row <= USHRT_MAX));
+
+ wp->ws_col = (unsigned short)ws_col;
+ wp->ws_row = (unsigned short)ws_row;
} else {
wp->ws_col = 100;
wp->ws_row = 36;
ttyclose(tp);
tty_unlock(tp);
- return (ret);
+ return ret;
}
int
ret = (*linesw[tp->t_line].l_read)(tp, uio, ioflag);
tty_unlock(tp);
- return (ret);
+ return ret;
}
int
ret = (*linesw[tp->t_line].l_write)(tp, uio, ioflag);
tty_unlock(tp);
- return (ret);
+ return ret;
}
int
error = EINVAL;
break;
- /* Bodge in the CLOCAL flag as the km device is always local */
+ /* Bodge in the CLOCAL flag as the km device is always local */
case TIOCSETA_32:
case TIOCSETAW_32:
case TIOCSETAF_32:
- {
- struct termios32 *t = (struct termios32 *)data;
- t->c_cflag |= CLOCAL;
- /* No Break */
- }
+ {
+ struct termios32 *t = (struct termios32 *)data;
+ t->c_cflag |= CLOCAL;
+ /* No Break */
+ }
goto fallthrough;
case TIOCSETA_64:
case TIOCSETAW_64:
case TIOCSETAF_64:
- {
- struct user_termios *t = (struct user_termios *)data;
- t->c_cflag |= CLOCAL;
- /* No Break */
- }
+ {
+ struct user_termios *t = (struct user_termios *)data;
+ t->c_cflag |= CLOCAL;
+ /* No Break */
+ }
fallthrough:
default:
- error = (*linesw[tp->t_line].l_ioctl) (tp, cmd, data, flag, p);
- if (ENOTTY != error)
+ error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
+ if (ENOTTY != error) {
break;
+ }
error = ttioctl_locked(tp, cmd, data, flag, p);
break;
}
tty_unlock(tp);
- return (error);
+ return error;
}
* assumptions here, this routine should be static (and
* inlined, given there is only one call site).
*/
-int
+int
kmputc(__unused dev_t dev, char c)
{
- if(!disableConsoleOutput && initialized) {
+ if (!disableConsoleOutput && initialized) {
/* OCRNL */
- if(c == '\n')
+ if (c == '\n') {
cnputcusr('\r');
+ }
cnputcusr(c);
}
- return (0);
+ return 0;
}
* Callouts from linesw.
*/
-#define KM_LOWAT_DELAY ((ns_time_t)1000)
+#define KM_LOWAT_DELAY ((ns_time_t)1000)
/*
* t_oproc for this driver; called from within the line discipline
static void
kmstart(struct tty *tp)
{
- if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP))
+ if (tp->t_state & (TS_TIMEOUT | TS_BUSY | TS_TTSTOP)) {
goto out;
- if (tp->t_outq.c_cc == 0)
+ }
+ if (tp->t_outq.c_cc == 0) {
goto out;
+ }
tp->t_state |= TS_BUSY;
if (tp->t_outq.c_cc > tp->t_lowat) {
/*
return;
out:
- (*linesw[tp->t_line].l_start) (tp);
+ (*linesw[tp->t_line].l_start)(tp);
return;
}
static int
kmoutput(struct tty * tp)
{
- unsigned char buf[80]; /* buffer; limits output per call */
- unsigned char *cp;
- int cc = -1;
+ unsigned char buf[80]; /* buffer; limits output per call */
+ unsigned char *cp;
+ int cc = -1;
/* While there is data available to be output... */
while (tp->t_outq.c_cc > 0) {
cc = ndqb(&tp->t_outq, 0);
- if (cc == 0)
+ if (cc == 0) {
break;
+ }
/*
* attempt to output as many characters as are available,
* up to the available transfer buffer size.
}
tp->t_state &= ~TS_BUSY;
/* Start the output processing for the line discipline */
- (*linesw[tp->t_line].l_start) (tp);
+ (*linesw[tp->t_line].l_start)(tp);
return 0;
}
void
cons_cinput(char ch)
{
- struct tty *tp = km_tty[0]; /* XXX */
+ struct tty *tp = km_tty[0]; /* XXX */
tty_lock(tp);
- (*linesw[tp->t_line].l_rint) (ch, tp);
+ (*linesw[tp->t_line].l_rint)(ch, tp);
tty_unlock(tp);
}