Subject: port-sparc/2561: [dM] console size sometimes wrong
To: None <gnats-bugs@NetBSD.ORG>
From: der Mouse <mouse@Collatz.McRCIM.McGill.EDU>
List: netbsd-bugs
Date: 06/20/1996 10:21:44
>Number:         2561
>Category:       port-sparc
>Synopsis:       [dM] console size sometimes wrong
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    gnats-admin (GNATS administrator)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Jun 20 11:20:01 1996
>Last-Modified:
>Originator:     der Mouse
>Organization:
	Dis-
>Release:        -current sup (ie, 1.2 release branch) of June 10th
>Environment:
	SPARC IPC, but any with RASTERCONSOLE is vulnerable
>Description:
	cnopen() always generates its t_winsize from the ROM
	screen-#rows and screen-#columns values (sun4c, sun4m) or the
	eeTtyRows and eeTtyCols values (sun4).  But if the console is
	not a framebuffer, or if RASTERCONSOLE and
	RASTERCONS_FULLSCREEN and RASTERCONS_SMALLFONT (possibly with
	just some of those), this does not reflect the actual screen
	size.
>How-To-Repeat:
	Build a kernel with RASTERCONSOLE and RASTERCONS_FULLSCREEN and
	RASTERCONS_SMALLFONT.  Boot it on a framebuffer-console
	machine.  Log in and "stty size".  Notice it gives you the size
	from the roms (probably 80x34) instead of the actual size
	(192x69).
>Fix:
	Here's what I did.  If fixes the problem for me, though
	admittedly I haven't tried using a serial console.

--- OLD/sys/arch/sparc/dev/cons.c	Thu Jan  1 00:00:00 1970
+++ NEW/sys/arch/sparc/dev/cons.c	Thu Jan  1 00:00:00 1970
@@ -277,7 +277,7 @@
 {
 	register struct tty *tp = &cons;
  	static int firstopen = 1;
-	static int rows = 0, cols = 0;
+	static int rows, cols;
 
 	if (firstopen) {
 		clalloc(&tp->t_rawq, 1024, 1);
@@ -288,17 +288,25 @@
 		/*
 		 * get the console struct winsize.
 		 */
+		rows = -1;
+		cols = -1;
+		if (fbconstty) {
+			extern int fb_get_rows(void); /* XXX these should be in a .h */
+			extern int fb_get_cols(void);
+			rows = fb_get_rows();
+			cols = fb_get_cols();
+		}
 		if (CPU_ISSUN4COR4M) {
 			int i;
 			char *prop;
 
-			if ((prop = getpropstring(optionsnode, "screen-#rows"))) {
+			if ((rows < 0) && (prop = getpropstring(optionsnode, "screen-#rows"))) {
 				i = 0;
 				while (*prop != '\0')
 					i = i * 10 + *prop++ - '0';
 				rows = (unsigned short)i;
 			}
-			if ((prop = getpropstring(optionsnode, "screen-#columns"))) {
+			if ((cols < 0) && (prop = getpropstring(optionsnode, "screen-#columns"))) {
 				i = 0;
 				while (*prop != '\0')
 					i = i * 10 + *prop++ - '0';
@@ -309,10 +317,12 @@
 			struct eeprom *ep = (struct eeprom *)eeprom_va;
 
 			if (ep) {
-				rows = (u_short)ep->eeTtyRows;
-				cols = (u_short)ep->eeTtyCols;
+				if (rows < 0) rows = (u_short)ep->eeTtyRows;
+				if (cols < 0) cols = (u_short)ep->eeTtyCols;
 			}
 		}
+		if (rows < 0) rows = 0;
+		if (cols < 0) cols = 0;
 		firstopen = 0;
 	}
 
--- OLD/sys/arch/sparc/dev/fb.c	Thu Jan  1 00:00:00 1970
+++ NEW/sys/arch/sparc/dev/fb.c	Thu Jan  1 00:00:00 1970
@@ -68,6 +68,11 @@
 static struct fbdevice *devfb;
 
 
+/* XXX these should be in a .h */
+int fb_get_rows(void);
+int fb_get_cols(void);
+
+
 void
 fb_unblank()
 {
@@ -76,6 +81,18 @@
 		(*devfb->fb_driver->fbd_unblank)(devfb->fb_device);
 }
 
+int
+fb_get_rows(void)
+{
+	return(devfb?devfb->fb_rcons.rc_maxrow:-1);
+}
+
+int
+fb_get_cols(void)
+{
+	return(devfb?devfb->fb_rcons.rc_maxcol:-1);
+}
+
 void
 fb_attach(fb, isconsole)
 	struct fbdevice *fb;

					der Mouse

			    mouse@collatz.mcrcim.mcgill.edu
>Audit-Trail:
>Unformatted: