Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 14 Mar 2018 07:39:28 +0000 (UTC)
From:      Eitan Adler <eadler@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r330915 - stable/11/sys/dev/syscons
Message-ID:  <201803140739.w2E7dSEl067184@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: eadler
Date: Wed Mar 14 07:39:28 2018
New Revision: 330915
URL: https://svnweb.freebsd.org/changeset/base/330915

Log:
  MFC r315003,r315065,r315066:
  
  Rename scteken_revattr() to scteken_sc_to_te_attr().  scteken_revattr()
  looked like it might handle reverse attributes, but it actually handles
  conversion of attributes in the direction indicated by the new name.
  Reverse attributes are just broken.
  
  Rename scteken_attr() to scteken_te_to_sc_attr().  scteken_attr() looked
  like it might give teken attributes, but it actually gives sc attributes.
  
  Change scteken_te_to_sc_attr() to return int instead of unsigned int.
  u_char would be enough, and it promotes to int, and syscons uses int
  or u_short for its attributes everywhere else (u_short holds a shifted
  form and it promotes to int too).
  
  Add a scteken_set_cursor() (sc to teken) method and use it to fix
  some cases of initialization and resetting of the teken cursor position.
  (This bad name is consistent with others, but it is too easy to confuse
  with scteken_cursor() which goes in the opposite direction.)
  
  The following cases were broken:
  - for booting without a syscons console, the teken and sc positions for
    ttyv0 were (0, 0), but are supposed to be somewhere in the middle of
    the screen (after carefully preserved BIOS and loader messages) (at
    least if there is no mode switch that loses the messages).
  - after mode switches, the screen is cleared and the cursor is supposed to
    be moved to (0, 0), but it was only moved there for sc.
  
  The following case was hacked to work:
  - for booting with a syscons console, it was arranged that scteken_init()
    for the console could see a nonzero cursor position and adjust, although
    this broke the sc seeing it in the non-console case above.
  
  Fix the attribute for scteken_clear() (change it back from the user
  user default normal attribute to the current attribute).
  
  This change only fixes a logic error.  scterm_clear() used to be
  used for terminal reset, but teken uses a general fill function for
  that, leaving scterm_clear() only used for initialization and mode
  change, when using the user default attribute is correct.  It is not
  really a terminal function, but needs to sync its changes with the
  terminal layer.  Syncing of the attribute is currently broken for
  terminal reset, but works for initialization and mode change.

Modified:
  stable/11/sys/dev/syscons/scterm-teken.c
  stable/11/sys/dev/syscons/syscons.c
  stable/11/sys/dev/syscons/syscons.h
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/dev/syscons/scterm-teken.c
==============================================================================
--- stable/11/sys/dev/syscons/scterm-teken.c	Wed Mar 14 07:32:48 2018	(r330914)
+++ stable/11/sys/dev/syscons/scterm-teken.c	Wed Mar 14 07:39:28 2018	(r330915)
@@ -53,8 +53,8 @@ __FBSDID("$FreeBSD$");
 
 #include <teken/teken.h>
 
-static void scteken_revattr(unsigned char, teken_attr_t *);
-static unsigned int scteken_attr(const teken_attr_t *);
+static void scteken_sc_to_te_attr(unsigned char, teken_attr_t *);
+static int scteken_te_to_sc_attr(const teken_attr_t *);
 
 static sc_term_init_t		scteken_init;
 static sc_term_term_t		scteken_term;
@@ -64,6 +64,7 @@ static sc_term_default_attr_t	scteken_default_attr;
 static sc_term_clear_t		scteken_clear;
 static sc_term_input_t		scteken_input;
 static sc_term_fkeystr_t	scteken_fkeystr;
+static sc_term_set_cursor_t	scteken_set_cursor;
 static void			scteken_nop(void);
 
 typedef struct {
@@ -90,6 +91,7 @@ static sc_term_sw_t sc_term_scteken = {
 	(sc_term_notify_t *)scteken_nop,
 	scteken_input,
 	scteken_fkeystr,
+	scteken_set_cursor,
 };
 
 SCTERM_MODULE(scteken, sc_term_scteken);
@@ -142,13 +144,6 @@ scteken_init(scr_stat *scp, void **softc, int code)
 		tp.tp_row = scp->ysize;
 		tp.tp_col = scp->xsize;
 		teken_set_winsize(&ts->ts_teken, &tp);
-
-		if (scp->cursor_pos < scp->ysize * scp->xsize) {
-			/* Valid old cursor position. */
-			tp.tp_row = scp->cursor_pos / scp->xsize;
-			tp.tp_col = scp->cursor_pos % scp->xsize;
-			teken_set_cursor(&ts->ts_teken, &tp);
-		}
 		break;
 	}
 
