Module Name: src Committed By: rin Date: Sun Jul 28 12:06:11 UTC 2019
Modified Files: src/sys/dev/rasops: rasops.c rasops.h rasops15.c rasops2.c rasops24.c rasops32.c rasops4.c rasops8.c rasops_bitops.h rasops_putchar.h rasops_putchar_width.h Log Message: Cast attr to uint32_t before right shift to avoid undefined behavior. Also, misc style/cosmetic changes for clarity. To generate a diff of this commit: cvs rdiff -u -r1.93 -r1.94 src/sys/dev/rasops/rasops.c cvs rdiff -u -r1.36 -r1.37 src/sys/dev/rasops/rasops.h cvs rdiff -u -r1.29 -r1.30 src/sys/dev/rasops/rasops15.c cvs rdiff -u -r1.24 -r1.25 src/sys/dev/rasops/rasops2.c cvs rdiff -u -r1.35 -r1.36 src/sys/dev/rasops/rasops24.c cvs rdiff -u -r1.37 -r1.38 src/sys/dev/rasops/rasops32.c cvs rdiff -u -r1.18 -r1.19 src/sys/dev/rasops/rasops4.c cvs rdiff -u -r1.42 -r1.43 src/sys/dev/rasops/rasops8.c cvs rdiff -u -r1.16 -r1.17 src/sys/dev/rasops/rasops_bitops.h cvs rdiff -u -r1.1 -r1.2 src/sys/dev/rasops/rasops_putchar.h cvs rdiff -u -r1.5 -r1.6 src/sys/dev/rasops/rasops_putchar_width.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/dev/rasops/rasops.c diff -u src/sys/dev/rasops/rasops.c:1.93 src/sys/dev/rasops/rasops.c:1.94 --- src/sys/dev/rasops/rasops.c:1.93 Sun Jul 28 10:24:08 2019 +++ src/sys/dev/rasops/rasops.c Sun Jul 28 12:06:10 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: rasops.c,v 1.93 2019/07/28 10:24:08 martin Exp $ */ +/* $NetBSD: rasops.c,v 1.94 2019/07/28 12:06:10 rin Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rasops.c,v 1.93 2019/07/28 10:24:08 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rasops.c,v 1.94 2019/07/28 12:06:10 rin Exp $"); #include "opt_rasops.h" #include "rasops_glue.h" @@ -232,7 +232,7 @@ int rasops_init(struct rasops_info *ri, int wantrows, int wantcols) { - memset (&ri->ri_optfont, 0, sizeof(ri->ri_optfont)); + memset(&ri->ri_optfont, 0, sizeof(ri->ri_optfont)); #ifdef _KERNEL /* Select a font if the caller doesn't care */ if (ri->ri_font == NULL) { @@ -952,7 +952,7 @@ rasops_eraserows(void *cookie, int row, return; #endif - clr = ri->ri_devcmap[(attr >> 16) & 0xf]; + clr = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf]; /* * XXX The wsdisplay_emulops interface seems a little deficient in @@ -1138,7 +1138,7 @@ rasops_erasecols(void *cookie, int row, hrp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale + col*ri->ri_xscale); height = ri->ri_font->fontheight; - clr = ri->ri_devcmap[(attr >> 16) & 0xf]; + clr = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf]; /* Don't bother using the full loop for <= 32 pels */ if (num <= 32) { @@ -1357,7 +1357,7 @@ rasops_putchar_rotated_cw(void *cookie, /* XXX this assumes 16-bit color depth */ if ((attr & WSATTR_UNDERLINE) != 0) { uint16_t c = - (uint16_t)ri->ri_devcmap[((u_int)attr >> 24) & 0xf]; + (uint16_t)ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf]; while (height--) { *(uint16_t *)rp = c; @@ -1480,7 +1480,7 @@ rasops_putchar_rotated_ccw(void *cookie, /* XXX this assumes 16-bit color depth */ if ((attr & WSATTR_UNDERLINE) != 0) { uint16_t c = - (uint16_t)ri->ri_devcmap[((u_int)attr >> 24) & 0xf]; + (uint16_t)ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf]; while (height--) { *(uint16_t *)rp = c; Index: src/sys/dev/rasops/rasops.h diff -u src/sys/dev/rasops/rasops.h:1.36 src/sys/dev/rasops/rasops.h:1.37 --- src/sys/dev/rasops/rasops.h:1.36 Thu Jul 25 03:02:44 2019 +++ src/sys/dev/rasops/rasops.h Sun Jul 28 12:06:10 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: rasops.h,v 1.36 2019/07/25 03:02:44 rin Exp $ */ +/* $NetBSD: rasops.h,v 1.37 2019/07/28 12:06:10 rin Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -139,7 +139,7 @@ struct rasops_info { #endif }; -#define DELTA(p, d, cast) ((p) = (cast)((char *)(p) + (d))) +#define DELTA(p, d, cast) ((p) = (cast)((uint8_t *)(p) + (d))) #define CHAR_IN_FONT(c,font) \ ((c) >= (font)->firstchar && \ Index: src/sys/dev/rasops/rasops15.c diff -u src/sys/dev/rasops/rasops15.c:1.29 src/sys/dev/rasops/rasops15.c:1.30 --- src/sys/dev/rasops/rasops15.c:1.29 Sun Jul 28 02:45:52 2019 +++ src/sys/dev/rasops/rasops15.c Sun Jul 28 12:06:10 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: rasops15.c,v 1.29 2019/07/28 02:45:52 rin Exp $ */ +/* $NetBSD: rasops15.c,v 1.30 2019/07/28 12:06:10 rin Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rasops15.c,v 1.29 2019/07/28 02:45:52 rin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rasops15.c,v 1.30 2019/07/28 12:06:10 rin Exp $"); #include "opt_rasops.h" @@ -42,34 +42,31 @@ __KERNEL_RCSID(0, "$NetBSD: rasops15.c,v #include <dev/wscons/wsconsio.h> #include <dev/rasops/rasops.h> -static void rasops15_putchar(void *, int, int, u_int, long attr); -static void rasops15_putchar_aa(void *, int, int, u_int, long attr); +static void rasops15_putchar(void *, int, int, u_int, long); +static void rasops15_putchar_aa(void *, int, int, u_int, long); #ifndef RASOPS_SMALL -static void rasops15_putchar8(void *, int, int, u_int, long attr); -static void rasops15_putchar12(void *, int, int, u_int, long attr); -static void rasops15_putchar16(void *, int, int, u_int, long attr); +static void rasops15_putchar8(void *, int, int, u_int, long); +static void rasops15_putchar12(void *, int, int, u_int, long); +static void rasops15_putchar16(void *, int, int, u_int, long); static void rasops15_makestamp(struct rasops_info *, long); #endif #ifndef RASOPS_SMALL /* - * (2x2)x1 stamp for optimized character blitting + * 4x1 stamp for optimized character blitting */ static uint32_t stamp[32]; static long stamp_attr; static int stamp_mutex; /* XXX see note in readme */ /* - * XXX this confuses the hell out of gcc2 (not egcs) which always insists - * that the shift count is negative. - * * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK * destination uint32_t[0] = STAMP_READ(offset) * destination uint32_t[1] = STAMP_READ(offset + 4) */ -#define STAMP_SHIFT(fb,n) ((n*4-3) >= 0 ? (fb)>>(n*4-3):(fb)<<-(n*4-3)) -#define STAMP_MASK (15 << 3) -#define STAMP_READ(o) (*(uint32_t *)((char *)stamp + (o))) +#define STAMP_SHIFT(fb, n) ((n) ? (fb) >> 1: (fb) << 3) +#define STAMP_MASK (0xf << 3) +#define STAMP_READ(o) (*(uint32_t *)((uint8_t *)stamp + (o))) #endif /* @@ -79,37 +76,36 @@ void rasops15_init(struct rasops_info *ri) { - if (FONT_IS_ALPHA(ri->ri_font)) { - ri->ri_ops.putchar = rasops15_putchar_aa; - } else { - switch (ri->ri_font->fontwidth) { -#ifndef RASOPS_SMALL - case 8: - ri->ri_ops.putchar = rasops15_putchar8; - break; - - case 12: - ri->ri_ops.putchar = rasops15_putchar12; - break; - - case 16: - ri->ri_ops.putchar = rasops15_putchar16; - break; -#endif /* !RASOPS_SMALL */ - default: - ri->ri_ops.putchar = rasops15_putchar; - break; - } - } - if (ri->ri_rnum == 0) { - ri->ri_rnum = 5; + ri->ri_rnum = ri->ri_gnum = ri->ri_bnum = 5; + ri->ri_gnum += (ri->ri_depth == 16); + ri->ri_rpos = 10 + (ri->ri_depth == 16); - ri->ri_gnum = 5 + (ri->ri_depth == 16); ri->ri_gpos = 5; - ri->ri_bnum = 5; ri->ri_bpos = 0; } + + if (FONT_IS_ALPHA(ri->ri_font)) { + ri->ri_ops.putchar = rasops15_putchar_aa; + return; + } + + switch (ri->ri_font->fontwidth) { +#ifndef RASOPS_SMALL + case 8: + ri->ri_ops.putchar = rasops15_putchar8; + break; + case 12: + ri->ri_ops.putchar = rasops15_putchar12; + break; + case 16: + ri->ri_ops.putchar = rasops15_putchar16; + break; +#endif /* !RASOPS_SMALL */ + default: + ri->ri_ops.putchar = rasops15_putchar; + break; + } } #define RASOPS_DEPTH 15 @@ -128,7 +124,6 @@ rasops15_putchar_aa(void *cookie, int ro int x, y, r, g, b, aval; int r1, g1, b1, r0, g0, b0, fgo, bgo; - #ifdef RASOPS_CLIPPING /* Catches 'row < 0' case too */ if ((unsigned)row >= (unsigned)ri->ri_rows) @@ -148,8 +143,8 @@ rasops15_putchar_aa(void *cookie, int ro height = font->fontheight; width = font->fontwidth; - clr[0] = ri->ri_devcmap[(attr >> 16) & 0xf]; - clr[1] = ri->ri_devcmap[(attr >> 24) & 0xf]; + clr[0] = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf]; + clr[1] = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf]; if (uc == ' ') { for (cnt = 0; cnt < width; cnt++) @@ -162,8 +157,8 @@ rasops15_putchar_aa(void *cookie, int ro } else { fr = FONT_GLYPH(uc, font, ri); - fgo = ((attr >> 24) & 0xf) * 3; - bgo = ((attr >> 16) & 0xf) * 3; + fgo = (((uint32_t)attr >> 24) & 0xf) * 3; + bgo = (((uint32_t)attr >> 16) & 0xf) * 3; r0 = rasops_cmap[bgo]; r1 = rasops_cmap[fgo]; @@ -209,7 +204,7 @@ rasops15_putchar_aa(void *cookie, int ro #ifndef RASOPS_SMALL /* - * Recompute the (2x2)x1 blitting stamp. + * Recompute the 4x1 blitting stamp. */ static void rasops15_makestamp(struct rasops_info *ri, long attr) @@ -217,21 +212,21 @@ rasops15_makestamp(struct rasops_info *r uint32_t fg, bg; int i; - fg = ri->ri_devcmap[((u_int)attr >> 24) & 0xf] & 0xffff; - bg = ri->ri_devcmap[((u_int)attr >> 16) & 0xf] & 0xffff; + fg = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf] & 0xffff; + bg = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf] & 0xffff; stamp_attr = attr; for (i = 0; i < 32; i += 2) { #if BYTE_ORDER == LITTLE_ENDIAN - stamp[i] = (i & 16 ? fg : bg); - stamp[i] |= ((i & 8 ? fg : bg) << 16); - stamp[i + 1] = (i & 4 ? fg : bg); - stamp[i + 1] |= ((i & 2 ? fg : bg) << 16); + stamp[i] = (i & 16 ? fg : bg); + stamp[i] |= (i & 8 ? fg : bg) << 16; + stamp[i + 1] = (i & 4 ? fg : bg); + stamp[i + 1] |= (i & 2 ? fg : bg) << 16; #else - stamp[i] = (i & 8 ? fg : bg); - stamp[i] |= ((i & 16 ? fg : bg) << 16); - stamp[i + 1] = (i & 2 ? fg : bg); - stamp[i + 1] |= ((i & 4 ? fg : bg) << 16); + stamp[i] = (i & 8 ? fg : bg); + stamp[i] |= (i & 16 ? fg : bg) << 16; + stamp[i + 1] = (i & 2 ? fg : bg); + stamp[i + 1] |= (i & 4 ? fg : bg) << 16; #endif } } Index: src/sys/dev/rasops/rasops2.c diff -u src/sys/dev/rasops/rasops2.c:1.24 src/sys/dev/rasops/rasops2.c:1.25 --- src/sys/dev/rasops/rasops2.c:1.24 Sun Jul 28 02:51:38 2019 +++ src/sys/dev/rasops/rasops2.c Sun Jul 28 12:06:10 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: rasops2.c,v 1.24 2019/07/28 02:51:38 rin Exp $ */ +/* $NetBSD: rasops2.c,v 1.25 2019/07/28 12:06:10 rin Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rasops2.c,v 1.24 2019/07/28 02:51:38 rin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rasops2.c,v 1.25 2019/07/28 12:06:10 rin Exp $"); #include "opt_rasops.h" @@ -124,8 +124,8 @@ rasops2_putchar(void *cookie, int row, i col = col & 31; rs = ri->ri_stride; - bg = ri->ri_devcmap[(attr >> 16) & 0xf]; - fg = ri->ri_devcmap[(attr >> 24) & 0xf]; + bg = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf]; + fg = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf]; /* If fg and bg match this becomes a space character */ if (fg == bg || uc == ' ') { @@ -224,8 +224,8 @@ rasops2_makestamp(struct rasops_info *ri { int i, fg, bg; - fg = ri->ri_devcmap[(attr >> 24) & 0xf] & 3; - bg = ri->ri_devcmap[(attr >> 16) & 0xf] & 3; + fg = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf] & 3; + bg = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf] & 3; stamp_attr = attr; for (i = 0; i < 16; i++) { Index: src/sys/dev/rasops/rasops24.c diff -u src/sys/dev/rasops/rasops24.c:1.35 src/sys/dev/rasops/rasops24.c:1.36 --- src/sys/dev/rasops/rasops24.c:1.35 Thu Jul 25 15:18:53 2019 +++ src/sys/dev/rasops/rasops24.c Sun Jul 28 12:06:10 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: rasops24.c,v 1.35 2019/07/25 15:18:53 rin Exp $ */ +/* $NetBSD: rasops24.c,v 1.36 2019/07/28 12:06:10 rin Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rasops24.c,v 1.35 2019/07/25 15:18:53 rin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rasops24.c,v 1.36 2019/07/28 12:06:10 rin Exp $"); #include "opt_rasops.h" @@ -47,11 +47,11 @@ __KERNEL_RCSID(0, "$NetBSD: rasops24.c,v static void rasops24_erasecols(void *, int, int, int, long); static void rasops24_eraserows(void *, int, int, long); -static void rasops24_putchar(void *, int, int, u_int, long attr); +static void rasops24_putchar(void *, int, int, u_int, long); #ifndef RASOPS_SMALL -static void rasops24_putchar8(void *, int, int, u_int, long attr); -static void rasops24_putchar12(void *, int, int, u_int, long attr); -static void rasops24_putchar16(void *, int, int, u_int, long attr); +static void rasops24_putchar8(void *, int, int, u_int, long); +static void rasops24_putchar12(void *, int, int, u_int, long); +static void rasops24_putchar16(void *, int, int, u_int, long); static void rasops24_makestamp(struct rasops_info *, long); /* @@ -63,17 +63,14 @@ static int stamp_mutex; /* XXX see note #endif /* - * XXX this confuses the hell out of gcc2 (not egcs) which always insists - * that the shift count is negative. - * * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK * destination uint32_t[0] = STAMP_READ(offset) * destination uint32_t[1] = STAMP_READ(offset + 4) * destination uint32_t[2] = STAMP_READ(offset + 8) */ -#define STAMP_SHIFT(fb,n) ((n*4-4) >= 0 ? (fb)>>(n*4-4):(fb)<<-(n*4-4)) -#define STAMP_MASK (0xf << 4) -#define STAMP_READ(o) (*(uint32_t *)((char *)stamp + (o))) +#define STAMP_SHIFT(fb, n) ((n) ? (fb) : (fb) << 4) +#define STAMP_MASK (0xf << 4) +#define STAMP_READ(o) (*(uint32_t *)((uint8_t *)stamp + (o))) /* * Initialize rasops_info struct for this colordepth. @@ -82,6 +79,17 @@ void rasops24_init(struct rasops_info *ri) { + if (ri->ri_rnum == 0) { + ri->ri_rnum = ri->ri_gnum = ri->ri_bnum = 8; + + ri->ri_rpos = 0; + ri->ri_gpos = 8; + ri->ri_bpos = 16; + } + + ri->ri_ops.erasecols = rasops24_erasecols; + ri->ri_ops.eraserows = rasops24_eraserows; + switch (ri->ri_font->fontwidth) { #ifndef RASOPS_SMALL case 8: @@ -98,18 +106,6 @@ rasops24_init(struct rasops_info *ri) ri->ri_ops.putchar = rasops24_putchar; break; } - - if (ri->ri_rnum == 0) { - ri->ri_rnum = 8; - ri->ri_rpos = 0; - ri->ri_gnum = 8; - ri->ri_gpos = 8; - ri->ri_bnum = 8; - ri->ri_bpos = 16; - } - - ri->ri_ops.erasecols = rasops24_erasecols; - ri->ri_ops.eraserows = rasops24_eraserows; } #define RASOPS_DEPTH 24 @@ -122,37 +118,37 @@ rasops24_init(struct rasops_info *ri) static void rasops24_makestamp(struct rasops_info *ri, long attr) { - u_int fg, bg, c1, c2, c3, c4; + uint32_t fg, bg, c1, c2, c3, c4; int i; - fg = ri->ri_devcmap[((u_int)attr >> 24) & 0xf] & 0xffffff; - bg = ri->ri_devcmap[((u_int)attr >> 16) & 0xf] & 0xffffff; + fg = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf] & 0xffffff; + bg = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf] & 0xffffff; stamp_attr = attr; for (i = 0; i < 64; i += 4) { #if BYTE_ORDER == LITTLE_ENDIAN - c1 = (i & 32 ? fg : bg); - c2 = (i & 16 ? fg : bg); - c3 = (i & 8 ? fg : bg); - c4 = (i & 4 ? fg : bg); + c1 = i & 32 ? fg : bg; + c2 = i & 16 ? fg : bg; + c3 = i & 8 ? fg : bg; + c4 = i & 4 ? fg : bg; #else - c1 = (i & 8 ? fg : bg); - c2 = (i & 4 ? fg : bg); - c3 = (i & 16 ? fg : bg); - c4 = (i & 32 ? fg : bg); + c1 = i & 8 ? fg : bg; + c2 = i & 4 ? fg : bg; + c3 = i & 16 ? fg : bg; + c4 = i & 32 ? fg : bg; #endif - stamp[i+0] = (c1 << 8) | (c2 >> 16); - stamp[i+1] = (c2 << 16) | (c3 >> 8); - stamp[i+2] = (c3 << 24) | c4; + stamp[i + 0] = (c1 << 8) | (c2 >> 16); + stamp[i + 1] = (c2 << 16) | (c3 >> 8); + stamp[i + 2] = (c3 << 24) | c4; #if BYTE_ORDER == LITTLE_ENDIAN if ((ri->ri_flg & RI_BSWAP) == 0) { #else if ((ri->ri_flg & RI_BSWAP) != 0) { #endif - stamp[i+0] = bswap32(stamp[i+0]); - stamp[i+1] = bswap32(stamp[i+1]); - stamp[i+2] = bswap32(stamp[i+2]); + stamp[i + 0] = bswap32(stamp[i + 0]); + stamp[i + 1] = bswap32(stamp[i + 1]); + stamp[i + 2] = bswap32(stamp[i + 2]); } } } @@ -205,7 +201,7 @@ rasops24_eraserows(void *cookie, int row return; #endif - clr = ri->ri_devcmap[(attr >> 16) & 0xf] & 0xffffff; + clr = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf] & 0xffffff; xstamp[0] = (clr << 8) | (clr >> 16); xstamp[1] = (clr << 16) | (clr >> 8); xstamp[2] = (clr << 24) | clr; @@ -315,7 +311,7 @@ rasops24_erasecols(void *cookie, int row num *= ri->ri_font->fontwidth; height = ri->ri_font->fontheight; - clr = ri->ri_devcmap[(attr >> 16) & 0xf] & 0xffffff; + clr = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf] & 0xffffff; xstamp[0] = (clr << 8) | (clr >> 16); xstamp[1] = (clr << 16) | (clr >> 8); xstamp[2] = (clr << 24) | clr; Index: src/sys/dev/rasops/rasops32.c diff -u src/sys/dev/rasops/rasops32.c:1.37 src/sys/dev/rasops/rasops32.c:1.38 --- src/sys/dev/rasops/rasops32.c:1.37 Thu Jul 25 15:18:53 2019 +++ src/sys/dev/rasops/rasops32.c Sun Jul 28 12:06:10 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: rasops32.c,v 1.37 2019/07/25 15:18:53 rin Exp $ */ +/* $NetBSD: rasops32.c,v 1.38 2019/07/28 12:06:10 rin Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rasops32.c,v 1.37 2019/07/25 15:18:53 rin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rasops32.c,v 1.38 2019/07/28 12:06:10 rin Exp $"); #include "opt_rasops.h" @@ -42,8 +42,8 @@ __KERNEL_RCSID(0, "$NetBSD: rasops32.c,v #include <dev/wscons/wsconsio.h> #include <dev/rasops/rasops.h> -static void rasops32_putchar(void *, int, int, u_int, long attr); -static void rasops32_putchar_aa(void *, int, int, u_int, long attr); +static void rasops32_putchar(void *, int, int, u_int, long); +static void rasops32_putchar_aa(void *, int, int, u_int, long); #ifndef RASOPS_SMALL static void rasops32_putchar8(void *, int, int, u_int, long); static void rasops32_putchar12(void *, int, int, u_int, long); @@ -67,7 +67,7 @@ static int stamp_mutex; /* XXX see note */ #define STAMP_SHIFT(fb, n) ((n) ? (fb) : (fb) << 4) #define STAMP_MASK (0xf << 4) -#define STAMP_READ(o) (*(uint32_t *)((char *)stamp + (o))) +#define STAMP_READ(o) (*(uint32_t *)((uint8_t *)stamp + (o))) /* * Initialize a 'rasops_info' descriptor for this depth. @@ -77,11 +77,10 @@ rasops32_init(struct rasops_info *ri) { if (ri->ri_rnum == 0) { - ri->ri_rnum = 8; + ri->ri_rnum = ri->ri_gnum = ri->ri_bnum = 8; + ri->ri_rpos = 0; - ri->ri_gnum = 8; ri->ri_gpos = 8; - ri->ri_bnum = 8; ri->ri_bpos = 16; } @@ -143,8 +142,8 @@ rasops32_putchar_aa(void *cookie, int ro height = font->fontheight; width = font->fontwidth; - clr[0] = ri->ri_devcmap[(attr >> 16) & 0xf]; - clr[1] = ri->ri_devcmap[(attr >> 24) & 0xf]; + clr[0] = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf]; + clr[1] = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf]; if (uc == ' ') { for (cnt = 0; cnt < width; cnt++) @@ -211,10 +210,10 @@ rasops32_makestamp(struct rasops_info *r stamp_attr = attr; for (i = 0; i < 64; i += 4) { - stamp[i + 0] = (i & 32 ? fg : bg); - stamp[i + 1] = (i & 16 ? fg : bg); - stamp[i + 2] = (i & 8 ? fg : bg); - stamp[i + 3] = (i & 4 ? fg : bg); + stamp[i + 0] = i & 32 ? fg : bg; + stamp[i + 1] = i & 16 ? fg : bg; + stamp[i + 2] = i & 8 ? fg : bg; + stamp[i + 3] = i & 4 ? fg : bg; } } Index: src/sys/dev/rasops/rasops4.c diff -u src/sys/dev/rasops/rasops4.c:1.18 src/sys/dev/rasops/rasops4.c:1.19 --- src/sys/dev/rasops/rasops4.c:1.18 Fri Jul 26 06:37:15 2019 +++ src/sys/dev/rasops/rasops4.c Sun Jul 28 12:06:10 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: rasops4.c,v 1.18 2019/07/26 06:37:15 rin Exp $ */ +/* $NetBSD: rasops4.c,v 1.19 2019/07/28 12:06:10 rin Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rasops4.c,v 1.18 2019/07/26 06:37:15 rin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rasops4.c,v 1.19 2019/07/28 12:06:10 rin Exp $"); #include "opt_rasops.h" @@ -124,8 +124,8 @@ rasops4_putchar(void *cookie, int row, i col = col & 31; rs = ri->ri_stride; - bg = ri->ri_devcmap[(attr >> 16) & 0xf]; - fg = ri->ri_devcmap[(attr >> 24) & 0xf]; + bg = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf]; + fg = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf]; /* If fg and bg match this becomes a space character */ if (fg == bg || uc == ' ') { @@ -224,8 +224,8 @@ rasops4_makestamp(struct rasops_info *ri { int i, fg, bg; - fg = ri->ri_devcmap[(attr >> 24) & 0xf] & 0xf; - bg = ri->ri_devcmap[(attr >> 16) & 0xf] & 0xf; + fg = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf] & 0xf; + bg = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf] & 0xf; stamp_attr = attr; for (i = 0; i < 16; i++) { Index: src/sys/dev/rasops/rasops8.c diff -u src/sys/dev/rasops/rasops8.c:1.42 src/sys/dev/rasops/rasops8.c:1.43 --- src/sys/dev/rasops/rasops8.c:1.42 Thu Jul 25 15:18:53 2019 +++ src/sys/dev/rasops/rasops8.c Sun Jul 28 12:06:10 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: rasops8.c,v 1.42 2019/07/25 15:18:53 rin Exp $ */ +/* $NetBSD: rasops8.c,v 1.43 2019/07/28 12:06:10 rin Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rasops8.c,v 1.42 2019/07/25 15:18:53 rin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rasops8.c,v 1.43 2019/07/28 12:06:10 rin Exp $"); #include "opt_rasops.h" @@ -42,12 +42,12 @@ __KERNEL_RCSID(0, "$NetBSD: rasops8.c,v #include <dev/wscons/wsconsio.h> #include <dev/rasops/rasops.h> -static void rasops8_putchar(void *, int, int, u_int, long attr); -static void rasops8_putchar_aa(void *, int, int, u_int, long attr); +static void rasops8_putchar(void *, int, int, u_int, long); +static void rasops8_putchar_aa(void *, int, int, u_int, long); #ifndef RASOPS_SMALL -static void rasops8_putchar8(void *, int, int, u_int, long attr); -static void rasops8_putchar12(void *, int, int, u_int, long attr); -static void rasops8_putchar16(void *, int, int, u_int, long attr); +static void rasops8_putchar8(void *, int, int, u_int, long); +static void rasops8_putchar12(void *, int, int, u_int, long); +static void rasops8_putchar16(void *, int, int, u_int, long); static void rasops8_makestamp(struct rasops_info *ri, long); /* @@ -59,15 +59,12 @@ static int stamp_mutex; /* XXX see note #endif /* - * XXX this confuses the hell out of gcc2 (not egcs) which always insists - * that the shift count is negative. - * * offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK * destination = STAMP_READ(offset) */ -#define STAMP_SHIFT(fb,n) ((n*4-2) >= 0 ? (fb)>>(n*4-2):(fb)<<-(n*4-2)) -#define STAMP_MASK (0xf << 2) -#define STAMP_READ(o) (*(uint32_t *)((char *)stamp + (o))) +#define STAMP_SHIFT(fb, n) ((n) ? (fb) >> 2 : (fb) << 2) +#define STAMP_MASK (0xf << 2) +#define STAMP_READ(o) (*(uint32_t *)((uint8_t *)stamp + (o))) /* * Initialize a 'rasops_info' descriptor for this depth. @@ -76,34 +73,36 @@ void rasops8_init(struct rasops_info *ri) { - if (FONT_IS_ALPHA(ri->ri_font)) { - ri->ri_ops.putchar = rasops8_putchar_aa; - } else { - switch (ri->ri_font->fontwidth) { -#ifndef RASOPS_SMALL - case 8: - ri->ri_ops.putchar = rasops8_putchar8; - break; - case 12: - ri->ri_ops.putchar = rasops8_putchar12; - break; - case 16: - ri->ri_ops.putchar = rasops8_putchar16; - break; -#endif /* !RASOPS_SMALL */ - default: - ri->ri_ops.putchar = rasops8_putchar; - break; - } - } if (ri->ri_flg & RI_8BIT_IS_RGB) { - ri->ri_rnum = 3; + ri->ri_rnum = ri->ri_gnum = 3; + ri->ri_bnum = 2; + ri->ri_rpos = 5; - ri->ri_gnum = 3; ri->ri_gpos = 2; - ri->ri_bnum = 2; ri->ri_bpos = 0; } + + if (FONT_IS_ALPHA(ri->ri_font)) { + ri->ri_ops.putchar = rasops8_putchar_aa; + return; + } + + switch (ri->ri_font->fontwidth) { +#ifndef RASOPS_SMALL + case 8: + ri->ri_ops.putchar = rasops8_putchar8; + break; + case 12: + ri->ri_ops.putchar = rasops8_putchar12; + break; + case 16: + ri->ri_ops.putchar = rasops8_putchar16; + break; +#endif /* !RASOPS_SMALL */ + default: + ri->ri_ops.putchar = rasops8_putchar; + break; + } } #define RASOPS_DEPTH 8 @@ -120,7 +119,7 @@ rasops8_putchar_aa(void *cookie, int row int r1, g1, b1, r0, g0, b0, fgo, bgo; uint8_t scanline[32] __attribute__ ((aligned(8))); - hrp = NULL; + hrp = NULL; /* XXX GCC */ if (!CHAR_IN_FONT(uc, font)) return; @@ -140,8 +139,8 @@ rasops8_putchar_aa(void *cookie, int row height = font->fontheight; width = font->fontwidth; - bg = (uint8_t)ri->ri_devcmap[(attr >> 16) & 0xf]; - fg = (uint8_t)ri->ri_devcmap[(attr >> 24) & 0xf]; + bg = (uint8_t)ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf]; + fg = (uint8_t)ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf]; if (uc == ' ') { @@ -158,8 +157,8 @@ rasops8_putchar_aa(void *cookie, int row /* * we need the RGB colours here, get offsets into rasops_cmap */ - fgo = ((attr >> 24) & 0xf) * 3; - bgo = ((attr >> 16) & 0xf) * 3; + fgo = (((uint32_t)attr >> 24) & 0xf) * 3; + bgo = (((uint32_t)attr >> 16) & 0xf) * 3; r0 = rasops_cmap[bgo]; r1 = rasops_cmap[fgo]; @@ -221,8 +220,8 @@ rasops8_makestamp(struct rasops_info *ri uint32_t fg, bg; int i; - fg = ri->ri_devcmap[(attr >> 24) & 0xf] & 0xff; - bg = ri->ri_devcmap[(attr >> 16) & 0xf] & 0xff; + fg = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf] & 0xff; + bg = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf] & 0xff; stamp_attr = attr; for (i = 0; i < 16; i++) { @@ -233,16 +232,16 @@ rasops8_makestamp(struct rasops_info *ri #endif if ((ri->ri_flg & RI_BSWAP) == NEED_LITTLE_ENDIAN_STAMP) { /* little endian */ - stamp[i] = (i & 8 ? fg : bg); - stamp[i] |= ((i & 4 ? fg : bg) << 8); - stamp[i] |= ((i & 2 ? fg : bg) << 16); - stamp[i] |= ((i & 1 ? fg : bg) << 24); + stamp[i] = (i & 8 ? fg : bg); + stamp[i] |= (i & 4 ? fg : bg) << 8; + stamp[i] |= (i & 2 ? fg : bg) << 16; + stamp[i] |= (i & 1 ? fg : bg) << 24; } else { /* big endian */ - stamp[i] = (i & 1 ? fg : bg); - stamp[i] |= ((i & 2 ? fg : bg) << 8); - stamp[i] |= ((i & 4 ? fg : bg) << 16); - stamp[i] |= ((i & 8 ? fg : bg) << 24); + stamp[i] = (i & 1 ? fg : bg); + stamp[i] |= (i & 2 ? fg : bg) << 8; + stamp[i] |= (i & 4 ? fg : bg) << 16; + stamp[i] |= (i & 8 ? fg : bg) << 24; } } } Index: src/sys/dev/rasops/rasops_bitops.h diff -u src/sys/dev/rasops/rasops_bitops.h:1.16 src/sys/dev/rasops/rasops_bitops.h:1.17 --- src/sys/dev/rasops/rasops_bitops.h:1.16 Thu Jul 25 02:26:32 2019 +++ src/sys/dev/rasops/rasops_bitops.h Sun Jul 28 12:06:10 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: rasops_bitops.h,v 1.16 2019/07/25 02:26:32 rin Exp $ */ +/* $NetBSD: rasops_bitops.h,v 1.17 2019/07/28 12:06:10 rin Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -63,7 +63,7 @@ NAME(erasecols)(void *cookie, int row, i col *= ri->ri_font->fontwidth << PIXEL_SHIFT; num *= ri->ri_font->fontwidth << PIXEL_SHIFT; height = ri->ri_font->fontheight; - clr = ri->ri_devcmap[(attr >> 16) & 0xf]; + clr = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf]; rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + ((col >> 3) & ~3)); if (ri->ri_hwbits) hrp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale + Index: src/sys/dev/rasops/rasops_putchar.h diff -u src/sys/dev/rasops/rasops_putchar.h:1.1 src/sys/dev/rasops/rasops_putchar.h:1.2 --- src/sys/dev/rasops/rasops_putchar.h:1.1 Thu Jul 25 15:18:53 2019 +++ src/sys/dev/rasops/rasops_putchar.h Sun Jul 28 12:06:10 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: rasops_putchar.h,v 1.1 2019/07/25 15:18:53 rin Exp $ */ +/* $NetBSD: rasops_putchar.h,v 1.2 2019/07/28 12:06:10 rin Exp $ */ /* NetBSD: rasops8.c,v 1.41 2019/07/25 03:02:44 rin Exp */ /*- @@ -68,13 +68,13 @@ static void PUTCHAR(RASOPS_DEPTH)(void *cookie, int row, int col, u_int uc, long attr) { - int width, height, cnt, fs, fb; - uint8_t *dp, *rp, *hp, *hrp, *fr; struct rasops_info *ri = (struct rasops_info *)cookie; struct wsdisplay_font *font = PICK_FONT(ri, uc); + int width, height, cnt, fs, fb; + uint8_t *dp, *rp, *hp, *hrp, *fr; CLR_TYPE clr[2]; - hp = hrp = NULL; + hp = hrp = NULL; /* XXX GCC */ if (!CHAR_IN_FONT(uc, font)) return; @@ -96,8 +96,8 @@ PUTCHAR(RASOPS_DEPTH)(void *cookie, int height = font->fontheight; width = font->fontwidth; - clr[0] = (CLR_TYPE)ri->ri_devcmap[(attr >> 16) & 0xf]; - clr[1] = (CLR_TYPE)ri->ri_devcmap[(attr >> 24) & 0xf]; + clr[0] = (CLR_TYPE)ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf]; + clr[1] = (CLR_TYPE)ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf]; if (uc == ' ') { while (height--) { Index: src/sys/dev/rasops/rasops_putchar_width.h diff -u src/sys/dev/rasops/rasops_putchar_width.h:1.5 src/sys/dev/rasops/rasops_putchar_width.h:1.6 --- src/sys/dev/rasops/rasops_putchar_width.h:1.5 Sun Jul 28 10:07:43 2019 +++ src/sys/dev/rasops/rasops_putchar_width.h Sun Jul 28 12:06:10 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: rasops_putchar_width.h,v 1.5 2019/07/28 10:07:43 rin Exp $ */ +/* $NetBSD: rasops_putchar_width.h,v 1.6 2019/07/28 12:06:10 rin Exp $ */ /* NetBSD: rasops8.c,v 1.41 2019/07/25 03:02:44 rin Exp */ /*- @@ -65,7 +65,7 @@ #define SUBST_GLYPH1(index, nibble, off) \ do { \ - so = STAMP_SHIFT(fr[index], nibble) & STAMP_MASK; \ + int so = STAMP_SHIFT(fr[index], nibble) & STAMP_MASK; \ rp[(off) * 1 + 0] = STAMP_READ(so); \ if (ri->ri_hwbits) { \ hrp[(off) * 1 + 0] = STAMP_READ(so); \ @@ -83,7 +83,7 @@ #define SUBST_GLYPH1(index, nibble, off) \ do { \ - so = STAMP_SHIFT(fr[index], nibble) & STAMP_MASK; \ + int so = STAMP_SHIFT(fr[index], nibble) & STAMP_MASK; \ rp[(off) * 2 + 0] = STAMP_READ(so); \ rp[(off) * 2 + 1] = STAMP_READ(so + 4); \ if (ri->ri_hwbits) { \ @@ -107,7 +107,7 @@ #define SUBST_GLYPH1(index, nibble, off) \ do { \ - so = STAMP_SHIFT(fr[index], nibble) & STAMP_MASK; \ + int so = STAMP_SHIFT(fr[index], nibble) & STAMP_MASK; \ rp[(off) * 3 + 0] = STAMP_READ(so); \ rp[(off) * 3 + 1] = STAMP_READ(so + 4); \ rp[(off) * 3 + 2] = STAMP_READ(so + 8); \ @@ -130,7 +130,7 @@ #define SUBST_GLYPH1(index, nibble, off) \ do { \ - so = STAMP_SHIFT(fr[index], nibble) & STAMP_MASK; \ + int so = STAMP_SHIFT(fr[index], nibble) & STAMP_MASK; \ rp[(off) * 4 + 0] = STAMP_READ(so); \ rp[(off) * 4 + 1] = STAMP_READ(so + 4); \ rp[(off) * 4 + 2] = STAMP_READ(so + 8); \ @@ -202,8 +202,8 @@ PUTCHAR_WIDTH(RASOPS_DEPTH, RASOPS_WIDTH { struct rasops_info *ri = (struct rasops_info *)cookie; struct wsdisplay_font *font = PICK_FONT(ri, uc); - int height, so, fs; - uint32_t *rp, *hrp = NULL; + int height, fs; + uint32_t *rp, *hrp; uint8_t *fr; hrp = NULL; /* XXX GCC */