From a7ac0cc69ec0cb6646abefa00c4b05d65f97358e Mon Sep 17 00:00:00 2001 From: macallan Date: Mon, 16 Mar 2020 22:02:37 +0000 Subject: [PATCH] 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 --- sys/arch/powerpc/oea/ofw_rascons.c | 57 +++++++++++++++++++-------- sys/arch/powerpc/oea/ofw_rasconsvar.h | 3 +- 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/sys/arch/powerpc/oea/ofw_rascons.c b/sys/arch/powerpc/oea/ofw_rascons.c index 1550ef4abc6f..65456751bb97 100644 --- a/sys/arch/powerpc/oea/ofw_rascons.c +++ b/sys/arch/powerpc/oea/ofw_rascons.c @@ -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 -__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) @@ -141,24 +146,38 @@ rascons_cnattach(void) return 0; } +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 rasops_info *ri) /* 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 rasops_info *ri) 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); diff --git a/sys/arch/powerpc/oea/ofw_rasconsvar.h b/sys/arch/powerpc/oea/ofw_rasconsvar.h index 64c64e892509..156231e3a902 100644 --- a/sys/arch/powerpc/oea/ofw_rasconsvar.h +++ b/sys/arch/powerpc/oea/ofw_rasconsvar.h @@ -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_console_screen; 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_ */