Module Name:    src
Committed By:   martin
Date:           Sun Oct  5 20:12:49 UTC 2014

Modified Files:
        src/sys/arch/luna68k/dev [netbsd-7]: lunafb.c omrasops.c omrasopsvar.h

Log Message:
Pull up following revision(s) (requested by tsutsui in ticket #130):
        sys/arch/luna68k/dev/omrasops.c: revision 1.17
        sys/arch/luna68k/dev/omrasops.c: revision 1.18
        sys/arch/luna68k/dev/omrasops.c: revision 1.19
        sys/arch/luna68k/dev/omrasopsvar.h: revision 1.3
        sys/arch/luna68k/dev/lunafb.c: revision 1.36
Pull readability changes from OpenBSD/luna88k.
- prepare and use unpack_attr() function to get fg and bg from attribute
- use proper variable names to clarify meanings
Tested on LUNA-II with 8bpp framebuffer.
Put dumb optimizations to avoid conditionals in putchar drawing loops.
~10% improvements of time cat results on LUNA-II 8bpp framebuffer.
Pull LUNA's framebuffer improvements by Kenji Aoyama from OpenBSD/luna88k.
http://marc.info/?l=openbsd-cvs&m=141199909120631&w=2
> Use raster(logic) operation, or ROP, function on LUNA frame buffer.
> It makes 4bpp wscons putchar ~20% faster.
This Makes 4bpp wscons putchar ~30% on LUNA-II.
Also use the similar ROP in 1bpp putchar and cursor functions
and the 1bpp putchar is also ~5% faster.
While here, reduce diffs from OpenBSD a bit.
Tested on all 1bpp/4bpp/8bpp framebuffers.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.35.2.1 src/sys/arch/luna68k/dev/lunafb.c
cvs rdiff -u -r1.16 -r1.16.4.1 src/sys/arch/luna68k/dev/omrasops.c
cvs rdiff -u -r1.2 -r1.2.4.1 src/sys/arch/luna68k/dev/omrasopsvar.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/luna68k/dev/lunafb.c
diff -u src/sys/arch/luna68k/dev/lunafb.c:1.35 src/sys/arch/luna68k/dev/lunafb.c:1.35.2.1
--- src/sys/arch/luna68k/dev/lunafb.c:1.35	Fri Jul 25 16:40:12 2014
+++ src/sys/arch/luna68k/dev/lunafb.c	Sun Oct  5 20:12:49 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: lunafb.c,v 1.35 2014/07/25 16:40:12 tsutsui Exp $ */
+/* $NetBSD: lunafb.c,v 1.35.2.1 2014/10/05 20:12:49 martin Exp $ */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: lunafb.c,v 1.35 2014/07/25 16:40:12 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lunafb.c,v 1.35.2.1 2014/10/05 20:12:49 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -75,11 +75,8 @@ struct bt458 {
 };
 
 #define	OMFB_RFCNT	0xB1000000	/* video h-origin/v-origin */
-#define	OMFB_PLANEMASK	0xB1040000	/* planemask register */
-#define	OMFB_FB_WADDR	0xB1080008	/* common plane */
-#define	OMFB_FB_RADDR	0xB10C0008	/* plane #0 */
-#define	OMFB_ROPFUNC	0xB12C0000	/* ROP function code */
 #define	OMFB_RAMDAC	0xC1100000	/* Bt454/Bt458 RAMDAC */
+
 #define	OMFB_SIZE	(0xB1300000 - 0xB1080000 + PAGE_SIZE)
 
 struct hwcmap {

Index: src/sys/arch/luna68k/dev/omrasops.c
diff -u src/sys/arch/luna68k/dev/omrasops.c:1.16 src/sys/arch/luna68k/dev/omrasops.c:1.16.4.1
--- src/sys/arch/luna68k/dev/omrasops.c:1.16	Sat Dec 28 09:17:23 2013
+++ src/sys/arch/luna68k/dev/omrasops.c	Sun Oct  5 20:12:49 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: omrasops.c,v 1.16 2013/12/28 09:17:23 tsutsui Exp $ */
+/* $NetBSD: omrasops.c,v 1.16.4.1 2014/10/05 20:12:49 martin Exp $ */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
 
-__KERNEL_RCSID(0, "$NetBSD: omrasops.c,v 1.16 2013/12/28 09:17:23 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: omrasops.c,v 1.16.4.1 2014/10/05 20:12:49 martin Exp $");
 
 /*
  * Designed speficically for 'm68k bitorder';
@@ -68,6 +68,7 @@ static void	om1_eraserows(void *, int, i
 static void	om4_eraserows(void *, int, int, long);
 static int	om1_allocattr(void *, int, int, int, long *);
 static int	om4_allocattr(void *, int, int, int, long *);
+static void	om4_unpack_attr(long, int *, int *, int *);
 
 static int	omrasops_init(struct rasops_info *, int, int);
 
@@ -77,13 +78,6 @@ static int	omrasops_init(struct rasops_i
 #define	ALIGNMASK	(0x1f)
 #define	BYTESDONE	(4)
 
-#define	W(p) (*(uint32_t *)(p))
-#define	R(p) (*(uint32_t *)((uint8_t *)(p) + 0x40000))
-#define	P0(p) (*(uint32_t *)((uint8_t *)(p) + 0x40000))
-#define	P1(p) (*(uint32_t *)((uint8_t *)(p) + 0x80000))
-#define	P2(p) (*(uint32_t *)((uint8_t *)(p) + 0xc0000))
-#define	P3(p) (*(uint32_t *)((uint8_t *)(p) + 0x100000))
-
 /*
  * macros to handle unaligned bit copy ops.
  * See src/sys/dev/rasops/rasops_mask.h for MI version.
@@ -95,13 +89,13 @@ static int	omrasops_init(struct rasops_i
 #define	FASTGETBITS(psrc, x, w, dst)					\
 	asm("bfextu %3{%1:%2},%0"					\
 	    : "=d" (dst) 						\
-	    : "di" (x), "di" (w), "o" ((uint32_t *)(psrc)))
+	    : "di" (x), "di" (w), "o" (*(uint32_t *)(psrc)))
 
 /* luna68k version PUTBITS() that puts w bits from bit x at pdst memory */
 /* XXX this macro assumes (x + w) <= 32 to handle unaligned residual bits */
 #define	FASTPUTBITS(src, x, w, pdst)					\
 	asm("bfins %3,%0{%1:%2}"					\
-	    : "+o" ((uint32_t *)(pdst))					\
+	    : "+o" (*(uint32_t *)(pdst))				\
 	    : "di" (x), "di" (w), "d" (src)				\
 	    : "memory" );
 
@@ -136,16 +130,23 @@ om1_putchar(void *cookie, int row, int s
 	rmask = ALL1BITS << (-width & ALIGNMASK);
 	if (width <= BLITWIDTH) {
 		lmask &= rmask;
+		/* set lmask as ROP mask value, with THROUGH mode */
+		((volatile uint32_t *)OMFB_ROPFUNC)[ROP_THROUGH] = lmask;
+
 		while (height > 0) {
 			glyph = 0;
 			for (i = ri->ri_font->stride; i != 0; i--)
 				glyph = (glyph << 8) | *fb++;
 			glyph <<= (4 - ri->ri_font->stride) * NBBY;
 			glyph = (glyph >> align) ^ inverse;
-			P0(p) = (P0(p) & ~lmask) | (glyph & lmask);
+
+			*W(p) = glyph;
+
 			p += scanspan;
 			height--;
 		}
+		/* reset mask value */
+		((volatile uint32_t *)OMFB_ROPFUNC)[ROP_THROUGH] = ALL1BITS;
 	} else {
 		uint8_t *q = p;
 		uint32_t lhalf, rhalf;
@@ -156,14 +157,26 @@ om1_putchar(void *cookie, int row, int s
 				glyph = (glyph << 8) | *fb++;
 			glyph <<= (4 - ri->ri_font->stride) * NBBY;
 			lhalf = (glyph >> align) ^ inverse;
-			P0(p) = (P0(p) & ~lmask) | (lhalf & lmask);
+			/* set lmask as ROP mask value, with THROUGH mode */
+			((volatile uint32_t *)OMFB_ROPFUNC)[ROP_THROUGH] =
+			    lmask;
+			
+			*W(p) = lhalf;
+
 			p += BYTESDONE;
+
 			rhalf = (glyph << (BLITWIDTH - align)) ^ inverse;
-			P0(p) = (rhalf & rmask) | (P0(p) & ~rmask);
+			/* set rmask as ROP mask value, with THROUGH mode */
+			((volatile uint32_t *)OMFB_ROPFUNC)[ROP_THROUGH] =
+			    rmask;
+
+			*W(p) = rhalf;
 
 			p = (q += scanspan);
 			height--;
 		}
+		/* reset mask value */
+		((volatile uint32_t *)OMFB_ROPFUNC)[ROP_THROUGH] = ALL1BITS;
 	}
 }
 
@@ -173,9 +186,10 @@ om4_putchar(void *cookie, int row, int s
 	struct rasops_info *ri = cookie;
 	uint8_t *p;
 	int scanspan, startx, height, width, align, y;
-	uint32_t lmask, rmask, glyph;
-	uint32_t glyphbg, fg, bg;
-	int i;
+	uint32_t lmask, rmask, glyph, glyphbg, fgpat, bgpat;
+	uint32_t fgmask0, fgmask1, fgmask2, fgmask3;
+	uint32_t bgmask0, bgmask1, bgmask2, bgmask3;
+	int i, fg, bg;
 	uint8_t *fb;
 
 	scanspan = ri->ri_stride;
@@ -184,14 +198,30 @@ om4_putchar(void *cookie, int row, int s
 	height = ri->ri_font->fontheight;
 	fb = (uint8_t *)ri->ri_font->data +
 	    (uc - ri->ri_font->firstchar) * ri->ri_fontscale;
+	om4_unpack_attr(attr, &fg, &bg, NULL);
+	fgmask0 = (fg & 0x01) ? ALL1BITS : ALL0BITS;
+	fgmask1 = (fg & 0x02) ? ALL1BITS : ALL0BITS;
+	fgmask2 = (fg & 0x04) ? ALL1BITS : ALL0BITS;
+	fgmask3 = (fg & 0x08) ? ALL1BITS : ALL0BITS;
+	bgmask0 = (bg & 0x01) ? ALL1BITS : ALL0BITS;
+	bgmask1 = (bg & 0x02) ? ALL1BITS : ALL0BITS;
+	bgmask2 = (bg & 0x04) ? ALL1BITS : ALL0BITS;
+	bgmask3 = (bg & 0x08) ? ALL1BITS : ALL0BITS;
 
 	p = (uint8_t *)ri->ri_bits + y * scanspan + ((startx / 32) * 4);
 	align = startx & ALIGNMASK;
 	width = ri->ri_font->fontwidth + align;
 	lmask = ALL1BITS >> align;
 	rmask = ALL1BITS << (-width & ALIGNMASK);
+
+	/* select all planes for later ROP function target */
+	*(volatile uint32_t *)OMFB_PLANEMASK = 0xff;
+
 	if (width <= BLITWIDTH) {
 		lmask &= rmask;
+		/* set lmask as ROP mask value, with THROUGH mode */
+		((volatile uint32_t *)OMFB_ROPFUNC)[ROP_THROUGH] = lmask;
+
 		while (height > 0) {
 			glyph = 0;
 			for (i = ri->ri_font->stride; i != 0; i--)
@@ -199,21 +229,25 @@ om4_putchar(void *cookie, int row, int s
 			glyph <<= (4 - ri->ri_font->stride) * NBBY;
 			glyph = (glyph >> align);
 			glyphbg = glyph ^ ALL1BITS;
-			fg = (attr & 0x01000000) ? glyph : 0;
-			bg = (attr & 0x00010000) ? glyphbg : 0;
-			P0(p) = (P0(p) & ~lmask) | ((fg | bg) & lmask);
-			fg = (attr & 0x02000000) ? glyph : 0;
-			bg = (attr & 0x00020000) ? glyphbg : 0;
-			P1(p) = (P1(p) & ~lmask) | ((fg | bg) & lmask);
-			fg = (attr & 0x04000000) ? glyph : 0;
-			bg = (attr & 0x00040000) ? glyphbg : 0;
-			P2(p) = (P2(p) & ~lmask) | ((fg | bg) & lmask);
-			fg = (attr & 0x08000000) ? glyph : 0;
-			bg = (attr & 0x00080000) ? glyphbg : 0;
-			P3(p) = (P3(p) & ~lmask) | ((fg | bg) & lmask);
+
+			fgpat = glyph   & fgmask0;
+			bgpat = glyphbg & bgmask0;
+			*P0(p) = (fgpat | bgpat);
+			fgpat = glyph   & fgmask1;
+			bgpat = glyphbg & bgmask1;
+			*P1(p) = (fgpat | bgpat);
+			fgpat = glyph   & fgmask2;
+			bgpat = glyphbg & bgmask2;
+			*P2(p) = (fgpat | bgpat);
+			fgpat = glyph   & fgmask3;
+			bgpat = glyphbg & bgmask3;
+			*P3(p) = (fgpat | bgpat);
+
 			p += scanspan;
 			height--;
 		}
+		/* reset mask value */
+		((volatile uint32_t *)OMFB_ROPFUNC)[ROP_THROUGH] = ALL1BITS;
 	} else {
 		uint8_t *q = p;
 		uint32_t lhalf, rhalf;
@@ -226,38 +260,52 @@ om4_putchar(void *cookie, int row, int s
 			glyph <<= (4 - ri->ri_font->stride) * NBBY;
 			lhalf = (glyph >> align);
 			lhalfbg = lhalf ^ ALL1BITS;
-			fg = (attr & 0x01000000) ? lhalf : 0;
-			bg = (attr & 0x00010000) ? lhalfbg : 0;
-			P0(p) = (P0(p) & ~lmask) | ((fg | bg) & lmask);
-			fg = (attr & 0x02000000) ? lhalf : 0;
-			bg = (attr & 0x00020000) ? lhalfbg : 0;
-			P1(p) = (P1(p) & ~lmask) | ((fg | bg) & lmask);
-			fg = (attr & 0x04000000) ? lhalf : 0;
-			bg = (attr & 0x00040000) ? lhalfbg : 0;
-			P2(p) = (P2(p) & ~lmask) | ((fg | bg) & lmask);
-			fg = (attr & 0x08000000) ? lhalf : 0;
-			bg = (attr & 0x00080000) ? lhalfbg : 0;
-			P3(p) = (P3(p) & ~lmask) | ((fg | bg) & lmask);
+			/* set lmask as ROP mask value, with THROUGH mode */
+			((volatile uint32_t *)OMFB_ROPFUNC)[ROP_THROUGH] =
+			    lmask;
+
+			fgpat = lhalf   & fgmask0;
+			bgpat = lhalfbg & bgmask0;
+			*P0(p) = (fgpat | bgpat);
+			fgpat = lhalf   & fgmask1;
+			bgpat = lhalfbg & bgmask1;
+			*P1(p) = (fgpat | bgpat);
+			fgpat = lhalf   & fgmask2;
+			bgpat = lhalfbg & bgmask2;
+			*P2(p) = (fgpat | bgpat);
+			fgpat = lhalf   & fgmask3;
+			bgpat = lhalfbg & bgmask3;
+			*P3(p) = (fgpat | bgpat);
+
 			p += BYTESDONE;
+
 			rhalf = (glyph << (BLITWIDTH - align));
 			rhalfbg = rhalf ^ ALL1BITS;
-			fg = (attr & 0x01000000) ? rhalf : 0;
-			bg = (attr & 0x00010000) ? rhalfbg : 0;
-			P0(p) = ((fg | bg) & rmask) | (P0(p) & ~rmask);
-			fg = (attr & 0x02000000) ? rhalf : 0;
-			bg = (attr & 0x00020000) ? rhalfbg : 0;
-			P1(p) = ((fg | bg) & rmask) | (P1(p) & ~rmask);
-			fg = (attr & 0x04000000) ? rhalf : 0;
-			bg = (attr & 0x00040000) ? rhalfbg : 0;
-			P2(p) = ((fg | bg) & rmask) | (P2(p) & ~rmask);
-			fg = (attr & 0x08000000) ? rhalf : 0;
-			bg = (attr & 0x00080000) ? rhalfbg : 0;
-			P3(p) = ((fg | bg) & rmask) | (P3(p) & ~rmask);
+			/* set rmask as ROP mask value, with THROUGH mode */
+			((volatile uint32_t *)OMFB_ROPFUNC)[ROP_THROUGH] =
+			    rmask;
+
+			fgpat = rhalf   & fgmask0;
+			bgpat = rhalfbg & bgmask0;
+			*P0(p) = (fgpat | bgpat);
+			fgpat = rhalf   & fgmask1;
+			bgpat = rhalfbg & bgmask1;
+			*P1(p) = (fgpat | bgpat);
+			fgpat = rhalf   & fgmask2;
+			bgpat = rhalfbg & bgmask2;
+			*P2(p) = (fgpat | bgpat);
+			fgpat = rhalf   & fgmask3;
+			bgpat = rhalfbg & bgmask3;
+			*P3(p) = (fgpat | bgpat);
 
 			p = (q += scanspan);
 			height--;
 		}
+		/* reset mask value */
+		((volatile uint32_t *)OMFB_ROPFUNC)[ROP_THROUGH] = ALL1BITS;
 	}
+	/* select plane #0 only; XXX need this ? */
+	*(volatile uint32_t *)OMFB_PLANEMASK = 0x01;
 }
 
 static void
@@ -284,22 +332,22 @@ om1_erasecols(void *cookie, int row, int
 		lmask &= rmask;
 		fill  &= lmask;
 		while (height > 0) {
-			P0(p) = (P0(p) & ~lmask) | fill;
+			*P0(p) = (*P0(p) & ~lmask) | fill;
 			p += scanspan;
 			height--;
 		}
 	} else {
 		uint8_t *q = p;
 		while (height > 0) {
-			P0(p) = (P0(p) & ~lmask) | (fill & lmask);
+			*P0(p) = (*P0(p) & ~lmask) | (fill & lmask);
 			width -= 2 * BLITWIDTH;
 			while (width > 0) {
 				p += BYTESDONE;
-				P0(p) = fill;
+				*P0(p) = fill;
 				width -= BLITWIDTH;
 			}
 			p += BYTESDONE;
-			P0(p) = (fill & rmask) | (P0(p) & ~rmask);
+			*P0(p) = (fill & rmask) | (*P0(p) & ~rmask);
 
 			p = (q += scanspan);
 			width = w + align;
@@ -313,7 +361,7 @@ om4_erasecols(void *cookie, int row, int
 {
 	struct rasops_info *ri = cookie;
 	uint8_t *p;
-	int scanspan, startx, height, width, align, w, y;
+	int scanspan, startx, height, width, align, w, y, fg, bg;
 	uint32_t lmask, rmask, fill0, fill1, fill2, fill3;
 
 	scanspan = ri->ri_stride;;
@@ -321,10 +369,11 @@ om4_erasecols(void *cookie, int row, int
 	startx = ri->ri_font->fontwidth * startcol;
 	height = ri->ri_font->fontheight;
 	w = ri->ri_font->fontwidth * ncols;
-	fill0 = ((attr & 0x00010000) != 0) ? ALL1BITS : ALL0BITS;
-	fill1 = ((attr & 0x00020000) != 0) ? ALL1BITS : ALL0BITS;
-	fill2 = ((attr & 0x00040000) != 0) ? ALL1BITS : ALL0BITS;
-	fill3 = ((attr & 0x00080000) != 0) ? ALL1BITS : ALL0BITS;
+	om4_unpack_attr(attr, &fg, &bg, NULL);
+	fill0 = ((bg & 0x01) != 0) ? ALL1BITS : ALL0BITS;
+	fill1 = ((bg & 0x02) != 0) ? ALL1BITS : ALL0BITS;
+	fill2 = ((bg & 0x04) != 0) ? ALL1BITS : ALL0BITS;
+	fill3 = ((bg & 0x08) != 0) ? ALL1BITS : ALL0BITS;
 
 	p = (uint8_t *)ri->ri_bits + y * scanspan + ((startx / 32) * 4);
 	align = startx & ALIGNMASK;
@@ -338,34 +387,34 @@ om4_erasecols(void *cookie, int row, int
 		fill2 &= lmask;
 		fill3 &= lmask;
 		while (height > 0) {
-			P0(p) = (P0(p) & ~lmask) | fill0;
-			P1(p) = (P1(p) & ~lmask) | fill1;
-			P2(p) = (P2(p) & ~lmask) | fill2;
-			P3(p) = (P3(p) & ~lmask) | fill3;
+			*P0(p) = (*P0(p) & ~lmask) | fill0;
+			*P1(p) = (*P1(p) & ~lmask) | fill1;
+			*P2(p) = (*P2(p) & ~lmask) | fill2;
+			*P3(p) = (*P3(p) & ~lmask) | fill3;
 			p += scanspan;
 			height--;
 		}
 	} else {
 		uint8_t *q = p;
 		while (height > 0) {
-			P0(p) = (P0(p) & ~lmask) | (fill0 & lmask);
-			P1(p) = (P1(p) & ~lmask) | (fill1 & lmask);
-			P2(p) = (P2(p) & ~lmask) | (fill2 & lmask);
-			P3(p) = (P3(p) & ~lmask) | (fill3 & lmask);
+			*P0(p) = (*P0(p) & ~lmask) | (fill0 & lmask);
+			*P1(p) = (*P1(p) & ~lmask) | (fill1 & lmask);
+			*P2(p) = (*P2(p) & ~lmask) | (fill2 & lmask);
+			*P3(p) = (*P3(p) & ~lmask) | (fill3 & lmask);
 			width -= 2 * BLITWIDTH;
 			while (width > 0) {
 				p += BYTESDONE;
-				P0(p) = fill0;
-				P1(p) = fill1;
-				P2(p) = fill2;
-				P3(p) = fill3;
+				*P0(p) = fill0;
+				*P1(p) = fill1;
+				*P2(p) = fill2;
+				*P3(p) = fill3;
 				width -= BLITWIDTH;
 			}
 			p += BYTESDONE;
-			P0(p) = (fill0 & rmask) | (P0(p) & ~rmask);
-			P1(p) = (fill1 & rmask) | (P1(p) & ~rmask);
-			P2(p) = (fill2 & rmask) | (P2(p) & ~rmask);
-			P3(p) = (fill3 & rmask) | (P3(p) & ~rmask);
+			*P0(p) = (fill0 & rmask) | (*P0(p) & ~rmask);
+			*P1(p) = (fill1 & rmask) | (*P1(p) & ~rmask);
+			*P2(p) = (fill2 & rmask) | (*P2(p) & ~rmask);
+			*P3(p) = (fill3 & rmask) | (*P3(p) & ~rmask);
 
 			p = (q += scanspan);
 			width = w + align;
@@ -393,15 +442,15 @@ om1_eraserows(void *cookie, int startrow
 	rmask = ALL1BITS << (-width & ALIGNMASK);
 	q = p;
 	while (height > 0) {
-		P0(p) = fill;				/* always aligned */
+		*P0(p) = fill;				/* always aligned */
 		width -= 2 * BLITWIDTH;
 		while (width > 0) {
 			p += BYTESDONE;
-			P0(p) = fill;
+			*P0(p) = fill;
 			width -= BLITWIDTH;
 		}
 		p += BYTESDONE;
-		P0(p) = (fill & rmask) | (P0(p) & ~rmask);
+		*P0(p) = (fill & rmask) | (*P0(p) & ~rmask);
 		p = (q += scanspan);
 		width = w;
 		height--;
@@ -413,41 +462,42 @@ om4_eraserows(void *cookie, int startrow
 {
 	struct rasops_info *ri = cookie;
 	uint8_t *p, *q;
-	int scanspan, starty, height, width, w;
+	int scanspan, starty, height, width, w, fg, bg;
 	uint32_t rmask, fill0, fill1, fill2, fill3;
 
 	scanspan = ri->ri_stride;
 	starty = ri->ri_font->fontheight * startrow;
 	height = ri->ri_font->fontheight * nrows;
 	w = ri->ri_emuwidth;
-	fill0 = ((attr & 0x00010000) != 0) ? ALL1BITS : ALL0BITS;
-	fill1 = ((attr & 0x00020000) != 0) ? ALL1BITS : ALL0BITS;
-	fill2 = ((attr & 0x00040000) != 0) ? ALL1BITS : ALL0BITS;
-	fill3 = ((attr & 0x00080000) != 0) ? ALL1BITS : ALL0BITS;
+	om4_unpack_attr(attr, &fg, &bg, NULL);
+	fill0 = ((bg & 0x01) != 0) ? ALL1BITS : ALL0BITS;
+	fill1 = ((bg & 0x02) != 0) ? ALL1BITS : ALL0BITS;
+	fill2 = ((bg & 0x04) != 0) ? ALL1BITS : ALL0BITS;
+	fill3 = ((bg & 0x08) != 0) ? ALL1BITS : ALL0BITS;
 
 	p = (uint8_t *)ri->ri_bits + starty * scanspan;
 	width = w;
 	rmask = ALL1BITS << (-width & ALIGNMASK);
 	q = p;
 	while (height > 0) {
-		P0(p) = fill0;				/* always aligned */
-		P1(p) = fill1;
-		P2(p) = fill2;
-		P3(p) = fill3;
+		*P0(p) = fill0;				/* always aligned */
+		*P1(p) = fill1;
+		*P2(p) = fill2;
+		*P3(p) = fill3;
 		width -= 2 * BLITWIDTH;
 		while (width > 0) {
 			p += BYTESDONE;
-			P0(p) = fill0;
-			P1(p) = fill1;
-			P2(p) = fill2;
-			P3(p) = fill3;
+			*P0(p) = fill0;
+			*P1(p) = fill1;
+			*P2(p) = fill2;
+			*P3(p) = fill3;
 			width -= BLITWIDTH;
 		}
 		p += BYTESDONE;
-		P0(p) = (fill0 & rmask) | (P0(p) & ~rmask);
-		P1(p) = (fill1 & rmask) | (P1(p) & ~rmask);
-		P2(p) = (fill2 & rmask) | (P2(p) & ~rmask);
-		P3(p) = (fill3 & rmask) | (P3(p) & ~rmask);
+		*P0(p) = (fill0 & rmask) | (*P0(p) & ~rmask);
+		*P1(p) = (fill1 & rmask) | (*P1(p) & ~rmask);
+		*P2(p) = (fill2 & rmask) | (*P2(p) & ~rmask);
+		*P3(p) = (fill3 & rmask) | (*P3(p) & ~rmask);
 		p = (q += scanspan);
 		width = w;
 		height--;
@@ -477,15 +527,15 @@ om1_copyrows(void *cookie, int srcrow, i
 	rmask = ALL1BITS << (-width & ALIGNMASK);
 	q = p;
 	while (height > 0) {
-		P0(p + offset) = P0(p);			/* always aligned */
+		*P0(p + offset) = *P0(p);		/* always aligned */
 		width -= 2 * BLITWIDTH;
 		while (width > 0) {
 			p += BYTESDONE;
-			P0(p + offset) = P0(p);
+			*P0(p + offset) = *P0(p);
 			width -= BLITWIDTH;
 		}
 		p += BYTESDONE;
-		P0(p + offset) = (P0(p) & rmask) | (P0(p + offset) & ~rmask);
+		*P0(p + offset) = (*P0(p) & rmask) | (*P0(p + offset) & ~rmask);
 
 		p = (q += scanspan);
 		width = w;
@@ -516,24 +566,24 @@ om4_copyrows(void *cookie, int srcrow, i
 	rmask = ALL1BITS << (-width & ALIGNMASK);
 	q = p;
 	while (height > 0) {
-		P0(p + offset) = P0(p);			/* always aligned */
-		P1(p + offset) = P1(p);
-		P2(p + offset) = P2(p);
-		P3(p + offset) = P3(p);
+		*P0(p + offset) = *P0(p);		/* always aligned */
+		*P1(p + offset) = *P1(p);
+		*P2(p + offset) = *P2(p);
+		*P3(p + offset) = *P3(p);
 		width -= 2 * BLITWIDTH;
 		while (width > 0) {
 			p += BYTESDONE;
-			P0(p + offset) = P0(p);
-			P1(p + offset) = P1(p);
-			P2(p + offset) = P2(p);
-			P3(p + offset) = P3(p);
+			*P0(p + offset) = *P0(p);
+			*P1(p + offset) = *P1(p);
+			*P2(p + offset) = *P2(p);
+			*P3(p + offset) = *P3(p);
 			width -= BLITWIDTH;
 		}
 		p += BYTESDONE;
-		P0(p + offset) = (P0(p) & rmask) | (P0(p + offset) & ~rmask);
-		P1(p + offset) = (P1(p) & rmask) | (P1(p + offset) & ~rmask);
-		P2(p + offset) = (P2(p) & rmask) | (P2(p + offset) & ~rmask);
-		P3(p + offset) = (P3(p) & rmask) | (P3(p + offset) & ~rmask);
+		*P0(p + offset) = (*P0(p) & rmask) | (*P0(p + offset) & ~rmask);
+		*P1(p + offset) = (*P1(p) & rmask) | (*P1(p + offset) & ~rmask);
+		*P2(p + offset) = (*P2(p) & rmask) | (*P2(p + offset) & ~rmask);
+		*P3(p + offset) = (*P3(p) & rmask) | (*P3(p + offset) & ~rmask);
 
 		p = (q += scanspan);
 		width = w;
@@ -615,7 +665,7 @@ om1_copycols(void *cookie, int startrow,
 
 			for (cnt = full; cnt; cnt--) {
 				GETBITS(P0(sp), sboff, 32, tmp);
-				P0(dp) = tmp;
+				*P0(dp) = tmp;
 				sp += BYTESDONE;
 				dp += BYTESDONE;
 			}
@@ -653,7 +703,7 @@ om1_copycols(void *cookie, int startrow,
 				sp -= BYTESDONE;
 				dp -= BYTESDONE;
 				GETBITS(P0(sp), sboff, 32, tmp);
-				P0(dp) = tmp;
+				*P0(dp) = tmp;
 			}
 
 			if (lmask != 0) {
@@ -757,13 +807,13 @@ om4_copycols(void *cookie, int startrow,
 
 			for (cnt = full; cnt; cnt--) {
 				GETBITS(P0(sp), sboff, 32, tmp);
-				P0(dp) = tmp;
+				*P0(dp) = tmp;
 				GETBITS(P1(sp), sboff, 32, tmp);
-				P1(dp) = tmp;
+				*P1(dp) = tmp;
 				GETBITS(P2(sp), sboff, 32, tmp);
-				P2(dp) = tmp;
+				*P2(dp) = tmp;
 				GETBITS(P3(sp), sboff, 32, tmp);
-				P3(dp) = tmp;
+				*P3(dp) = tmp;
 				sp += BYTESDONE;
 				dp += BYTESDONE;
 			}
@@ -813,13 +863,13 @@ om4_copycols(void *cookie, int startrow,
 				sp -= BYTESDONE;
 				dp -= BYTESDONE;
 				GETBITS(P0(sp), sboff, 32, tmp);
-				P0(dp) = tmp;
+				*P0(dp) = tmp;
 				GETBITS(P1(sp), sboff, 32, tmp);
-				P1(dp) = tmp;
+				*P1(dp) = tmp;
 				GETBITS(P2(sp), sboff, 32, tmp);
-				P2(dp) = tmp;
+				*P2(dp) = tmp;
 				GETBITS(P3(sp), sboff, 32, tmp);
-				P3(dp) = tmp;
+				*P3(dp) = tmp;
 			}
 
 			if (lmask != 0) {
@@ -878,7 +928,7 @@ om1_cursor(void *cookie, int on, int row
 	struct rasops_info *ri = cookie;
 	uint8_t *p;
 	int scanspan, startx, height, width, align, y;
-	uint32_t lmask, rmask, image;
+	uint32_t lmask, rmask;
 
 	if (!on) {
 		/* make sure it's on */
@@ -905,25 +955,35 @@ om1_cursor(void *cookie, int on, int row
 	rmask = ALL1BITS << (-width & ALIGNMASK);
 	if (width <= BLITWIDTH) {
 		lmask &= rmask;
+		/* set lmask as ROP mask value, with INV2 mode */
+		((volatile uint32_t *)OMFB_ROPFUNC)[ROP_INV2] = lmask;
+
 		while (height > 0) {
-			image = P0(p);
-			P0(p) = (image & ~lmask) | ((image ^ ALL1BITS) & lmask);
+			*P0(p) = ALL1BITS;
 			p += scanspan;
 			height--;
 		}
+		/* reset mask value */
+		((volatile uint32_t *)OMFB_ROPFUNC)[ROP_THROUGH] = ALL1BITS;
 	} else {
 		uint8_t *q = p;
 
 		while (height > 0) {
-			image = P0(p);
-			P0(p) = (image & ~lmask) | ((image ^ ALL1BITS) & lmask);
+			/* set lmask as ROP mask value, with INV2 mode */
+			((volatile uint32_t *)OMFB_ROPFUNC)[ROP_INV2] = lmask;
+			*W(p) = ALL1BITS;
+
 			p += BYTESDONE;
-			image = P0(p);
-			P0(p) = ((image ^ ALL1BITS) & rmask) | (image & ~rmask);
+
+			/* set lmask as ROP mask value, with INV2 mode */
+			((volatile uint32_t *)OMFB_ROPFUNC)[ROP_INV2] = rmask;
+			*W(p) = ALL1BITS;
 
 			p = (q += scanspan);
 			height--;
 		}
+		/* reset mask value */
+		((volatile uint32_t *)OMFB_ROPFUNC)[ROP_THROUGH] = ALL1BITS;
 	}
 	ri->ri_flg ^= RI_CURSOR;
 }
@@ -934,7 +994,7 @@ om4_cursor(void *cookie, int on, int row
 	struct rasops_info *ri = cookie;
 	uint8_t *p;
 	int scanspan, startx, height, width, align, y;
-	uint32_t lmask, rmask, image;
+	uint32_t lmask, rmask;
 
 	if (!on) {
 		/* make sure it's on */
@@ -959,46 +1019,45 @@ om4_cursor(void *cookie, int on, int row
 	width = ri->ri_font->fontwidth + align;
 	lmask = ALL1BITS >> align;
 	rmask = ALL1BITS << (-width & ALIGNMASK);
+
+	/* select all planes for later ROP function target */
+	*(volatile uint32_t *)OMFB_PLANEMASK = 0xff;
+
 	if (width <= BLITWIDTH) {
 		lmask &= rmask;
+		/* set lmask as ROP mask value, with INV2 mode */
+		((volatile uint32_t *)OMFB_ROPFUNC)[ROP_INV2] = lmask;
+
 		while (height > 0) {
-			image = P0(p);
-			P0(p) = (image & ~lmask) | ((image ^ ALL1BITS) & lmask);
-			image = P1(p);
-			P1(p) = (image & ~lmask) | ((image ^ ALL1BITS) & lmask);
-			image = P2(p);
-			P2(p) = (image & ~lmask) | ((image ^ ALL1BITS) & lmask);
-			image = P3(p);
-			P3(p) = (image & ~lmask) | ((image ^ ALL1BITS) & lmask);
+			*W(p) = ALL1BITS;
 			p += scanspan;
 			height--;
 		}
+		/* reset mask value */
+		((volatile uint32_t *)OMFB_ROPFUNC)[ROP_THROUGH] = ALL1BITS;
 	} else {
 		uint8_t *q = p;
 
 		while (height > 0) {
-			image = P0(p);
-			P0(p) = (image & ~lmask) | ((image ^ ALL1BITS) & lmask);
-			image = P1(p);
-			P1(p) = (image & ~lmask) | ((image ^ ALL1BITS) & lmask);
-			image = P2(p);
-			P2(p) = (image & ~lmask) | ((image ^ ALL1BITS) & lmask);
-			image = P3(p);
-			P3(p) = (image & ~lmask) | ((image ^ ALL1BITS) & lmask);
+			/* set lmask as ROP mask value, with INV2 mode */
+			((volatile uint32_t *)OMFB_ROPFUNC)[ROP_INV2] = lmask;
+			*W(p) = ALL1BITS;
+
 			p += BYTESDONE;
-			image = P0(p);
-			P0(p) = ((image ^ ALL1BITS) & rmask) | (image & ~rmask);
-			image = P1(p);
-			P1(p) = ((image ^ ALL1BITS) & rmask) | (image & ~rmask);
-			image = P2(p);
-			P2(p) = ((image ^ ALL1BITS) & rmask) | (image & ~rmask);
-			image = P3(p);
-			P3(p) = ((image ^ ALL1BITS) & rmask) | (image & ~rmask);
+
+			/* set rmask as ROP mask value, with INV2 mode */
+			((volatile uint32_t *)OMFB_ROPFUNC)[ROP_INV2] = rmask;
+			*W(p) = ALL1BITS;
 
 			p = (q += scanspan);
 			height--;
 		}
+		/* reset mask value */
+		((volatile uint32_t *)OMFB_ROPFUNC)[ROP_THROUGH] = ALL1BITS;
 	}
+	/* select plane #0 only; XXX need this ? */
+	*(volatile uint32_t *)OMFB_PLANEMASK = 0x01;
+
 	ri->ri_flg ^= RI_CURSOR;
 }
 
@@ -1044,6 +1103,14 @@ om4_allocattr(void *id, int fg, int bg, 
 	return 0;
 }
 
+static void
+om4_unpack_attr(long attr, int *fg, int *bg, int *underline)
+{
+
+	*fg = ((u_int)attr >> 24) & 0xf;
+	*bg = ((u_int)attr >> 16) & 0xf;
+}
+
 /*
  * Init subset of rasops(9) for omrasops.
  */

Index: src/sys/arch/luna68k/dev/omrasopsvar.h
diff -u src/sys/arch/luna68k/dev/omrasopsvar.h:1.2 src/sys/arch/luna68k/dev/omrasopsvar.h:1.2.4.1
--- src/sys/arch/luna68k/dev/omrasopsvar.h:1.2	Sat Dec 28 09:17:23 2013
+++ src/sys/arch/luna68k/dev/omrasopsvar.h	Sun Oct  5 20:12:49 2014
@@ -1,30 +1,69 @@
-/* $NetBSD: omrasopsvar.h,v 1.2 2013/12/28 09:17:23 tsutsui Exp $ */
+/* $NetBSD: omrasopsvar.h,v 1.2.4.1 2014/10/05 20:12:49 martin Exp $ */
+/*
+ * Copyright (c) 2013 Kenji Aoyama
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * Base addresses of LUNA's frame buffer
+ * XXX: We consider only 1bpp and 4bpp for now
+ */
 
-/*-
- * Copyright (c) 2012 The NetBSD Foundation, Inc.
- * All rights reserved.
+#define OMFB_PLANEMASK	0xB1040000	/* BMSEL register */
+#define OMFB_FB_WADDR	0xB1080008	/* common plane */
+#define OMFB_FB_RADDR	0xB10C0008	/* plane #0 */
+#define OMFB_ROPFUNC	0xB12C0000	/* common ROP function */
+
+/*
+ * Helper macros
+ */
+#define W(addr)  ((uint32_t *)(addr))
+#define R(addr)  ((uint32_t *)((uint8_t *)(addr) +  0x40000))
+#define P0(addr) ((uint32_t *)((uint8_t *)(addr) +  0x40000))
+#define P1(addr) ((uint32_t *)((uint8_t *)(addr) +  0x80000))
+#define P2(addr) ((uint32_t *)((uint8_t *)(addr) +  0xC0000))
+#define P3(addr) ((uint32_t *)((uint8_t *)(addr) + 0x100000))
+
+/*
+ * ROP function
  *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
+ * LUNA's frame buffer uses Hitach HM53462 video RAM, which has raster
+ * (logic) operation, or ROP, function.  To use ROP function on LUNA, write
+ * a 32bit `mask' value to the specified address corresponding to each ROP
+ * logic.
  *
- * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
+ * D: the data writing to the video RAM
+ * M: the data already stored on the video RAM
  */
 
+/* operation		index	the video RAM contents will be */
+#define ROP_ZERO	 0	/* all 0	*/
+#define ROP_AND1	 1	/* D & M	*/ 
+#define ROP_AND2	 2	/* ~D & M	*/
+/* Not used on LUNA	 3			*/
+#define ROP_AND3	 4	/* D & ~M	*/
+#define ROP_THROUGH	 5	/* D		*/
+#define ROP_EOR		 6	/* (~D & M) | (D & ~M)	*/
+#define ROP_OR1		 7	/* D | M	*/
+#define ROP_NOR		 8	/* ~D | ~M	*/
+#define ROP_ENOR	 9	/* (D & M) | (~D & ~M)	*/
+#define ROP_INV1	10	/* ~D		*/
+#define ROP_OR2		11	/* ~D | M	*/
+#define ROP_INV2	12	/* ~M		*/
+#define ROP_OR3		13	/* D | ~M	*/
+#define ROP_NAND	14	/* ~D | ~M	*/
+#define ROP_ONE		15	/* all 1	*/
+
 int omrasops1_init(struct rasops_info *, int, int);
 int omrasops4_init(struct rasops_info *, int, int);

Reply via email to