@@ -178,7 +173,7 @@ scteken_puts(scr_stat *scp, u_char *buf, int len, int 
 	if (kernel) {
 		/* Use special colors for kernel messages. */
 		backup = *teken_get_curattr(&ts->ts_teken);
-		scteken_revattr(sc_kattr(), &kattr);
+		scteken_sc_to_te_attr(sc_kattr(), &kattr);
 		teken_set_curattr(&ts->ts_teken, &kattr);
 		teken_input(&ts->ts_teken, buf, len);
 		teken_set_curattr(&ts->ts_teken, &backup);
@@ -195,19 +190,19 @@ scteken_ioctl(scr_stat *scp, struct tty *tp, u_long cm
 {
 	teken_stat *ts = scp->ts;
 	vid_info_t *vi;
-	unsigned int attr;
+	int attr;
 
 	switch (cmd) {
 	case GIO_ATTR:      	/* get current attributes */
 		*(int*)data =
-		    scteken_attr(teken_get_curattr(&ts->ts_teken));
+		    scteken_te_to_sc_attr(teken_get_curattr(&ts->ts_teken));
 		return (0);
 	case CONS_GETINFO:  	/* get current (virtual) console info */
 		vi = (vid_info_t *)data;
 		if (vi->size != sizeof(struct vid_info))
 			return EINVAL;
 
-		attr = scteken_attr(teken_get_defattr(&ts->ts_teken));
+		attr = scteken_te_to_sc_attr(teken_get_defattr(&ts->ts_teken));
 		vi->mv_norm.fore = attr & 0x0f;
 		vi->mv_norm.back = (attr >> 4) & 0x0f;
 		vi->mv_rev.fore = vi->mv_norm.back;
@@ -227,16 +222,20 @@ scteken_default_attr(scr_stat *scp, int color, int rev
 	teken_stat *ts = scp->ts;
 	teken_attr_t ta;
 
-	scteken_revattr(color, &ta);
+	scteken_sc_to_te_attr(color, &ta);
 	teken_set_defattr(&ts->ts_teken, &ta);
 }
 
 static void
 scteken_clear(scr_stat *scp)
 {
+	teken_stat *ts = scp->ts;
 
 	sc_move_cursor(scp, 0, 0);
-	sc_vtb_clear(&scp->vtb, scp->sc->scr_map[0x20], SC_NORM_ATTR << 8);
+	scteken_set_cursor(scp, 0, 0);
+	sc_vtb_clear(&scp->vtb, scp->sc->scr_map[0x20],
+		     scteken_te_to_sc_attr(teken_get_curattr(&ts->ts_teken))
+		     << 8);
 	mark_all(scp);
 }
 
@@ -298,6 +297,17 @@ scteken_fkeystr(scr_stat *scp, int c)
 }
 
 static void
+scteken_set_cursor(scr_stat *scp, int col, int row)
+{
+	teken_stat *ts = scp->ts;
+	teken_pos_t tp;
+
+	tp.tp_col = col;
+	tp.tp_row = row;
+	teken_set_cursor(&ts->ts_teken, &tp);
+}
+
+static void
 scteken_nop(void)
 {
 
@@ -323,7 +333,7 @@ static const unsigned char bgcolors[TC_NCOLORS] = {
 };
 
 static void
-scteken_revattr(unsigned char color, teken_attr_t *a)
+scteken_sc_to_te_attr(unsigned char color, teken_attr_t *a)
 {
 	teken_color_t fg, bg;
 
@@ -362,10 +372,10 @@ scteken_revattr(unsigned char color, teken_attr_t *a)
 	}
 }
 
-static unsigned int
-scteken_attr(const teken_attr_t *a)
+static int
+scteken_te_to_sc_attr(const teken_attr_t *a)
 {
-	unsigned int attr = 0;
+	int attr = 0;
 	teken_color_t fg, bg;
 
 	if (a->ta_format & TF_REVERSE) {
@@ -560,7 +570,7 @@ scteken_putchar(void *arg, const teken_pos_t *tp, teke
 	 * characters. Simply print a space and assume that the left
 	 * hand side describes the entire character.
 	 */
-	attr = scteken_attr(a) << 8;
+	attr = scteken_te_to_sc_attr(a) << 8;
 	if (a->ta_format & TF_CJK_RIGHT)
 		c = ' ';
 #ifdef TEKEN_UTF8
@@ -592,7 +602,7 @@ scteken_fill(void *arg, const teken_rect_t *r, teken_c
 	unsigned int width;
 	int attr, row;
 
-	attr = scteken_attr(a) << 8;
+	attr = scteken_te_to_sc_attr(a) << 8;
 #ifdef TEKEN_UTF8
 	scteken_get_cp437(&c, &attr);
 #endif /* TEKEN_UTF8 */

Modified: stable/11/sys/dev/syscons/syscons.c
==============================================================================
--- stable/11/sys/dev/syscons/syscons.c	Wed Mar 14 07:32:48 2018	(r330914)
+++ stable/11/sys/dev/syscons/syscons.c	Wed Mar 14 07:39:28 2018	(r330915)
@@ -3148,16 +3148,6 @@ scinit(int unit, int flags)
 	    init_scp(sc, sc->first_vty, scp);
 	    sc_vtb_init(&scp->vtb, VTB_MEMORY, scp->xsize, scp->ysize,
 			(void *)sc_buffer, FALSE);
-
-	    /* move cursors to the initial positions */
-	    if (col >= scp->xsize)
-		col = 0;
-	    if (row >= scp->ysize)
-		row = scp->ysize - 1;
-	    scp->xpos = col;
-	    scp->ypos = row;
-	    scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
-
 	    if (sc_init_emulator(scp, SC_DFLT_TERM))
 		sc_init_emulator(scp, "*");
 	    (*scp->tsw->te_default_attr)(scp, SC_NORM_ATTR, SC_NORM_REV_ATTR);
@@ -3179,6 +3169,17 @@ scinit(int unit, int flags)
 	    sc_vtb_copy(&scp->scr, 0, &scp->vtb, 0, scp->xsize*scp->ysize);
 #endif
 
+	/* Sync h/w cursor position to s/w (sc and teken). */
+	if (col >= scp->xsize)
+	    col = 0;
+	if (row >= scp->ysize)
+	    row = scp->ysize - 1;
+	scp->xpos = col;
+	scp->ypos = row;
+	scp->cursor_pos = scp->cursor_oldpos = row*scp->xsize + col;
+	(*scp->tsw->te_set_cursor)(scp, col, row);
+
+	/* Sync BIOS cursor shape to s/w (sc only). */
 	if (bios_value.cursor_end < scp->font_size)
 	    sc->dflt_curs_attr.base = scp->font_size - 
 					  bios_value.cursor_end - 1;

Modified: stable/11/sys/dev/syscons/syscons.h
==============================================================================
--- stable/11/sys/dev/syscons/syscons.h	Wed Mar 14 07:32:48 2018	(r330914)
+++ stable/11/sys/dev/syscons/syscons.h	Wed Mar 14 07:39:28 2018	(r330915)
@@ -404,6 +404,7 @@ typedef void	sc_term_notify_t(scr_stat *scp, int event
 #define SC_TE_NOTIFY_VTSWITCH_OUT	1
 typedef int	sc_term_input_t(scr_stat *scp, int c, struct tty *tp);
 typedef const char *sc_term_fkeystr_t(scr_stat *scp, int c);
+typedef void sc_term_set_cursor_t(scr_stat *scp, int col, int row);
 
 typedef struct sc_term_sw {
 	LIST_ENTRY(sc_term_sw)	link;
@@ -422,6 +423,7 @@ typedef struct sc_term_sw {
 	sc_term_notify_t	*te_notify;
 	sc_term_input_t		*te_input;
 	sc_term_fkeystr_t	*te_fkeystr;
+	sc_term_set_cursor_t	*te_set_cursor;
 } sc_term_sw_t;
 
 #define SCTERM_MODULE(name, sw)					\



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201803140739.w2E7dSEl067184>