diff options
| author | rin <rin@NetBSD.org> | 2019-07-28 12:06:10 +0000 |
|---|---|---|
| committer | rin <rin@NetBSD.org> | 2019-07-28 12:06:10 +0000 |
| commit | 6cbf2283abb6b97956aef1c41b2b151b6f3ca5a9 (patch) | |
| tree | 641ddf707e896249409cbe60227396c559af90ea /sys/dev | |
| parent | dc554d654fe0fd8d14df8082b4f4be2ec263353b (diff) | |
Cast attr to uint32_t before right shift to avoid undefined behavior.
Also, misc style/cosmetic changes for clarity.
Diffstat (limited to 'sys/dev')
| -rw-r--r-- | sys/dev/rasops/rasops.c | 14 | ||||
| -rw-r--r-- | sys/dev/rasops/rasops.h | 4 | ||||
| -rw-r--r-- | sys/dev/rasops/rasops15.c | 107 | ||||
| -rw-r--r-- | sys/dev/rasops/rasops2.c | 12 | ||||
| -rw-r--r-- | sys/dev/rasops/rasops24.c | 82 | ||||
| -rw-r--r-- | sys/dev/rasops/rasops32.c | 27 | ||||
| -rw-r--r-- | sys/dev/rasops/rasops4.c | 12 | ||||
| -rw-r--r-- | sys/dev/rasops/rasops8.c | 101 | ||||
| -rw-r--r-- | sys/dev/rasops/rasops_bitops.h | 4 | ||||
| -rw-r--r-- | sys/dev/rasops/rasops_putchar.h | 12 | ||||
| -rw-r--r-- | sys/dev/rasops/rasops_putchar_width.h | 14 |
11 files changed, 189 insertions, 200 deletions
diff --git a/sys/dev/rasops/rasops.c b/sys/dev/rasops/rasops.c index 21e9d18be88..be810661ed4 100644 --- a/sys/dev/rasops/rasops.c +++ b/sys/dev/rasops/rasops.c @@ -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, int num, long attr) 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, int col, int num, long attr) 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, int row, int col, u_int uc, long attr) /* 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, int row, int col, u_int uc, long attr) /* 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; diff --git a/sys/dev/rasops/rasops.h b/sys/dev/rasops/rasops.h index 3b6c8239ac4..d68758f7c9e 100644 --- a/sys/dev/rasops/rasops.h +++ b/sys/dev/rasops/rasops.h @@ -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 && \ diff --git a/sys/dev/rasops/rasops15.c b/sys/dev/rasops/rasops15.c index 04befcc2e00..32a91fc2b4e 100644 --- a/sys/dev/rasops/rasops15.c +++ b/sys/dev/rasops/rasops15.c @@ -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 1.29 2019/07/28 02:45:52 rin Exp $"); #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 row, int col, u_int uc, long attr) 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 row, int col, u_int uc, long attr) 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 row, int col, u_int uc, long attr) } 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 row, int col, u_int uc, long attr) #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 *ri, long attr) 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 } } diff --git a/sys/dev/rasops/rasops2.c b/sys/dev/rasops/rasops2.c index 456d8579e24..2eaaf63a8a9 100644 --- a/sys/dev/rasops/rasops2.c +++ b/sys/dev/rasops/rasops2.c @@ -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, int col, u_int uc, long attr) 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, long attr) { 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++) { diff --git a/sys/dev/rasops/rasops24.c b/sys/dev/rasops/rasops24.c index 3ce959c8d53..1b28cc9fe31 100644 --- a/sys/dev/rasops/rasops24.c +++ b/sys/dev/rasops/rasops24.c @@ -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 1.35 2019/07/25 15:18:53 rin Exp $"); 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 in readme */ #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, int num, long attr) 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, int col, int num, long attr) 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; diff --git a/sys/dev/rasops/rasops32.c b/sys/dev/rasops/rasops32.c index 73b984018cb..ef65fa280ec 100644 --- a/sys/dev/rasops/rasops32.c +++ b/sys/dev/rasops/rasops32.c @@ -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 1.37 2019/07/25 15:18:53 rin Exp $"); #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 in readme */ */ #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 row, int col, u_int uc, long attr) 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 *ri, long attr) 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; } } diff --git a/sys/dev/rasops/rasops4.c b/sys/dev/rasops/rasops4.c index 815e3a48919..38903c12b1b 100644 --- a/sys/dev/rasops/rasops4.c +++ b/sys/dev/rasops/rasops4.c @@ -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, int col, u_int uc, long attr) 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, long attr) { 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++) { diff --git a/sys/dev/rasops/rasops8.c b/sys/dev/rasops/rasops8.c index b07bacd50d0..0e3ef300584 100644 --- a/sys/dev/rasops/rasops8.c +++ b/sys/dev/rasops/rasops8.c @@ -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 1.42 2019/07/25 15:18:53 rin Exp $"); #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 in README */ #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 col, u_int uc, long attr) 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, int col, u_int uc, long attr) 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, int col, u_int uc, long attr) /* * 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, long attr) 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, long attr) #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; } } } diff --git a/sys/dev/rasops/rasops_bitops.h b/sys/dev/rasops/rasops_bitops.h index 04d213f0ad5..c51da38c78a 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.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, int col, int num, long attr) 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 + diff --git a/sys/dev/rasops/rasops_putchar.h b/sys/dev/rasops/rasops_putchar.h index e578e05880e..6da3e65807c 100644 --- a/sys/dev/rasops/rasops_putchar.h +++ b/sys/dev/rasops/rasops_putchar.h @@ -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 row, int col, u_int uc, long attr) 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--) { diff --git a/sys/dev/rasops/rasops_putchar_width.h b/sys/dev/rasops/rasops_putchar_width.h index e8cb2c35de4..1c0fbce1cb2 100644 --- a/sys/dev/rasops/rasops_putchar_width.h +++ b/sys/dev/rasops/rasops_putchar_width.h @@ -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)(void *cookie, int row, int col, { 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 */ |
