Module Name:    src
Committed By:   macallan
Date:           Mon Mar 16 22:02:38 UTC 2020

Modified Files:
        src/sys/arch/powerpc/oea: ofw_rascons.c ofw_rasconsvar.h

Log Message:
make the ROM font usable on G5s:
- copy the font data into a buffer instead of just pointing at the ROM
- don't blindly assume the font's width
- don't try to center output ourselves - rasops_init() will do it for us
- provide a hook to add the ROM font to wsfont when we're ready


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/arch/powerpc/oea/ofw_rascons.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/powerpc/oea/ofw_rasconsvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/powerpc/oea/ofw_rascons.c
diff -u src/sys/arch/powerpc/oea/ofw_rascons.c:1.13 src/sys/arch/powerpc/oea/ofw_rascons.c:1.14
--- src/sys/arch/powerpc/oea/ofw_rascons.c:1.13	Mon Sep  3 16:29:26 2018
+++ src/sys/arch/powerpc/oea/ofw_rascons.c	Mon Mar 16 22:02:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_rascons.c,v 1.13 2018/09/03 16:29:26 riastradh Exp $	*/
+/*	$NetBSD: ofw_rascons.c,v 1.14 2020/03/16 22:02:37 macallan Exp $	*/
 
 /*
  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ofw_rascons.c,v 1.13 2018/09/03 16:29:26 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_rascons.c,v 1.14 2020/03/16 22:02:37 macallan Exp $");
 
 #include "wsdisplay.h"
 
@@ -65,6 +65,9 @@ static vaddr_t fbaddr;
 static int romfont_loaded = 0;
 static int needs_finalize = 0;
 
+#define FONTBUFSIZE (2048)	/* enough for 96 6x11 bitmap characters */ 
+static uint8_t fontbuf[FONTBUFSIZE];
+
 struct vcons_screen rascons_console_screen;
 
 struct wsscreen_descr rascons_stdscreen = {
@@ -86,8 +89,10 @@ rascons_cnattach(void)
 	OF_interpret("line#", 0, 1, &crow);
 
 	/* move (rom monitor) cursor to the lowest line - 1 */
+	/* XXXX - Why? */
+#if 0
 	OF_interpret("#lines 2 - to line#", 0, 0);
-
+#endif
 	wsfont_init();
 	if (copy_rom_font() == 0) {
 #if !defined(OFWOEA_WSCONS_NO_ROM_FONT)
@@ -142,23 +147,37 @@ rascons_cnattach(void)
 }
 
 void
+rascons_add_rom_font(void)
+{
+	wsfont_init();
+	if (romfont_loaded) {
+		wsfont_add(&openfirm6x11, 0);
+	}
+}
+
+void
 rascons_finalize(void)
 {
 	struct rasops_info *ri = &rascons_console_screen.scr_ri;
 	long defattr;
+	int crow = 0;
 
 	if (needs_finalize == 0) return;
-	
+
+	/* get current cursor position */
+	if (romfont_loaded) OF_interpret("line#", 0, 1, &crow);
+
 	ri->ri_ops.allocattr(ri, 0, 0, 0, &defattr);
-	wsdisplay_preattach(&rascons_stdscreen, ri, 0, 0, defattr);
+	wsdisplay_preattach(&rascons_stdscreen, ri, 0, uimax(0,
+		    uimin(crow, ri->ri_rows - 1)), defattr);
 }
 
 static int
 copy_rom_font(void)
 {
 	u_char *romfont;
-	int char_width, char_height;
-	int chosen, mmu, m, e;
+	int char_width, char_height, stride;
+	int chosen, mmu, m, e, size;
 
 	/* Get ROM FONT address. */
 	OF_interpret("font-adr", 0, 1, &romfont);
@@ -178,16 +197,22 @@ copy_rom_font(void)
 	OF_interpret("char-width", 0, 1, &char_width);
 	OF_interpret("char-height", 0, 1, &char_height);
 
+	stride = (char_width + 7) >> 3;
+	size = stride * char_height * 96;
+	if (size > FONTBUFSIZE) return -1;
+	
+	memcpy(fontbuf, romfont, size);
+
 	openfirm6x11.name = "Open Firmware";
 	openfirm6x11.firstchar = 32;
 	openfirm6x11.numchars = 96;
 	openfirm6x11.encoding = WSDISPLAY_FONTENC_ISO;
 	openfirm6x11.fontwidth = char_width;
 	openfirm6x11.fontheight = char_height;
-	openfirm6x11.stride = 1;
+	openfirm6x11.stride = stride;
 	openfirm6x11.bitorder = WSDISPLAY_FONTORDER_L2R;
 	openfirm6x11.byteorder = WSDISPLAY_FONTORDER_L2R;
-	openfirm6x11.data = romfont;
+	openfirm6x11.data = fontbuf;
 
 	return 0;
 }
@@ -223,7 +248,7 @@ rascons_init_rasops(int node, struct ras
 
 	/* mimic firmware output if we can find the ROM font */
 	if (romfont_loaded) {
-		int cols, rows;
+		int cols = 0, rows = 0;
 
 		/*
 		 * XXX this assumes we're the console which may or may not
@@ -234,12 +259,12 @@ rascons_init_rasops(int node, struct ras
 		ri->ri_font = &openfirm6x11;
 		ri->ri_wsfcookie = -1;		/* not using wsfont */
 		rasops_init(ri, rows, cols);
-
-		ri->ri_xorigin = (width - cols * ri->ri_font->fontwidth) >> 1;
-		ri->ri_yorigin = (height - rows * ri->ri_font->fontheight)
-		    >> 1;
-		ri->ri_bits = (char *)fbaddr + ri->ri_xorigin +
-			      ri->ri_stride * ri->ri_yorigin;
+#ifdef RASCONS_DEBUG
+		char buffer[128];
+		snprintf(buffer, 128, "bits %08x c %d w %d -> %d %d\n",
+		    (uint32_t)ri->ri_bits, cols, width, ri->ri_xorigin, ri->ri_yorigin);
+		OF_write(console_instance, buffer, strlen(buffer));
+#endif
 	} else {
 		/* use as much of the screen as the font permits */
 		rasops_init(ri, height/8, width/8);

Index: src/sys/arch/powerpc/oea/ofw_rasconsvar.h
diff -u src/sys/arch/powerpc/oea/ofw_rasconsvar.h:1.2 src/sys/arch/powerpc/oea/ofw_rasconsvar.h:1.3
--- src/sys/arch/powerpc/oea/ofw_rasconsvar.h:1.2	Fri Mar  2 14:37:18 2018
+++ src/sys/arch/powerpc/oea/ofw_rasconsvar.h	Mon Mar 16 22:02:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_rasconsvar.h,v 1.2 2018/03/02 14:37:18 macallan Exp $	*/
+/*	$NetBSD: ofw_rasconsvar.h,v 1.3 2020/03/16 22:02:37 macallan Exp $	*/
 
 /*
  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
@@ -34,5 +34,6 @@ extern struct vcons_screen rascons_conso
 extern struct wsscreen_descr rascons_stdscreen;
 int rascons_init_rasops(int, struct rasops_info *);
 void rascons_finalize(void);
+void rascons_add_rom_font(void);
 
 #endif /* _OFW_RASCONSVAR_H_ */

Reply via email to