Make a 1:1 mapping between syscons stats and terminal emulators.

After I imported libteken into the source tree, I noticed syscons didn't
store the cursor position inside the terminal emulator, but inside the
virtual terminal stat. This is not very useful, because when you
implement more complex forms of line wrapping, you need to keep track of
more state than just the cursor position.

Because the kernel messages didn't share the same terminal emulator as
ttyv0, this caused a lot of strange things, like kernel messages being
misplaced and a missing notification to resize the terminal emulator for
kernel messages never to be resized when using vidcontrol.

This patch just removes kernel_console_ts and adds a special parameter
to te_puts to determine whether messages should be printed using regular
colors or the ones for kernel messages.

Reported by:	ache
Tested by:	nyan, garga (older version)
This commit is contained in:
Ed Schouten 2009-03-10 11:28:54 +00:00
parent 9541ada9a0
commit 630b9bf23f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=189617
6 changed files with 39 additions and 37 deletions

View File

@ -153,12 +153,23 @@ scteken_term(scr_stat *scp, void **softc)
}
static void
scteken_puts(scr_stat *scp, u_char *buf, int len)
scteken_puts(scr_stat *scp, u_char *buf, int len, int kernel)
{
teken_stat *ts = scp->ts;
teken_attr_t backup, kattr;
scp->sc->write_in_progress++;
teken_input(&ts->ts_teken, buf, len);
if (kernel) {
/* Use special colors for kernel messages. */
backup = *teken_get_curattr(&ts->ts_teken);
scteken_revattr(SC_KERNEL_CONS_ATTR, &kattr);
teken_set_curattr(&ts->ts_teken, &kattr);
teken_input(&ts->ts_teken, buf, len);
teken_set_curattr(&ts->ts_teken, &backup);
} else {
/* Print user messages with regular colors. */
teken_input(&ts->ts_teken, buf, len);
}
scp->sc->write_in_progress--;
}

View File

