Module Name: src Committed By: macallan Date: Thu Nov 29 23:44:50 UTC 2018
Modified Files: src/sys/dev/rasops: rasops.c Log Message: rasops_do_cursor(): - simplify & sanitize the unaligned case - use only 32bit accesses ... no longer crash with odd sized fonts in 8bit To generate a diff of this commit: cvs rdiff -u -r1.77 -r1.78 src/sys/dev/rasops/rasops.c 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.77 src/sys/dev/rasops/rasops.c:1.78 --- src/sys/dev/rasops/rasops.c:1.77 Thu Jun 1 02:45:11 2017 +++ src/sys/dev/rasops/rasops.c Thu Nov 29 23:44:50 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: rasops.c,v 1.77 2017/06/01 02:45:11 chs Exp $ */ +/* $NetBSD: rasops.c,v 1.78 2018/11/29 23:44:50 macallan Exp $ */ /*- * Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: rasops.c,v 1.77 2017/06/01 02:45:11 chs Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rasops.c,v 1.78 2018/11/29 23:44:50 macallan Exp $"); #include "opt_rasops.h" #include "rasops_glue.h" @@ -995,7 +995,7 @@ static void rasops_do_cursor(struct rasops_info *ri) { int full1, height, cnt, slop1, slop2, row, col; - u_char *dp, *rp, *hrp, *hp, tmp = 0; + u_char *dp, *rp, *hrp, *hp; hrp = hp = NULL; @@ -1055,33 +1055,26 @@ rasops_do_cursor(struct rasops_info *ri) } } } else { - uint16_t tmp16; - uint32_t tmp32; - /* XXX this is stupid.. use masks instead */ + uint32_t tmp32, msk1, msk2; + + msk1 = be32toh(0xffffffff >> (32 - (8 * slop1))); + msk2 = be32toh(0xffffffff << (32 - (8 * slop2))); + while (height--) { - dp = rp; + dp = (u_char *)((uintptr_t)rp & ~3); rp += ri->ri_stride; if (ri->ri_hwbits) { - hp = hrp; + hp = (u_char *)((uintptr_t)hrp & ~3); hrp += ri->ri_stride; } - if (slop1 & 1) { - tmp = *dp ^ ~0; - *dp = tmp; - dp++; - if (ri->ri_hwbits) { - *hp++ = tmp; - } - } - - if (slop1 & 2) { - tmp16 = *(int16_t *)dp ^ ~0; - *(uint16_t *)dp = tmp16; - dp += 2; + if (msk1 != 0) { + tmp32 = *(int32_t *)dp ^ msk1; + *(uint32_t *)dp = tmp32; + dp += 4; if (ri->ri_hwbits) { - *(int16_t *)hp = tmp16; - hp += 2; + *(int32_t *)hp = tmp32; + hp += 4; } } @@ -1095,19 +1088,11 @@ rasops_do_cursor(struct rasops_info *ri) } } - if (slop2 & 1) { - tmp = *dp ^ ~0; - *dp = tmp; - dp++; - if (ri->ri_hwbits) - *hp++ = tmp; - } - - if (slop2 & 2) { - tmp16 = *(int16_t *)dp ^ ~0; - *(uint16_t *)dp = tmp16; + if (msk2 != 0) { + tmp32 = *(int32_t *)dp ^ msk2; + *(uint32_t *)dp = tmp32; if (ri->ri_hwbits) - *(int16_t *)hp = tmp16; + *(int32_t *)hp = tmp32; } } }