1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
|
/* $OpenBSD: smg.c,v 1.1 2000/04/27 02:34:50 bjc Exp $ */
/* $NetBSD: smg.c,v 1.21 2000/03/23 06:46:44 thorpej Exp $ */
/*
* Copyright (c) 1998 Ludd, University of Lule}, Sweden.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed at Ludd, University of
* Lule}, Sweden and its contributors.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/param.h>
#include <sys/device.h>
#include <sys/systm.h>
#include <sys/callout.h>
#include <sys/time.h>
#include <sys/malloc.h>
#include <sys/conf.h>
#include <sys/kernel.h>
#include <dev/cons.h>
#include <dev/wscons/wsdisplayvar.h>
#include <dev/wscons/wsconsio.h>
#include <dev/wscons/wscons_callbacks.h>
#include <machine/vsbus.h>
#include <machine/sid.h>
#include <machine/cpu.h>
#include <machine/ka420.h>
#include "lkc.h"
#define SM_COLS 128 /* char width of screen */
#define SM_ROWS 57 /* rows of char on screen */
#define SM_CHEIGHT 15 /* lines a char consists of */
#define SM_NEXTROW (SM_COLS * SM_CHEIGHT)
static int smg_match __P((struct device *, struct cfdata *, void *));
static void smg_attach __P((struct device *, struct device *, void *));
struct smg_softc {
struct device ss_dev;
};
struct cfattach smg_ca = {
sizeof(struct smg_softc), smg_match, smg_attach,
};
static void smg_cursor __P((void *, int, int, int));
static int smg_mapchar __P((void *, int, unsigned int *));
static void smg_putchar __P((void *, int, int, u_int, long));
static void smg_copycols __P((void *, int, int, int,int));
static void smg_erasecols __P((void *, int, int, int, long));
static void smg_copyrows __P((void *, int, int, int));
static void smg_eraserows __P((void *, int, int, long));
static int smg_alloc_attr __P((void *, int, int, int, long *));
const struct wsdisplay_emulops smg_emulops = {
smg_cursor,
smg_mapchar,
smg_putchar,
smg_copycols,
smg_erasecols,
smg_copyrows,
smg_eraserows,
smg_alloc_attr
};
const struct wsscreen_descr smg_stdscreen = {
"128x57", SM_COLS, SM_ROWS,
&smg_emulops,
8, SM_CHEIGHT,
WSSCREEN_UNDERLINE|WSSCREEN_REVERSE,
};
const struct wsscreen_descr *_smg_scrlist[] = {
&smg_stdscreen,
};
const struct wsscreen_list smg_screenlist = {
sizeof(_smg_scrlist) / sizeof(struct wsscreen_descr *),
_smg_scrlist,
};
static caddr_t sm_addr;
extern char q_font[];
#define QCHAR(c) (c < 32 ? 32 : (c > 127 ? c - 66 : c - 32))
#define QFONT(c,line) q_font[QCHAR(c) * 15 + line]
#define SM_ADDR(row, col, line) \
sm_addr[col + (row * SM_CHEIGHT * SM_COLS) + line * SM_COLS]
static int smg_ioctl __P((void *, u_long, caddr_t, int, struct proc *));
static int smg_mmap __P((void *, off_t, int));
static int smg_alloc_screen __P((void *, const struct wsscreen_descr *,
void **, int *, int *, long *));
static void smg_free_screen __P((void *, void *));
static int smg_show_screen __P((void *, void *, int,
void (*) (void *, int, int), void *));
static void smg_crsr_blink __P((void *));
const struct wsdisplay_accessops smg_accessops = {
smg_ioctl,
smg_mmap,
smg_alloc_screen,
smg_free_screen,
smg_show_screen,
0 /* load_font */
};
struct smg_screen {
int ss_curx;
int ss_cury;
u_char ss_image[SM_ROWS][SM_COLS]; /* Image of current screen */
u_char ss_attr[SM_ROWS][SM_COLS]; /* Reversed etc... */
};
static struct smg_screen smg_conscreen;
static struct smg_screen *curscr;
static struct callout smg_cursor_ch = CALLOUT_INITIALIZER;
int
smg_match(parent, match, aux)
struct device *parent;
struct cfdata *match;
void *aux;
{
struct vsbus_attach_args *va = aux;
volatile short *curcmd;
volatile short *cfgtst;
short tmp, tmp2;
if (vax_boardtype == VAX_BTYP_49)
return 0;
curcmd = (short *)va->va_addr;
cfgtst = (short *)vax_map_physmem(VS_CFGTST, 1);
/*
* Try to find the cursor chip by testing the flip-flop.
* If nonexistent, no glass tty.
*/
curcmd[0] = 0x7fff;
DELAY(300000);
tmp = cfgtst[0];
curcmd[0] = 0x8000;
DELAY(300000);
tmp2 = cfgtst[0];
vax_unmap_physmem((vaddr_t)cfgtst, 1);
if (tmp2 != tmp)
return 20; /* Using periodic interrupt */
else
return 0;
}
void
smg_attach(parent, self, aux)
struct device *parent, *self;
void *aux;
{
struct wsemuldisplaydev_attach_args aa;
printf("\n");
sm_addr = (caddr_t)vax_map_physmem(SMADDR, (SMSIZE/VAX_NBPG));
if (sm_addr == 0) {
printf("%s: Couldn't alloc graphics memory.\n", self->dv_xname);
return;
}
curscr = &smg_conscreen;
aa.console = !(vax_confdata & 0x20);
aa.scrdata = &smg_screenlist;
aa.accessops = &smg_accessops;
callout_reset(&smc_cursor_ch, hz / 2, smg_crsr_blink, NULL);
config_found(self, &aa, wsemuldisplaydevprint);
}
static u_char *cursor;
static int cur_on;
static void
smg_crsr_blink(arg)
void *arg;
{
if (cur_on)
*cursor ^= 255;
callout_reset(&smg_cursor_ch, hz / 2, smg_crsr_blink, NULL);
}
void
smg_cursor(id, on, row, col)
void *id;
int on, row, col;
{
struct smg_screen *ss = id;
if (ss == curscr) {
SM_ADDR(ss->ss_cury, ss->ss_curx, 14) =
QFONT(ss->ss_image[ss->ss_cury][ss->ss_curx], 14);
cursor = &SM_ADDR(row, col, 14);
if ((cur_on = on))
*cursor ^= 255;
}
ss->ss_curx = col;
ss->ss_cury = row;
}
int
smg_mapchar(id, uni, index)
void *id;
int uni;
unsigned int *index;
{
if (uni < 256) {
*index = uni;
return (5);
}
*index = ' ';
return (0);
}
static void
smg_putchar(id, row, col, c, attr)
void *id;
int row, col;
u_int c;
long attr;
{
struct smg_screen *ss = id;
int i;
c &= 0xff;
ss->ss_image[row][col] = c;
ss->ss_attr[row][col] = attr;
if (ss != curscr)
return;
for (i = 0; i < 15; i++) {
unsigned char ch = QFONT(c, i);
SM_ADDR(row, col, i) = (attr & WSATTR_REVERSE ? ~ch : ch);
}
if (attr & WSATTR_UNDERLINE)
SM_ADDR(row, col, 14) ^= SM_ADDR(row, col, 14);
}
/*
* copies columns inside a row.
*/
static void
smg_copycols(id, row, srccol, dstcol, ncols)
void *id;
int row, srccol, dstcol, ncols;
{
struct smg_screen *ss = id;
int i;
bcopy(&ss->ss_image[row][srccol], &ss->ss_image[row][dstcol], ncols);
bcopy(&ss->ss_attr[row][srccol], &ss->ss_attr[row][dstcol], ncols);
if (ss != curscr)
return;
for (i = 0; i < SM_CHEIGHT; i++)
bcopy(&SM_ADDR(row,srccol, i), &SM_ADDR(row, dstcol, i),ncols);
}
/*
* Erases a bunch of chars inside one row.
*/
static void
smg_erasecols(id, row, startcol, ncols, fillattr)
void *id;
int row, startcol, ncols;
long fillattr;
{
struct smg_screen *ss = id;
int i;
bzero(&ss->ss_image[row][startcol], ncols);
bzero(&ss->ss_attr[row][startcol], ncols);
if (ss != curscr)
return;
for (i = 0; i < SM_CHEIGHT; i++)
bzero(&SM_ADDR(row, startcol, i), ncols);
}
static void
smg_copyrows(id, srcrow, dstrow, nrows)
void *id;
int srcrow, dstrow, nrows;
{
struct smg_screen *ss = id;
int frows;
bcopy(&ss->ss_image[srcrow][0], &ss->ss_image[dstrow][0],
nrows * SM_COLS);
bcopy(&ss->ss_attr[srcrow][0], &ss->ss_attr[dstrow][0],
nrows * SM_COLS);
if (ss != curscr)
return;
if (nrows > 25) {
frows = nrows >> 1;
if (srcrow > dstrow) {
bcopy(&sm_addr[(srcrow * SM_NEXTROW)],
&sm_addr[(dstrow * SM_NEXTROW)],
frows * SM_NEXTROW);
bcopy(&sm_addr[((srcrow + frows) * SM_NEXTROW)],
&sm_addr[((dstrow + frows) * SM_NEXTROW)],
(nrows - frows) * SM_NEXTROW);
} else {
bcopy(&sm_addr[((srcrow + frows) * SM_NEXTROW)],
&sm_addr[((dstrow + frows) * SM_NEXTROW)],
(nrows - frows) * SM_NEXTROW);
bcopy(&sm_addr[(srcrow * SM_NEXTROW)],
&sm_addr[(dstrow * SM_NEXTROW)],
frows * SM_NEXTROW);
}
} else
bcopy(&sm_addr[(srcrow * SM_NEXTROW)],
&sm_addr[(dstrow * SM_NEXTROW)], nrows * SM_NEXTROW);
}
static void
smg_eraserows(id, startrow, nrows, fillattr)
void *id;
int startrow, nrows;
long fillattr;
{
struct smg_screen *ss = id;
int frows;
bzero(&ss->ss_image[startrow][0], nrows * SM_COLS);
bzero(&ss->ss_attr[startrow][0], nrows * SM_COLS);
if (ss != curscr)
return;
if (nrows > 25) {
frows = nrows >> 1;
bzero(&sm_addr[(startrow * SM_NEXTROW)], frows * SM_NEXTROW);
bzero(&sm_addr[((startrow + frows) * SM_NEXTROW)],
(nrows - frows) * SM_NEXTROW);
} else
bzero(&sm_addr[(startrow * SM_NEXTROW)], nrows * SM_NEXTROW);
}
static int
smg_alloc_attr(id, fg, bg, flags, attrp)
void *id;
int fg, bg;
int flags;
long *attrp;
{
*attrp = flags;
return 0;
}
int
smg_ioctl(v, cmd, data, flag, p)
void *v;
u_long cmd;
caddr_t data;
int flag;
struct proc *p;
{
struct wsdisplay_fbinfo fb;
switch (cmd) {
case WSDISPLAYIO_GTYPE:
*(u_int *)data = WSDISPLAY_TYPE_PM_MONO;
break;
case WSDISPLAYIO_GINFO:
fb.height = 864;
fb.width = 1024;
return copyout(&fb, data, sizeof(struct wsdisplay_fbinfo));
default:
return -1;
}
return 0;
}
static int
smg_mmap(v, offset, prot)
void *v;
off_t offset;
int prot;
{
if (offset >= SMSIZE || offset < 0)
return -1;
return (SMADDR + offset) >> PGSHIFT;
}
int
smg_alloc_screen(v, type, cookiep, curxp, curyp, defattrp)
void *v;
const struct wsscreen_descr *type;
void **cookiep;
int *curxp, *curyp;
long *defattrp;
{
*cookiep = malloc(sizeof(struct smg_screen), M_DEVBUF, M_WAITOK);
bzero(*cookiep, sizeof(struct smg_screen));
*curxp = *curyp = *defattrp = 0;
return 0;
}
void
smg_free_screen(v, cookie)
void *v;
void *cookie;
{
}
int
smg_show_screen(v, cookie, waitok, cb, cbarg)
void *v;
void *cookie;
int waitok;
void (*cb) __P((void *, int, int));
void *cbarg;
{
struct smg_screen *ss = cookie;
int row, col, line;
if (ss == curscr)
return (0);
for (row = 0; row < SM_ROWS; row++)
for (line = 0; line < SM_CHEIGHT; line++) {
for (col = 0; col < SM_COLS; col++) {
u_char s, c = ss->ss_image[row][col];
if (c < 32)
c = 32;
s = QFONT(c, line);
if (ss->ss_attr[row][col] & WSATTR_REVERSE)
s ^= 255;
SM_ADDR(row, col, line) = s;
}
if (ss->ss_attr[row][col] & WSATTR_UNDERLINE)
SM_ADDR(row, col, line) = 255;
}
cursor = &sm_addr[(ss->ss_cury * SM_CHEIGHT * SM_COLS) + ss->ss_curx +
((SM_CHEIGHT - 1) * SM_COLS)];
curscr = ss;
return (0);
}
cons_decl(smg);
#define WSCONSOLEMAJOR 68
void
smgcninit(cndev)
struct consdev *cndev;
{
extern void lkccninit __P((struct consdev *));
extern int lkccngetc __P((dev_t));
/* Clear screen */
memset(sm_addr, 0, 128*864);
curscr = &smg_conscreen;
wsdisplay_cnattach(&smg_stdscreen, &smg_conscreen, 0, 0, 0);
cn_tab->cn_pri = CN_INTERNAL;
#if 0
lkccninit(cndev);
wsdisplay_set_cons_kbd(lkccngetc, nullcnpollc);
#endif
}
/*
* Called very early to setup the glass tty as console.
* Because it's called before the VM system is inited, virtual memory
* for the framebuffer can be stolen directly without disturbing anything.
*/
void
smgcnprobe(cndev)
struct consdev *cndev;
{
extern vaddr_t virtual_avail;
switch (vax_boardtype) {
case VAX_BTYP_410:
case VAX_BTYP_420:
case VAX_BTYP_43:
if ((vax_confdata & KA420_CFG_L3CON) ||
(vax_confdata & KA420_CFG_MULTU))
break; /* doesn't use graphics console */
sm_addr = (caddr_t)virtual_avail;
virtual_avail += SMSIZE;
ioaccess((vaddr_t)sm_addr, SMADDR, (SMSIZE/VAX_NBPG));
cndev->cn_pri = CN_INTERNAL;
cndev->cn_dev = makedev(WSCONSOLEMAJOR, 0);
break;
default:
break;
}
}
|