xref: /netbsd-src/sys/dev/sbus/tcx.c (revision de4fa6c51a9708fc05f88b618fa6fad87c9508ec)
1 /*	$NetBSD: tcx.c,v 1.40 2009/08/26 22:36:07 macallan Exp $ */
2 
3 /*
4  *  Copyright (c) 1996, 1998, 2009 The NetBSD Foundation, Inc.
5  *  All rights reserved.
6  *
7  *  This code is derived from software contributed to The NetBSD Foundation
8  *  by Paul Kranenburg and Michael Lorenz.
9  *
10  *  Redistribution and use in source and binary forms, with or without
11  *  modification, are permitted provided that the following conditions
12  *  are met:
13  *  1. Redistributions of source code must retain the above copyright
14  *     notice, this list of conditions and the following disclaimer.
15  *  2. Redistributions in binary form must reproduce the above copyright
16  *     notice, this list of conditions and the following disclaimer in the
17  *     documentation and/or other materials provided with the distribution.
18  *
19  *  THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  *  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  *  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  *  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  *  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  *  POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 /*
33  * color display (TCX) driver.
34  *
35  * Does not handle interrupts, even though they can occur.
36  *
37  * XXX should defer colormap updates to vertical retrace interrupts
38  */
39 
40 #include <sys/cdefs.h>
41 __KERNEL_RCSID(0, "$NetBSD: tcx.c,v 1.40 2009/08/26 22:36:07 macallan Exp $");
42 
43 /*
44  * define for cg8 emulation on S24 (24-bit version of tcx) for the SS5;
45  * it is bypassed on the 8-bit version (onboard framebuffer for SS4)
46  */
47 #undef TCX_CG8
48 
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/buf.h>
52 #include <sys/device.h>
53 #include <sys/ioctl.h>
54 #include <sys/malloc.h>
55 #include <sys/mman.h>
56 #include <sys/tty.h>
57 #include <sys/conf.h>
58 
59 #ifdef DEBUG
60 #include <sys/proc.h>
61 #include <sys/syslog.h>
62 #endif
63 
64 #include <sys/bus.h>
65 #include <machine/autoconf.h>
66 
67 #include <dev/sun/fbio.h>
68 #include <dev/sun/fbvar.h>
69 #include <dev/sun/btreg.h>
70 #include <dev/sun/btvar.h>
71 
72 #include <dev/sbus/sbusvar.h>
73 #include <dev/sbus/tcxreg.h>
74 
75 #include <dev/wscons/wsdisplayvar.h>
76 #include <dev/wscons/wsconsio.h>
77 #include <dev/wsfont/wsfont.h>
78 #include <dev/rasops/rasops.h>
79 
80 #include <dev/wscons/wsdisplay_vconsvar.h>
81 
82 #include "opt_wsemul.h"
83 
84 /* per-display variables */
85 struct tcx_softc {
86 	device_t	sc_dev;		/* base device */
87 	struct sbusdev	sc_sd;		/* sbus device */
88 	struct fbdevice	sc_fb;		/* frame buffer device */
89 	bus_space_tag_t	sc_bustag;
90 	struct openprom_addr sc_physaddr[TCX_NREG];/* phys addr of h/w */
91 
92 	bus_space_handle_t sc_bt;	/* Brooktree registers */
93 	bus_space_handle_t sc_thc;	/* THC registers */
94 	uint8_t *sc_fbaddr;		/* framebuffer */
95 	uint64_t *sc_rblit;		/* blitspace */
96 	uint64_t *sc_rstip;		/* stipple space */
97 
98 	short	sc_8bit;		/* true if 8-bit hardware */
99 	short	sc_blanked;		/* true if blanked */
100 	u_char	sc_cmap_red[256];
101 	u_char	sc_cmap_green[256];
102 	u_char	sc_cmap_blue[256];
103 	int 	sc_mode, sc_bg;
104 	int	sc_cursor_x, sc_cursor_y;
105 	int	sc_hotspot_x, sc_hotspot_y;
106 	struct vcons_data vd;
107 };
108 
109 static struct vcons_screen tcx_console_screen;
110 
111 extern const u_char rasops_cmap[768];
112 
113 struct wsscreen_descr tcx_defscreendesc = {
114 	"default",
115 	0, 0,
116 	NULL,
117 	8, 16,
118 	WSSCREEN_WSCOLORS,
119 };
120 
121 const struct wsscreen_descr *_tcx_scrlist[] = {
122 	&tcx_defscreendesc,
123 	/* XXX other formats, graphics screen? */
124 };
125 
126 struct wsscreen_list tcx_screenlist = {
127 	sizeof(_tcx_scrlist) / sizeof(struct wsscreen_descr *),
128 	_tcx_scrlist
129 };
130 
131 /*
132  * The S24 provides the framebuffer RAM mapped in three ways:
133  * 26 bits per pixel, in 32-bit words; the low-order 24 bits are
134  * blue, green, and red values, and the other two bits select the
135  * display modes, per pixel);
136  * 24 bits per pixel, in 32-bit words; the high-order byte reads as
137  * zero, and is ignored on writes (so the mode bits cannot be altered);
138  * 8 bits per pixel, unpadded; writes to this space do not modify the
139  * other 18 bits.
140  */
141 #define TCX_CTL_8_MAPPED	0x00000000	/* 8 bits, uses color map */
142 #define TCX_CTL_24_MAPPED	0x01000000	/* 24 bits, uses color map */
143 #define TCX_CTL_24_LEVEL	0x03000000	/* 24 bits, ignores color map */
144 #define TCX_CTL_PIXELMASK	0x00FFFFFF	/* mask for index/level */
145 
146 /* autoconfiguration driver */
147 static void	tcxattach(device_t, device_t, void *);
148 static int	tcxmatch(device_t, cfdata_t, void *);
149 static void	tcx_unblank(device_t);
150 
151 CFATTACH_DECL_NEW(tcx, sizeof(struct tcx_softc),
152     tcxmatch, tcxattach, NULL, NULL);
153 
154 extern struct cfdriver tcx_cd;
155 
156 dev_type_open(tcxopen);
157 dev_type_close(tcxclose);
158 dev_type_ioctl(tcxioctl);
159 dev_type_mmap(tcxmmap);
160 
161 const struct cdevsw tcx_cdevsw = {
162 	tcxopen, tcxclose, noread, nowrite, tcxioctl,
163 	nostop, notty, nopoll, tcxmmap, nokqfilter,
164 };
165 
166 /* frame buffer generic driver */
167 static struct fbdriver tcx_fbdriver = {
168 	tcx_unblank, tcxopen, tcxclose, tcxioctl, nopoll, tcxmmap,
169 	nokqfilter
170 };
171 
172 static void tcx_reset(struct tcx_softc *);
173 static void tcx_loadcmap(struct tcx_softc *, int, int);
174 
175 static int	tcx_ioctl(void *, void *, u_long, void *, int, struct lwp *);
176 static paddr_t	tcx_mmap(void *, void *, off_t, int);
177 
178 static void	tcx_init_screen(void *, struct vcons_screen *, int, long *);
179 static void	tcx_clearscreen(struct tcx_softc *, int);
180 static void	tcx_copyrows(void *, int, int, int);
181 static void	tcx_eraserows(void *, int, int, long);
182 static void	tcx_putchar(void *, int, int, u_int, long);
183 static void	tcx_set_video(struct tcx_softc *, int);
184 static int	tcx_do_cursor(struct tcx_softc *, struct wsdisplay_cursor *);
185 static void	tcx_set_cursor(struct tcx_softc *);
186 
187 struct wsdisplay_accessops tcx_accessops = {
188 	tcx_ioctl,
189 	tcx_mmap,
190 	NULL,	/* vcons_alloc_screen */
191 	NULL,	/* vcons_free_screen */
192 	NULL,	/* vcons_show_screen */
193 	NULL,	/* load_font */
194 	NULL,	/* polls */
195 	NULL,	/* scroll */
196 };
197 
198 #define OBPNAME	"SUNW,tcx"
199 
200 #ifdef TCX_CG8
201 /*
202  * For CG8 emulation, we map the 32-bit-deep framebuffer at an offset of
203  * 256K; the cg8 space begins with a mono overlay plane and an overlay
204  * enable plane (128K bytes each, 1 bit per pixel), immediately followed
205  * by the color planes, 32 bits per pixel.  We also map just the 32-bit
206  * framebuffer at 0x04000000 (TCX_USER_RAM_COMPAT), for compatibility
207  * with the cg8 driver.
208  */
209 #define	TCX_CG8OVERLAY	(256 * 1024)
210 #define	TCX_SIZE_DFB32	(1152 * 900 * 4) /* max size of the framebuffer */
211 #endif
212 
213 /*
214  * Match a tcx.
215  */
216 int
217 tcxmatch(device_t parent, cfdata_t cf, void *aux)
218 {
219 	struct sbus_attach_args *sa = aux;
220 
221 	return (strcmp(sa->sa_name, OBPNAME) == 0);
222 }
223 
224 /*
225  * Attach a display.
226  */
227 void
228 tcxattach(device_t parent, device_t self, void *args)
229 {
230 	struct tcx_softc *sc = device_private(self);
231 	struct sbus_attach_args *sa = args;
232 	struct wsemuldisplaydev_attach_args aa;
233 	struct rasops_info *ri;
234 	unsigned long defattr;
235 	int node, ramsize;
236 	struct fbdevice *fb = &sc->sc_fb;
237 	bus_space_handle_t bh;
238 	int isconsole, i, j;
239 	uint32_t confreg;
240 
241 	sc->sc_dev = self;
242 	sc->sc_bustag = sa->sa_bustag;
243 	node = sa->sa_node;
244 
245 	sc->sc_cursor_x = 0x7fff;
246 	sc->sc_cursor_y = 0x7fff;
247 	sc->sc_hotspot_x = 0;
248 	sc->sc_hotspot_y = 0;
249 
250 	fb->fb_driver = &tcx_fbdriver;
251 	fb->fb_device = sc->sc_dev;
252 	/* Mask out invalid flags from the user. */
253 	fb->fb_flags = device_cfdata(sc->sc_dev)->cf_flags & FB_USERMASK;
254 	/*
255 	 * The onboard framebuffer on the SS4 supports only 8-bit mode;
256 	 * it can be distinguished from the S24 card for the SS5 by the
257 	 * presence of the "tcx-8-bit" attribute on the SS4 version.
258 	 */
259 	sc->sc_8bit = node_has_property(node, "tcx-8-bit");
260 	fb->fb_type.fb_depth = 8;
261 	fb_setsize_obp(fb, fb->fb_type.fb_depth, 1152, 900, node);
262 
263 	if (sc->sc_8bit) {
264 		printf(" (8bit only TCX)");
265 		ramsize = 1024 * 1024;
266 		/* XXX - fix THC and TEC offsets */
267 		sc->sc_physaddr[TCX_REG_TEC].oa_base += 0x1000;
268 		sc->sc_physaddr[TCX_REG_THC].oa_base += 0x1000;
269 	} else {
270 		printf(" (S24)\n");
271 		ramsize = 4 * 1024 * 1024;
272 	}
273 
274 	fb->fb_type.fb_cmsize = 256;
275 	fb->fb_type.fb_size = ramsize;
276 	printf("%s: %s, %d x %d", device_xname(self), OBPNAME,
277 		fb->fb_type.fb_width,
278 		fb->fb_type.fb_height);
279 
280 	fb->fb_type.fb_type = FBTYPE_TCXCOLOR;
281 
282 
283 	if (sa->sa_nreg != TCX_NREG) {
284 		printf("%s: only %d register sets\n",
285 			device_xname(self), sa->sa_nreg);
286 		return;
287 	}
288 	memcpy(sc->sc_physaddr, sa->sa_reg,
289 	      sa->sa_nreg * sizeof(struct openprom_addr));
290 
291 	/* Map the register banks we care about */
292 	if (sbus_bus_map(sa->sa_bustag,
293 			 sc->sc_physaddr[TCX_REG_THC].oa_space,
294 			 sc->sc_physaddr[TCX_REG_THC].oa_base,
295 			 0x1000,
296 			 BUS_SPACE_MAP_LINEAR, &sc->sc_thc) != 0) {
297 		printf("tcxattach: cannot map thc registers\n");
298 		return;
299 	}
300 
301 	if (sbus_bus_map(sa->sa_bustag,
302 			 sc->sc_physaddr[TCX_REG_CMAP].oa_space,
303 			 sc->sc_physaddr[TCX_REG_CMAP].oa_base,
304 			 0x1000,
305 			 BUS_SPACE_MAP_LINEAR, &sc->sc_bt) != 0) {
306 		printf("tcxattach: cannot map bt registers\n");
307 		return;
308 	}
309 
310 	/* map the 8bit dumb FB for the console */
311 	if (sbus_bus_map(sa->sa_bustag,
312 		 sc->sc_physaddr[TCX_REG_DFB8].oa_space,
313 		 sc->sc_physaddr[TCX_REG_DFB8].oa_base,
314 			 1024 * 1024,
315 			 BUS_SPACE_MAP_LINEAR,
316 			 &bh) != 0) {
317 		printf("tcxattach: cannot map framebuffer\n");
318 		return;
319 	}
320 	sc->sc_fbaddr = bus_space_vaddr(sa->sa_bustag, bh);
321 
322 	/* RBLIT space */
323 	if (sbus_bus_map(sa->sa_bustag,
324 		 sc->sc_physaddr[TCX_REG_RBLIT].oa_space,
325 		 sc->sc_physaddr[TCX_REG_RBLIT].oa_base,
326 			 8 * 1024 * 1024,
327 			 BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_LARGE,
328 			 &bh) != 0) {
329 		printf("tcxattach: cannot map RBLIT space\n");
330 		return;
331 	}
332 	sc->sc_rblit = bus_space_vaddr(sa->sa_bustag, bh);
333 
334 	/* RSTIP space */
335 	if (sbus_bus_map(sa->sa_bustag,
336 		 sc->sc_physaddr[TCX_REG_RSTIP].oa_space,
337 		 sc->sc_physaddr[TCX_REG_RSTIP].oa_base,
338 			 8 * 1024 * 1024,
339 			 BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_LARGE,
340 			 &bh) != 0) {
341 		printf("tcxattach: cannot map RSTIP space\n");
342 		return;
343 	}
344 	sc->sc_rstip = bus_space_vaddr(sa->sa_bustag, bh);
345 
346 	isconsole = fb_is_console(node);
347 
348 	confreg = bus_space_read_4(sa->sa_bustag, sc->sc_thc, THC_CONFIG);
349 	printf(", id %d, rev %d, sense %d",
350 		(confreg & THC_CFG_FBID) >> THC_CFG_FBID_SHIFT,
351 		(confreg & THC_CFG_REV) >> THC_CFG_REV_SHIFT,
352 		(confreg & THC_CFG_SENSE) >> THC_CFG_SENSE_SHIFT
353 	);
354 
355 	/* reset cursor & frame buffer controls */
356 	tcx_reset(sc);
357 
358 	/* Initialize the default color map. */
359 	j = 0;
360 	for (i = 0; i < 256; i++) {
361 
362 		sc->sc_cmap_red[i] = rasops_cmap[j];
363 		sc->sc_cmap_green[i] = rasops_cmap[j + 1];
364 		sc->sc_cmap_blue[i] = rasops_cmap[j + 2];
365 		j += 3;
366 	}
367 	tcx_loadcmap(sc, 0, 256);
368 
369 	tcx_set_cursor(sc);
370 	/* enable video */
371 	confreg = bus_space_read_4(sa->sa_bustag, sc->sc_thc, THC_MISC);
372 	confreg |= THC_MISC_VIDEN;
373 	bus_space_write_4(sa->sa_bustag, sc->sc_thc, THC_MISC, confreg);
374 
375 	if (isconsole) {
376 		printf(" (console)\n");
377 	} else
378 		printf("\n");
379 
380 	sbus_establish(&sc->sc_sd, sc->sc_dev);
381 	fb_attach(&sc->sc_fb, isconsole);
382 
383 	sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
384 	wsfont_init();
385 
386 	vcons_init(&sc->vd, sc, &tcx_defscreendesc, &tcx_accessops);
387 	sc->vd.init_screen = tcx_init_screen;
388 
389 	vcons_init_screen(&sc->vd, &tcx_console_screen, 1, &defattr);
390 	tcx_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
391 
392 	sc->sc_bg = (defattr >> 16) & 0xff;
393 	tcx_clearscreen(sc, 0);
394 
395 	ri = &tcx_console_screen.scr_ri;
396 
397 	tcx_defscreendesc.nrows = ri->ri_rows;
398 	tcx_defscreendesc.ncols = ri->ri_cols;
399 	tcx_defscreendesc.textops = &ri->ri_ops;
400 	tcx_defscreendesc.capabilities = ri->ri_caps;
401 
402 	if(isconsole) {
403 		wsdisplay_cnattach(&tcx_defscreendesc, ri, 0, 0, defattr);
404 		vcons_replay_msgbuf(&tcx_console_screen);
405 	}
406 
407 	aa.console = isconsole;
408 	aa.scrdata = &tcx_screenlist;
409 	aa.accessops = &tcx_accessops;
410 	aa.accesscookie = &sc->vd;
411 
412 	config_found(self, &aa, wsemuldisplaydevprint);
413 	/*
414 	 * we need to do this again - something overwrites a handful
415 	 * palette registers and we end up with white in reg. 0
416 	 */
417 	tcx_loadcmap(sc, 0, 256);
418 }
419 
420 int
421 tcxopen(dev_t dev, int flags, int mode, struct lwp *l)
422 {
423 	return (0);
424 }
425 
426 int
427 tcxclose(dev_t dev, int flags, int mode, struct lwp *l)
428 {
429 	struct tcx_softc *sc = device_lookup_private(&tcx_cd, minor(dev));
430 
431 	tcx_reset(sc);
432 	/* we may want to clear and redraw the console here */
433 	return (0);
434 }
435 
436 int
437 tcxioctl(dev_t dev, u_long cmd, void *data, int flags, struct lwp *l)
438 {
439 	struct tcx_softc *sc = device_lookup_private(&tcx_cd, minor(dev));
440 
441 	switch (cmd) {
442 
443 	case FBIOGTYPE:
444 		*(struct fbtype *)data = sc->sc_fb.fb_type;
445 		break;
446 
447 	case FBIOGATTR:
448 #define fba ((struct fbgattr *)data)
449 		fba->real_type = sc->sc_fb.fb_type.fb_type;
450 		fba->owner = 0;		/* XXX ??? */
451 		fba->fbtype = sc->sc_fb.fb_type;
452 		fba->sattr.flags = 0;
453 		fba->sattr.emu_type = sc->sc_fb.fb_type.fb_type;
454 		fba->sattr.dev_specific[0] = -1;
455 		fba->emu_types[0] = sc->sc_fb.fb_type.fb_type;
456 		fba->emu_types[1] = FBTYPE_SUN3COLOR;
457 		fba->emu_types[2] = -1;
458 #undef fba
459 		break;
460 
461 	case FBIOGETCMAP:
462 #define	p ((struct fbcmap *)data)
463 		if (copyout(&sc->sc_cmap_red[p->index], p->red, p->count) != 0)
464 			return EINVAL;
465 		if (copyout(&sc->sc_cmap_green[p->index], p->green, p->count)
466 		    != 0)
467 			return EINVAL;
468 		if (copyout(&sc->sc_cmap_blue[p->index], p->blue, p->count)
469 		    != 0)
470 			return EINVAL;
471 		return 0;
472 
473 	case FBIOPUTCMAP:
474 		/* copy to software map */
475 		if (copyin(p->red, &sc->sc_cmap_red[p->index], p->count) != 0)
476 			return EINVAL;
477 		if (copyin(p->green, &sc->sc_cmap_green[p->index], p->count)
478 		    != 0)
479 			return EINVAL;
480 		if (copyin(p->blue, &sc->sc_cmap_blue[p->index], p->count) != 0)
481 			return EINVAL;
482 		tcx_loadcmap(sc, p->index, p->count);
483 #undef p
484 		break;
485 	case FBIOGVIDEO:
486 		*(int *)data = sc->sc_blanked;
487 		break;
488 
489 	case FBIOSVIDEO:
490 		tcx_set_video(sc, *(int *)data);
491 		break;
492 
493 	default:
494 #ifdef DEBUG
495 		log(LOG_NOTICE, "tcxioctl(0x%lx) (%s[%d])\n", cmd,
496 		    l->l_proc->p_comm, l->l_proc->p_pid);
497 #endif
498 		return (ENOTTY);
499 	}
500 	return (0);
501 }
502 
503 /*
504  * Clean up hardware state (e.g., after bootup or after X crashes).
505  */
506 static void
507 tcx_reset(struct tcx_softc *sc)
508 {
509 	uint32_t reg;
510 
511 	reg = bus_space_read_4(sc->sc_bustag, sc->sc_thc, THC_MISC);
512 	reg |= THC_MISC_CURSRES;
513 	bus_space_write_4(sc->sc_bustag, sc->sc_thc, THC_MISC, reg);
514 }
515 
516 static void
517 tcx_loadcmap(struct tcx_softc *sc, int start, int ncolors)
518 {
519 	int i;
520 
521 	for (i = 0; i < ncolors; i++) {
522 		bus_space_write_4(sc->sc_bustag, sc->sc_bt, DAC_ADDRESS,
523 		    (start + i) << 24);
524 		bus_space_write_4(sc->sc_bustag, sc->sc_bt, DAC_FB_LUT,
525 		    sc->sc_cmap_red[i + start] << 24);
526 		bus_space_write_4(sc->sc_bustag, sc->sc_bt, DAC_FB_LUT,
527 		    sc->sc_cmap_green[i + start] << 24);
528 		bus_space_write_4(sc->sc_bustag, sc->sc_bt, DAC_FB_LUT,
529 		    sc->sc_cmap_blue[i + start] << 24);
530 	}
531 	bus_space_write_4(sc->sc_bustag, sc->sc_bt, DAC_ADDRESS, 0);
532 }
533 
534 static void
535 tcx_unblank(device_t dev)
536 {
537 	struct tcx_softc *sc = device_private(dev);
538 
539 	if (sc->sc_blanked) {
540 		uint32_t reg;
541 		sc->sc_blanked = 0;
542 		reg = bus_space_read_4(sc->sc_bustag, sc->sc_thc, THC_MISC);
543 		reg &= ~THC_MISC_VSYNC_DISABLE;
544 		reg &= ~THC_MISC_HSYNC_DISABLE;
545 		reg |= THC_MISC_VIDEN;
546 		bus_space_write_4(sc->sc_bustag, sc->sc_thc, THC_MISC, reg);
547 	}
548 }
549 
550 static void
551 tcx_set_video(struct tcx_softc *sc, int unblank)
552 {
553 	uint32_t reg;
554 	if (unblank) {
555 		sc->sc_blanked = 0;
556 		reg = bus_space_read_4(sc->sc_bustag, sc->sc_thc, THC_MISC);
557 		reg &= ~THC_MISC_VSYNC_DISABLE;
558 		reg &= ~THC_MISC_HSYNC_DISABLE;
559 		reg |= THC_MISC_VIDEN;
560 		bus_space_write_4(sc->sc_bustag, sc->sc_thc, THC_MISC, reg);
561 	} else {
562 		sc->sc_blanked = 1;
563 		reg = bus_space_read_4(sc->sc_bustag, sc->sc_thc, THC_MISC);
564 		reg |= THC_MISC_VSYNC_DISABLE;
565 		reg |= THC_MISC_HSYNC_DISABLE;
566 		reg &= ~THC_MISC_VIDEN;
567 		bus_space_write_4(sc->sc_bustag, sc->sc_thc, THC_MISC, reg);
568 	}
569 }
570 
571 /*
572  * Base addresses at which users can mmap() the various pieces of a tcx.
573  */
574 #define	TCX_USER_RAM	0x00000000
575 #define	TCX_USER_RAM24	0x01000000
576 #define	TCX_USER_RAM_COMPAT	0x04000000	/* cg3 emulation */
577 #define	TCX_USER_STIP	0x10000000
578 #define	TCX_USER_BLIT	0x20000000
579 #define	TCX_USER_RDFB32	0x28000000
580 #define	TCX_USER_RSTIP	0x30000000
581 #define	TCX_USER_RBLIT	0x38000000
582 #define	TCX_USER_TEC	0x70001000
583 #define	TCX_USER_BTREGS	0x70002000
584 #define	TCX_USER_THC	0x70004000
585 #define	TCX_USER_DHC	0x70008000
586 #define	TCX_USER_ALT	0x7000a000
587 #define	TCX_USER_UART	0x7000c000
588 #define	TCX_USER_VRT	0x7000e000
589 #define	TCX_USER_ROM	0x70010000
590 
591 struct mmo {
592 	u_int	mo_uaddr;	/* user (virtual) address */
593 	u_int	mo_size;	/* size, or 0 for video ram size */
594 	u_int	mo_bank;	/* register bank number */
595 };
596 
597 /*
598  * Return the address that would map the given device at the given
599  * offset, allowing for the given protection, or return -1 for error.
600  *
601  * XXX	needs testing against `demanding' applications (e.g., aviator)
602  */
603 paddr_t
604 tcxmmap(dev_t dev, off_t off, int prot)
605 {
606 	struct tcx_softc *sc = device_lookup_private(&tcx_cd, minor(dev));
607 	struct openprom_addr *rr = sc->sc_physaddr;
608 	struct mmo *mo, *mo_end;
609 	u_int u, sz;
610 	static struct mmo mmo[] = {
611 		{ TCX_USER_RAM, 0, TCX_REG_DFB8 },
612 		{ TCX_USER_RAM24, 0, TCX_REG_DFB24 },
613 		{ TCX_USER_RAM_COMPAT, 0, TCX_REG_DFB8 },
614 
615 		{ TCX_USER_STIP, 1, TCX_REG_STIP },
616 		{ TCX_USER_BLIT, 1, TCX_REG_BLIT },
617 		{ TCX_USER_RDFB32, 0, TCX_REG_RDFB32 },
618 		{ TCX_USER_RSTIP, 1, TCX_REG_RSTIP },
619 		{ TCX_USER_RBLIT, 1, TCX_REG_RBLIT },
620 		{ TCX_USER_TEC, 1, TCX_REG_TEC },
621 		{ TCX_USER_BTREGS, 8192 /* XXX */, TCX_REG_CMAP },
622 		{ TCX_USER_THC, 0x2000, TCX_REG_THC },
623 		{ TCX_USER_DHC, 1, TCX_REG_DHC },
624 		{ TCX_USER_ALT, 1, TCX_REG_ALT },
625 		{ TCX_USER_ROM, 65536, TCX_REG_ROM },
626 	};
627 #define NMMO (sizeof mmo / sizeof *mmo)
628 
629 	if (off & PGOFSET)
630 		panic("tcxmmap");
631 
632 	/*
633 	 * Entries with size 0 map video RAM (i.e., the size in fb data).
634 	 * Entries that map 32-bit deep regions are adjusted for their
635 	 * depth (fb_size gives the size of the 8-bit-deep region).
636 	 *
637 	 * Since we work in pages, the fact that the map offset table's
638 	 * sizes are sometimes bizarre (e.g., 1) is effectively ignored:
639 	 * one byte is as good as one page.
640 	 */
641 
642 	mo = mmo;
643 	mo_end = &mmo[NMMO];
644 
645 	for (; mo < mo_end; mo++) {
646 		if ((u_int)off < mo->mo_uaddr)
647 			continue;
648 
649 		u = off - mo->mo_uaddr;
650 		sz = mo->mo_size;
651 
652 		if (sz == 0) {
653 			sz = sc->sc_fb.fb_type.fb_size;
654 			/*
655 			 * check for the 32-bit-deep regions and adjust
656 			 * accordingly
657 			 */
658 			if (mo->mo_uaddr == TCX_USER_RAM24 ||
659 			    mo->mo_uaddr == TCX_USER_RDFB32) {
660 				if (sc->sc_8bit) {
661 					/*
662 					 * not present on 8-bit hardware
663 					 */
664 					continue;
665 				}
666 				sz *= 4;
667 			}
668 		}
669 		if (sz == 1)
670 			sz = rr[mo->mo_bank].oa_size;
671 
672 		if (u < sz) {
673 			return (bus_space_mmap(sc->sc_bustag,
674 				BUS_ADDR(rr[mo->mo_bank].oa_space,
675 					 rr[mo->mo_bank].oa_base),
676 				u,
677 				prot,
678 				BUS_SPACE_MAP_LINEAR));
679 		}
680 	}
681 	return (-1);
682 }
683 
684 int
685 tcx_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
686 	struct lwp *l)
687 {
688 	struct vcons_data *vd = v;
689 	struct tcx_softc *sc = vd->cookie;
690 	struct wsdisplay_fbinfo *wdf;
691 	struct vcons_screen *ms = vd->active;
692 
693 	switch (cmd) {
694 		case WSDISPLAYIO_GTYPE:
695 			*(u_int *)data = WSDISPLAY_TYPE_SUNTCX;
696 			return 0;
697 
698 		case FBIOGVIDEO:
699 		case WSDISPLAYIO_GVIDEO:
700 			*(int *)data = !sc->sc_blanked;
701 			return 0;
702 
703 		case WSDISPLAYIO_SVIDEO:
704 		case FBIOSVIDEO:
705 			tcx_set_video(sc, *(int *)data);
706 			return 0;
707 
708 		case WSDISPLAYIO_GINFO:
709 			wdf = (void *)data;
710 			wdf->height = ms->scr_ri.ri_height;
711 			wdf->width = ms->scr_ri.ri_width;
712 			if (sc->sc_8bit) {
713 				wdf->depth = 8;
714 			} else {
715 				wdf->depth = 32;
716 			}
717 			wdf->cmsize = 256;
718 			return 0;
719 		case WSDISPLAYIO_LINEBYTES:
720 			{
721 				int *ret = (int *)data;
722 				*ret = sc->sc_8bit ? ms->scr_ri.ri_width :
723 				    ms->scr_ri.ri_width << 2;
724 			}
725 			return 0;
726 #if 0
727 		case WSDISPLAYIO_GETCMAP:
728 			return tcx_getcmap(sc, (struct wsdisplay_cmap *)data);
729 
730 		case WSDISPLAYIO_PUTCMAP:
731 			return tcx_putcmap(sc, (struct wsdisplay_cmap *)data);
732 #endif
733 		case WSDISPLAYIO_SMODE:
734 			{
735 				int new_mode = *(int*)data;
736 				if (new_mode != sc->sc_mode)
737 				{
738 					sc->sc_mode = new_mode;
739 					if (new_mode == WSDISPLAYIO_MODE_EMUL)
740 					{
741 						tcx_loadcmap(sc, 0, 256);
742 						tcx_clearscreen(sc, 0);
743 						vcons_redraw_screen(ms);
744 					} else if (!sc->sc_8bit)
745 						tcx_clearscreen(sc, 3);
746 				}
747 			}
748 		case WSDISPLAYIO_GCURPOS:
749 			{
750 				struct wsdisplay_curpos *cp = (void *)data;
751 
752 				cp->x = sc->sc_cursor_x;
753 				cp->y = sc->sc_cursor_y;
754 			}
755 			return 0;
756 
757 		case WSDISPLAYIO_SCURPOS:
758 			{
759 				struct wsdisplay_curpos *cp = (void *)data;
760 
761 				sc->sc_cursor_x = cp->x;
762 				sc->sc_cursor_y = cp->y;
763 				tcx_set_cursor(sc);
764 			}
765 			return 0;
766 
767 		case WSDISPLAYIO_GCURMAX:
768 			{
769 				struct wsdisplay_curpos *cp = (void *)data;
770 
771 				cp->x = 32;
772 				cp->y = 32;
773 			}
774 			return 0;
775 
776 		case WSDISPLAYIO_SCURSOR:
777 			{
778 				struct wsdisplay_cursor *cursor = (void *)data;
779 
780 				return tcx_do_cursor(sc, cursor);
781 			}
782 	}
783 	return EPASSTHROUGH;
784 }
785 
786 static paddr_t
787 tcx_mmap(void *v, void *vs, off_t offset, int prot)
788 {
789 	struct vcons_data *vd = v;
790 	struct tcx_softc *sc = vd->cookie;
791 
792 	/* 'regular' framebuffer mmap()ing */
793 	if (sc->sc_8bit) {
794 		/* on 8Bit boards hand over the 8 bit aperture */
795 		if (offset > 1024 * 1024)
796 			return -1;
797 		return bus_space_mmap(sc->sc_bustag,
798 		    sc->sc_physaddr[TCX_REG_DFB8].oa_base + offset, 0, prot,
799 		    BUS_SPACE_MAP_LINEAR);
800 	} else {
801 		/* ... but if we have a 24bit aperture we use it */
802 		if (offset > 1024 * 1024 * 4)
803 			return -1;
804 		return bus_space_mmap(sc->sc_bustag,
805 		    sc->sc_physaddr[TCX_REG_DFB24].oa_base + offset, 0, prot,
806 		    BUS_SPACE_MAP_LINEAR);
807 	}
808 	return -1;
809 }
810 
811 static void
812 tcx_init_screen(void *cookie, struct vcons_screen *scr,
813     int existing, long *defattr)
814 {
815 	struct tcx_softc *sc = cookie;
816 	struct rasops_info *ri = &scr->scr_ri;
817 
818 	ri->ri_depth = 8;
819 	ri->ri_width = sc->sc_fb.fb_type.fb_width;
820 	ri->ri_height = sc->sc_fb.fb_type.fb_height;
821 	ri->ri_stride = sc->sc_fb.fb_linebytes;
822 	ri->ri_flg = RI_CENTER | RI_FULLCLEAR;
823 
824 	ri->ri_bits = sc->sc_fbaddr;
825 
826 	rasops_init(ri, ri->ri_height/8, ri->ri_width/8);
827 	ri->ri_caps = WSSCREEN_WSCOLORS;
828 	rasops_reconfig(ri, ri->ri_height / ri->ri_font->fontheight,
829 		    ri->ri_width / ri->ri_font->fontwidth);
830 
831 	/* enable acceleration */
832 	ri->ri_ops.copyrows  = tcx_copyrows;
833 	ri->ri_ops.eraserows = tcx_eraserows;
834 	ri->ri_ops.putchar   = tcx_putchar;
835 #if 0
836 	ri->ri_ops.cursor    = tcx_cursor;
837 	ri->ri_ops.copycols  = tcx_copycols;
838 	ri->ri_ops.erasecols = tcx_erasecols;
839 #endif
840 }
841 
842 static void
843 tcx_clearscreen(struct tcx_softc *sc, int spc)
844 {
845 	uint64_t bg = ((uint64_t)sc->sc_bg << 32) | 0xffffffffLL;
846 	uint64_t spc64;
847 	int i;
848 
849 	spc64 = spc & 3;
850 	spc64 = spc64 << 56;
851 
852 	for (i = 0; i < 1024 * 1024; i += 32)
853 		sc->sc_rstip[i] = bg | spc64;
854 }
855 
856 static void
857 tcx_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
858 {
859 	struct rasops_info *ri = cookie;
860 	struct vcons_screen *scr = ri->ri_hw;
861 	struct tcx_softc *sc = scr->scr_cookie;
862 	int i, last, first, len, dest, leftover;
863 
864 	i = ri->ri_width * ri->ri_font->fontheight * nrows;
865 	len = i & 0xffffe0;
866 	leftover = i & 0x1f;
867 	if (srcrow < dstrow) {
868 		/* we must go bottom to top */
869 		first = ri->ri_width *
870 		    (ri->ri_font->fontheight * srcrow + ri->ri_yorigin);
871 		last = first + len;
872 		dest = ri->ri_width *
873 		    (ri->ri_font->fontheight * dstrow + ri->ri_yorigin) + len;
874 		if (leftover > 0) {
875 			sc->sc_rblit[dest + 32] =
876 			    (uint64_t)((leftover - 1) << 24) |
877 			    (uint64_t)(i + 32);
878 		}
879 		for (i = last; i >= first; i -= 32) {
880 			sc->sc_rblit[dest] = 0x300000001f000000LL | (uint64_t)i;
881 			dest -= 32;
882 		}
883 	} else {
884 		/* top to bottom */
885 		first = ri->ri_width *
886 		    (ri->ri_font->fontheight * srcrow + ri->ri_yorigin);
887 		dest = ri->ri_width *
888 		    (ri->ri_font->fontheight * dstrow + ri->ri_yorigin);
889 		last = first + len;
890 		for (i = first; i <= last; i+= 32) {
891 			sc->sc_rblit[dest] = 0x300000001f000000LL | (uint64_t)i;
892 			dest += 32;
893 		}
894 		if (leftover > 0) {
895 			sc->sc_rblit[dest] =
896 			    (uint64_t)((leftover - 1) << 24) | (uint64_t)i;
897 		}
898 	}
899 }
900 
901 static void
902 tcx_eraserows(void *cookie, int start, int nrows, long attr)
903 {
904 	struct rasops_info *ri = cookie;
905 	struct vcons_screen *scr = ri->ri_hw;
906 	struct tcx_softc *sc = scr->scr_cookie;
907 	uint64_t temp;
908 	int i, last, first, len, leftover;
909 
910 	i = ri->ri_width * ri->ri_font->fontheight * nrows;
911 	len = i & 0xffffe0;
912 	leftover = i & 0x1f;
913 	first = ri->ri_width *
914 	    (ri->ri_font->fontheight * start + ri->ri_yorigin);
915 	last = first + len;
916 	temp = 0x30000000ffffffffLL |
917 	    ((uint64_t)ri->ri_devcmap[(attr >> 16) & 0xff] << 32);
918 
919 	for (i = first; i <= last; i+= 32)
920 		sc->sc_rblit[i] = temp;
921 
922 	if (leftover > 0) {
923 		temp &= 0xffffffffffffffffLL << (32 - leftover);
924 		sc->sc_rblit[i] = temp;
925 	}
926 }
927 /*
928  * The stipple engine is 100% retarded. All drawing operations have to start
929  * at 32 pixel boundaries so we'll have to deal with characters being split.
930  */
931 
932 static void
933 tcx_putchar(void *cookie, int row, int col, u_int c, long attr)
934 {
935 	struct rasops_info *ri = cookie;
936 	struct vcons_screen *scr = ri->ri_hw;
937 	struct tcx_softc *sc = scr->scr_cookie;
938 	uint64_t bg, fg, temp, mask;
939 	int addr, i, uc, shift;
940 	uint32_t fmask;
941 	uint8_t *cdata;
942 	uint16_t *wdata;
943 
944 	addr = ri->ri_xorigin +
945 	    col * ri->ri_font->fontwidth +
946 	    (ri->ri_yorigin + row * ri->ri_font->fontheight) * ri->ri_width;
947 
948 	/* check if the character is crossing a 32 pixel boundary */
949 	if ((addr & 0xffffe0) ==
950 	    ((addr + ri->ri_font->fontwidth - 1) & 0xffffe0)) {
951 		/* phew, not split */
952 		shift = addr & 0x1f;
953 		addr &= 0xffffe0;
954 		fmask = 0xffffffff >> (32 - ri->ri_font->fontwidth);
955 		fmask = fmask << (32 - ri->ri_font->fontwidth - shift);
956 		mask = fmask;
957 		bg = 0x3000000000000000LL |
958 		    ((uint64_t)ri->ri_devcmap[(attr >> 16) & 0xff] &
959 		      0xff) << 32;
960 		bg |= mask;
961 		temp = 0x3000000000000000LL |
962 		    ((uint64_t)ri->ri_devcmap[(attr >> 24) & 0xff] & 0xff) <<
963 		    	32;
964 		uc = c - ri->ri_font->firstchar;
965 		cdata = (uint8_t *)ri->ri_font->data + uc * ri->ri_fontscale;
966 
967 		if (ri->ri_font->fontwidth < 9) {
968 			/* byte by byte */
969 			for (i = 0; i < ri->ri_font->fontheight; i++) {
970 				sc->sc_rstip[addr] = bg;
971 				if (*cdata != 0) {
972 					if (shift > 24) {
973 						fg = (uint64_t)*cdata >>
974 					  	  (shift - 24);
975 					} else {
976 						fg = (uint64_t)*cdata <<
977 					  	  (24 - shift);
978 					}
979 					sc->sc_rstip[addr] = fg | temp;
980 				}
981 				cdata++;
982 				addr += ri->ri_width;
983 			}
984 		} else if (ri->ri_font->fontwidth < 17) {
985 			/* short by short */
986 			wdata = (uint16_t *)cdata;
987 			for (i = 0; i < ri->ri_font->fontheight; i++) {
988 				sc->sc_rstip[addr] = bg;
989 				if (*wdata != 0) {
990 					if (shift > 16) {
991 						fg = temp | (uint64_t)*wdata >>
992 					  	  (shift - 16);
993 					} else {
994 						fg = temp | (uint64_t)*wdata <<
995 					  	  (16 - shift);
996 					}
997 					sc->sc_rstip[addr] = fg;
998 				}
999 				wdata++;
1000 				addr += ri->ri_width;
1001 			}
1002 		}
1003 	} else {
1004 		/* and now the split case ( man this hardware is dumb ) */
1005 		uint64_t bgr, maskr, fgr;
1006 		uint32_t bork;
1007 
1008 		shift = addr & 0x1f;
1009 		addr &= 0xffffe0;
1010 		mask = 0xffffffff >> shift;
1011 		maskr = (uint64_t)(0xffffffffUL <<
1012 		    (32 - (ri->ri_font->fontwidth + shift - 32)));
1013 		bg = 0x3000000000000000LL |
1014 		    ((uint64_t)ri->ri_devcmap[(attr >> 16) & 0xff] &
1015 		      0xff) << 32;
1016 		bgr = bg | maskr;
1017 		bg |= mask;
1018 		temp = 0x3000000000000000LL |
1019 		    ((uint64_t)ri->ri_devcmap[(attr >> 24) & 0xff] & 0xff) <<
1020 		      32;
1021 
1022 		uc = c - ri->ri_font->firstchar;
1023 		cdata = (uint8_t *)ri->ri_font->data + uc * ri->ri_fontscale;
1024 
1025 		if (ri->ri_font->fontwidth < 9) {
1026 			/* byte by byte */
1027 			for (i = 0; i < ri->ri_font->fontheight; i++) {
1028 				sc->sc_rstip[addr] = bg;
1029 				sc->sc_rstip[addr + 32] = bgr;
1030 				bork = *cdata;
1031 				if (bork != 0) {
1032 					fg = (uint64_t)bork >> (shift - 24);
1033 					sc->sc_rstip[addr] = fg | temp;
1034 					fgr = (uint64_t)(bork << (52 - shift));
1035 					sc->sc_rstip[addr] = fgr | temp;
1036 				}
1037 				cdata++;
1038 				addr += ri->ri_width;
1039 			}
1040 		} else if (ri->ri_font->fontwidth < 17) {
1041 			/* short by short */
1042 			wdata = (uint16_t *)cdata;
1043 			for (i = 0; i < ri->ri_font->fontheight; i++) {
1044 				sc->sc_rstip[addr] = bg;
1045 				sc->sc_rstip[addr + 32] = bgr;
1046 				bork = *wdata;
1047 				if (bork != 0) {
1048 					fg = (uint64_t)bork >> (shift - 16);
1049 					sc->sc_rstip[addr] = fg | temp;
1050 					fgr = (uint64_t)(bork << (48 - shift));
1051 					sc->sc_rstip[addr + 32] = fgr | temp;
1052 				}
1053 				wdata++;
1054 				addr += ri->ri_width;
1055 			}
1056 		}
1057 
1058 	}
1059 }
1060 
1061 static int
1062 tcx_do_cursor(struct tcx_softc *sc, struct wsdisplay_cursor *cur)
1063 {
1064 	if (cur->which & WSDISPLAY_CURSOR_DOCUR) {
1065 
1066 		if (cur->enable) {
1067 			tcx_set_cursor(sc);
1068 		} else {
1069 			/* move the cursor out of sight */
1070 			bus_space_write_4(sc->sc_bustag, sc->sc_thc,
1071 			    THC_CURSOR_POS, 0x7fff7fff);
1072 		}
1073 	}
1074 	if (cur->which & WSDISPLAY_CURSOR_DOHOT) {
1075 
1076 		sc->sc_hotspot_x = cur->hot.x;
1077 		sc->sc_hotspot_y = cur->hot.y;
1078 		tcx_set_cursor(sc);
1079 	}
1080 	if (cur->which & WSDISPLAY_CURSOR_DOPOS) {
1081 
1082 		sc->sc_cursor_x = cur->pos.x;
1083 		sc->sc_cursor_y = cur->pos.y;
1084 		tcx_set_cursor(sc);
1085 	}
1086 	if (cur->which & WSDISPLAY_CURSOR_DOCMAP) {
1087 #if 0
1088 	/*
1089 	 * apparently we're not writing in the right register here - if we do
1090 	 * this the screen goes all funky
1091 	 */
1092 		int i;
1093 
1094 		for (i = 0; i < cur->cmap.count; i++) {
1095 			bus_space_write_4(sc->sc_bustag, sc->sc_bt, DAC_ADDRESS,
1096 			    (cur->cmap.index + i + 2) << 24);
1097 			bus_space_write_4(sc->sc_bustag, sc->sc_bt,
1098 			    DAC_CURSOR_LUT, cur->cmap.red[i] << 24);
1099 			bus_space_write_4(sc->sc_bustag, sc->sc_bt,
1100 			    DAC_CURSOR_LUT, cur->cmap.green[i] << 24);
1101 			bus_space_write_4(sc->sc_bustag, sc->sc_bt,
1102 			    DAC_CURSOR_LUT, cur->cmap.blue[i] << 24);
1103 		}
1104 #endif
1105 	}
1106 	if (cur->which & WSDISPLAY_CURSOR_DOSHAPE) {
1107 		int i;
1108 		uint32_t temp, poof;
1109 
1110 		for (i = 0; i < 128; i += 4) {
1111 			memcpy(&temp, &cur->mask[i], 4);
1112 			printf("%08x -> ", temp);
1113 			poof = ((temp & 0x80808080) >> 7) |
1114 			       ((temp & 0x40404040) >> 5) |
1115 			       ((temp & 0x20202020) >> 3) |
1116 			       ((temp & 0x10101010) >> 1) |
1117 			       ((temp & 0x08080808) << 1) |
1118 			       ((temp & 0x04040404) << 3) |
1119 			       ((temp & 0x02020202) << 5) |
1120 			       ((temp & 0x01010101) << 7);
1121 			printf("%08x\n", poof);
1122 			bus_space_write_4(sc->sc_bustag, sc->sc_thc,
1123 			    THC_CURSOR_1 + i, poof);
1124 			memcpy(&temp, &cur->image[i], 4);
1125 			poof = ((temp & 0x80808080) >> 7) |
1126 			       ((temp & 0x40404040) >> 5) |
1127 			       ((temp & 0x20202020) >> 3) |
1128 			       ((temp & 0x10101010) >> 1) |
1129 			       ((temp & 0x08080808) << 1) |
1130 			       ((temp & 0x04040404) << 3) |
1131 			       ((temp & 0x02020202) << 5) |
1132 			       ((temp & 0x01010101) << 7);
1133 			bus_space_write_4(sc->sc_bustag, sc->sc_thc,
1134 			    THC_CURSOR_0 + i, poof);
1135 		}
1136 	}
1137 	return 0;
1138 }
1139 
1140 static void
1141 tcx_set_cursor(struct tcx_softc *sc)
1142 {
1143 	uint32_t reg;
1144 
1145 	reg = (sc->sc_cursor_x - sc->sc_hotspot_x) << 16 |
1146 	     ((sc->sc_cursor_y - sc->sc_hotspot_y) & 0xffff);
1147 	bus_space_write_4(sc->sc_bustag, sc->sc_thc, THC_CURSOR_POS, reg);
1148 }
1149 
1150