]> git.saurik.com Git - apple/xnu.git/blob - osfmk/console/video_console.c
0afd153b73379e2b031bc0be9c285eaa2acb0eae
[apple/xnu.git] / osfmk / console / video_console.c
1 /*
2 * Copyright (c) 2000-2009 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
29 * @OSF_FREE_COPYRIGHT@
30 *
31 */
32 /*
33 * @APPLE_FREE_COPYRIGHT@
34 */
35 /*
36 * NetBSD: ite.c,v 1.16 1995/07/17 01:24:34 briggs Exp
37 *
38 * Copyright (c) 1988 University of Utah.
39 * Copyright (c) 1990, 1993
40 * The Regents of the University of California. All rights reserved.
41 *
42 * This code is derived from software contributed to Berkeley by
43 * the Systems Programming Group of the University of Utah Computer
44 * Science Department.
45 *
46 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
48 * are met:
49 * 1. Redistributions of source code must retain the above copyright
50 * notice, this list of conditions and the following disclaimer.
51 * 2. Redistributions in binary form must reproduce the above copyright
52 * notice, this list of conditions and the following disclaimer in the
53 * documentation and/or other materials provided with the distribution.
54 * 3. All advertising materials mentioning features or use of this software
55 * must display the following acknowledgement:
56 * This product includes software developed by the University of
57 * California, Berkeley and its contributors.
58 * 4. Neither the name of the University nor the names of its contributors
59 * may be used to endorse or promote products derived from this software
60 * without specific prior written permission.
61 *
62 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
63 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
66 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
67 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72 * SUCH DAMAGE.
73 *
74 * from: Utah $Hdr: ite.c 1.28 92/12/20$
75 *
76 * @(#)ite.c 8.2 (Berkeley) 1/12/94
77 */
78
79 /*
80 * ite.c
81 *
82 * The ite module handles the system console; that is, stuff printed
83 * by the kernel and by user programs while "desktop" and X aren't
84 * running. Some (very small) parts are based on hp300's 4.4 ite.c,
85 * hence the above copyright.
86 *
87 * -- Brad and Lawrence, June 26th, 1994
88 *
89 */
90
91 #include <vc.h>
92
93 #include <console/video_console.h>
94 #include <console/serial_protos.h>
95
96 #include <kern/kern_types.h>
97 #include <kern/kalloc.h>
98 #include <kern/debug.h>
99 #include <kern/lock.h>
100 #include <kern/spl.h>
101 #include <kern/thread_call.h>
102
103 #include <vm/pmap.h>
104 #include <vm/vm_kern.h>
105 #include <machine/io_map_entries.h>
106 #include <machine/machine_cpu.h>
107
108 #include <pexpert/pexpert.h>
109 #include <sys/kdebug.h>
110
111 #include "iso_font.c"
112 #if !CONFIG_EMBEDDED
113 #include "progress_meter_data.c"
114 #endif
115
116 #include "sys/msgbuf.h"
117
118 /*
119 * Generic Console (Front-End)
120 * ---------------------------
121 */
122
123 struct vc_info vinfo;
124 /* if panicDialogDesired is true then we use the panic dialog when its */
125 /* allowed otherwise we won't use the panic dialog even if it is allowed */
126 boolean_t panicDialogDesired;
127
128 void noroot_icon_test(void);
129
130
131 extern int disableConsoleOutput;
132 static boolean_t gc_enabled = FALSE;
133 static boolean_t gc_initialized = FALSE;
134 static boolean_t vm_initialized = FALSE;
135
136 static struct {
137 void (*initialize)(struct vc_info * info);
138 void (*enable)(boolean_t enable);
139 void (*paint_char)(unsigned int xx, unsigned int yy, unsigned char ch,
140 int attrs, unsigned char ch_previous,
141 int attrs_previous);
142 void (*clear_screen)(unsigned int xx, unsigned int yy, unsigned int top,
143 unsigned int bottom, int which);
144 void (*scroll_down)(int num, unsigned int top, unsigned int bottom);
145 void (*scroll_up)(int num, unsigned int top, unsigned int bottom);
146 void (*hide_cursor)(unsigned int xx, unsigned int yy);
147 void (*show_cursor)(unsigned int xx, unsigned int yy);
148 void (*update_color)(int color, boolean_t fore);
149 } gc_ops;
150
151 static unsigned char *gc_buffer_attributes;
152 static unsigned char *gc_buffer_characters;
153 static unsigned char *gc_buffer_colorcodes;
154 static unsigned char *gc_buffer_tab_stops;
155 static uint32_t gc_buffer_columns;
156 static uint32_t gc_buffer_rows;
157 static uint32_t gc_buffer_size;
158
159 #if defined(__i386__) || defined(__x86_64__)
160 decl_simple_lock_data(static, vcputc_lock);
161
162 #define VCPUTC_LOCK_INIT() \
163 MACRO_BEGIN \
164 simple_lock_init(&vcputc_lock, 0); \
165 MACRO_END
166
167 #define VCPUTC_LOCK_LOCK() \
168 MACRO_BEGIN \
169 boolean_t istate = ml_get_interrupts_enabled(); \
170 while (!simple_lock_try(&vcputc_lock)) \
171 { \
172 if (!istate) \
173 handle_pending_TLB_flushes(); \
174 cpu_pause(); \
175 } \
176 MACRO_END
177
178 #define VCPUTC_LOCK_UNLOCK() \
179 MACRO_BEGIN \
180 simple_unlock(&vcputc_lock); \
181 MACRO_END
182 #else
183 static hw_lock_data_t vcputc_lock;
184
185 #define VCPUTC_LOCK_INIT() \
186 MACRO_BEGIN \
187 hw_lock_init(&vcputc_lock); \
188 MACRO_END
189
190 #define VCPUTC_LOCK_LOCK() \
191 MACRO_BEGIN \
192 if (!hw_lock_to(&vcputc_lock, hwLockTimeOut*10))\
193 { \
194 panic("VCPUTC_LOCK_LOCK"); \
195 } \
196 MACRO_END
197
198 #define VCPUTC_LOCK_UNLOCK() \
199 MACRO_BEGIN \
200 hw_lock_unlock(&vcputc_lock); \
201 MACRO_END
202 #endif
203
204 /*
205 # Attribute codes:
206 # 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
207 # Text color codes:
208 # 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
209 # Background color codes:
210 # 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
211 */
212
213 #define ATTR_NONE 0
214 #define ATTR_BOLD 1
215 #define ATTR_UNDER 2
216 #define ATTR_REVERSE 4
217
218 #define COLOR_BACKGROUND 0
219 #define COLOR_FOREGROUND 7
220
221 #define COLOR_CODE_GET(code, fore) (((code) & ((fore) ? 0xF0 : 0x0F)) >> ((fore) ? 4 : 0))
222 #define COLOR_CODE_SET(code, color, fore) (((code) & ((fore) ? 0x0F : 0xF0)) | ((color) << ((fore) ? 4 : 0)))
223
224 static unsigned char gc_color_code;
225
226 /* VT100 state: */
227 #define MAXPARS 16
228 static unsigned int gc_x, gc_y, gc_savex, gc_savey;
229 static unsigned int gc_par[MAXPARS], gc_numpars, gc_hanging_cursor, gc_attr, gc_saveattr;
230
231 /* VT100 scroll region */
232 static unsigned int gc_scrreg_top, gc_scrreg_bottom;
233
234 enum vt100state_e {
235 ESnormal, /* Nothing yet */
236 ESesc, /* Got ESC */
237 ESsquare, /* Got ESC [ */
238 ESgetpars, /* About to get or getting the parameters */
239 ESgotpars, /* Finished getting the parameters */
240 ESfunckey, /* Function key */
241 EShash, /* DEC-specific stuff (screen align, etc.) */
242 ESsetG0, /* Specify the G0 character set */
243 ESsetG1, /* Specify the G1 character set */
244 ESask,
245 EScharsize,
246 ESignore /* Ignore this sequence */
247 } gc_vt100state = ESnormal;
248
249
250 #ifdef CONFIG_VC_PROGRESS_WHITE
251 enum { kProgressAcquireDelay = 0 /* secs */ };
252 #else
253 enum { kProgressAcquireDelay = 5 /* secs */ };
254 #endif
255
256 static int8_t vc_rotate_matr[4][2][2] = {
257 { { 1, 0 },
258 { 0, 1 } },
259 { { 0, 1 },
260 { -1, 0 } },
261 { { -1, 0 },
262 { 0, -1 } },
263 { { 0, -1 },
264 { 1, 0 } }
265 };
266
267 static int gc_wrap_mode = 1, gc_relative_origin = 0;
268 static int gc_charset_select = 0, gc_save_charset_s = 0;
269 static int gc_charset[2] = { 0, 0 };
270 static int gc_charset_save[2] = { 0, 0 };
271
272 static void gc_clear_line(unsigned int xx, unsigned int yy, int which);
273 static void gc_clear_screen(unsigned int xx, unsigned int yy, int top,
274 unsigned int bottom, int which);
275 static void gc_enable(boolean_t enable);
276 static void gc_hide_cursor(unsigned int xx, unsigned int yy);
277 static void gc_initialize(struct vc_info * info);
278 static boolean_t gc_is_tab_stop(unsigned int column);
279 static void gc_paint_char(unsigned int xx, unsigned int yy, unsigned char ch,
280 int attrs);
281 static void gc_putchar(char ch);
282 static void gc_putc_askcmd(unsigned char ch);
283 static void gc_putc_charsetcmd(int charset, unsigned char ch);
284 static void gc_putc_charsizecmd(unsigned char ch);
285 static void gc_putc_esc(unsigned char ch);
286 static void gc_putc_getpars(unsigned char ch);
287 static void gc_putc_gotpars(unsigned char ch);
288 static void gc_putc_normal(unsigned char ch);
289 static void gc_putc_square(unsigned char ch);
290 static void gc_reset_screen(void);
291 static void gc_reset_tabs(void);
292 static void gc_reset_vt100(void);
293 static void gc_scroll_down(int num, unsigned int top, unsigned int bottom);
294 static void gc_scroll_up(int num, unsigned int top, unsigned int bottom);
295 static void gc_set_tab_stop(unsigned int column, boolean_t enabled);
296 static void gc_show_cursor(unsigned int xx, unsigned int yy);
297 static void gc_update_color(int color, boolean_t fore);
298
299 static void
300 gc_clear_line(unsigned int xx, unsigned int yy, int which)
301 {
302 unsigned int start, end, i;
303
304 /*
305 * This routine runs extremely slowly. I don't think it's
306 * used all that often, except for To end of line. I'll go
307 * back and speed this up when I speed up the whole vc
308 * module. --LK
309 */
310
311 switch (which) {
312 case 0: /* To end of line */
313 start = xx;
314 end = vinfo.v_columns-1;
315 break;
316 case 1: /* To start of line */
317 start = 0;
318 end = xx;
319 break;
320 case 2: /* Whole line */
321 start = 0;
322 end = vinfo.v_columns-1;
323 break;
324 default:
325 return;
326 }
327
328 for (i = start; i <= end; i++) {
329 gc_paint_char(i, yy, ' ', ATTR_NONE);
330 }
331 }
332
333 static void
334 gc_clear_screen(unsigned int xx, unsigned int yy, int top, unsigned int bottom,
335 int which)
336 {
337 if (!gc_buffer_size) return;
338
339 if ( xx < gc_buffer_columns && yy < gc_buffer_rows && bottom <= gc_buffer_rows )
340 {
341 uint32_t start, end;
342
343 switch (which) {
344 case 0: /* To end of screen */
345 start = (yy * gc_buffer_columns) + xx;
346 end = (bottom * gc_buffer_columns) - 1;
347 break;
348 case 1: /* To start of screen */
349 start = (top * gc_buffer_columns);
350 end = (yy * gc_buffer_columns) + xx;
351 break;
352 case 2: /* Whole screen */
353 start = (top * gc_buffer_columns);
354 end = (bottom * gc_buffer_columns) - 1;
355 break;
356 default:
357 start = 0;
358 end = 0;
359 break;
360 }
361
362 memset(gc_buffer_attributes + start, ATTR_NONE, end - start + 1);
363 memset(gc_buffer_characters + start, ' ', end - start + 1);
364 memset(gc_buffer_colorcodes + start, gc_color_code, end - start + 1);
365 }
366
367 gc_ops.clear_screen(xx, yy, top, bottom, which);
368 }
369
370 static void
371 gc_enable( boolean_t enable )
372 {
373 unsigned char *buffer_attributes = NULL;
374 unsigned char *buffer_characters = NULL;
375 unsigned char *buffer_colorcodes = NULL;
376 unsigned char *buffer_tab_stops = NULL;
377 uint32_t buffer_columns = 0;
378 uint32_t buffer_rows = 0;
379 uint32_t buffer_size = 0;
380 spl_t s;
381
382 if ( enable == FALSE )
383 {
384 // only disable console output if it goes to the graphics console
385 if ( console_is_serial() == FALSE )
386 disableConsoleOutput = TRUE;
387 gc_enabled = FALSE;
388 gc_ops.enable(FALSE);
389 }
390
391 s = splhigh( );
392 VCPUTC_LOCK_LOCK( );
393
394 if ( gc_buffer_size )
395 {
396 buffer_attributes = gc_buffer_attributes;
397 buffer_characters = gc_buffer_characters;
398 buffer_colorcodes = gc_buffer_colorcodes;
399 buffer_tab_stops = gc_buffer_tab_stops;
400 buffer_columns = gc_buffer_columns;
401 buffer_rows = gc_buffer_rows;
402 buffer_size = gc_buffer_size;
403
404 gc_buffer_attributes = NULL;
405 gc_buffer_characters = NULL;
406 gc_buffer_colorcodes = NULL;
407 gc_buffer_tab_stops = NULL;
408 gc_buffer_columns = 0;
409 gc_buffer_rows = 0;
410 gc_buffer_size = 0;
411
412 VCPUTC_LOCK_UNLOCK( );
413 splx( s );
414
415 kfree( buffer_attributes, buffer_size );
416 kfree( buffer_characters, buffer_size );
417 kfree( buffer_colorcodes, buffer_size );
418 kfree( buffer_tab_stops, buffer_columns );
419 }
420 else
421 {
422 VCPUTC_LOCK_UNLOCK( );
423 splx( s );
424 }
425
426 if ( enable )
427 {
428 if ( vm_initialized )
429 {
430 buffer_columns = vinfo.v_columns;
431 buffer_rows = vinfo.v_rows;
432 buffer_size = buffer_columns * buffer_rows;
433
434 if ( buffer_size )
435 {
436 buffer_attributes = (unsigned char *) kalloc( buffer_size );
437 buffer_characters = (unsigned char *) kalloc( buffer_size );
438 buffer_colorcodes = (unsigned char *) kalloc( buffer_size );
439 buffer_tab_stops = (unsigned char *) kalloc( buffer_columns );
440
441 if ( buffer_attributes == NULL ||
442 buffer_characters == NULL ||
443 buffer_colorcodes == NULL ||
444 buffer_tab_stops == NULL )
445 {
446 if ( buffer_attributes ) kfree( buffer_attributes, buffer_size );
447 if ( buffer_characters ) kfree( buffer_characters, buffer_size );
448 if ( buffer_colorcodes ) kfree( buffer_colorcodes, buffer_size );
449 if ( buffer_tab_stops ) kfree( buffer_tab_stops, buffer_columns );
450
451 buffer_columns = 0;
452 buffer_rows = 0;
453 buffer_size = 0;
454 }
455 else
456 {
457 memset( buffer_attributes, ATTR_NONE, buffer_size );
458 memset( buffer_characters, ' ', buffer_size );
459 memset( buffer_colorcodes, COLOR_CODE_SET( 0, COLOR_FOREGROUND, TRUE ), buffer_size );
460 memset( buffer_tab_stops, 0, buffer_columns );
461 }
462 }
463 }
464
465 s = splhigh( );
466 VCPUTC_LOCK_LOCK( );
467
468 gc_buffer_attributes = buffer_attributes;
469 gc_buffer_characters = buffer_characters;
470 gc_buffer_colorcodes = buffer_colorcodes;
471 gc_buffer_tab_stops = buffer_tab_stops;
472 gc_buffer_columns = buffer_columns;
473 gc_buffer_rows = buffer_rows;
474 gc_buffer_size = buffer_size;
475
476 gc_reset_screen();
477
478 VCPUTC_LOCK_UNLOCK( );
479 splx( s );
480
481 gc_ops.clear_screen(gc_x, gc_y, 0, vinfo.v_rows, 2);
482 gc_ops.show_cursor(gc_x, gc_y);
483
484 gc_ops.enable(TRUE);
485 gc_enabled = TRUE;
486 disableConsoleOutput = FALSE;
487 }
488 }
489
490 static void
491 gc_hide_cursor(unsigned int xx, unsigned int yy)
492 {
493 if ( xx < gc_buffer_columns && yy < gc_buffer_rows )
494 {
495 uint32_t index = (yy * gc_buffer_columns) + xx;
496 unsigned char attribute = gc_buffer_attributes[index];
497 unsigned char character = gc_buffer_characters[index];
498 unsigned char colorcode = gc_buffer_colorcodes[index];
499 unsigned char colorcodesave = gc_color_code;
500
501 gc_update_color(COLOR_CODE_GET(colorcode, TRUE ), TRUE );
502 gc_update_color(COLOR_CODE_GET(colorcode, FALSE), FALSE);
503
504 gc_ops.paint_char(xx, yy, character, attribute, 0, 0);
505
506 gc_update_color(COLOR_CODE_GET(colorcodesave, TRUE ), TRUE );
507 gc_update_color(COLOR_CODE_GET(colorcodesave, FALSE), FALSE);
508 }
509 else
510 {
511 gc_ops.hide_cursor(xx, yy);
512 }
513 }
514
515 static void
516 gc_initialize(struct vc_info * info)
517 {
518 if ( gc_initialized == FALSE )
519 {
520 /* Init our lock */
521 VCPUTC_LOCK_INIT();
522
523 gc_initialized = TRUE;
524 }
525
526 gc_ops.initialize(info);
527
528 gc_reset_vt100();
529 gc_x = gc_y = 0;
530 }
531
532 static void
533 gc_paint_char(unsigned int xx, unsigned int yy, unsigned char ch, int attrs)
534 {
535 if ( xx < gc_buffer_columns && yy < gc_buffer_rows )
536 {
537 uint32_t index = (yy * gc_buffer_columns) + xx;
538
539 gc_buffer_attributes[index] = attrs;
540 gc_buffer_characters[index] = ch;
541 gc_buffer_colorcodes[index] = gc_color_code;
542 }
543
544 gc_ops.paint_char(xx, yy, ch, attrs, 0, 0);
545 }
546
547 static void
548 gc_putchar(char ch)
549 {
550 if (!ch) {
551 return; /* ignore null characters */
552 }
553 switch (gc_vt100state) {
554 default:gc_vt100state = ESnormal; /* FALLTHROUGH */
555 case ESnormal:
556 gc_putc_normal(ch);
557 break;
558 case ESesc:
559 gc_putc_esc(ch);
560 break;
561 case ESsquare:
562 gc_putc_square(ch);
563 break;
564 case ESgetpars:
565 gc_putc_getpars(ch);
566 break;
567 case ESgotpars:
568 gc_putc_gotpars(ch);
569 break;
570 case ESask:
571 gc_putc_askcmd(ch);
572 break;
573 case EScharsize:
574 gc_putc_charsizecmd(ch);
575 break;
576 case ESsetG0:
577 gc_putc_charsetcmd(0, ch);
578 break;
579 case ESsetG1:
580 gc_putc_charsetcmd(1, ch);
581 break;
582 }
583
584 if (gc_x >= vinfo.v_columns) {
585 if (0 == vinfo.v_columns)
586 gc_x = 0;
587 else
588 gc_x = vinfo.v_columns - 1;
589 }
590 if (gc_y >= vinfo.v_rows) {
591 if (0 == vinfo.v_rows)
592 gc_y = 0;
593 else
594 gc_y = vinfo.v_rows - 1;
595 }
596 }
597
598 static void
599 gc_putc_askcmd(unsigned char ch)
600 {
601 if (ch >= '0' && ch <= '9') {
602 gc_par[gc_numpars] = (10*gc_par[gc_numpars]) + (ch-'0');
603 return;
604 }
605 gc_vt100state = ESnormal;
606
607 switch (gc_par[0]) {
608 case 6:
609 gc_relative_origin = ch == 'h';
610 break;
611 case 7: /* wrap around mode h=1, l=0*/
612 gc_wrap_mode = ch == 'h';
613 break;
614 default:
615 break;
616 }
617
618 }
619
620 static void
621 gc_putc_charsetcmd(int charset, unsigned char ch)
622 {
623 gc_vt100state = ESnormal;
624
625 switch (ch) {
626 case 'A' :
627 case 'B' :
628 default:
629 gc_charset[charset] = 0;
630 break;
631 case '0' : /* Graphic characters */
632 case '2' :
633 gc_charset[charset] = 0x21;
634 break;
635 }
636
637 }
638
639 static void
640 gc_putc_charsizecmd(unsigned char ch)
641 {
642 gc_vt100state = ESnormal;
643
644 switch (ch) {
645 case '3' :
646 case '4' :
647 case '5' :
648 case '6' :
649 break;
650 case '8' : /* fill 'E's */
651 {
652 unsigned int xx, yy;
653 for (yy = 0; yy < vinfo.v_rows; yy++)
654 for (xx = 0; xx < vinfo.v_columns; xx++)
655 gc_paint_char(xx, yy, 'E', ATTR_NONE);
656 }
657 break;
658 }
659
660 }
661
662 static void
663 gc_putc_esc(unsigned char ch)
664 {
665 gc_vt100state = ESnormal;
666
667 switch (ch) {
668 case '[':
669 gc_vt100state = ESsquare;
670 break;
671 case 'c': /* Reset terminal */
672 gc_reset_vt100();
673 gc_clear_screen(gc_x, gc_y, 0, vinfo.v_rows, 2);
674 gc_x = gc_y = 0;
675 break;
676 case 'D': /* Line feed */
677 case 'E':
678 if (gc_y >= gc_scrreg_bottom -1) {
679 gc_scroll_up(1, gc_scrreg_top, gc_scrreg_bottom);
680 gc_y = gc_scrreg_bottom - 1;
681 } else {
682 gc_y++;
683 }
684 if (ch == 'E') gc_x = 0;
685 break;
686 case 'H': /* Set tab stop */
687 gc_set_tab_stop(gc_x, TRUE);
688 break;
689 case 'M': /* Cursor up */
690 if (gc_y <= gc_scrreg_top) {
691 gc_scroll_down(1, gc_scrreg_top, gc_scrreg_bottom);
692 gc_y = gc_scrreg_top;
693 } else {
694 gc_y--;
695 }
696 break;
697 case '>':
698 gc_reset_vt100();
699 break;
700 case '7': /* Save cursor */
701 gc_savex = gc_x;
702 gc_savey = gc_y;
703 gc_saveattr = gc_attr;
704 gc_save_charset_s = gc_charset_select;
705 gc_charset_save[0] = gc_charset[0];
706 gc_charset_save[1] = gc_charset[1];
707 break;
708 case '8': /* Restore cursor */
709 gc_x = gc_savex;
710 gc_y = gc_savey;
711 gc_attr = gc_saveattr;
712 gc_charset_select = gc_save_charset_s;
713 gc_charset[0] = gc_charset_save[0];
714 gc_charset[1] = gc_charset_save[1];
715 break;
716 case 'Z': /* return terminal ID */
717 break;
718 case '#': /* change characters height */
719 gc_vt100state = EScharsize;
720 break;
721 case '(':
722 gc_vt100state = ESsetG0;
723 break;
724 case ')': /* character set sequence */
725 gc_vt100state = ESsetG1;
726 break;
727 case '=':
728 break;
729 default:
730 /* Rest not supported */
731 break;
732 }
733
734 }
735
736 static void
737 gc_putc_getpars(unsigned char ch)
738 {
739 if (ch == '?') {
740 gc_vt100state = ESask;
741 return;
742 }
743 if (ch == '[') {
744 gc_vt100state = ESnormal;
745 /* Not supported */
746 return;
747 }
748 if (ch == ';' && gc_numpars < MAXPARS - 1) {
749 gc_numpars++;
750 } else
751 if (ch >= '0' && ch <= '9') {
752 gc_par[gc_numpars] *= 10;
753 gc_par[gc_numpars] += ch - '0';
754 } else {
755 gc_numpars++;
756 gc_vt100state = ESgotpars;
757 gc_putc_gotpars(ch);
758 }
759 }
760
761 static void
762 gc_putc_gotpars(unsigned char ch)
763 {
764 unsigned int i;
765
766 if (ch < ' ') {
767 /* special case for vttest for handling cursor
768 movement in escape sequences */
769 gc_putc_normal(ch);
770 gc_vt100state = ESgotpars;
771 return;
772 }
773 gc_vt100state = ESnormal;
774 switch (ch) {
775 case 'A': /* Up */
776 gc_y -= gc_par[0] ? gc_par[0] : 1;
777 if (gc_y < gc_scrreg_top)
778 gc_y = gc_scrreg_top;
779 break;
780 case 'B': /* Down */
781 gc_y += gc_par[0] ? gc_par[0] : 1;
782 if (gc_y >= gc_scrreg_bottom)
783 gc_y = gc_scrreg_bottom - 1;
784 break;
785 case 'C': /* Right */
786 gc_x += gc_par[0] ? gc_par[0] : 1;
787 if (gc_x >= vinfo.v_columns)
788 gc_x = vinfo.v_columns-1;
789 break;
790 case 'D': /* Left */
791 if (gc_par[0] > gc_x)
792 gc_x = 0;
793 else if (gc_par[0])
794 gc_x -= gc_par[0];
795 else if (gc_x)
796 --gc_x;
797 break;
798 case 'H': /* Set cursor position */
799 case 'f':
800 gc_x = gc_par[1] ? gc_par[1] - 1 : 0;
801 gc_y = gc_par[0] ? gc_par[0] - 1 : 0;
802 if (gc_relative_origin)
803 gc_y += gc_scrreg_top;
804 gc_hanging_cursor = 0;
805 break;
806 case 'X': /* clear p1 characters */
807 if (gc_numpars) {
808 for (i = gc_x; i < gc_x + gc_par[0]; i++)
809 gc_paint_char(i, gc_y, ' ', ATTR_NONE);
810 }
811 break;
812 case 'J': /* Clear part of screen */
813 gc_clear_screen(gc_x, gc_y, 0, vinfo.v_rows, gc_par[0]);
814 break;
815 case 'K': /* Clear part of line */
816 gc_clear_line(gc_x, gc_y, gc_par[0]);
817 break;
818 case 'g': /* tab stops */
819 switch (gc_par[0]) {
820 case 1:
821 case 2: /* reset tab stops */
822 /* gc_reset_tabs(); */
823 break;
824 case 3: /* Clear every tabs */
825 {
826 for (i = 0; i <= vinfo.v_columns; i++)
827 gc_set_tab_stop(i, FALSE);
828 }
829 break;
830 case 0:
831 gc_set_tab_stop(gc_x, FALSE);
832 break;
833 }
834 break;
835 case 'm': /* Set attribute */
836 for (i = 0; i < gc_numpars; i++) {
837 switch (gc_par[i]) {
838 case 0:
839 gc_attr = ATTR_NONE;
840 gc_update_color(COLOR_BACKGROUND, FALSE);
841 gc_update_color(COLOR_FOREGROUND, TRUE );
842 break;
843 case 1:
844 gc_attr |= ATTR_BOLD;
845 break;
846 case 4:
847 gc_attr |= ATTR_UNDER;
848 break;
849 case 7:
850 gc_attr |= ATTR_REVERSE;
851 break;
852 case 22:
853 gc_attr &= ~ATTR_BOLD;
854 break;
855 case 24:
856 gc_attr &= ~ATTR_UNDER;
857 break;
858 case 27:
859 gc_attr &= ~ATTR_REVERSE;
860 break;
861 case 5:
862 case 25: /* blink/no blink */
863 break;
864 default:
865 if (gc_par[i] >= 30 && gc_par[i] <= 37)
866 gc_update_color(gc_par[i] - 30, TRUE);
867 if (gc_par[i] >= 40 && gc_par[i] <= 47)
868 gc_update_color(gc_par[i] - 40, FALSE);
869 break;
870 }
871 }
872 break;
873 case 'r': /* Set scroll region */
874 gc_x = gc_y = 0;
875 /* ensure top < bottom, and both within limits */
876 if ((gc_numpars > 0) && (gc_par[0] < vinfo.v_rows)) {
877 gc_scrreg_top = gc_par[0] ? gc_par[0] - 1 : 0;
878 } else {
879 gc_scrreg_top = 0;
880 }
881 if ((gc_numpars > 1) && (gc_par[1] <= vinfo.v_rows) && (gc_par[1] > gc_par[0])) {
882 gc_scrreg_bottom = gc_par[1];
883 if (gc_scrreg_bottom > vinfo.v_rows)
884 gc_scrreg_bottom = vinfo.v_rows;
885 } else {
886 gc_scrreg_bottom = vinfo.v_rows;
887 }
888 if (gc_relative_origin)
889 gc_y = gc_scrreg_top;
890 break;
891 }
892
893 }
894
895 static void
896 gc_putc_normal(unsigned char ch)
897 {
898 switch (ch) {
899 case '\a': /* Beep */
900 break;
901 case 127: /* Delete */
902 case '\b': /* Backspace */
903 if (gc_hanging_cursor) {
904 gc_hanging_cursor = 0;
905 } else
906 if (gc_x > 0) {
907 gc_x--;
908 }
909 break;
910 case '\t': /* Tab */
911 if (gc_buffer_tab_stops) while (gc_x < vinfo.v_columns && !gc_is_tab_stop(++gc_x));
912
913 if (gc_x >= vinfo.v_columns)
914 gc_x = vinfo.v_columns-1;
915 break;
916 case 0x0b:
917 case 0x0c:
918 case '\n': /* Line feed */
919 if (gc_y >= gc_scrreg_bottom -1 ) {
920 gc_scroll_up(1, gc_scrreg_top, gc_scrreg_bottom);
921 gc_y = gc_scrreg_bottom - 1;
922 } else {
923 gc_y++;
924 }
925 break;
926 case '\r': /* Carriage return */
927 gc_x = 0;
928 gc_hanging_cursor = 0;
929 break;
930 case 0x0e: /* Select G1 charset (Control-N) */
931 gc_charset_select = 1;
932 break;
933 case 0x0f: /* Select G0 charset (Control-O) */
934 gc_charset_select = 0;
935 break;
936 case 0x18 : /* CAN : cancel */
937 case 0x1A : /* like cancel */
938 /* well, i do nothing here, may be later */
939 break;
940 case '\033': /* Escape */
941 gc_vt100state = ESesc;
942 gc_hanging_cursor = 0;
943 break;
944 default:
945 if (ch >= ' ') {
946 if (gc_hanging_cursor) {
947 gc_x = 0;
948 if (gc_y >= gc_scrreg_bottom -1 ) {
949 gc_scroll_up(1, gc_scrreg_top, gc_scrreg_bottom);
950 gc_y = gc_scrreg_bottom - 1;
951 } else {
952 gc_y++;
953 }
954 gc_hanging_cursor = 0;
955 }
956 gc_paint_char(gc_x, gc_y, (ch >= 0x60 && ch <= 0x7f) ? ch + gc_charset[gc_charset_select]
957 : ch, gc_attr);
958 if (gc_x == vinfo.v_columns - 1) {
959 gc_hanging_cursor = gc_wrap_mode;
960 } else {
961 gc_x++;
962 }
963 }
964 break;
965 }
966
967 }
968
969 static void
970 gc_putc_square(unsigned char ch)
971 {
972 int i;
973
974 for (i = 0; i < MAXPARS; i++) {
975 gc_par[i] = 0;
976 }
977
978 gc_numpars = 0;
979 gc_vt100state = ESgetpars;
980
981 gc_putc_getpars(ch);
982
983 }
984
985 static void
986 gc_reset_screen(void)
987 {
988 gc_reset_vt100();
989 gc_x = gc_y = 0;
990 }
991
992 static void
993 gc_reset_tabs(void)
994 {
995 unsigned int i;
996
997 if (!gc_buffer_tab_stops) return;
998
999 for (i = 0; i < vinfo.v_columns; i++) {
1000 gc_buffer_tab_stops[i] = ((i % 8) == 0);
1001 }
1002
1003 }
1004
1005 static void
1006 gc_set_tab_stop(unsigned int column, boolean_t enabled)
1007 {
1008 if (gc_buffer_tab_stops && (column < vinfo.v_columns)) {
1009 gc_buffer_tab_stops[column] = enabled;
1010 }
1011 }
1012
1013 static boolean_t gc_is_tab_stop(unsigned int column)
1014 {
1015 if (gc_buffer_tab_stops == NULL)
1016 return ((column % 8) == 0);
1017 if (column < vinfo.v_columns)
1018 return gc_buffer_tab_stops[column];
1019 else
1020 return FALSE;
1021 }
1022
1023 static void
1024 gc_reset_vt100(void)
1025 {
1026 gc_reset_tabs();
1027 gc_scrreg_top = 0;
1028 gc_scrreg_bottom = vinfo.v_rows;
1029 gc_attr = ATTR_NONE;
1030 gc_charset[0] = gc_charset[1] = 0;
1031 gc_charset_select = 0;
1032 gc_wrap_mode = 1;
1033 gc_relative_origin = 0;
1034 gc_update_color(COLOR_BACKGROUND, FALSE);
1035 gc_update_color(COLOR_FOREGROUND, TRUE);
1036 }
1037
1038 static void
1039 gc_scroll_down(int num, unsigned int top, unsigned int bottom)
1040 {
1041 if (!gc_buffer_size) return;
1042
1043 if ( bottom <= gc_buffer_rows )
1044 {
1045 unsigned char colorcodesave = gc_color_code;
1046 uint32_t column, row;
1047 uint32_t index, jump;
1048
1049 jump = num * gc_buffer_columns;
1050
1051 for ( row = bottom - 1 ; row >= top + num ; row-- )
1052 {
1053 index = row * gc_buffer_columns;
1054
1055 for ( column = 0 ; column < gc_buffer_columns ; index++, column++ )
1056 {
1057 if ( gc_buffer_attributes[index] != gc_buffer_attributes[index - jump] ||
1058 gc_buffer_characters[index] != gc_buffer_characters[index - jump] ||
1059 gc_buffer_colorcodes[index] != gc_buffer_colorcodes[index - jump] )
1060 {
1061 if ( gc_color_code != gc_buffer_colorcodes[index - jump] )
1062 {
1063 gc_update_color(COLOR_CODE_GET(gc_buffer_colorcodes[index - jump], TRUE ), TRUE );
1064 gc_update_color(COLOR_CODE_GET(gc_buffer_colorcodes[index - jump], FALSE), FALSE);
1065 }
1066
1067 if ( gc_buffer_colorcodes[index] != gc_buffer_colorcodes[index - jump] )
1068 {
1069 gc_ops.paint_char( /* xx */ column,
1070 /* yy */ row,
1071 /* ch */ gc_buffer_characters[index - jump],
1072 /* attrs */ gc_buffer_attributes[index - jump],
1073 /* ch_previous */ 0,
1074 /* attrs_previous */ 0 );
1075 }
1076 else
1077 {
1078 gc_ops.paint_char( /* xx */ column,
1079 /* yy */ row,
1080 /* ch */ gc_buffer_characters[index - jump],
1081 /* attrs */ gc_buffer_attributes[index - jump],
1082 /* ch_previous */ gc_buffer_characters[index],
1083 /* attrs_previous */ gc_buffer_attributes[index] );
1084 }
1085
1086 gc_buffer_attributes[index] = gc_buffer_attributes[index - jump];
1087 gc_buffer_characters[index] = gc_buffer_characters[index - jump];
1088 gc_buffer_colorcodes[index] = gc_buffer_colorcodes[index - jump];
1089 }
1090 }
1091 }
1092
1093 if ( colorcodesave != gc_color_code )
1094 {
1095 gc_update_color(COLOR_CODE_GET(colorcodesave, TRUE ), TRUE );
1096 gc_update_color(COLOR_CODE_GET(colorcodesave, FALSE), FALSE);
1097 }
1098
1099 /* Now set the freed up lines to the background colour */
1100
1101 for ( row = top ; row < top + num ; row++ )
1102 {
1103 index = row * gc_buffer_columns;
1104
1105 for ( column = 0 ; column < gc_buffer_columns ; index++, column++ )
1106 {
1107 if ( gc_buffer_attributes[index] != ATTR_NONE ||
1108 gc_buffer_characters[index] != ' ' ||
1109 gc_buffer_colorcodes[index] != gc_color_code )
1110 {
1111 if ( gc_buffer_colorcodes[index] != gc_color_code )
1112 {
1113 gc_ops.paint_char( /* xx */ column,
1114 /* yy */ row,
1115 /* ch */ ' ',
1116 /* attrs */ ATTR_NONE,
1117 /* ch_previous */ 0,
1118 /* attrs_previous */ 0 );
1119 }
1120 else
1121 {
1122 gc_ops.paint_char( /* xx */ column,
1123 /* yy */ row,
1124 /* ch */ ' ',
1125 /* attrs */ ATTR_NONE,
1126 /* ch_previous */ gc_buffer_characters[index],
1127 /* attrs_previous */ gc_buffer_attributes[index] );
1128 }
1129
1130 gc_buffer_attributes[index] = ATTR_NONE;
1131 gc_buffer_characters[index] = ' ';
1132 gc_buffer_colorcodes[index] = gc_color_code;
1133 }
1134 }
1135 }
1136 }
1137 else
1138 {
1139 gc_ops.scroll_down(num, top, bottom);
1140
1141 /* Now set the freed up lines to the background colour */
1142
1143 gc_clear_screen(vinfo.v_columns - 1, top + num - 1, top, bottom, 1);
1144 }
1145 }
1146
1147 static void
1148 gc_scroll_up(int num, unsigned int top, unsigned int bottom)
1149 {
1150 if (!gc_buffer_size) return;
1151
1152 if ( bottom <= gc_buffer_rows )
1153 {
1154 unsigned char colorcodesave = gc_color_code;
1155 uint32_t column, row;
1156 uint32_t index, jump;
1157
1158 jump = num * gc_buffer_columns;
1159
1160 for ( row = top ; row < bottom - num ; row++ )
1161 {
1162 index = row * gc_buffer_columns;
1163
1164 for ( column = 0 ; column < gc_buffer_columns ; index++, column++ )
1165 {
1166 if ( gc_buffer_attributes[index] != gc_buffer_attributes[index + jump] ||
1167 gc_buffer_characters[index] != gc_buffer_characters[index + jump] ||
1168 gc_buffer_colorcodes[index] != gc_buffer_colorcodes[index + jump] )
1169 {
1170 if ( gc_color_code != gc_buffer_colorcodes[index + jump] )
1171 {
1172 gc_update_color(COLOR_CODE_GET(gc_buffer_colorcodes[index + jump], TRUE ), TRUE );
1173 gc_update_color(COLOR_CODE_GET(gc_buffer_colorcodes[index + jump], FALSE), FALSE);
1174 }
1175
1176 if ( gc_buffer_colorcodes[index] != gc_buffer_colorcodes[index + jump] )
1177 {
1178 gc_ops.paint_char( /* xx */ column,
1179 /* yy */ row,
1180 /* ch */ gc_buffer_characters[index + jump],
1181 /* attrs */ gc_buffer_attributes[index + jump],
1182 /* ch_previous */ 0,
1183 /* attrs_previous */ 0 );
1184 }
1185 else
1186 {
1187 gc_ops.paint_char( /* xx */ column,
1188 /* yy */ row,
1189 /* ch */ gc_buffer_characters[index + jump],
1190 /* attrs */ gc_buffer_attributes[index + jump],
1191 /* ch_previous */ gc_buffer_characters[index],
1192 /* attrs_previous */ gc_buffer_attributes[index] );
1193 }
1194
1195 gc_buffer_attributes[index] = gc_buffer_attributes[index + jump];
1196 gc_buffer_characters[index] = gc_buffer_characters[index + jump];
1197 gc_buffer_colorcodes[index] = gc_buffer_colorcodes[index + jump];
1198 }
1199 }
1200 }
1201
1202 if ( colorcodesave != gc_color_code )
1203 {
1204 gc_update_color(COLOR_CODE_GET(colorcodesave, TRUE ), TRUE );
1205 gc_update_color(COLOR_CODE_GET(colorcodesave, FALSE), FALSE);
1206 }
1207
1208 /* Now set the freed up lines to the background colour */
1209
1210 for ( row = bottom - num ; row < bottom ; row++ )
1211 {
1212 index = row * gc_buffer_columns;
1213
1214 for ( column = 0 ; column < gc_buffer_columns ; index++, column++ )
1215 {
1216 if ( gc_buffer_attributes[index] != ATTR_NONE ||
1217 gc_buffer_characters[index] != ' ' ||
1218 gc_buffer_colorcodes[index] != gc_color_code )
1219 {
1220 if ( gc_buffer_colorcodes[index] != gc_color_code )
1221 {
1222 gc_ops.paint_char( /* xx */ column,
1223 /* yy */ row,
1224 /* ch */ ' ',
1225 /* attrs */ ATTR_NONE,
1226 /* ch_previous */ 0,
1227 /* attrs_previous */ 0 );
1228 }
1229 else
1230 {
1231 gc_ops.paint_char( /* xx */ column,
1232 /* yy */ row,
1233 /* ch */ ' ',
1234 /* attrs */ ATTR_NONE,
1235 /* ch_previous */ gc_buffer_characters[index],
1236 /* attrs_previous */ gc_buffer_attributes[index] );
1237 }
1238
1239 gc_buffer_attributes[index] = ATTR_NONE;
1240 gc_buffer_characters[index] = ' ';
1241 gc_buffer_colorcodes[index] = gc_color_code;
1242 }
1243 }
1244 }
1245 }
1246 else
1247 {
1248 gc_ops.scroll_up(num, top, bottom);
1249
1250 /* Now set the freed up lines to the background colour */
1251
1252 gc_clear_screen(0, bottom - num, top, bottom, 0);
1253 }
1254 }
1255
1256 static void
1257 gc_show_cursor(unsigned int xx, unsigned int yy)
1258 {
1259 if ( xx < gc_buffer_columns && yy < gc_buffer_rows )
1260 {
1261 uint32_t index = (yy * gc_buffer_columns) + xx;
1262 unsigned char attribute = gc_buffer_attributes[index];
1263 unsigned char character = gc_buffer_characters[index];
1264 unsigned char colorcode = gc_buffer_colorcodes[index];
1265 unsigned char colorcodesave = gc_color_code;
1266
1267 gc_update_color(COLOR_CODE_GET(colorcode, FALSE), TRUE );
1268 gc_update_color(COLOR_CODE_GET(colorcode, TRUE ), FALSE);
1269
1270 gc_ops.paint_char(xx, yy, character, attribute, 0, 0);
1271
1272 gc_update_color(COLOR_CODE_GET(colorcodesave, TRUE ), TRUE );
1273 gc_update_color(COLOR_CODE_GET(colorcodesave, FALSE), FALSE);
1274 }
1275 else
1276 {
1277 gc_ops.show_cursor(xx, yy);
1278 }
1279 }
1280
1281 static void
1282 gc_update_color(int color, boolean_t fore)
1283 {
1284 gc_color_code = COLOR_CODE_SET(gc_color_code, color, fore);
1285 gc_ops.update_color(color, fore);
1286 }
1287
1288 void
1289 vcputc(__unused int l, __unused int u, int c)
1290 {
1291 if ( gc_initialized && ( gc_enabled || debug_mode ) )
1292 {
1293 spl_t s;
1294
1295 s = splhigh();
1296 #if defined(__i386__) || defined(__x86_64__)
1297 x86_filter_TLB_coherency_interrupts(TRUE);
1298 #endif
1299 VCPUTC_LOCK_LOCK();
1300 if ( gc_enabled || debug_mode )
1301 {
1302 gc_hide_cursor(gc_x, gc_y);
1303 gc_putchar(c);
1304 gc_show_cursor(gc_x, gc_y);
1305 }
1306 VCPUTC_LOCK_UNLOCK();
1307 #if defined(__i386__) || defined(__x86_64__)
1308 x86_filter_TLB_coherency_interrupts(FALSE);
1309 #endif
1310 splx(s);
1311 }
1312 }
1313
1314 /*
1315 * Video Console (Back-End)
1316 * ------------------------
1317 */
1318
1319 /*
1320 * For the color support (Michel Pollet)
1321 */
1322 static unsigned char vc_color_index_table[33] =
1323 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1324 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 2 };
1325
1326 static uint32_t vc_colors[8][4] = {
1327 { 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000 }, /* black */
1328 { 0x23232323, 0x7C007C00, 0x00FF0000, 0x3FF00000 }, /* red */
1329 { 0xb9b9b9b9, 0x03e003e0, 0x0000FF00, 0x000FFC00 }, /* green */
1330 { 0x05050505, 0x7FE07FE0, 0x00FFFF00, 0x3FFFFC00 }, /* yellow */
1331 { 0xd2d2d2d2, 0x001f001f, 0x000000FF, 0x000003FF }, /* blue */
1332 // { 0x80808080, 0x31933193, 0x00666699, 0x00000000 }, /* blue */
1333 { 0x18181818, 0x7C1F7C1F, 0x00FF00FF, 0x3FF003FF }, /* magenta */
1334 { 0xb4b4b4b4, 0x03FF03FF, 0x0000FFFF, 0x000FFFFF }, /* cyan */
1335 { 0x00000000, 0x7FFF7FFF, 0x00FFFFFF, 0x3FFFFFFF } /* white */
1336 };
1337
1338 static uint32_t vc_color_fore = 0;
1339 static uint32_t vc_color_back = 0;
1340
1341 /*
1342 * New Rendering code from Michel Pollet
1343 */
1344
1345 /* Rendered Font Buffer */
1346 static unsigned char *vc_rendered_font = NULL;
1347
1348 /* Rendered Font Size */
1349 static uint32_t vc_rendered_font_size = 0;
1350
1351 /* Size of a character in the table (bytes) */
1352 static int vc_rendered_char_size = 0;
1353
1354 #define REN_MAX_DEPTH 32
1355 static unsigned char vc_rendered_char[ISO_CHAR_HEIGHT * ((REN_MAX_DEPTH / 8) * ISO_CHAR_WIDTH)];
1356
1357 static void
1358 vc_clear_screen(unsigned int xx, unsigned int yy, unsigned int scrreg_top,
1359 unsigned int scrreg_bottom, int which)
1360 {
1361 uint32_t *p, *endp, *row;
1362 int linelongs, col;
1363 int rowline, rowlongs;
1364
1365 if(!vinfo.v_depth)
1366 return;
1367
1368 linelongs = vinfo.v_rowbytes * (ISO_CHAR_HEIGHT >> 2);
1369 rowline = vinfo.v_rowscanbytes >> 2;
1370 rowlongs = vinfo.v_rowbytes >> 2;
1371
1372 p = (uint32_t*) vinfo.v_baseaddr;
1373 endp = (uint32_t*) vinfo.v_baseaddr;
1374
1375 switch (which) {
1376 case 0: /* To end of screen */
1377 gc_clear_line(xx, yy, 0);
1378 if (yy < scrreg_bottom - 1) {
1379 p += (yy + 1) * linelongs;
1380 endp += scrreg_bottom * linelongs;
1381 }
1382 break;
1383 case 1: /* To start of screen */
1384 gc_clear_line(xx, yy, 1);
1385 if (yy > scrreg_top) {
1386 p += scrreg_top * linelongs;
1387 endp += yy * linelongs;
1388 }
1389 break;
1390 case 2: /* Whole screen */
1391 p += scrreg_top * linelongs;
1392 if (scrreg_bottom == vinfo.v_rows) {
1393 endp += rowlongs * vinfo.v_height;
1394 } else {
1395 endp += scrreg_bottom * linelongs;
1396 }
1397 break;
1398 }
1399
1400 for (row = p ; row < endp ; row += rowlongs) {
1401 for (col = 0; col < rowline; col++)
1402 *(row+col) = vc_color_back;
1403 }
1404 }
1405
1406 static void
1407 vc_render_char(unsigned char ch, unsigned char *renderptr, short newdepth)
1408 {
1409 union {
1410 unsigned char *charptr;
1411 unsigned short *shortptr;
1412 uint32_t *longptr;
1413 } current; /* current place in rendered font, multiple types. */
1414 unsigned char *theChar; /* current char in iso_font */
1415 int line;
1416
1417 current.charptr = renderptr;
1418 theChar = iso_font + (ch * ISO_CHAR_HEIGHT);
1419
1420 for (line = 0; line < ISO_CHAR_HEIGHT; line++) {
1421 unsigned char mask = 1;
1422 do {
1423 switch (newdepth) {
1424 case 8:
1425 *current.charptr++ = (*theChar & mask) ? 0xFF : 0;
1426 break;
1427 case 16:
1428 *current.shortptr++ = (*theChar & mask) ? 0xFFFF : 0;
1429 break;
1430
1431 case 30:
1432 case 32:
1433 *current.longptr++ = (*theChar & mask) ? 0xFFFFFFFF : 0;
1434 break;
1435 }
1436 mask <<= 1;
1437 } while (mask); /* while the single bit drops to the right */
1438 theChar++;
1439 }
1440 }
1441
1442 static void
1443 vc_paint_char_8(unsigned int xx, unsigned int yy, unsigned char ch, int attrs,
1444 __unused unsigned char ch_previous, __unused int attrs_previous)
1445 {
1446 uint32_t *theChar;
1447 uint32_t *where;
1448 int i;
1449
1450 if (vc_rendered_font) {
1451 theChar = (uint32_t*)(vc_rendered_font + (ch * vc_rendered_char_size));
1452 } else {
1453 vc_render_char(ch, vc_rendered_char, 8);
1454 theChar = (uint32_t*)(vc_rendered_char);
1455 }
1456 where = (uint32_t*)(vinfo.v_baseaddr +
1457 (yy * ISO_CHAR_HEIGHT * vinfo.v_rowbytes) +
1458 (xx * ISO_CHAR_WIDTH));
1459
1460 if (!attrs) for (i = 0; i < ISO_CHAR_HEIGHT; i++) { /* No attr? FLY !*/
1461 uint32_t *store = where;
1462 int x;
1463 for (x = 0; x < 2; x++) {
1464 uint32_t val = *theChar++;
1465 val = (vc_color_back & ~val) | (vc_color_fore & val);
1466 *store++ = val;
1467 }
1468
1469 where = (uint32_t*)(((unsigned char*)where)+vinfo.v_rowbytes);
1470 } else for (i = 0; i < ISO_CHAR_HEIGHT; i++) { /* a little slower */
1471 uint32_t *store = where, lastpixel = 0;
1472 int x;
1473 for (x = 0 ; x < 2; x++) {
1474 uint32_t val = *theChar++, save = val;
1475 if (attrs & ATTR_BOLD) { /* bold support */
1476 if (lastpixel && !(save & 0xFF000000))
1477 val |= 0xff000000;
1478 if ((save & 0xFFFF0000) == 0xFF000000)
1479 val |= 0x00FF0000;
1480 if ((save & 0x00FFFF00) == 0x00FF0000)
1481 val |= 0x0000FF00;
1482 if ((save & 0x0000FFFF) == 0x0000FF00)
1483 val |= 0x000000FF;
1484 }
1485 if (attrs & ATTR_REVERSE) val = ~val;
1486 if (attrs & ATTR_UNDER && i == ISO_CHAR_HEIGHT-1) val = ~val;
1487
1488 val = (vc_color_back & ~val) | (vc_color_fore & val);
1489 *store++ = val;
1490 lastpixel = save & 0xff;
1491 }
1492
1493 where = (uint32_t*)(((unsigned char*)where)+vinfo.v_rowbytes);
1494 }
1495
1496 }
1497
1498 static void
1499 vc_paint_char_16(unsigned int xx, unsigned int yy, unsigned char ch, int attrs,
1500 __unused unsigned char ch_previous,
1501 __unused int attrs_previous)
1502 {
1503 uint32_t *theChar;
1504 uint32_t *where;
1505 int i;
1506
1507 if (vc_rendered_font) {
1508 theChar = (uint32_t*)(vc_rendered_font + (ch * vc_rendered_char_size));
1509 } else {
1510 vc_render_char(ch, vc_rendered_char, 16);
1511 theChar = (uint32_t*)(vc_rendered_char);
1512 }
1513 where = (uint32_t*)(vinfo.v_baseaddr +
1514 (yy * ISO_CHAR_HEIGHT * vinfo.v_rowbytes) +
1515 (xx * ISO_CHAR_WIDTH * 2));
1516
1517 if (!attrs) for (i = 0; i < ISO_CHAR_HEIGHT; i++) { /* No attrs ? FLY ! */
1518 uint32_t *store = where;
1519 int x;
1520 for (x = 0; x < 4; x++) {
1521 uint32_t val = *theChar++;
1522 val = (vc_color_back & ~val) | (vc_color_fore & val);
1523 *store++ = val;
1524 }
1525
1526 where = (uint32_t*)(((unsigned char*)where)+vinfo.v_rowbytes);
1527 } else for (i = 0; i < ISO_CHAR_HEIGHT; i++) { /* a little bit slower */
1528 uint32_t *store = where, lastpixel = 0;
1529 int x;
1530 for (x = 0 ; x < 4; x++) {
1531 uint32_t val = *theChar++, save = val;
1532 if (attrs & ATTR_BOLD) { /* bold support */
1533 if (save == 0xFFFF0000) val |= 0xFFFF;
1534 else if (lastpixel && !(save & 0xFFFF0000))
1535 val |= 0xFFFF0000;
1536 }
1537 if (attrs & ATTR_REVERSE) val = ~val;
1538 if (attrs & ATTR_UNDER && i == ISO_CHAR_HEIGHT-1) val = ~val;
1539
1540 val = (vc_color_back & ~val) | (vc_color_fore & val);
1541
1542 *store++ = val;
1543 lastpixel = save & 0x7fff;
1544 }
1545
1546 where = (uint32_t*)(((unsigned char*)where)+vinfo.v_rowbytes);
1547 }
1548
1549 }
1550
1551 static void
1552 vc_paint_char_32(unsigned int xx, unsigned int yy, unsigned char ch, int attrs,
1553 unsigned char ch_previous, int attrs_previous)
1554 {
1555 uint32_t *theChar;
1556 uint32_t *theCharPrevious;
1557 uint32_t *where;
1558 int i;
1559
1560 if (vc_rendered_font) {
1561 theChar = (uint32_t*)(vc_rendered_font + (ch * vc_rendered_char_size));
1562 theCharPrevious = (uint32_t*)(vc_rendered_font + (ch_previous * vc_rendered_char_size));
1563 } else {
1564 vc_render_char(ch, vc_rendered_char, 32);
1565 theChar = (uint32_t*)(vc_rendered_char);
1566 theCharPrevious = NULL;
1567 }
1568 if (!ch_previous) {
1569 theCharPrevious = NULL;
1570 }
1571 if (attrs_previous) {
1572 theCharPrevious = NULL;
1573 }
1574 where = (uint32_t*)(vinfo.v_baseaddr +
1575 (yy * ISO_CHAR_HEIGHT * vinfo.v_rowbytes) +
1576 (xx * ISO_CHAR_WIDTH * 4));
1577
1578 if (!attrs) for (i = 0; i < ISO_CHAR_HEIGHT; i++) { /* No attrs ? FLY ! */
1579 uint32_t *store = where;
1580 int x;
1581 for (x = 0; x < 8; x++) {
1582 uint32_t val = *theChar++;
1583 if (theCharPrevious == NULL || val != *theCharPrevious++ ) {
1584 val = (vc_color_back & ~val) | (vc_color_fore & val);
1585 *store++ = val;
1586 } else {
1587 store++;
1588 }
1589 }
1590
1591 where = (uint32_t *)(((unsigned char*)where)+vinfo.v_rowbytes);
1592 } else for (i = 0; i < ISO_CHAR_HEIGHT; i++) { /* a little slower */
1593 uint32_t *store = where, lastpixel = 0;
1594 int x;
1595 for (x = 0 ; x < 8; x++) {
1596 uint32_t val = *theChar++, save = val;
1597 if (attrs & ATTR_BOLD) { /* bold support */
1598 if (lastpixel && !save)
1599 val = 0xFFFFFFFF;
1600 }
1601 if (attrs & ATTR_REVERSE) val = ~val;
1602 if (attrs & ATTR_UNDER && i == ISO_CHAR_HEIGHT-1) val = ~val;
1603
1604 val = (vc_color_back & ~val) | (vc_color_fore & val);
1605 *store++ = val;
1606 lastpixel = save;
1607 }
1608
1609 where = (uint32_t*)(((unsigned char*)where)+vinfo.v_rowbytes);
1610 }
1611
1612 }
1613
1614 static void
1615 vc_paint_char(unsigned int xx, unsigned int yy, unsigned char ch, int attrs,
1616 unsigned char ch_previous, int attrs_previous)
1617 {
1618 if(!vinfo.v_depth)
1619 return;
1620
1621 switch(vinfo.v_depth) {
1622 case 8:
1623 vc_paint_char_8(xx, yy, ch, attrs, ch_previous, attrs_previous);
1624 break;
1625 case 16:
1626 vc_paint_char_16(xx, yy, ch, attrs, ch_previous,
1627 attrs_previous);
1628 break;
1629 case 30:
1630 case 32:
1631 vc_paint_char_32(xx, yy, ch, attrs, ch_previous,
1632 attrs_previous);
1633 break;
1634 }
1635 }
1636
1637 static void
1638 vc_render_font(short newdepth)
1639 {
1640 static short olddepth = 0;
1641
1642 int charindex; /* index in ISO font */
1643 unsigned char *rendered_font;
1644 unsigned int rendered_font_size;
1645 int rendered_char_size;
1646 spl_t s;
1647
1648 if (vm_initialized == FALSE) {
1649 return; /* nothing to do */
1650 }
1651 if (olddepth == newdepth && vc_rendered_font) {
1652 return; /* nothing to do */
1653 }
1654
1655 s = splhigh();
1656 VCPUTC_LOCK_LOCK();
1657
1658 rendered_font = vc_rendered_font;
1659 rendered_font_size = vc_rendered_font_size;
1660 rendered_char_size = vc_rendered_char_size;
1661
1662 vc_rendered_font = NULL;
1663 vc_rendered_font_size = 0;
1664 vc_rendered_char_size = 0;
1665
1666 VCPUTC_LOCK_UNLOCK();
1667 splx(s);
1668
1669 if (rendered_font) {
1670 kfree(rendered_font, rendered_font_size);
1671 rendered_font = NULL;
1672 }
1673
1674 if (newdepth) {
1675 rendered_char_size = ISO_CHAR_HEIGHT * (((newdepth + 7) / 8) * ISO_CHAR_WIDTH);
1676 rendered_font_size = (ISO_CHAR_MAX-ISO_CHAR_MIN+1) * rendered_char_size;
1677 rendered_font = (unsigned char *) kalloc(rendered_font_size);
1678 }
1679
1680 if (rendered_font == NULL) {
1681 return;
1682 }
1683
1684 for (charindex = ISO_CHAR_MIN; charindex <= ISO_CHAR_MAX; charindex++) {
1685 vc_render_char(charindex, rendered_font + (charindex * rendered_char_size), newdepth);
1686 }
1687
1688 olddepth = newdepth;
1689
1690 s = splhigh();
1691 VCPUTC_LOCK_LOCK();
1692
1693 vc_rendered_font = rendered_font;
1694 vc_rendered_font_size = rendered_font_size;
1695 vc_rendered_char_size = rendered_char_size;
1696
1697 VCPUTC_LOCK_UNLOCK();
1698 splx(s);
1699 }
1700
1701 static void
1702 vc_enable(boolean_t enable)
1703 {
1704 vc_render_font(enable ? vinfo.v_depth : 0);
1705 }
1706
1707 static void
1708 vc_reverse_cursor(unsigned int xx, unsigned int yy)
1709 {
1710 uint32_t *where;
1711 int line, col;
1712
1713 if(!vinfo.v_depth)
1714 return;
1715
1716 where = (uint32_t*)(vinfo.v_baseaddr +
1717 (yy * ISO_CHAR_HEIGHT * vinfo.v_rowbytes) +
1718 (xx /** ISO_CHAR_WIDTH*/ * vinfo.v_depth));
1719 for (line = 0; line < ISO_CHAR_HEIGHT; line++) {
1720 switch (vinfo.v_depth) {
1721 case 8:
1722 where[0] = ~where[0];
1723 where[1] = ~where[1];
1724 break;
1725 case 16:
1726 for (col = 0; col < 4; col++)
1727 where[col] = ~where[col];
1728 break;
1729 case 32:
1730 for (col = 0; col < 8; col++)
1731 where[col] = ~where[col];
1732 break;
1733 }
1734 where = (uint32_t*)(((unsigned char*)where)+vinfo.v_rowbytes);
1735 }
1736 }
1737
1738 static void
1739 vc_scroll_down(int num, unsigned int scrreg_top, unsigned int scrreg_bottom)
1740 {
1741 uint32_t *from, *to, linelongs, i, line, rowline, rowscanline;
1742
1743 if(!vinfo.v_depth)
1744 return;
1745
1746 linelongs = vinfo.v_rowbytes * (ISO_CHAR_HEIGHT >> 2);
1747 rowline = vinfo.v_rowbytes >> 2;
1748 rowscanline = vinfo.v_rowscanbytes >> 2;
1749
1750 to = (uint32_t *) vinfo.v_baseaddr + (linelongs * scrreg_bottom)
1751 - (rowline - rowscanline);
1752 from = to - (linelongs * num); /* handle multiple line scroll (Michel Pollet) */
1753
1754 i = (scrreg_bottom - scrreg_top) - num;
1755
1756 while (i-- > 0) {
1757 for (line = 0; line < ISO_CHAR_HEIGHT; line++) {
1758 /*
1759 * Only copy what is displayed
1760 */
1761 video_scroll_down(from,
1762 (from-(vinfo.v_rowscanbytes >> 2)),
1763 to);
1764
1765 from -= rowline;
1766 to -= rowline;
1767 }
1768 }
1769 }
1770
1771 static void
1772 vc_scroll_up(int num, unsigned int scrreg_top, unsigned int scrreg_bottom)
1773 {
1774 uint32_t *from, *to, linelongs, i, line, rowline, rowscanline;
1775
1776 if(!vinfo.v_depth)
1777 return;
1778
1779 linelongs = vinfo.v_rowbytes * (ISO_CHAR_HEIGHT >> 2);
1780 rowline = vinfo.v_rowbytes >> 2;
1781 rowscanline = vinfo.v_rowscanbytes >> 2;
1782
1783 to = (uint32_t *) vinfo.v_baseaddr + (scrreg_top * linelongs);
1784 from = to + (linelongs * num); /* handle multiple line scroll (Michel Pollet) */
1785
1786 i = (scrreg_bottom - scrreg_top) - num;
1787
1788 while (i-- > 0) {
1789 for (line = 0; line < ISO_CHAR_HEIGHT; line++) {
1790 /*
1791 * Only copy what is displayed
1792 */
1793 video_scroll_up(from,
1794 (from+(vinfo.v_rowscanbytes >> 2)),
1795 to);
1796
1797 from += rowline;
1798 to += rowline;
1799 }
1800 }
1801 }
1802
1803 static void
1804 vc_update_color(int color, boolean_t fore)
1805 {
1806 if (!vinfo.v_depth)
1807 return;
1808 if (fore) {
1809 vc_color_fore = vc_colors[color][vc_color_index_table[vinfo.v_depth]];
1810 } else {
1811 vc_color_back = vc_colors[color][vc_color_index_table[vinfo.v_depth]];
1812 }
1813 }
1814
1815 /*
1816 * Video Console (Back-End): Icon Control
1817 * --------------------------------------
1818 */
1819
1820 static vc_progress_element * vc_progress;
1821 static const unsigned char * vc_progress_data[2];
1822 static const unsigned char * vc_progress_alpha;
1823 static boolean_t vc_progress_enable;
1824 static const unsigned char * vc_clut;
1825 static const unsigned char * vc_clut8;
1826 static unsigned char vc_revclut8[256];
1827 static uint32_t vc_progress_interval;
1828 static uint32_t vc_progress_count;
1829 static uint32_t vc_progress_angle;
1830 static uint64_t vc_progress_deadline;
1831 static thread_call_data_t vc_progress_call;
1832 static boolean_t vc_needsave;
1833 static void * vc_saveunder;
1834 static vm_size_t vc_saveunder_len;
1835 static int8_t vc_uiselect = 0;
1836 decl_simple_lock_data(,vc_progress_lock)
1837
1838 enum {
1839 kSave = 0x10,
1840 kDataIndexed = 0x20,
1841 kDataAlpha = 0x40,
1842 kDataBack = 0x80,
1843 kDataRotate = 0x03,
1844 kDataRotate0 = 0,
1845 kDataRotate90 = 1,
1846 kDataRotate180 = 2,
1847 kDataRotate270 = 3
1848 };
1849
1850 static void vc_blit_rect(int x, int y, int bx,
1851 int width, int height,
1852 int sourceRow, int backRow,
1853 const unsigned char * dataPtr,
1854 void * backBuffer,
1855 unsigned int flags);
1856 static void vc_blit_rect_8(int x, int y, int bx,
1857 int width, int height,
1858 int sourceRow, int backRow,
1859 const unsigned char * dataPtr,
1860 unsigned char * backBuffer,
1861 unsigned int flags);
1862 static void vc_blit_rect_16(int x, int y, int bx,
1863 int width, int height,
1864 int sourceRow, int backRow,
1865 const unsigned char * dataPtr,
1866 unsigned short * backBuffer,
1867 unsigned int flags);
1868 static void vc_blit_rect_32(int x, int y, int bx,
1869 int width, int height,
1870 int sourceRow, int backRow,
1871 const unsigned char * dataPtr,
1872 unsigned int * backBuffer,
1873 unsigned int flags);
1874 static void vc_blit_rect_30(int x, int y, int bx,
1875 int width, int height,
1876 int sourceRow, int backRow,
1877 const unsigned char * dataPtr,
1878 unsigned int * backBuffer,
1879 unsigned int flags);
1880 static void vc_progress_task( void * arg0, void * arg );
1881
1882 static void vc_blit_rect(int x, int y, int bx,
1883 int width, int height,
1884 int sourceRow, int backRow,
1885 const unsigned char * dataPtr,
1886 void * backBuffer,
1887 unsigned int flags)
1888 {
1889 if(!vinfo.v_depth)
1890 return;
1891
1892 switch( vinfo.v_depth) {
1893 case 8:
1894 if( vc_clut8 == vc_clut)
1895 vc_blit_rect_8( x, y, bx, width, height, sourceRow, backRow, dataPtr, (unsigned char *) backBuffer, flags );
1896 break;
1897 case 16:
1898 vc_blit_rect_16( x, y, bx, width, height, sourceRow, backRow, dataPtr, (unsigned short *) backBuffer, flags );
1899 break;
1900 case 32:
1901 vc_blit_rect_32( x, y, bx, width, height, sourceRow, backRow, dataPtr, (unsigned int *) backBuffer, flags );
1902 break;
1903 case 30:
1904 vc_blit_rect_30( x, y, bx, width, height, sourceRow, backRow, dataPtr, (unsigned int *) backBuffer, flags );
1905 break;
1906 }
1907 }
1908
1909 static void
1910 vc_blit_rect_8(int x, int y, __unused int bx,
1911 int width, int height,
1912 int sourceRow, __unused int backRow,
1913 const unsigned char * dataPtr,
1914 __unused unsigned char * backBuffer,
1915 __unused unsigned int flags)
1916 {
1917 volatile unsigned short * dst;
1918 int line, col;
1919 unsigned int data = 0, out = 0;
1920 int sx, sy, a, b, c, d;
1921 int scale = 0x10000;
1922
1923 a = vc_rotate_matr[kDataRotate & flags][0][0] * scale;
1924 b = vc_rotate_matr[kDataRotate & flags][0][1] * scale;
1925 c = vc_rotate_matr[kDataRotate & flags][1][0] * scale;
1926 d = vc_rotate_matr[kDataRotate & flags][1][1] * scale;
1927 sx = ((a + b) < 0) ? ((width * scale) - 0x8000) : 0;
1928 sy = ((c + d) < 0) ? ((height * scale) - 0x8000) : 0;
1929
1930 if (!sourceRow) data = (unsigned int)(uintptr_t)dataPtr;
1931 else if (1 == sourceRow) a = 0;
1932
1933 dst = (volatile unsigned short *) (vinfo.v_baseaddr +
1934 (y * vinfo.v_rowbytes) +
1935 (x * 4));
1936
1937 for( line = 0; line < height; line++)
1938 {
1939 for( col = 0; col < width; col++)
1940 {
1941 if (sourceRow) data = dataPtr[((sx + (col * a) + (line * b)) >> 16)
1942 + sourceRow * (((sy + (col * c) + (line * d)) >> 16))];
1943 if (kDataAlpha & flags)
1944 out = vc_revclut8[data];
1945 else
1946 out = data;
1947 *(dst + col) = out;
1948 }
1949 dst = (volatile unsigned short *) (((volatile char*)dst) + vinfo.v_rowbytes);
1950 }
1951 }
1952
1953 /* For ARM, 16-bit is 565 (RGB); it is 1555 (XRGB) on other platforms */
1954
1955 #define CLUT_MASK_R 0xf8
1956 #define CLUT_MASK_G 0xf8
1957 #define CLUT_MASK_B 0xf8
1958 #define CLUT_SHIFT_R << 7
1959 #define CLUT_SHIFT_G << 2
1960 #define CLUT_SHIFT_B >> 3
1961 #define MASK_R 0x7c00
1962 #define MASK_G 0x03e0
1963 #define MASK_B 0x001f
1964 #define MASK_R_8 0x3fc00
1965 #define MASK_G_8 0x01fe0
1966 #define MASK_B_8 0x000ff
1967
1968 static void vc_blit_rect_16( int x, int y, int bx,
1969 int width, int height,
1970 int sourceRow, int backRow,
1971 const unsigned char * dataPtr,
1972 unsigned short * backPtr,
1973 unsigned int flags)
1974 {
1975 volatile unsigned short * dst;
1976 int line, col;
1977 unsigned int data = 0, out = 0, back = 0;
1978 int sx, sy, a, b, c, d;
1979 int scale = 0x10000;
1980
1981 a = vc_rotate_matr[kDataRotate & flags][0][0] * scale;
1982 b = vc_rotate_matr[kDataRotate & flags][0][1] * scale;
1983 c = vc_rotate_matr[kDataRotate & flags][1][0] * scale;
1984 d = vc_rotate_matr[kDataRotate & flags][1][1] * scale;
1985 sx = ((a + b) < 0) ? ((width * scale) - 0x8000) : 0;
1986 sy = ((c + d) < 0) ? ((height * scale) - 0x8000) : 0;
1987
1988 if (!sourceRow) data = (unsigned int)(uintptr_t)dataPtr;
1989 else if (1 == sourceRow) a = 0;
1990
1991 if (backPtr)
1992 backPtr += bx;
1993 dst = (volatile unsigned short *) (vinfo.v_baseaddr +
1994 (y * vinfo.v_rowbytes) +
1995 (x * 2));
1996
1997 for( line = 0; line < height; line++)
1998 {
1999 for( col = 0; col < width; col++)
2000 {
2001 if (sourceRow) data = dataPtr[((sx + (col * a) + (line * b)) >> 16)
2002 + sourceRow * (((sy + (col * c) + (line * d)) >> 16))];
2003 if (backPtr) {
2004 if (kSave & flags) {
2005 back = *(dst + col);
2006 *backPtr++ = back;
2007 } else
2008 back = *backPtr++;
2009 }
2010 if (kDataIndexed & flags) {
2011 out = ( (CLUT_MASK_R & (vc_clut[data*3 + 0])) CLUT_SHIFT_R)
2012 | ( (CLUT_MASK_G & (vc_clut[data*3 + 1])) CLUT_SHIFT_G)
2013 | ( (CLUT_MASK_B & (vc_clut[data*3 + 2])) CLUT_SHIFT_B);
2014 } else if (kDataAlpha & flags) {
2015 out = (((((back & MASK_R) * data) + MASK_R_8) >> 8) & MASK_R)
2016 | (((((back & MASK_G) * data) + MASK_G_8) >> 8) & MASK_G)
2017 | (((((back & MASK_B) * data) + MASK_B_8) >> 8) & MASK_B);
2018 #ifdef CONFIG_VC_PROGRESS_WHITE
2019 out += (((0xff - data) & CLUT_MASK_R) CLUT_SHIFT_R)
2020 | (((0xff - data) & CLUT_MASK_G) CLUT_SHIFT_G)
2021 | (((0xff - data) & CLUT_MASK_B) CLUT_SHIFT_B);
2022 #endif
2023 } else
2024 out = back;
2025 *(dst + col) = out;
2026 }
2027 dst = (volatile unsigned short *) (((volatile char*)dst) + vinfo.v_rowbytes);
2028 if (backPtr)
2029 backPtr += backRow - width;
2030 }
2031 }
2032
2033
2034 static void vc_blit_rect_32(int x, int y, int bx,
2035 int width, int height,
2036 int sourceRow, int backRow,
2037 const unsigned char * dataPtr,
2038 unsigned int * backPtr,
2039 unsigned int flags)
2040 {
2041 volatile unsigned int * dst;
2042 int line, col;
2043 unsigned int data = 0, out = 0, back = 0;
2044 int sx, sy, a, b, c, d;
2045 int scale = 0x10000;
2046
2047 a = vc_rotate_matr[kDataRotate & flags][0][0] * scale;
2048 b = vc_rotate_matr[kDataRotate & flags][0][1] * scale;
2049 c = vc_rotate_matr[kDataRotate & flags][1][0] * scale;
2050 d = vc_rotate_matr[kDataRotate & flags][1][1] * scale;
2051 sx = ((a + b) < 0) ? ((width * scale) - 0x8000) : 0;
2052 sy = ((c + d) < 0) ? ((height * scale) - 0x8000) : 0;
2053
2054 if (!sourceRow) data = (unsigned int)(uintptr_t)dataPtr;
2055 else if (1 == sourceRow) a = 0;
2056
2057 if (backPtr)
2058 backPtr += bx;
2059 dst = (volatile unsigned int *) (vinfo.v_baseaddr +
2060 (y * vinfo.v_rowbytes) +
2061 (x * 4));
2062
2063 for( line = 0; line < height; line++)
2064 {
2065 for( col = 0; col < width; col++)
2066 {
2067 if (sourceRow) data = dataPtr[((sx + (col * a) + (line * b)) >> 16)
2068 + sourceRow * (((sy + (col * c) + (line * d)) >> 16))];
2069 if (backPtr) {
2070 if (kSave & flags) {
2071 back = *(dst + col);
2072 *backPtr++ = back;
2073 } else
2074 back = *backPtr++;
2075 }
2076 if (kDataIndexed & flags) {
2077 out = (vc_clut[data*3 + 0] << 16)
2078 | (vc_clut[data*3 + 1] << 8)
2079 | (vc_clut[data*3 + 2]);
2080 } else if (kDataAlpha & flags) {
2081 out = (((((back & 0x00ff00ff) * data) + 0x00ff00ff) >> 8) & 0x00ff00ff)
2082 | (((((back & 0x0000ff00) * data) + 0x0000ff00) >> 8) & 0x0000ff00);
2083 #ifdef CONFIG_VC_PROGRESS_WHITE
2084 out += ((0xff - data) << 16)
2085 | ((0xff - data) << 8)
2086 | (0xff - data);
2087 #endif
2088 } else
2089 out = back;
2090 *(dst + col) = out;
2091 }
2092 dst = (volatile unsigned int *) (((volatile char*)dst) + vinfo.v_rowbytes);
2093 if (backPtr)
2094 backPtr += backRow - width;
2095 }
2096 }
2097
2098 static void vc_blit_rect_30(int x, int y, int bx,
2099 int width, int height,
2100 int sourceRow, int backRow,
2101 const unsigned char * dataPtr,
2102 unsigned int * backPtr,
2103 unsigned int flags)
2104 {
2105 volatile unsigned int * dst;
2106 int line, col;
2107 unsigned int data = 0, out = 0, back = 0;
2108 unsigned long long exp;
2109 int sx, sy, a, b, c, d;
2110 int scale = 0x10000;
2111
2112 a = vc_rotate_matr[kDataRotate & flags][0][0] * scale;
2113 b = vc_rotate_matr[kDataRotate & flags][0][1] * scale;
2114 c = vc_rotate_matr[kDataRotate & flags][1][0] * scale;
2115 d = vc_rotate_matr[kDataRotate & flags][1][1] * scale;
2116 sx = ((a + b) < 0) ? ((width * scale) - 0x8000) : 0;
2117 sy = ((c + d) < 0) ? ((height * scale) - 0x8000) : 0;
2118
2119 if (!sourceRow) data = (unsigned int)(uintptr_t)dataPtr;
2120 else if (1 == sourceRow) a = 0;
2121
2122 if (backPtr)
2123 backPtr += bx;
2124 dst = (volatile unsigned int *) (vinfo.v_baseaddr +
2125 (y * vinfo.v_rowbytes) +
2126 (x * 4));
2127
2128 for( line = 0; line < height; line++)
2129 {
2130 for( col = 0; col < width; col++)
2131 {
2132 if (col < sourceRow)
2133 data = *dataPtr++;
2134
2135 if (backPtr) {
2136 if (kSave & flags) {
2137 back = *(dst + col);
2138 *backPtr++ = back;
2139 } else
2140 back = *backPtr++;
2141 }
2142 if (kDataIndexed & flags) {
2143 out = (vc_clut[data*3 + 0] << 22)
2144 | (vc_clut[data*3 + 1] << 12)
2145 | (vc_clut[data*3 + 2] << 2);
2146 } else if (kDataAlpha & flags) {
2147 exp = back;
2148 exp = (((((exp & 0x3FF003FF) * data) + 0x0FF000FF) >> 8) & 0x3FF003FF)
2149 | (((((exp & 0x000FFC00) * data) + 0x0003FC00) >> 8) & 0x000FFC00);
2150 out = (unsigned int)exp;
2151 #ifdef CONFIG_VC_PROGRESS_WHITE
2152 out += ((0xFF - data) << 22)
2153 | ((0xFF - data) << 12)
2154 | ((0xFF - data) << 2);
2155 #endif
2156 } else
2157 out = back;
2158 *(dst + col) = out;
2159 }
2160 dst = (volatile unsigned int *) (((volatile char*)dst) + vinfo.v_rowbytes);
2161 if (backPtr)
2162 backPtr += backRow - width;
2163 }
2164 }
2165
2166
2167 /*
2168 * Routines to render the lzss image format
2169 */
2170
2171 struct lzss_image_state {
2172 uint32_t col;
2173 uint32_t row;
2174 uint32_t width;
2175 uint32_t height;
2176 uint32_t bytes_per_row;
2177 volatile uint32_t * row_start;
2178 const uint8_t* clut;
2179 };
2180 typedef struct lzss_image_state lzss_image_state;
2181
2182 // returns 0 if OK, 1 if error
2183 static inline int
2184 vc_decompress_lzss_next_pixel (int next_data, lzss_image_state* state)
2185 {
2186 uint32_t palette_index = 0;
2187 uint32_t pixel_value = 0;
2188
2189 palette_index = next_data * 3;
2190
2191 pixel_value = ( (uint32_t) state->clut[palette_index + 0] << 16)
2192 | ( (uint32_t) state->clut[palette_index + 1] << 8)
2193 | ( (uint32_t) state->clut[palette_index + 2]);
2194
2195 *(state->row_start + state->col) = pixel_value;
2196
2197 if (++state->col >= state->width) {
2198 state->col = 0;
2199 if (++state->row >= state->height) {
2200 return 1;
2201 }
2202 state->row_start = (volatile uint32_t *) (((uintptr_t)state->row_start) + state->bytes_per_row);
2203 }
2204 return 0;
2205 }
2206
2207
2208 /*
2209 * Blit an lzss compressed image to the framebuffer
2210 * Assumes 32 bit screen (which is everything we ship at the moment)
2211 * The function vc_display_lzss_icon was copied from libkern/mkext.c, then modified.
2212 */
2213
2214 /*
2215 * TODO: Does lzss use too much stack? 4096 plus bytes...
2216 * Can probably chop it down by 1/2.
2217 */
2218
2219 /**************************************************************
2220 LZSS.C -- A Data Compression Program
2221 ***************************************************************
2222 4/6/1989 Haruhiko Okumura
2223 Use, distribute, and modify this program freely.
2224 Please send me your improved versions.
2225 PC-VAN SCIENCE
2226 NIFTY-Serve PAF01022
2227 CompuServe 74050,1022
2228
2229 **************************************************************/
2230
2231 #define N 4096 /* size of ring buffer - must be power of 2 */
2232 #define F 18 /* upper limit for match_length */
2233 #define THRESHOLD 2 /* encode string into position and length
2234 if match_length is greater than this */
2235
2236 // returns 0 if OK, 1 if error
2237 // x and y indicate upper left corner of image location on screen
2238 int
2239 vc_display_lzss_icon(uint32_t dst_x, uint32_t dst_y,
2240 uint32_t image_width, uint32_t image_height,
2241 const uint8_t *compressed_image,
2242 uint32_t compressed_size,
2243 const uint8_t *clut)
2244 {
2245 uint32_t* image_start;
2246 uint32_t bytes_per_pixel = 4;
2247 uint32_t bytes_per_row = vinfo.v_rowbytes;
2248
2249 image_start = (uint32_t *) (vinfo.v_baseaddr + (dst_y * bytes_per_row) + (dst_x * bytes_per_pixel));
2250
2251 lzss_image_state state = {0, 0, image_width, image_height, bytes_per_row, image_start, clut};
2252
2253 int rval = 0;
2254
2255 const uint8_t *src = compressed_image;
2256 uint32_t srclen = compressed_size;
2257
2258 /* ring buffer of size N, with extra F-1 bytes to aid string comparison */
2259 uint8_t text_buf[N + F - 1];
2260 const uint8_t *srcend = src + srclen;
2261 int i, j, k, r, c;
2262 unsigned int flags;
2263
2264 srcend = src + srclen;
2265 for (i = 0; i < N - F; i++)
2266 text_buf[i] = ' ';
2267 r = N - F;
2268 flags = 0;
2269 for ( ; ; ) {
2270 if (((flags >>= 1) & 0x100) == 0) {
2271 if (src < srcend) c = *src++; else break;
2272 flags = c | 0xFF00; /* uses higher byte cleverly */
2273 } /* to count eight */
2274 if (flags & 1) {
2275 if (src < srcend) c = *src++; else break;
2276 rval = vc_decompress_lzss_next_pixel(c, &state);
2277 if (rval != 0)
2278 return rval;
2279 text_buf[r++] = c;
2280 r &= (N - 1);
2281 } else {
2282 if (src < srcend) i = *src++; else break;
2283 if (src < srcend) j = *src++; else break;
2284 i |= ((j & 0xF0) << 4);
2285 j = (j & 0x0F) + THRESHOLD;
2286 for (k = 0; k <= j; k++) {
2287 c = text_buf[(i + k) & (N - 1)];
2288 rval = vc_decompress_lzss_next_pixel(c, &state);
2289 if (rval != 0 )
2290 return rval;
2291 text_buf[r++] = c;
2292 r &= (N - 1);
2293 }
2294 }
2295 }
2296 return 0;
2297 }
2298
2299 void noroot_icon_test(void) {
2300 boolean_t o_vc_progress_enable = vc_progress_enable;
2301
2302 vc_progress_enable = 1;
2303
2304 PE_display_icon( 0, "noroot");
2305
2306 vc_progress_enable = o_vc_progress_enable;
2307 }
2308
2309
2310 void vc_display_icon( vc_progress_element * desc,
2311 const unsigned char * data )
2312 {
2313 int x, y, width, height;
2314
2315 if( vc_progress_enable && vc_clut) {
2316
2317 width = desc->width;
2318 height = desc->height;
2319 x = desc->dx;
2320 y = desc->dy;
2321 if( 1 & desc->flags) {
2322 x += ((vinfo.v_width - width) / 2);
2323 y += ((vinfo.v_height - height) / 2);
2324 }
2325 vc_blit_rect( x, y, 0, width, height, width, 0, data, NULL, kDataIndexed );
2326 }
2327 }
2328
2329 void
2330 vc_progress_initialize( vc_progress_element * desc,
2331 const unsigned char * data1x,
2332 const unsigned char * data2x,
2333 const unsigned char * clut )
2334 {
2335 uint64_t abstime;
2336
2337 if( (!clut) || (!desc) || (!data1x))
2338 return;
2339 vc_clut = clut;
2340 vc_clut8 = clut;
2341
2342 simple_lock_init(&vc_progress_lock, 0);
2343
2344 vc_progress = desc;
2345 vc_progress_data[0] = data1x;
2346 vc_progress_data[1] = data2x;
2347 if( 2 & vc_progress->flags)
2348 vc_progress_alpha = data1x
2349 + vc_progress->count * vc_progress->width * vc_progress->height;
2350 else
2351 vc_progress_alpha = NULL;
2352
2353 thread_call_setup(&vc_progress_call, vc_progress_task, NULL);
2354
2355 clock_interval_to_absolutetime_interval(vc_progress->time, 1000 * 1000, &abstime);
2356 vc_progress_interval = (uint32_t)abstime;
2357 }
2358
2359 void
2360 vc_progress_set(boolean_t enable, uint32_t vc_delay)
2361 {
2362 spl_t s;
2363 void *saveBuf = NULL;
2364 vm_size_t saveLen = 0;
2365 unsigned int count;
2366 unsigned int index;
2367 unsigned char pdata8;
2368 unsigned short pdata16;
2369 unsigned short * buf16;
2370 unsigned int pdata32;
2371 unsigned int * buf32;
2372
2373 if( !vc_progress)
2374 return;
2375
2376 if( enable) {
2377 saveLen = (vc_progress->width << vc_uiselect) * (vc_progress->height << vc_uiselect) * vinfo.v_depth / 8;
2378 saveBuf = kalloc( saveLen );
2379
2380 switch( vinfo.v_depth) {
2381 case 8 :
2382 for( count = 0; count < 256; count++) {
2383 vc_revclut8[count] = vc_clut[0x01 * 3];
2384 pdata8 = (vc_clut[0x01 * 3] * count + 0x0ff) >> 8;
2385 for( index = 0; index < 256; index++) {
2386 if( (pdata8 == vc_clut[index * 3 + 0]) &&
2387 (pdata8 == vc_clut[index * 3 + 1]) &&
2388 (pdata8 == vc_clut[index * 3 + 2])) {
2389 vc_revclut8[count] = index;
2390 break;
2391 }
2392 }
2393 }
2394 memset( saveBuf, 0x01, saveLen );
2395 break;
2396
2397 case 16 :
2398 buf16 = (unsigned short *) saveBuf;
2399 pdata16 = ((vc_clut[0x01 * 3 + 0] & CLUT_MASK_R) CLUT_SHIFT_R)
2400 | ((vc_clut[0x01 * 3 + 0] & CLUT_MASK_G) CLUT_SHIFT_G)
2401 | ((vc_clut[0x01 * 3 + 0] & CLUT_MASK_B) CLUT_SHIFT_B);
2402 for( count = 0; count < saveLen / 2; count++)
2403 buf16[count] = pdata16;
2404 break;
2405
2406 case 32 :
2407 buf32 = (unsigned int *) saveBuf;
2408 pdata32 = ((vc_clut[0x01 * 3 + 0] & 0xff) << 16)
2409 | ((vc_clut[0x01 * 3 + 1] & 0xff) << 8)
2410 | ((vc_clut[0x01 * 3 + 2] & 0xff) << 0);
2411 for( count = 0; count < saveLen / 4; count++)
2412 buf32[count] = pdata32;
2413 break;
2414 }
2415 }
2416
2417 s = splhigh();
2418 simple_lock(&vc_progress_lock);
2419
2420 if( vc_progress_enable != enable) {
2421 vc_progress_enable = enable;
2422 if( enable) {
2423 vc_needsave = TRUE;
2424 vc_saveunder = saveBuf;
2425 vc_saveunder_len = saveLen;
2426 saveBuf = NULL;
2427 saveLen = 0;
2428 vc_progress_count = 0;
2429 vc_progress_angle = 0;
2430
2431 clock_interval_to_deadline(vc_delay,
2432 1000 * 1000 * 1000 /*second scale*/,
2433 &vc_progress_deadline);
2434 thread_call_enter_delayed(&vc_progress_call, vc_progress_deadline);
2435
2436 } else {
2437 if( vc_saveunder) {
2438 saveBuf = vc_saveunder;
2439 saveLen = vc_saveunder_len;
2440 vc_saveunder = NULL;
2441 vc_saveunder_len = 0;
2442 }
2443
2444 thread_call_cancel(&vc_progress_call);
2445 }
2446 }
2447
2448 simple_unlock(&vc_progress_lock);
2449 splx(s);
2450
2451 if( saveBuf)
2452 kfree( saveBuf, saveLen );
2453 }
2454
2455
2456 static void
2457 vc_progress_task(__unused void *arg0, __unused void *arg)
2458 {
2459 spl_t s;
2460 int x, y, width, height;
2461 const unsigned char * data;
2462
2463 s = splhigh();
2464 simple_lock(&vc_progress_lock);
2465
2466 if( vc_progress_enable) {
2467
2468 KERNEL_DEBUG_CONSTANT(0x7020008, vc_progress_count, 0, 0, 0, 0);
2469
2470 vc_progress_count++;
2471 if( vc_progress_count >= vc_progress->count) {
2472 vc_progress_count = 0;
2473 vc_progress_angle++;
2474 }
2475
2476 width = (vc_progress->width << vc_uiselect);
2477 height = (vc_progress->height << vc_uiselect);
2478 x = (vc_progress->dx << vc_uiselect);
2479 y = (vc_progress->dy << vc_uiselect);
2480 data = vc_progress_data[vc_uiselect];
2481 data += vc_progress_count * width * height;
2482 if( 1 & vc_progress->flags) {
2483 x += ((vinfo.v_width - width) / 2);
2484 y += ((vinfo.v_height - height) / 2);
2485 }
2486 vc_blit_rect( x, y, 0,
2487 width, height, width, width,
2488 data, vc_saveunder,
2489 kDataAlpha
2490 | (vc_progress_angle & kDataRotate)
2491 | (vc_needsave ? kSave : 0) );
2492 vc_needsave = FALSE;
2493
2494 clock_deadline_for_periodic_event(vc_progress_interval, mach_absolute_time(), &vc_progress_deadline);
2495 thread_call_enter_delayed(&vc_progress_call, vc_progress_deadline);
2496 }
2497 simple_unlock(&vc_progress_lock);
2498 splx(s);
2499 }
2500
2501 /*
2502 * Generic Console (Front-End): Master Control
2503 * -------------------------------------------
2504 */
2505
2506 #if defined (__i386__) || defined (__x86_64__)
2507 #include <pexpert/i386/boot.h>
2508 #endif
2509
2510 static boolean_t gc_acquired = FALSE;
2511 static boolean_t gc_graphics_boot = FALSE;
2512 static boolean_t gc_desire_text = FALSE;
2513
2514 static uint64_t lastVideoPhys = 0;
2515 static vm_offset_t lastVideoVirt = 0;
2516 static vm_size_t lastVideoSize = 0;
2517 static boolean_t lastVideoMapped = FALSE;
2518
2519 static void
2520 gc_pause( boolean_t pause, boolean_t graphics_now )
2521 {
2522 spl_t s;
2523
2524 s = splhigh( );
2525 VCPUTC_LOCK_LOCK( );
2526
2527 disableConsoleOutput = (pause && !console_is_serial());
2528 gc_enabled = (!pause && !graphics_now);
2529
2530 VCPUTC_LOCK_UNLOCK( );
2531
2532 simple_lock(&vc_progress_lock);
2533
2534 vc_progress_enable = gc_graphics_boot && !gc_desire_text && !pause;
2535 if (vc_progress_enable)
2536 thread_call_enter_delayed(&vc_progress_call, vc_progress_deadline);
2537
2538 simple_unlock(&vc_progress_lock);
2539 splx(s);
2540 }
2541
2542 static void
2543 vc_initialize(__unused struct vc_info * vinfo_p)
2544 {
2545
2546 vinfo.v_rows = vinfo.v_height / ISO_CHAR_HEIGHT;
2547 vinfo.v_columns = vinfo.v_width / ISO_CHAR_WIDTH;
2548 vinfo.v_rowscanbytes = ((vinfo.v_depth + 7) / 8) * vinfo.v_width;
2549 vc_uiselect = (2 == vinfo.v_scale) ? 1 : 0;
2550 }
2551
2552 void
2553 initialize_screen(PE_Video * boot_vinfo, unsigned int op)
2554 {
2555 unsigned int fbsize = 0;
2556 vm_offset_t newVideoVirt = 0;
2557 boolean_t graphics_now;
2558 ppnum_t fbppage;
2559
2560 if ( boot_vinfo )
2561 {
2562 struct vc_info new_vinfo = vinfo;
2563 /*
2564 * First, check if we are changing the size and/or location of the framebuffer
2565 */
2566 new_vinfo.v_name[0] = 0;
2567 new_vinfo.v_physaddr = boot_vinfo->v_baseAddr & ~3; /* Get the physical address */
2568 #ifndef __LP64__
2569 new_vinfo.v_physaddr |= (((uint64_t) boot_vinfo->v_baseAddrHigh) << 32);
2570 #endif
2571 if (kPEBaseAddressChange != op)
2572 {
2573 new_vinfo.v_width = (unsigned int)boot_vinfo->v_width;
2574 new_vinfo.v_height = (unsigned int)boot_vinfo->v_height;
2575 new_vinfo.v_depth = (unsigned int)boot_vinfo->v_depth;
2576 new_vinfo.v_rowbytes = (unsigned int)boot_vinfo->v_rowBytes;
2577 #if defined(__i386__) || defined(__x86_64__)
2578 new_vinfo.v_type = (unsigned int)boot_vinfo->v_display;
2579 #else
2580 new_vinfo.v_type = 0;
2581 #endif
2582 new_vinfo.v_scale = boot_vinfo->v_scale;
2583 }
2584
2585 if (!lastVideoMapped)
2586 kprintf("initialize_screen: b=%08llX, w=%08X, h=%08X, r=%08X, d=%08X\n", /* (BRINGUP) */
2587 new_vinfo.v_physaddr, new_vinfo.v_width, new_vinfo.v_height, new_vinfo.v_rowbytes, new_vinfo.v_type); /* (BRINGUP) */
2588
2589 if (!new_vinfo.v_physaddr) /* Check to see if we have a framebuffer */
2590 {
2591 kprintf("initialize_screen: No video - forcing serial mode\n"); /* (BRINGUP) */
2592 new_vinfo.v_depth = 0; /* vc routines are nop */
2593 (void)switch_to_serial_console(); /* Switch into serial mode */
2594 gc_graphics_boot = FALSE; /* Say we are not in graphics mode */
2595 disableConsoleOutput = FALSE; /* Allow printfs to happen */
2596 gc_acquired = TRUE;
2597 }
2598 else
2599 {
2600 /*
2601 * If VM is up, we are given a virtual address, unless b0 is set to indicate physical.
2602 */
2603 if ((kernel_map != VM_MAP_NULL) && (0 == (1 & boot_vinfo->v_baseAddr)))
2604 {
2605 fbppage = pmap_find_phys(kernel_pmap, (addr64_t)boot_vinfo->v_baseAddr); /* Get the physical address of frame buffer */
2606 if(!fbppage) /* Did we find it? */
2607 {
2608 panic("initialize_screen: Strange framebuffer - addr = %08X\n", (uint32_t)boot_vinfo->v_baseAddr);
2609 }
2610 new_vinfo.v_physaddr = (((uint64_t)fbppage) << 12) | (boot_vinfo->v_baseAddr & PAGE_MASK); /* Get the physical address */
2611 }
2612
2613 if (boot_vinfo->v_length != 0)
2614 fbsize = (unsigned int) round_page(boot_vinfo->v_length);
2615 else
2616 fbsize = (unsigned int) round_page(new_vinfo.v_height * new_vinfo.v_rowbytes); /* Remember size */
2617
2618
2619 if ((lastVideoPhys != new_vinfo.v_physaddr) || (fbsize > lastVideoSize)) /* Did framebuffer change location or get bigger? */
2620 {
2621 unsigned int flags = VM_WIMG_IO;
2622 newVideoVirt = io_map_spec((vm_map_offset_t)new_vinfo.v_physaddr, fbsize, flags); /* Allocate address space for framebuffer */
2623 }
2624 }
2625
2626 if (newVideoVirt != 0)
2627 new_vinfo.v_baseaddr = newVideoVirt + boot_vinfo->v_offset; /* Set the new framebuffer address */
2628 else
2629 new_vinfo.v_baseaddr = lastVideoVirt + boot_vinfo->v_offset; /* Set the new framebuffer address */
2630
2631 #if defined(__x86_64__)
2632 // Adjust the video buffer pointer to point to where it is in high virtual (above the hole)
2633 new_vinfo.v_baseaddr |= (VM_MIN_KERNEL_ADDRESS & ~LOW_4GB_MASK);
2634 #endif
2635
2636 /* Update the vinfo structure atomically with respect to the vc_progress task if running */
2637 if (vc_progress)
2638 {
2639 simple_lock(&vc_progress_lock);
2640 vinfo = new_vinfo;
2641 simple_unlock(&vc_progress_lock);
2642 }
2643 else
2644 {
2645 vinfo = new_vinfo;
2646 }
2647
2648 // If we changed the virtual address, remove the old mapping
2649 if (newVideoVirt != 0)
2650 {
2651 if (lastVideoVirt) /* Was the framebuffer mapped before? */
2652 {
2653 #if FALSE
2654 if(lastVideoMapped) /* Was this not a special pre-VM mapping? */
2655 #endif
2656 {
2657 pmap_remove(kernel_pmap, trunc_page_64(lastVideoVirt),
2658 round_page_64(lastVideoVirt + lastVideoSize)); /* Toss mappings */
2659 }
2660 if(lastVideoMapped) /* Was this not a special pre-VM mapping? */
2661 {
2662 kmem_free(kernel_map, lastVideoVirt, lastVideoSize); /* Toss kernel addresses */
2663 }
2664 }
2665 lastVideoPhys = new_vinfo.v_physaddr; /* Remember the framebuffer address */
2666 lastVideoSize = fbsize; /* Remember the size */
2667 lastVideoVirt = newVideoVirt; /* Remember the virtual framebuffer address */
2668 lastVideoMapped = (NULL != kernel_map);
2669 }
2670
2671 if (kPEBaseAddressChange != op)
2672 {
2673 // Graphics mode setup by the booter.
2674
2675 gc_ops.initialize = vc_initialize;
2676 gc_ops.enable = vc_enable;
2677 gc_ops.paint_char = vc_paint_char;
2678 gc_ops.scroll_down = vc_scroll_down;
2679 gc_ops.scroll_up = vc_scroll_up;
2680 gc_ops.clear_screen = vc_clear_screen;
2681 gc_ops.hide_cursor = vc_reverse_cursor;
2682 gc_ops.show_cursor = vc_reverse_cursor;
2683 gc_ops.update_color = vc_update_color;
2684 gc_initialize(&vinfo);
2685 }
2686
2687 #ifdef GRATEFULDEBUGGER
2688 GratefulDebInit((bootBumbleC *)boot_vinfo); /* Re-initialize GratefulDeb */
2689 #endif /* GRATEFULDEBUGGER */
2690 }
2691
2692 graphics_now = gc_graphics_boot && !gc_desire_text;
2693 switch ( op )
2694 {
2695 case kPEGraphicsMode:
2696 panicDialogDesired = TRUE;
2697 gc_graphics_boot = TRUE;
2698 gc_desire_text = FALSE;
2699 break;
2700
2701 case kPETextMode:
2702 panicDialogDesired = FALSE;
2703 disable_debug_output = FALSE;
2704 gc_graphics_boot = FALSE;
2705 break;
2706
2707 case kPEAcquireScreen:
2708 if ( gc_acquired ) break;
2709 vc_progress_set( graphics_now, kProgressAcquireDelay );
2710 gc_enable( !graphics_now );
2711 gc_acquired = TRUE;
2712 gc_desire_text = FALSE;
2713 break;
2714
2715 case kPEDisableScreen:
2716 if (gc_acquired)
2717 {
2718 gc_pause( TRUE, graphics_now );
2719 }
2720 break;
2721
2722 case kPEEnableScreen:
2723 if (gc_acquired)
2724 {
2725 gc_pause( FALSE, graphics_now );
2726 }
2727 break;
2728
2729 case kPETextScreen:
2730 if ( console_is_serial() ) break;
2731
2732 panicDialogDesired = FALSE;
2733 disable_debug_output = FALSE;
2734 if ( gc_acquired == FALSE )
2735 {
2736 gc_desire_text = TRUE;
2737 break;
2738 }
2739 if ( gc_graphics_boot == FALSE ) break;
2740
2741 vc_progress_set( FALSE, 0 );
2742 #if !CONFIG_EMBEDDED
2743 vc_enable_progressmeter( FALSE );
2744 #endif
2745 gc_enable( TRUE );
2746 break;
2747
2748 case kPEReleaseScreen:
2749 gc_acquired = FALSE;
2750 gc_desire_text = FALSE;
2751 gc_enable( FALSE );
2752 vc_progress_set( FALSE, 0 );
2753 #if !CONFIG_EMBEDDED
2754 vc_enable_progressmeter( FALSE );
2755 #endif
2756
2757 vc_clut8 = NULL;
2758 #ifdef GRATEFULDEBUGGER
2759 GratefulDebInit(0); /* Stop grateful debugger */
2760 #endif /* GRATEFULDEBUGGER */
2761 break;
2762 }
2763 #ifdef GRATEFULDEBUGGER
2764 if ( boot_vinfo ) GratefulDebInit((bootBumbleC *)boot_vinfo); /* Re initialize GratefulDeb */
2765 #endif /* GRATEFULDEBUGGER */
2766 }
2767
2768 void
2769 dim_screen(void)
2770 {
2771 unsigned int *p, *endp, *row;
2772 int col, rowline, rowlongs;
2773 register unsigned int mask;
2774
2775 if(!vinfo.v_depth)
2776 return;
2777
2778 if ( vinfo.v_depth == 32 )
2779 mask = 0x007F7F7F;
2780 else if ( vinfo.v_depth == 30 )
2781 mask = (0x1ff<<20) | (0x1ff<<10) | 0x1ff;
2782 else if ( vinfo.v_depth == 16 )
2783 mask = 0x3DEF3DEF;
2784 else
2785 return;
2786
2787 rowline = (int)(vinfo.v_rowscanbytes / 4);
2788 rowlongs = (int)(vinfo.v_rowbytes / 4);
2789
2790 p = (unsigned int*) vinfo.v_baseaddr;
2791 endp = p + (rowlongs * vinfo.v_height);
2792
2793 for (row = p ; row < endp ; row += rowlongs) {
2794 for (p = &row[0], col = 0; col < rowline; col++) {
2795 *p = (*p >> 1) & mask;
2796 ++p;
2797 }
2798 }
2799 }
2800
2801 void vcattach(void); /* XXX gcc 4 warning cleanup */
2802
2803 void
2804 vcattach(void)
2805 {
2806 vm_initialized = TRUE;
2807
2808 if ( gc_graphics_boot == FALSE )
2809 {
2810 long index;
2811
2812 if ( gc_acquired )
2813 {
2814 initialize_screen(NULL, kPEReleaseScreen);
2815 }
2816
2817 initialize_screen(NULL, kPEAcquireScreen);
2818
2819 for ( index = 0 ; index < msgbufp->msg_bufx ; index++ )
2820 {
2821 if (msgbufp->msg_bufc[index] == '\0') {
2822 continue;
2823 }
2824
2825 vcputc( 0, 0, msgbufp->msg_bufc[index] );
2826
2827 if ( msgbufp->msg_bufc[index] == '\n' )
2828 {
2829 vcputc( 0, 0,'\r' );
2830 }
2831 }
2832 }
2833 }
2834
2835 #if !CONFIG_EMBEDDED
2836
2837 int vc_progress_meter_enable;
2838 int vc_progress_meter_value;
2839
2840 static void * vc_progress_meter_backbuffer;
2841 static int vc_progress_meter_drawn;
2842
2843 static void
2844 vc_draw_progress_meter(int select, unsigned int flags, int x1, int x2)
2845 {
2846 const unsigned char * data;
2847 int x, w;
2848 int ox, oy;
2849
2850 ox = ((vinfo.v_width - (kProgressBarWidth << vc_uiselect)) / 2);
2851 oy = vinfo.v_height - (((vinfo.v_height / 2) - ((vc_progress->dy + kProgressBarHeight) << vc_uiselect)) / 2);
2852
2853 if (kDataBack == flags)
2854 {
2855 // restore back bits
2856 vc_blit_rect(ox + x1, oy, x1,
2857 x2, (kProgressBarHeight << vc_uiselect), 0, (kProgressBarWidth << vc_uiselect),
2858 NULL, vc_progress_meter_backbuffer, flags);
2859 return;
2860 }
2861
2862 for (x = x1; x < x2; x += w)
2863 {
2864 if (x < (kProgressBarCapWidth << vc_uiselect))
2865 {
2866 if (x2 < (kProgressBarCapWidth << vc_uiselect))
2867 w = x2 - x;
2868 else
2869 w = (kProgressBarCapWidth << vc_uiselect) - x;
2870 data = progressmeter_leftcap[vc_uiselect & 1][select & 1];
2871 data += x;
2872 vc_blit_rect(ox + x, oy, x, w,
2873 (kProgressBarHeight << vc_uiselect),
2874 (kProgressBarCapWidth << vc_uiselect),
2875 (kProgressBarWidth << vc_uiselect),
2876 data, vc_progress_meter_backbuffer, flags);
2877 }
2878 else if (x < ((kProgressBarWidth - kProgressBarCapWidth) << vc_uiselect))
2879 {
2880 if (x2 < ((kProgressBarWidth - kProgressBarCapWidth) << vc_uiselect))
2881 w = x2 - x;
2882 else
2883 w = ((kProgressBarWidth - kProgressBarCapWidth) << vc_uiselect) - x;
2884 data = progressmeter_middle[vc_uiselect & 1][select & 1];
2885 vc_blit_rect(ox + x, oy, x, w,
2886 (kProgressBarHeight << vc_uiselect),
2887 1,
2888 (kProgressBarWidth << vc_uiselect),
2889 data, vc_progress_meter_backbuffer, flags);
2890 }
2891 else
2892 {
2893 w = x2 - x;
2894 data = progressmeter_rightcap[vc_uiselect & 1][select & 1];
2895 data += x - ((kProgressBarWidth - kProgressBarCapWidth) << vc_uiselect);
2896 vc_blit_rect(ox + x, oy, x, w,
2897 (kProgressBarHeight << vc_uiselect),
2898 (kProgressBarCapWidth << vc_uiselect),
2899 (kProgressBarWidth << vc_uiselect),
2900 data, vc_progress_meter_backbuffer, flags);
2901 }
2902 }
2903 }
2904
2905 void
2906 vc_enable_progressmeter(int new_value)
2907 {
2908 spl_t s;
2909 void * new_buffer = NULL;
2910
2911 if (new_value)
2912 new_buffer = kalloc((kProgressBarWidth << vc_uiselect)
2913 * (kProgressBarHeight << vc_uiselect) * sizeof(int));
2914
2915 s = splhigh();
2916 simple_lock(&vc_progress_lock);
2917
2918 if (gc_enabled || !gc_acquired || !gc_graphics_boot)
2919 new_value = FALSE;
2920
2921 if (new_value != vc_progress_meter_enable)
2922 {
2923 if (new_value)
2924 {
2925 vc_progress_meter_backbuffer = new_buffer;
2926 vc_draw_progress_meter(FALSE, kDataAlpha | kSave, 0, (kProgressBarWidth << vc_uiselect));
2927 vc_progress_meter_enable = TRUE;
2928 new_buffer = NULL;
2929 vc_progress_meter_drawn = 0;
2930 }
2931 else if (vc_progress_meter_backbuffer)
2932 {
2933 vc_draw_progress_meter(0, kDataBack, 0, (kProgressBarWidth << vc_uiselect));
2934 new_buffer = vc_progress_meter_backbuffer;
2935 vc_progress_meter_backbuffer = NULL;
2936 vc_progress_meter_enable = FALSE;
2937 }
2938 }
2939
2940 simple_unlock(&vc_progress_lock);
2941 splx(s);
2942
2943 if (new_buffer)
2944 kfree(new_buffer, (kProgressBarWidth << vc_uiselect)
2945 * (kProgressBarHeight << vc_uiselect) * sizeof(int));
2946 }
2947
2948 void
2949 vc_set_progressmeter(int new_value)
2950 {
2951 spl_t s;
2952 int x2;
2953
2954 if ((new_value < 0) | (new_value > 100))
2955 return;
2956
2957 s = splhigh();
2958 simple_lock(&vc_progress_lock);
2959
2960 if (vc_progress_meter_enable)
2961 {
2962 vc_progress_meter_value = new_value;
2963 x2 = ((kProgressBarWidth << vc_uiselect) * new_value) / 100;
2964 if (x2 > vc_progress_meter_drawn)
2965 vc_draw_progress_meter(TRUE, kDataAlpha, vc_progress_meter_drawn, x2);
2966 else
2967 vc_draw_progress_meter(FALSE, kDataAlpha, x2, vc_progress_meter_drawn);
2968 vc_progress_meter_drawn = x2;
2969 }
2970
2971 simple_unlock(&vc_progress_lock);
2972 splx(s);
2973 }
2974
2975 #endif /* !CONFIG_EMBEDDED */
2976