summaryrefslogtreecommitdiff
path: root/sys/dev/rasops
diff options
context:
space:
mode:
authortsutsui <tsutsui@NetBSD.org>2013-12-02 14:05:51 +0000
committertsutsui <tsutsui@NetBSD.org>2013-12-02 14:05:51 +0000
commit9b79eefa63dbd8b2f10609d49650d9dcd633042e (patch)
tree58980c7bf366306c132e9661571d4ac244d4f73d /sys/dev/rasops
parent639e04fbf62079693b33ff1971e5f2f3187728b2 (diff)
Fix 1 bpp rasops copycols() op:
- fix inverted shift direction in MBL() and MBR() macro in BE case (used by GETBITS() and PUTBITS() in copycols() function in rasops_bitops.h) - make all bitmask values unsigned and use proper uint32_t types for bitmap variables (to avoid arithmetic right shift) - fix various botches in right-to-left copy op (logic is taken from hp300) Tested on bwtwo(4) on NetBSD/sparc.
Diffstat (limited to 'sys/dev/rasops')
-rw-r--r--sys/dev/rasops/README3
-rw-r--r--sys/dev/rasops/rasops_bitops.h132
-rw-r--r--sys/dev/rasops/rasops_masks.c10
-rw-r--r--sys/dev/rasops/rasops_masks.h12
4 files changed, 79 insertions, 78 deletions
diff --git a/sys/dev/rasops/README b/sys/dev/rasops/README
index 0530f39edb5..232ab223f80 100644
--- a/sys/dev/rasops/README
+++ b/sys/dev/rasops/README
@@ -1,4 +1,4 @@
-$NetBSD: README,v 1.5 2008/01/07 00:25:19 bjs Exp $
+$NetBSD: README,v 1.6 2013/12/02 14:05:51 tsutsui Exp $
This directory contains `rasops', a set of raster operations intended to
replace the dev/rcons/raster stuff for both wscons and rcons. It yields
@@ -8,7 +8,6 @@ Issues/TODO:
- There is no generic `putchar' function for 2bpp
- Color handling for 2bpp is broken
-- copycols() from rasops_bitops.h is broken in right->left case
- 64-bit types are not used on machines that are 64-bit
- We should never be doing reads/writes of less than 32-bits
- Flags in attribute values are hardcoded
diff --git a/sys/dev/rasops/rasops_bitops.h b/sys/dev/rasops/rasops_bitops.h
index 5b12a8243a6..c8a6540dc2a 100644
--- a/sys/dev/rasops/rasops_bitops.h
+++ b/sys/dev/rasops/rasops_bitops.h
@@ -1,4 +1,4 @@
-/* $NetBSD: rasops_bitops.h,v 1.14 2013/05/21 15:57:21 tsutsui Exp $ */
+/* $NetBSD: rasops_bitops.h,v 1.15 2013/12/02 14:05:51 tsutsui Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -38,9 +38,9 @@
static void
NAME(erasecols)(void *cookie, int row, int col, int num, long attr)
{
- int lmask, rmask, lclr, rclr, clr;
+ int lclr, rclr, clr;
struct rasops_info *ri;
- int32_t *dp, *rp, *hrp = NULL, *hp = NULL, tmp;
+ uint32_t *dp, *rp, *hrp = NULL, *hp = NULL, tmp, lmask, rmask;
int height, cnt;
ri = (struct rasops_info *)cookie;
@@ -64,9 +64,9 @@ NAME(erasecols)(void *cookie, int row, int col, int num, long attr)
num *= ri->ri_font->fontwidth << PIXEL_SHIFT;
height = ri->ri_font->fontheight;
clr = ri->ri_devcmap[(attr >> 16) & 0xf];
- rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + ((col >> 3) & ~3));
+ rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + ((col >> 3) & ~3));
if (ri->ri_hwbits)
- hrp = (int32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
+ hrp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
((col >> 3) & ~3));
if ((col & 31) + num <= 32) {
lmask = ~rasops_pmask[col & 31][num];
@@ -74,13 +74,13 @@ NAME(erasecols)(void *cookie, int row, int col, int num, long attr)
while (height--) {
dp = rp;
- DELTA(rp, ri->ri_stride, int32_t *);
+ DELTA(rp, ri->ri_stride, uint32_t *);
tmp = (*dp & lmask) | lclr;
*dp = tmp;
if (ri->ri_hwbits) {
*hrp = tmp;
- DELTA(hrp, ri->ri_stride, int32_t *);
+ DELTA(hrp, ri->ri_stride, uint32_t *);
}
}
} else {
@@ -97,10 +97,10 @@ NAME(erasecols)(void *cookie, int row, int col, int num, long attr)
while (height--) {
dp = rp;
- DELTA(rp, ri->ri_stride, int32_t *);
+ DELTA(rp, ri->ri_stride, uint32_t *);
if (ri->ri_hwbits) {
hp = hrp;
- DELTA(hrp, ri->ri_stride, int32_t *);
+ DELTA(hrp, ri->ri_stride, uint32_t *);
}
if (lmask) {
@@ -136,16 +136,16 @@ NAME(erasecols)(void *cookie, int row, int col, int num, long attr)
static void
NAME(do_cursor)(struct rasops_info *ri)
{
- int lmask, rmask, height, row, col, num;
- int32_t *dp, *rp, *hp = NULL, *hrp = NULL, tmp;
+ int height, row, col, num;
+ uint32_t *dp, *rp, *hp = NULL, *hrp = NULL, tmp, lmask, rmask;
row = ri->ri_crow;
col = ri->ri_ccol * ri->ri_font->fontwidth << PIXEL_SHIFT;
height = ri->ri_font->fontheight;
num = ri->ri_font->fontwidth << PIXEL_SHIFT;
- rp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale + ((col >> 3) & ~3));
+ rp = (uint32_t *)(ri->ri_bits + row * ri->ri_yscale + ((col >> 3) & ~3));
if (ri->ri_hwbits)
- hrp = (int32_t *)(ri->ri_hwbits + row * ri->ri_yscale +
+ hrp = (uint32_t *)(ri->ri_hwbits + row * ri->ri_yscale +
((col >> 3) & ~3));
if ((col & 31) + num <= 32) {
@@ -153,14 +153,14 @@ NAME(do_cursor)(struct rasops_info *ri)
while (height--) {
dp = rp;
- DELTA(rp, ri->ri_stride, int32_t *);
+ DELTA(rp, ri->ri_stride, uint32_t *);
*dp ^= lmask;
}
if (ri->ri_hwbits) {
height = ri->ri_font->fontheight;
while (height--) {
hp = hrp;
- DELTA(hrp, ri->ri_stride, int32_t *);
+ DELTA(hrp, ri->ri_stride, uint32_t *);
*hp ^= lmask;
}
}
@@ -170,10 +170,10 @@ NAME(do_cursor)(struct rasops_info *ri)
while (height--) {
dp = rp;
- DELTA(rp, ri->ri_stride, int32_t *);
+ DELTA(rp, ri->ri_stride, uint32_t *);
if (ri->ri_hwbits) {
hp = hrp;
- DELTA(hrp, ri->ri_stride, int32_t *);
+ DELTA(hrp, ri->ri_stride, uint32_t *);
}
if (lmask != -1) {
tmp = *dp ^ lmask;
@@ -201,8 +201,9 @@ NAME(do_cursor)(struct rasops_info *ri)
static void
NAME(copycols)(void *cookie, int row, int src, int dst, int num)
{
- int tmp, lmask, rmask, height, lnum, rnum, sb, db, cnt, full;
- int32_t *sp, *dp, *srp, *drp, *dhp = NULL, *hp = NULL;
+ int height, lnum, rnum, sb, db, cnt, full;
+ uint32_t tmp, lmask, rmask;
+ uint32_t *sp, *dp, *srp, *drp, *dhp = NULL, *hp = NULL;
struct rasops_info *ri;
ri = (struct rasops_info *)cookie;
@@ -245,10 +246,10 @@ NAME(copycols)(void *cookie, int row, int src, int dst, int num)
if (db + num <= 32) {
/* Destination is contained within a single word */
- srp = (int32_t *)(ri->ri_bits + row + ((src >> 3) & ~3));
- drp = (int32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3));
+ srp = (uint32_t *)(ri->ri_bits + row + ((src >> 3) & ~3));
+ drp = (uint32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3));
if (ri->ri_hwbits)
- dhp = (int32_t *)(ri->ri_hwbits + row +
+ dhp = (uint32_t *)(ri->ri_hwbits + row +
((dst >> 3) & ~3));
sb = src & 31;
@@ -257,10 +258,10 @@ NAME(copycols)(void *cookie, int row, int src, int dst, int num)
PUTBITS(tmp, db, num, drp);
if (ri->ri_hwbits) {
PUTBITS(tmp, db, num, dhp);
- DELTA(dhp, ri->ri_stride, int32_t *);
+ DELTA(dhp, ri->ri_stride, uint32_t *);
}
- DELTA(srp, ri->ri_stride, int32_t *);
- DELTA(drp, ri->ri_stride, int32_t *);
+ DELTA(srp, ri->ri_stride, uint32_t *);
+ DELTA(drp, ri->ri_stride, uint32_t *);
}
return;
@@ -278,22 +279,23 @@ NAME(copycols)(void *cookie, int row, int src, int dst, int num)
if (src < dst && src + num > dst) {
/* Copy right-to-left */
- sb = src & 31;
- src = src + num;
- dst = dst + num;
- srp = (int32_t *)(ri->ri_bits + row + ((src >> 3) & ~3));
- drp = (int32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3));
- if (ri->ri_hwbits)
- dhp = (int32_t *)(ri->ri_hwbits + row +
- ((dst >> 3) & ~3));
+ bool sbover;
+ int sboff;
- src = src & 31;
- rnum = 32 - lnum;
- db = dst & 31;
+ srp = (uint32_t *)(ri->ri_bits + row +
+ (((src + num) >> 3) & ~3));
+ drp = (uint32_t *)(ri->ri_bits + row +
+ (((dst + num) >> 3) & ~3));
+ if (ri->ri_hwbits)
+ dhp = (uint32_t *)(ri->ri_hwbits + row +
+ (((dst + num) >> 3) & ~3));
- if ((src -= db) < 0) {
+ sb = src & 31;
+ sbover = (sb + lnum) >= 32;
+ sboff = (src + num) & 31;
+ if ((sboff -= rnum) < 0) {
srp--;
- src += 32;
+ sboff += 32;
}
while (height--) {
@@ -301,47 +303,47 @@ NAME(copycols)(void *cookie, int row, int src, int dst, int num)
dp = drp;
if (ri->ri_hwbits) {
hp = dhp;
- DELTA(dhp, ri->ri_stride, int32_t *);
+ DELTA(dhp, ri->ri_stride, uint32_t *);
}
- DELTA(srp, ri->ri_stride, int32_t *);
- DELTA(drp, ri->ri_stride, int32_t *);
+ DELTA(srp, ri->ri_stride, uint32_t *);
+ DELTA(drp, ri->ri_stride, uint32_t *);
- if (db) {
- GETBITS(sp, src, db, tmp);
- PUTBITS(tmp, 0, db, dp);
+ if (rnum) {
+ GETBITS(sp, sboff, rnum, tmp);
+ PUTBITS(tmp, 0, rnum, dp);
if (ri->ri_hwbits) {
- PUTBITS(tmp, 0, db, hp);
- hp--;
+ PUTBITS(tmp, 0, rnum, hp);
}
- dp--;
- sp--;
}
/* Now aligned to 32-bits wrt dp */
- for (cnt = full; cnt; cnt--, sp--) {
- GETBITS(sp, src, 32, tmp);
- *dp-- = tmp;
- if (ri->ri_hwbits)
- *hp-- = tmp;
+ for (cnt = full; cnt; cnt--) {
+ --dp;
+ --sp;
+ GETBITS(sp, sboff, 32, tmp);
+ *dp = tmp;
+ if (ri->ri_hwbits) {
+ --hp;
+ *hp = tmp;
+ }
}
if (lmask) {
-#if 0
- if (src > sb)
- sp++;
-#endif
+ if (sbover)
+ --sp;
+ --dp;
GETBITS(sp, sb, lnum, tmp);
- PUTBITS(tmp, rnum, lnum, dp);
+ PUTBITS(tmp, db, lnum, dp);
if (ri->ri_hwbits)
- PUTBITS(tmp, rnum, lnum, hp);
+ PUTBITS(tmp, db, lnum, hp);
}
}
} else {
/* Copy left-to-right */
- srp = (int32_t *)(ri->ri_bits + row + ((src >> 3) & ~3));
- drp = (int32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3));
+ srp = (uint32_t *)(ri->ri_bits + row + ((src >> 3) & ~3));
+ drp = (uint32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3));
if (ri->ri_hwbits)
- dhp = (int32_t *)(ri->ri_hwbits + row +
+ dhp = (uint32_t *)(ri->ri_hwbits + row +
((dst >> 3) & ~3));
db = dst & 31;
@@ -351,10 +353,10 @@ NAME(copycols)(void *cookie, int row, int src, int dst, int num)
dp = drp;
if (ri->ri_hwbits) {
hp = dhp;
- DELTA(dhp, ri->ri_stride, int32_t *);
+ DELTA(dhp, ri->ri_stride, uint32_t *);
}
- DELTA(srp, ri->ri_stride, int32_t *);
- DELTA(drp, ri->ri_stride, int32_t *);
+ DELTA(srp, ri->ri_stride, uint32_t *);
+ DELTA(drp, ri->ri_stride, uint32_t *);
if (lmask) {
GETBITS(sp, sb, lnum, tmp);
diff --git a/sys/dev/rasops/rasops_masks.c b/sys/dev/rasops/rasops_masks.c
index a70e21df43d..40f61099c7f 100644
--- a/sys/dev/rasops/rasops_masks.c
+++ b/sys/dev/rasops/rasops_masks.c
@@ -1,4 +1,4 @@
-/* $NetBSD: rasops_masks.c,v 1.8 2008/04/28 20:23:57 martin Exp $ */
+/* $NetBSD: rasops_masks.c,v 1.9 2013/12/02 14:05:51 tsutsui Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,12 +30,12 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rasops_masks.c,v 1.8 2008/04/28 20:23:57 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops_masks.c,v 1.9 2013/12/02 14:05:51 tsutsui Exp $");
#include "rasops_masks.h"
/* `ragged edge' bitmasks */
-const int32_t rasops_lmask[32+1] = {
+const uint32_t rasops_lmask[32+1] = {
MBE(0x00000000), MBE(0x7fffffff), MBE(0x3fffffff), MBE(0x1fffffff),
MBE(0x0fffffff), MBE(0x07ffffff), MBE(0x03ffffff), MBE(0x01ffffff),
MBE(0x00ffffff), MBE(0x007fffff), MBE(0x003fffff), MBE(0x001fffff),
@@ -47,7 +47,7 @@ const int32_t rasops_lmask[32+1] = {
MBE(0x00000000)
};
-const int32_t rasops_rmask[32+1] = {
+const uint32_t rasops_rmask[32+1] = {
MBE(0x00000000), MBE(0x80000000), MBE(0xc0000000), MBE(0xe0000000),
MBE(0xf0000000), MBE(0xf8000000), MBE(0xfc000000), MBE(0xfe000000),
MBE(0xff000000), MBE(0xff800000), MBE(0xffc00000), MBE(0xffe00000),
@@ -60,7 +60,7 @@ const int32_t rasops_rmask[32+1] = {
};
/* Part bitmasks */
-const int32_t rasops_pmask[32][32] = {
+const uint32_t rasops_pmask[32][32] = {
{ MBE(0xffffffff), MBE(0x80000000), MBE(0xc0000000), MBE(0xe0000000),
MBE(0xf0000000), MBE(0xf8000000), MBE(0xfc000000), MBE(0xfe000000),
MBE(0xff000000), MBE(0xff800000), MBE(0xffc00000), MBE(0xffe00000),
diff --git a/sys/dev/rasops/rasops_masks.h b/sys/dev/rasops/rasops_masks.h
index b60162c9d0b..e0862334739 100644
--- a/sys/dev/rasops/rasops_masks.h
+++ b/sys/dev/rasops/rasops_masks.h
@@ -1,4 +1,4 @@
-/* $NetBSD: rasops_masks.h,v 1.7 2008/04/28 20:23:57 martin Exp $ */
+/* $NetBSD: rasops_masks.h,v 1.8 2013/12/02 14:05:51 tsutsui Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -46,8 +46,8 @@
*/
#if BYTE_ORDER == BIG_ENDIAN
-#define MBL(x,y) ((y) > 31 ? 0 : (x) >> (y))
-#define MBR(x,y) ((y) > 31 ? 0 : (x) << (y))
+#define MBL(x,y) ((y) > 31 ? 0 : (x) << (y))
+#define MBR(x,y) ((y) > 31 ? 0 : (x) >> (y))
#define MBE(x) (x)
#else
@@ -88,8 +88,8 @@
} while(0);
/* rasops_masks.c */
-extern const int32_t rasops_lmask[32+1];
-extern const int32_t rasops_rmask[32+1];
-extern const int32_t rasops_pmask[32][32];
+extern const uint32_t rasops_lmask[32+1];
+extern const uint32_t rasops_rmask[32+1];
+extern const uint32_t rasops_pmask[32][32];
#endif /* _RASOPS_MASKS_H_ */