The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/ic/pcdisplay_subr.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /* $NetBSD: pcdisplay_subr.c,v 1.28.2.1 2007/08/06 11:21:57 ghen Exp $ */
    2 
    3 /*
    4  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
    5  * All rights reserved.
    6  *
    7  * Author: Chris G. Demetriou
    8  *
    9  * Permission to use, copy, modify and distribute this software and
   10  * its documentation is hereby granted, provided that both the copyright
   11  * notice and this permission notice appear in all copies of the
   12  * software, derivative works or modified versions, and any portions
   13  * thereof, and that both notices appear in supporting documentation.
   14  *
   15  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
   16  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
   17  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
   18  *
   19  * Carnegie Mellon requests users of this software to return to
   20  *
   21  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
   22  *  School of Computer Science
   23  *  Carnegie Mellon University
   24  *  Pittsburgh PA 15213-3890
   25  *
   26  * any improvements or extensions that they make and grant Carnegie the
   27  * rights to redistribute these changes.
   28  */
   29 
   30 #include <sys/cdefs.h>
   31 __KERNEL_RCSID(0, "$NetBSD: pcdisplay_subr.c,v 1.28.2.1 2007/08/06 11:21:57 ghen Exp $");
   32 
   33 #include "opt_wsdisplay_compat.h" /* for WSDISPLAY_CHARFUNCS */
   34 #include "opt_wsmsgattrs.h" /* for WSDISPLAY_CUSTOM_OUTPUT */
   35 
   36 #include <sys/param.h>
   37 #include <sys/systm.h>
   38 #include <sys/device.h>
   39 #include <machine/bus.h>
   40 
   41 #include <dev/ic/mc6845reg.h>
   42 #include <dev/ic/pcdisplayvar.h>
   43 #include <dev/wscons/wsconsio.h>
   44 
   45 #include <dev/wscons/wsdisplayvar.h>
   46 
   47 void
   48 pcdisplay_cursor_init(scr, existing)
   49         struct pcdisplayscreen *scr;
   50         int existing;
   51 {
   52 #ifdef PCDISPLAY_SOFTCURSOR
   53         bus_space_tag_t memt;
   54         bus_space_handle_t memh;
   55         int off;
   56 
   57         pcdisplay_6845_write(scr->hdl, curstart, 0x10);
   58         pcdisplay_6845_write(scr->hdl, curend, 0x10);
   59 
   60         if (existing) {
   61                 /*
   62                  * This is the first screen. At this point, scr->mem is NULL
   63                  * (no backing store), so we can't use pcdisplay_cursor() to
   64                  * do this.
   65                  */
   66                 memt = scr->hdl->ph_memt;
   67                 memh = scr->hdl->ph_memh;
   68                 off = (scr->cursorrow * scr->type->ncols + scr->cursorcol) * 2
   69                     + scr->dispoffset;
   70 
   71                 scr->cursortmp = bus_space_read_2(memt, memh, off);
   72                 bus_space_write_2(memt, memh, off, scr->cursortmp ^ 0x7700);
   73         } else
   74                 scr->cursortmp = 0;
   75 #else
   76         /*
   77          * Firmware might not have initialized the cursor shape.  Make
   78          * sure there's something we can see.
   79          * Don't touch the hardware if this is not the first screen.
   80          */
   81         if (existing) {
   82                 pcdisplay_6845_write(scr->hdl, curstart,
   83                                      scr->type->fontheight - 2);
   84                 pcdisplay_6845_write(scr->hdl, curend,
   85                                      scr->type->fontheight - 1);
   86         }
   87 #endif
   88         scr->cursoron = 1;
   89 }
   90 
   91 void
   92 pcdisplay_cursor(id, on, row, col)
   93         void *id;
   94         int on, row, col;
   95 {
   96 #ifdef PCDISPLAY_SOFTCURSOR
   97         struct pcdisplayscreen *scr = id;
   98         bus_space_tag_t memt = scr->hdl->ph_memt;
   99         bus_space_handle_t memh = scr->hdl->ph_memh;
  100         int off;
  101 
  102         /* Remove old cursor image */
  103         if (scr->cursoron) {
  104                 off = scr->cursorrow * scr->type->ncols + scr->cursorcol;
  105                 if (scr->active)
  106                         bus_space_write_2(memt, memh, scr->dispoffset + off * 2,
  107                             scr->cursortmp);
  108                 else
  109                         scr->mem[off] = scr->cursortmp;
  110         }
  111 
  112         scr->cursorrow = row;
  113         scr->cursorcol = col;
  114 
  115         if ((scr->cursoron = on) == 0)
  116                 return;
  117 
  118         off = (scr->cursorrow * scr->type->ncols + scr->cursorcol);
  119         if (scr->active) {
  120                 off = off * 2 + scr->dispoffset;
  121                 scr->cursortmp = bus_space_read_2(memt, memh, off);
  122                 bus_space_write_2(memt, memh, off, scr->cursortmp ^ 0x7700);
  123         } else {
  124                 scr->cursortmp = scr->mem[off];
  125                 scr->mem[off] = scr->cursortmp ^ 0x7700;
  126         }
  127 #else   /* PCDISPLAY_SOFTCURSOR */
  128         struct pcdisplayscreen *scr = id;
  129         int pos;
  130 
  131         scr->cursorrow = row;
  132         scr->cursorcol = col;
  133         scr->cursoron = on;
  134 
  135         if (scr->active) {
  136                 if (!on)
  137                         pos = 0x3fff;
  138                 else
  139                         pos = scr->dispoffset / 2
  140                                 + row * scr->type->ncols + col;
  141 
  142                 pcdisplay_6845_write(scr->hdl, cursorh, pos >> 8);
  143                 pcdisplay_6845_write(scr->hdl, cursorl, pos);
  144         }
  145 #endif  /* PCDISPLAY_SOFTCURSOR */
  146 }
  147 
  148 #if 0
  149 unsigned int
  150 pcdisplay_mapchar_simple(id, uni)
  151         void *id;
  152         int uni;
  153 {
  154         if (uni < 128)
  155                 return (uni);
  156 
  157         return (1); /* XXX ??? smiley */
  158 }
  159 #endif
  160 
  161 void
  162 pcdisplay_putchar(id, row, col, c, attr)
  163         void *id;
  164         int row, col;
  165         u_int c;
  166         long attr;
  167 {
  168         struct pcdisplayscreen *scr = id;
  169         bus_space_tag_t memt = scr->hdl->ph_memt;
  170         bus_space_handle_t memh = scr->hdl->ph_memh;
  171         size_t off;
  172 
  173         off = row * scr->type->ncols + col;
  174 
  175         /* check for bogus row and column sizes */
  176         if (__predict_false(off >= (scr->type->ncols * scr->type->nrows)))
  177                 return;
  178 
  179         if (scr->active)
  180                 bus_space_write_2(memt, memh, scr->dispoffset + off * 2,
  181                                   c | (attr << 8));
  182         else
  183                 scr->mem[off] = c | (attr << 8);
  184 
  185         scr->visibleoffset = scr->dispoffset;
  186 }
  187 
  188 void
  189 pcdisplay_copycols(id, row, srccol, dstcol, ncols)
  190         void *id;
  191         int row, srccol, dstcol, ncols;
  192 {
  193         struct pcdisplayscreen *scr = id;
  194         bus_space_tag_t memt = scr->hdl->ph_memt;
  195         bus_space_handle_t memh = scr->hdl->ph_memh;
  196         bus_size_t srcoff, dstoff;
  197 
  198         srcoff = dstoff = row * scr->type->ncols;
  199         srcoff += srccol;
  200         dstoff += dstcol;
  201 
  202         if (scr->active)
  203                 bus_space_copy_region_2(memt, memh,
  204                                         scr->dispoffset + srcoff * 2,
  205                                         memh, scr->dispoffset + dstoff * 2,
  206                                         ncols);
  207         else
  208                 memcpy(&scr->mem[dstoff], &scr->mem[srcoff], ncols * 2);
  209 }
  210 
  211 void
  212 pcdisplay_erasecols(id, row, startcol, ncols, fillattr)
  213         void *id;
  214         int row, startcol, ncols;
  215         long fillattr;
  216 {
  217         struct pcdisplayscreen *scr = id;
  218         bus_space_tag_t memt = scr->hdl->ph_memt;
  219         bus_space_handle_t memh = scr->hdl->ph_memh;
  220         bus_size_t off;
  221         u_int16_t val;
  222         int i;
  223 
  224         off = row * scr->type->ncols + startcol;
  225 
  226         val = (fillattr << 8) | ' ';
  227 
  228         if (scr->active)
  229                 bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2,
  230                                        val, ncols);
  231         else
  232                 for (i = 0; i < ncols; i++)
  233                         scr->mem[off + i] = val;
  234 }
  235 
  236 void
  237 pcdisplay_copyrows(id, srcrow, dstrow, nrows)
  238         void *id;
  239         int srcrow, dstrow, nrows;
  240 {
  241         struct pcdisplayscreen *scr = id;
  242         bus_space_tag_t memt = scr->hdl->ph_memt;
  243         bus_space_handle_t memh = scr->hdl->ph_memh;
  244         int ncols = scr->type->ncols;
  245         bus_size_t srcoff, dstoff;
  246 
  247         srcoff = srcrow * ncols + 0;
  248         dstoff = dstrow * ncols + 0;
  249 
  250         if (scr->active)
  251                 bus_space_copy_region_2(memt, memh,
  252                                         scr->dispoffset + srcoff * 2,
  253                                         memh, scr->dispoffset + dstoff * 2,
  254                                         nrows * ncols);
  255         else
  256                 memcpy(&scr->mem[dstoff], &scr->mem[srcoff],
  257                       nrows * ncols * 2);
  258 }
  259 
  260 void
  261 pcdisplay_eraserows(id, startrow, nrows, fillattr)
  262         void *id;
  263         int startrow, nrows;
  264         long fillattr;
  265 {
  266         struct pcdisplayscreen *scr = id;
  267         bus_space_tag_t memt = scr->hdl->ph_memt;
  268         bus_space_handle_t memh = scr->hdl->ph_memh;
  269         bus_size_t off, count;
  270         u_int16_t val;
  271         u_int i;
  272 
  273         off = startrow * scr->type->ncols;
  274         count = nrows * scr->type->ncols;
  275 
  276         val = (fillattr << 8) | ' ';
  277 
  278         if (scr->active)
  279                 bus_space_set_region_2(memt, memh, scr->dispoffset + off * 2,
  280                                        val, count);
  281         else
  282                 for (i = 0; i < count; i++)
  283                         scr->mem[off + i] = val;
  284 }
  285 
  286 #ifdef WSDISPLAY_CUSTOM_OUTPUT
  287 void
  288 pcdisplay_replaceattr(id, oldattr, newattr)
  289         void *id;
  290         long oldattr, newattr;
  291 {
  292         struct pcdisplayscreen *scr = id;
  293         bus_space_tag_t memt = scr->hdl->ph_memt;
  294         bus_space_handle_t memh = scr->hdl->ph_memh;
  295         int off;
  296         uint16_t chardata;
  297 
  298         if (scr->active)
  299                 for (off = 0; off < scr->type->nrows * scr->type->ncols;
  300                      off++) {
  301                         chardata = bus_space_read_2(memt, memh,
  302                                                     scr->dispoffset + off * 2);
  303                         if ((long)(chardata >> 8) == oldattr)
  304                                 bus_space_write_2(memt, memh,
  305                                                   scr->dispoffset + off * 2,
  306                                                   ((u_int16_t)(newattr << 8)) |
  307                                                   (chardata & 0x00FF));
  308                 }
  309         else
  310                 for (off = 0; off < scr->type->nrows * scr->type->ncols;
  311                      off++) {
  312                         chardata = scr->mem[off];
  313                         if ((long)(chardata >> 8) == oldattr)
  314                                 scr->mem[off] = ((u_int16_t)(newattr << 8)) |
  315                                                 (chardata & 0x00FF);
  316                 }
  317 }
  318 #endif /* WSDISPLAY_CUSTOM_OUTPUT */
  319 
  320 #ifdef WSDISPLAY_CHARFUNCS
  321 int
  322 pcdisplay_getwschar(id, wschar)
  323         void *id;
  324         struct wsdisplay_char *wschar;
  325 {
  326         struct pcdisplayscreen *scr = id;
  327         bus_space_tag_t memt = scr->hdl->ph_memt;
  328         bus_space_handle_t memh = scr->hdl->ph_memh;
  329         int off;
  330         uint16_t chardata;
  331         uint8_t attrbyte;
  332 
  333         off = wschar->row * scr->type->ncols + wschar->col;
  334         if (off >= scr->type->ncols * scr->type->nrows)
  335                 return -1;
  336 
  337         if (scr->active)
  338                 chardata = bus_space_read_2(memt, memh,
  339                                             scr->dispoffset + off * 2);
  340         else
  341                 chardata = scr->mem[off];
  342 
  343         wschar->letter = (chardata & 0x00FF);
  344         wschar->flags = 0;
  345         attrbyte = (chardata & 0xFF00) >> 8;
  346         if ((attrbyte & 0x08)) wschar->flags |= WSDISPLAY_CHAR_BRIGHT;
  347         if ((attrbyte & 0x80)) wschar->flags |= WSDISPLAY_CHAR_BLINK;
  348         wschar->foreground = attrbyte & 0x07;
  349         wschar->background = (attrbyte >> 4) & 0x07;
  350 
  351         return 0;
  352 }
  353 
  354 int
  355 pcdisplay_putwschar(id, wschar)
  356         void *id;
  357         struct wsdisplay_char *wschar;
  358 {
  359         struct pcdisplayscreen *scr = id;
  360         bus_space_tag_t memt = scr->hdl->ph_memt;
  361         bus_space_handle_t memh = scr->hdl->ph_memh;
  362         int off;
  363         uint16_t chardata;
  364         uint8_t attrbyte;
  365 
  366         off = wschar->row * scr->type->ncols + wschar->col;
  367         if (off >= (scr->type->ncols * scr->type->nrows))
  368                 return -1;
  369 
  370         attrbyte = wschar->background & 0x07;
  371         if (wschar->flags & WSDISPLAY_CHAR_BLINK) attrbyte |= 0x08;
  372         attrbyte <<= 4;
  373         attrbyte |= wschar->foreground & 0x07;
  374         if (wschar->flags & WSDISPLAY_CHAR_BRIGHT) attrbyte |= 0x08;
  375         chardata = (attrbyte << 8) | wschar->letter;
  376 
  377         if (scr->active)
  378                 bus_space_write_2(memt, memh, scr->dispoffset + off * 2,
  379                                   chardata);
  380         else
  381                 scr->mem[off] = chardata;
  382 
  383         return 0;
  384 }
  385 #endif /* WSDISPLAY_CHARFUNCS */

Cache object: 4a3ec47c84eb0a7d92f7e76584d1582e


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.