@ -95,16 +95,10 @@ static default_attr user_default = {
SC_NORM_REV_ATTR,
};
static default_attr kernel_default = {
SC_KERNEL_CONS_ATTR,
SC_KERNEL_CONS_REV_ATTR,
};
static int sc_console_unit = -1;
static int sc_saver_keyb_only = 1;
static scr_stat *sc_console;
static struct consdev *sc_consptr;
static void *kernel_console_ts;
static scr_stat main_console;
static struct tty *main_devs[MAXCONS];
@ -323,7 +317,7 @@ sctty_outwakeup(struct tty *tp)
len = ttydisc_getc(tp, buf, sizeof buf);
if (len == 0)
break;
sc_puts(scp, buf, len);
sc_puts(scp, buf, len, 0);
}
}
@ -373,22 +367,8 @@ sc_attach_unit(int unit, int flags)
/* assert(sc_console != NULL) */
flags |= SC_KERNEL_CONSOLE;
scmeminit(NULL);
scinit(unit, flags);
if (sc_console->tsw->te_size > 0) {
/* assert(sc_console->ts != NULL); */
kernel_console_ts = sc_console->ts;
sc_console->ts = malloc(sc_console->tsw->te_size,
M_DEVBUF, M_WAITOK);
bcopy(kernel_console_ts, sc_console->ts, sc_console->tsw->te_size);
(*sc_console->tsw->te_default_attr)(sc_console,
user_default.std_color,
user_default.rev_color);
}
} else {
scinit(unit, flags);
}
scinit(unit, flags);
sc = sc_get_softc(unit, flags & SC_KERNEL_CONSOLE);
sc->config = flags;
@ -1507,7 +1487,6 @@ sc_cnputc(struct consdev *cd, int c)
{
u_char buf[1];
scr_stat *scp = sc_console;
void *save;
#ifndef SC_NO_HISTORY
#if 0
struct tty *tp;
@ -1543,12 +1522,8 @@ sc_cnputc(struct consdev *cd, int c)
}
#endif /* !SC_NO_HISTORY */
save = scp->ts;
if (kernel_console_ts != NULL)
scp->ts = kernel_console_ts;
buf[0] = c;
sc_puts(scp, buf, 1);
scp->ts = save;
sc_puts(scp, buf, 1, 1);
s = spltty(); /* block sckbdevent and scrn_timer */
sccnupdate(scp);
@ -2492,7 +2467,7 @@ exchange_scr(sc_softc_t *sc)
}
void
sc_puts(scr_stat *scp, u_char *buf, int len)
sc_puts(scr_stat *scp, u_char *buf, int len, int kernel)
{
int need_unlock = 0;
@ -2507,7 +2482,7 @@ sc_puts(scr_stat *scp, u_char *buf, int len)
need_unlock = 1;
mtx_lock_spin(&scp->scr_lock);
}
(*scp->tsw->te_puts)(scp, buf, len);
(*scp->tsw->te_puts)(scp, buf, len, kernel);
if (need_unlock)
mtx_unlock_spin(&scp->scr_lock);
}
@ -2754,8 +2729,8 @@ scinit(int unit, int flags)
if (sc_init_emulator(scp, SC_DFLT_TERM))
sc_init_emulator(scp, "*");
(*scp->tsw->te_default_attr)(scp,
kernel_default.std_color,
kernel_default.rev_color);
user_default.std_color,
user_default.rev_color);
} else {
/* assert(sc_malloc) */
sc->dev = malloc(sizeof(struct tty *)*sc->vtys, M_DEVBUF,

View File

@ -368,7 +368,7 @@ typedef int sc_term_init_t(scr_stat *scp, void **tcp, int code);
#define SC_TE_COLD_INIT 0
#define SC_TE_WARM_INIT 1
typedef int sc_term_term_t(scr_stat *scp, void **tcp);
typedef void sc_term_puts_t(scr_stat *scp, u_char *buf, int len);
typedef void sc_term_puts_t(scr_stat *scp, u_char *buf, int len, int kernel);
typedef int sc_term_ioctl_t(scr_stat *scp, struct tty *tp, u_long cmd,
caddr_t data, struct thread *td);
typedef int sc_term_reset_t(scr_stat *scp, int code);
@ -553,7 +553,7 @@ void sc_save_font(scr_stat *scp, int page, int size, int width,
void sc_show_font(scr_stat *scp, int page);
void sc_touch_scrn_saver(void);
void sc_puts(scr_stat *scp, u_char *buf, int len);
void sc_puts(scr_stat *scp, u_char *buf, int len, int kernel);
void sc_draw_cursor_image(scr_stat *scp);
void sc_remove_cursor_image(scr_stat *scp);
void sc_set_cursor_image(scr_stat *scp);

View File

@ -336,6 +336,13 @@ teken_get_curattr(teken_t *t)
return (&t->t_curattr);
}
void
teken_set_curattr(teken_t *t, const teken_attr_t *a)
{
t->t_curattr = *a;
}
const teken_attr_t *
teken_get_defattr(teken_t *t)
{

View File

@ -174,6 +174,7 @@ void teken_input(teken_t *, const void *, size_t);
const teken_attr_t *teken_get_curattr(teken_t *);
const teken_attr_t *teken_get_defattr(teken_t *);
void teken_set_cursor(teken_t *, const teken_pos_t *);
void teken_set_curattr(teken_t *, const teken_attr_t *);
void teken_set_defattr(teken_t *, const teken_attr_t *);
void teken_set_winsize(teken_t *, const teken_pos_t *);

View File

@ -907,18 +907,24 @@ scterm_scan_esc(scr_stat *scp, term_stat *tcp, u_char c)
}
static void
scterm_puts(scr_stat *scp, u_char *buf, int len)
scterm_puts(scr_stat *scp, u_char *buf, int len, int kernel)
{
term_stat *tcp;
u_char *ptr;
#ifdef KANJI
u_short kanji_code;
#endif
color_t backup;
tcp = scp->ts;
ptr = buf;
outloop:
scp->sc->write_in_progress++;
backup = tcp->cur_color;
if (kernel) {
tcp->cur_color.fg = SC_KERNEL_CONS_ATTR & 0x0f;
tcp->cur_color.bg = (SC_KERNEL_CONS_ATTR >> 4) & 0x0f;
}
if (tcp->esc) {
scterm_scan_esc(scp, tcp, *ptr++);
@ -1101,6 +1107,8 @@ scterm_puts(scr_stat *scp, u_char *buf, int len)
sc_term_gen_scroll(scp, scp->sc->scr_map[0x20], tcp->cur_attr);
if (kernel)
tcp->cur_color = backup;
scp->sc->write_in_progress--;
if (len)
goto outloop;