2 * Copyright (c) 2000-2009 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * @OSF_FREE_COPYRIGHT@
33 * @APPLE_FREE_COPYRIGHT@
36 * NetBSD: ite.c,v 1.16 1995/07/17 01:24:34 briggs Exp
38 * Copyright (c) 1988 University of Utah.
39 * Copyright (c) 1990, 1993
40 * The Regents of the University of California. All rights reserved.
42 * This code is derived from software contributed to Berkeley by
43 * the Systems Programming Group of the University of Utah Computer
46 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
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.
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
74 * from: Utah $Hdr: ite.c 1.28 92/12/20$
76 * @(#)ite.c 8.2 (Berkeley) 1/12/94
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.
87 * -- Brad and Lawrence, June 26th, 1994
91 #include <console/video_console.h>
92 #include <console/serial_protos.h>
94 #include <kern/kern_types.h>
95 #include <kern/kalloc.h>
96 #include <kern/debug.h>
98 #include <kern/thread_call.h>
101 #include <vm/vm_kern.h>
102 #include <machine/io_map_entries.h>
103 #include <machine/machine_cpu.h>
105 #include <pexpert/pexpert.h>
106 #include <sys/kdebug.h>
108 #include "iso_font.c"
109 #include "progress_meter_data.c"
111 #include "sys/msgbuf.h"
114 * Generic Console (Front-End)
115 * ---------------------------
118 struct vc_info vinfo
;
120 void noroot_icon_test(void);
123 extern int disableConsoleOutput
;
124 static boolean_t gc_enabled
= FALSE
;
125 static boolean_t gc_initialized
= FALSE
;
126 static boolean_t vm_initialized
= FALSE
;
129 void (*initialize
)(struct vc_info
* info
);
130 void (*enable
)(boolean_t enable
);
131 void (*paint_char
)(unsigned int xx
, unsigned int yy
, unsigned char ch
,
132 int attrs
, unsigned char ch_previous
,
134 void (*clear_screen
)(unsigned int xx
, unsigned int yy
, unsigned int top
,
135 unsigned int bottom
, int which
);
136 void (*scroll_down
)(int num
, unsigned int top
, unsigned int bottom
);
137 void (*scroll_up
)(int num
, unsigned int top
, unsigned int bottom
);
138 void (*hide_cursor
)(unsigned int xx
, unsigned int yy
);
139 void (*show_cursor
)(unsigned int xx
, unsigned int yy
);
140 void (*update_color
)(int color
, boolean_t fore
);
143 static unsigned char *gc_buffer_attributes
;
144 static unsigned char *gc_buffer_characters
;
145 static unsigned char *gc_buffer_colorcodes
;
146 static unsigned char *gc_buffer_tab_stops
;
147 static uint32_t gc_buffer_columns
;
148 static uint32_t gc_buffer_rows
;
149 static uint32_t gc_buffer_size
;
151 #if defined(__i386__) || defined(__x86_64__)
152 decl_simple_lock_data(static, vcputc_lock
);
154 #define VCPUTC_LOCK_INIT() \
156 simple_lock_init(&vcputc_lock, 0); \
159 #define VCPUTC_LOCK_LOCK() \
161 boolean_t istate = ml_get_interrupts_enabled(); \
162 while (!simple_lock_try(&vcputc_lock)) \
165 handle_pending_TLB_flushes(); \
170 #define VCPUTC_LOCK_UNLOCK() \
172 simple_unlock(&vcputc_lock); \
175 static hw_lock_data_t vcputc_lock
;
177 #define VCPUTC_LOCK_INIT() \
179 hw_lock_init(&vcputc_lock); \
182 #define VCPUTC_LOCK_LOCK() \
184 if (!hw_lock_to(&vcputc_lock, ~0U))\
186 panic("VCPUTC_LOCK_LOCK"); \
190 #define VCPUTC_LOCK_UNLOCK() \
192 hw_lock_unlock(&vcputc_lock); \
198 # 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
200 # 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
201 # Background color codes:
202 # 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
208 #define ATTR_REVERSE 4
210 #define COLOR_BACKGROUND 0
211 #define COLOR_FOREGROUND 7
213 #define COLOR_CODE_GET(code, fore) (((code) & ((fore) ? 0xF0 : 0x0F)) >> ((fore) ? 4 : 0))
214 #define COLOR_CODE_SET(code, color, fore) (((code) & ((fore) ? 0x0F : 0xF0)) | ((color) << ((fore) ? 4 : 0)))
216 static unsigned char gc_color_code
;
220 static unsigned int gc_x
, gc_y
, gc_savex
, gc_savey
;
221 static unsigned int gc_par
[MAXPARS
], gc_numpars
, gc_hanging_cursor
, gc_attr
, gc_saveattr
;
223 /* VT100 scroll region */
224 static unsigned int gc_scrreg_top
, gc_scrreg_bottom
;
227 ESnormal
, /* Nothing yet */
229 ESsquare
, /* Got ESC [ */
230 ESgetpars
, /* About to get or getting the parameters */
231 ESgotpars
, /* Finished getting the parameters */
232 ESfunckey
, /* Function key */
233 EShash
, /* DEC-specific stuff (screen align, etc.) */
234 ESsetG0
, /* Specify the G0 character set */
235 ESsetG1
, /* Specify the G1 character set */
238 ESignore
/* Ignore this sequence */
239 } gc_vt100state
= ESnormal
;
245 kProgressAcquireDelay
= 0,
246 kProgressReacquireDelay
= 5,
249 static int8_t vc_rotate_matr
[4][2][2] = {
260 static int gc_wrap_mode
= 1, gc_relative_origin
= 0;
261 static int gc_charset_select
= 0, gc_save_charset_s
= 0;
262 static int gc_charset
[2] = { 0, 0 };
263 static int gc_charset_save
[2] = { 0, 0 };
265 static void gc_clear_line(unsigned int xx
, unsigned int yy
, int which
);
266 static void gc_clear_screen(unsigned int xx
, unsigned int yy
, int top
,
267 unsigned int bottom
, int which
);
268 static void gc_enable(boolean_t enable
);
269 static void gc_hide_cursor(unsigned int xx
, unsigned int yy
);
270 static void gc_initialize(struct vc_info
* info
);
271 static boolean_t
gc_is_tab_stop(unsigned int column
);
272 static void gc_paint_char(unsigned int xx
, unsigned int yy
, unsigned char ch
,
274 static void gc_putchar(char ch
);
275 static void gc_putc_askcmd(unsigned char ch
);
276 static void gc_putc_charsetcmd(int charset
, unsigned char ch
);
277 static void gc_putc_charsizecmd(unsigned char ch
);
278 static void gc_putc_esc(unsigned char ch
);
279 static void gc_putc_getpars(unsigned char ch
);
280 static void gc_putc_gotpars(unsigned char ch
);
281 static void gc_putc_normal(unsigned char ch
);
282 static void gc_putc_square(unsigned char ch
);
283 static void gc_reset_screen(void);
284 static void gc_reset_tabs(void);
285 static void gc_reset_vt100(void);
286 static void gc_scroll_down(int num
, unsigned int top
, unsigned int bottom
);
287 static void gc_scroll_up(int num
, unsigned int top
, unsigned int bottom
);
288 static void gc_set_tab_stop(unsigned int column
, boolean_t enabled
);
289 static void gc_show_cursor(unsigned int xx
, unsigned int yy
);
290 static void gc_update_color(int color
, boolean_t fore
);
293 gc_clear_line(unsigned int xx
, unsigned int yy
, int which
)
295 unsigned int start
, end
, i
;
298 * This routine runs extremely slowly. I don't think it's
299 * used all that often, except for To end of line. I'll go
300 * back and speed this up when I speed up the whole vc
305 case 0: /* To end of line */
307 end
= vinfo
.v_columns
-1;
309 case 1: /* To start of line */
313 case 2: /* Whole line */
315 end
= vinfo
.v_columns
-1;
321 for (i
= start
; i
<= end
; i
++) {
322 gc_paint_char(i
, yy
, ' ', ATTR_NONE
);
327 gc_clear_screen(unsigned int xx
, unsigned int yy
, int top
, unsigned int bottom
,
330 if (!gc_buffer_size
) return;
332 if ( xx
< gc_buffer_columns
&& yy
< gc_buffer_rows
&& bottom
<= gc_buffer_rows
)
337 case 0: /* To end of screen */
338 start
= (yy
* gc_buffer_columns
) + xx
;
339 end
= (bottom
* gc_buffer_columns
) - 1;
341 case 1: /* To start of screen */
342 start
= (top
* gc_buffer_columns
);
343 end
= (yy
* gc_buffer_columns
) + xx
;
345 case 2: /* Whole screen */
346 start
= (top
* gc_buffer_columns
);
347 end
= (bottom
* gc_buffer_columns
) - 1;
355 memset(gc_buffer_attributes
+ start
, ATTR_NONE
, end
- start
+ 1);
356 memset(gc_buffer_characters
+ start
, ' ', end
- start
+ 1);
357 memset(gc_buffer_colorcodes
+ start
, gc_color_code
, end
- start
+ 1);
360 gc_ops
.clear_screen(xx
, yy
, top
, bottom
, which
);
364 gc_enable( boolean_t enable
)
366 unsigned char *buffer_attributes
= NULL
;
367 unsigned char *buffer_characters
= NULL
;
368 unsigned char *buffer_colorcodes
= NULL
;
369 unsigned char *buffer_tab_stops
= NULL
;
370 uint32_t buffer_columns
= 0;
371 uint32_t buffer_rows
= 0;
372 uint32_t buffer_size
= 0;
375 if ( enable
== FALSE
)
377 // only disable console output if it goes to the graphics console
378 if ( console_is_serial() == FALSE
)
379 disableConsoleOutput
= TRUE
;
381 gc_ops
.enable(FALSE
);
387 if ( gc_buffer_size
)
389 buffer_attributes
= gc_buffer_attributes
;
390 buffer_characters
= gc_buffer_characters
;
391 buffer_colorcodes
= gc_buffer_colorcodes
;
392 buffer_tab_stops
= gc_buffer_tab_stops
;
393 buffer_columns
= gc_buffer_columns
;
394 buffer_rows
= gc_buffer_rows
;
395 buffer_size
= gc_buffer_size
;
397 gc_buffer_attributes
= NULL
;
398 gc_buffer_characters
= NULL
;
399 gc_buffer_colorcodes
= NULL
;
400 gc_buffer_tab_stops
= NULL
;
401 gc_buffer_columns
= 0;
405 VCPUTC_LOCK_UNLOCK( );
408 kfree( buffer_attributes
, buffer_size
);
409 kfree( buffer_characters
, buffer_size
);
410 kfree( buffer_colorcodes
, buffer_size
);
411 kfree( buffer_tab_stops
, buffer_columns
);
415 VCPUTC_LOCK_UNLOCK( );
421 if ( vm_initialized
)
423 buffer_columns
= vinfo
.v_columns
;
424 buffer_rows
= vinfo
.v_rows
;
425 buffer_size
= buffer_columns
* buffer_rows
;
429 buffer_attributes
= (unsigned char *) kalloc( buffer_size
);
430 buffer_characters
= (unsigned char *) kalloc( buffer_size
);
431 buffer_colorcodes
= (unsigned char *) kalloc( buffer_size
);
432 buffer_tab_stops
= (unsigned char *) kalloc( buffer_columns
);
434 if ( buffer_attributes
== NULL
||
435 buffer_characters
== NULL
||
436 buffer_colorcodes
== NULL
||
437 buffer_tab_stops
== NULL
)
439 if ( buffer_attributes
) kfree( buffer_attributes
, buffer_size
);
440 if ( buffer_characters
) kfree( buffer_characters
, buffer_size
);
441 if ( buffer_colorcodes
) kfree( buffer_colorcodes
, buffer_size
);
442 if ( buffer_tab_stops
) kfree( buffer_tab_stops
, buffer_columns
);
444 buffer_attributes
= NULL
;
445 buffer_characters
= NULL
;
446 buffer_colorcodes
= NULL
;
447 buffer_tab_stops
= NULL
;
454 memset( buffer_attributes
, ATTR_NONE
, buffer_size
);
455 memset( buffer_characters
, ' ', buffer_size
);
456 memset( buffer_colorcodes
, COLOR_CODE_SET( 0, COLOR_FOREGROUND
, TRUE
), buffer_size
);
457 memset( buffer_tab_stops
, 0, buffer_columns
);
465 gc_buffer_attributes
= buffer_attributes
;
466 gc_buffer_characters
= buffer_characters
;
467 gc_buffer_colorcodes
= buffer_colorcodes
;
468 gc_buffer_tab_stops
= buffer_tab_stops
;
469 gc_buffer_columns
= buffer_columns
;
470 gc_buffer_rows
= buffer_rows
;
471 gc_buffer_size
= buffer_size
;
475 VCPUTC_LOCK_UNLOCK( );
478 gc_ops
.clear_screen(gc_x
, gc_y
, 0, vinfo
.v_rows
, 2);
479 gc_ops
.show_cursor(gc_x
, gc_y
);
483 disableConsoleOutput
= FALSE
;
488 gc_hide_cursor(unsigned int xx
, unsigned int yy
)
490 if ( xx
< gc_buffer_columns
&& yy
< gc_buffer_rows
)
492 uint32_t index
= (yy
* gc_buffer_columns
) + xx
;
493 unsigned char attribute
= gc_buffer_attributes
[index
];
494 unsigned char character
= gc_buffer_characters
[index
];
495 unsigned char colorcode
= gc_buffer_colorcodes
[index
];
496 unsigned char colorcodesave
= gc_color_code
;
498 gc_update_color(COLOR_CODE_GET(colorcode
, TRUE
), TRUE
);
499 gc_update_color(COLOR_CODE_GET(colorcode
, FALSE
), FALSE
);
501 gc_ops
.paint_char(xx
, yy
, character
, attribute
, 0, 0);
503 gc_update_color(COLOR_CODE_GET(colorcodesave
, TRUE
), TRUE
);
504 gc_update_color(COLOR_CODE_GET(colorcodesave
, FALSE
), FALSE
);
508 gc_ops
.hide_cursor(xx
, yy
);
513 gc_initialize(struct vc_info
* info
)
515 if ( gc_initialized
== FALSE
)
520 gc_initialized
= TRUE
;
523 gc_ops
.initialize(info
);
530 gc_paint_char(unsigned int xx
, unsigned int yy
, unsigned char ch
, int attrs
)
532 if ( xx
< gc_buffer_columns
&& yy
< gc_buffer_rows
)
534 uint32_t index
= (yy
* gc_buffer_columns
) + xx
;
536 gc_buffer_attributes
[index
] = attrs
;
537 gc_buffer_characters
[index
] = ch
;
538 gc_buffer_colorcodes
[index
] = gc_color_code
;
541 gc_ops
.paint_char(xx
, yy
, ch
, attrs
, 0, 0);
548 return; /* ignore null characters */
550 switch (gc_vt100state
) {
551 default:gc_vt100state
= ESnormal
; /* FALLTHROUGH */
571 gc_putc_charsizecmd(ch
);
574 gc_putc_charsetcmd(0, ch
);
577 gc_putc_charsetcmd(1, ch
);
581 if (gc_x
>= vinfo
.v_columns
) {
582 if (0 == vinfo
.v_columns
)
585 gc_x
= vinfo
.v_columns
- 1;
587 if (gc_y
>= vinfo
.v_rows
) {
588 if (0 == vinfo
.v_rows
)
591 gc_y
= vinfo
.v_rows
- 1;
596 gc_putc_askcmd(unsigned char ch
)
598 if (ch
>= '0' && ch
<= '9') {
599 gc_par
[gc_numpars
] = (10*gc_par
[gc_numpars
]) + (ch
-'0');
602 gc_vt100state
= ESnormal
;
606 gc_relative_origin
= ch
== 'h';
608 case 7: /* wrap around mode h=1, l=0*/
609 gc_wrap_mode
= ch
== 'h';
618 gc_putc_charsetcmd(int charset
, unsigned char ch
)
620 gc_vt100state
= ESnormal
;
626 gc_charset
[charset
] = 0;
628 case '0' : /* Graphic characters */
630 gc_charset
[charset
] = 0x21;
637 gc_putc_charsizecmd(unsigned char ch
)
639 gc_vt100state
= ESnormal
;
647 case '8' : /* fill 'E's */
650 for (yy
= 0; yy
< vinfo
.v_rows
; yy
++)
651 for (xx
= 0; xx
< vinfo
.v_columns
; xx
++)
652 gc_paint_char(xx
, yy
, 'E', ATTR_NONE
);
660 gc_putc_esc(unsigned char ch
)
662 gc_vt100state
= ESnormal
;
666 gc_vt100state
= ESsquare
;
668 case 'c': /* Reset terminal */
670 gc_clear_screen(gc_x
, gc_y
, 0, vinfo
.v_rows
, 2);
673 case 'D': /* Line feed */
675 if (gc_y
>= gc_scrreg_bottom
-1) {
676 gc_scroll_up(1, gc_scrreg_top
, gc_scrreg_bottom
);
677 gc_y
= gc_scrreg_bottom
- 1;
681 if (ch
== 'E') gc_x
= 0;
683 case 'H': /* Set tab stop */
684 gc_set_tab_stop(gc_x
, TRUE
);
686 case 'M': /* Cursor up */
687 if (gc_y
<= gc_scrreg_top
) {
688 gc_scroll_down(1, gc_scrreg_top
, gc_scrreg_bottom
);
689 gc_y
= gc_scrreg_top
;
697 case '7': /* Save cursor */
700 gc_saveattr
= gc_attr
;
701 gc_save_charset_s
= gc_charset_select
;
702 gc_charset_save
[0] = gc_charset
[0];
703 gc_charset_save
[1] = gc_charset
[1];
705 case '8': /* Restore cursor */
708 gc_attr
= gc_saveattr
;
709 gc_charset_select
= gc_save_charset_s
;
710 gc_charset
[0] = gc_charset_save
[0];
711 gc_charset
[1] = gc_charset_save
[1];
713 case 'Z': /* return terminal ID */
715 case '#': /* change characters height */
716 gc_vt100state
= EScharsize
;
719 gc_vt100state
= ESsetG0
;
721 case ')': /* character set sequence */
722 gc_vt100state
= ESsetG1
;
727 /* Rest not supported */
734 gc_putc_getpars(unsigned char ch
)
737 gc_vt100state
= ESask
;
741 gc_vt100state
= ESnormal
;
745 if (ch
== ';' && gc_numpars
< MAXPARS
- 1) {
748 if (ch
>= '0' && ch
<= '9') {
749 gc_par
[gc_numpars
] *= 10;
750 gc_par
[gc_numpars
] += ch
- '0';
753 gc_vt100state
= ESgotpars
;
759 gc_putc_gotpars(unsigned char ch
)
764 /* special case for vttest for handling cursor
765 movement in escape sequences */
767 gc_vt100state
= ESgotpars
;
770 gc_vt100state
= ESnormal
;
773 gc_y
-= gc_par
[0] ? gc_par
[0] : 1;
774 if (gc_y
< gc_scrreg_top
)
775 gc_y
= gc_scrreg_top
;
778 gc_y
+= gc_par
[0] ? gc_par
[0] : 1;
779 if (gc_y
>= gc_scrreg_bottom
)
780 gc_y
= gc_scrreg_bottom
- 1;
782 case 'C': /* Right */
783 gc_x
+= gc_par
[0] ? gc_par
[0] : 1;
784 if (gc_x
>= vinfo
.v_columns
)
785 gc_x
= vinfo
.v_columns
-1;
788 if (gc_par
[0] > gc_x
)
795 case 'H': /* Set cursor position */
797 gc_x
= gc_par
[1] ? gc_par
[1] - 1 : 0;
798 gc_y
= gc_par
[0] ? gc_par
[0] - 1 : 0;
799 if (gc_relative_origin
)
800 gc_y
+= gc_scrreg_top
;
801 gc_hanging_cursor
= 0;
803 case 'X': /* clear p1 characters */
805 for (i
= gc_x
; i
< gc_x
+ gc_par
[0]; i
++)
806 gc_paint_char(i
, gc_y
, ' ', ATTR_NONE
);
809 case 'J': /* Clear part of screen */
810 gc_clear_screen(gc_x
, gc_y
, 0, vinfo
.v_rows
, gc_par
[0]);
812 case 'K': /* Clear part of line */
813 gc_clear_line(gc_x
, gc_y
, gc_par
[0]);
815 case 'g': /* tab stops */
818 case 2: /* reset tab stops */
819 /* gc_reset_tabs(); */
821 case 3: /* Clear every tabs */
823 for (i
= 0; i
<= vinfo
.v_columns
; i
++)
824 gc_set_tab_stop(i
, FALSE
);
828 gc_set_tab_stop(gc_x
, FALSE
);
832 case 'm': /* Set attribute */
833 for (i
= 0; i
< gc_numpars
; i
++) {
837 gc_update_color(COLOR_BACKGROUND
, FALSE
);
838 gc_update_color(COLOR_FOREGROUND
, TRUE
);
841 gc_attr
|= ATTR_BOLD
;
844 gc_attr
|= ATTR_UNDER
;
847 gc_attr
|= ATTR_REVERSE
;
850 gc_attr
&= ~ATTR_BOLD
;
853 gc_attr
&= ~ATTR_UNDER
;
856 gc_attr
&= ~ATTR_REVERSE
;
859 case 25: /* blink/no blink */
862 if (gc_par
[i
] >= 30 && gc_par
[i
] <= 37)
863 gc_update_color(gc_par
[i
] - 30, TRUE
);
864 if (gc_par
[i
] >= 40 && gc_par
[i
] <= 47)
865 gc_update_color(gc_par
[i
] - 40, FALSE
);
870 case 'r': /* Set scroll region */
872 /* ensure top < bottom, and both within limits */
873 if ((gc_numpars
> 0) && (gc_par
[0] < vinfo
.v_rows
)) {
874 gc_scrreg_top
= gc_par
[0] ? gc_par
[0] - 1 : 0;
878 if ((gc_numpars
> 1) && (gc_par
[1] <= vinfo
.v_rows
) && (gc_par
[1] > gc_par
[0])) {
879 gc_scrreg_bottom
= gc_par
[1];
880 if (gc_scrreg_bottom
> vinfo
.v_rows
)
881 gc_scrreg_bottom
= vinfo
.v_rows
;
883 gc_scrreg_bottom
= vinfo
.v_rows
;
885 if (gc_relative_origin
)
886 gc_y
= gc_scrreg_top
;
893 gc_putc_normal(unsigned char ch
)
896 case '\a': /* Beep */
898 case 127: /* Delete */
899 case '\b': /* Backspace */
900 if (gc_hanging_cursor
) {
901 gc_hanging_cursor
= 0;
908 if (gc_buffer_tab_stops
) while (gc_x
< vinfo
.v_columns
&& !gc_is_tab_stop(++gc_x
));
910 if (gc_x
>= vinfo
.v_columns
)
911 gc_x
= vinfo
.v_columns
-1;
915 case '\n': /* Line feed */
916 if (gc_y
>= gc_scrreg_bottom
-1 ) {
917 gc_scroll_up(1, gc_scrreg_top
, gc_scrreg_bottom
);
918 gc_y
= gc_scrreg_bottom
- 1;
923 case '\r': /* Carriage return */
925 gc_hanging_cursor
= 0;
927 case 0x0e: /* Select G1 charset (Control-N) */
928 gc_charset_select
= 1;
930 case 0x0f: /* Select G0 charset (Control-O) */
931 gc_charset_select
= 0;
933 case 0x18 : /* CAN : cancel */
934 case 0x1A : /* like cancel */
935 /* well, i do nothing here, may be later */
937 case '\033': /* Escape */
938 gc_vt100state
= ESesc
;
939 gc_hanging_cursor
= 0;
943 if (gc_hanging_cursor
) {
945 if (gc_y
>= gc_scrreg_bottom
-1 ) {
946 gc_scroll_up(1, gc_scrreg_top
, gc_scrreg_bottom
);
947 gc_y
= gc_scrreg_bottom
- 1;
951 gc_hanging_cursor
= 0;
953 gc_paint_char(gc_x
, gc_y
, (ch
>= 0x60 && ch
<= 0x7f) ? ch
+ gc_charset
[gc_charset_select
]
955 if (gc_x
== vinfo
.v_columns
- 1) {
956 gc_hanging_cursor
= gc_wrap_mode
;
967 gc_putc_square(unsigned char ch
)
971 for (i
= 0; i
< MAXPARS
; i
++) {
976 gc_vt100state
= ESgetpars
;
983 gc_reset_screen(void)
994 if (!gc_buffer_tab_stops
) return;
996 for (i
= 0; i
< vinfo
.v_columns
; i
++) {
997 gc_buffer_tab_stops
[i
] = ((i
% 8) == 0);
1003 gc_set_tab_stop(unsigned int column
, boolean_t enabled
)
1005 if (gc_buffer_tab_stops
&& (column
< vinfo
.v_columns
)) {
1006 gc_buffer_tab_stops
[column
] = enabled
;
1010 static boolean_t
gc_is_tab_stop(unsigned int column
)
1012 if (gc_buffer_tab_stops
== NULL
)
1013 return ((column
% 8) == 0);
1014 if (column
< vinfo
.v_columns
)
1015 return gc_buffer_tab_stops
[column
];
1021 gc_reset_vt100(void)
1025 gc_scrreg_bottom
= vinfo
.v_rows
;
1026 gc_attr
= ATTR_NONE
;
1027 gc_charset
[0] = gc_charset
[1] = 0;
1028 gc_charset_select
= 0;
1030 gc_relative_origin
= 0;
1031 gc_update_color(COLOR_BACKGROUND
, FALSE
);
1032 gc_update_color(COLOR_FOREGROUND
, TRUE
);
1036 gc_scroll_down(int num
, unsigned int top
, unsigned int bottom
)
1038 if (!gc_buffer_size
) return;
1040 if ( bottom
<= gc_buffer_rows
)
1042 unsigned char colorcodesave
= gc_color_code
;
1043 uint32_t column
, row
;
1044 uint32_t index
, jump
;
1046 jump
= num
* gc_buffer_columns
;
1048 for ( row
= bottom
- 1 ; row
>= top
+ num
; row
-- )
1050 index
= row
* gc_buffer_columns
;
1052 for ( column
= 0 ; column
< gc_buffer_columns
; index
++, column
++ )
1054 if ( gc_buffer_attributes
[index
] != gc_buffer_attributes
[index
- jump
] ||
1055 gc_buffer_characters
[index
] != gc_buffer_characters
[index
- jump
] ||
1056 gc_buffer_colorcodes
[index
] != gc_buffer_colorcodes
[index
- jump
] )
1058 if ( gc_color_code
!= gc_buffer_colorcodes
[index
- jump
] )
1060 gc_update_color(COLOR_CODE_GET(gc_buffer_colorcodes
[index
- jump
], TRUE
), TRUE
);
1061 gc_update_color(COLOR_CODE_GET(gc_buffer_colorcodes
[index
- jump
], FALSE
), FALSE
);
1064 if ( gc_buffer_colorcodes
[index
] != gc_buffer_colorcodes
[index
- jump
] )
1066 gc_ops
.paint_char( /* xx */ column
,
1068 /* ch */ gc_buffer_characters
[index
- jump
],
1069 /* attrs */ gc_buffer_attributes
[index
- jump
],
1070 /* ch_previous */ 0,
1071 /* attrs_previous */ 0 );
1075 gc_ops
.paint_char( /* xx */ column
,
1077 /* ch */ gc_buffer_characters
[index
- jump
],
1078 /* attrs */ gc_buffer_attributes
[index
- jump
],
1079 /* ch_previous */ gc_buffer_characters
[index
],
1080 /* attrs_previous */ gc_buffer_attributes
[index
] );
1083 gc_buffer_attributes
[index
] = gc_buffer_attributes
[index
- jump
];
1084 gc_buffer_characters
[index
] = gc_buffer_characters
[index
- jump
];
1085 gc_buffer_colorcodes
[index
] = gc_buffer_colorcodes
[index
- jump
];
1090 if ( colorcodesave
!= gc_color_code
)
1092 gc_update_color(COLOR_CODE_GET(colorcodesave
, TRUE
), TRUE
);
1093 gc_update_color(COLOR_CODE_GET(colorcodesave
, FALSE
), FALSE
);
1096 /* Now set the freed up lines to the background colour */
1098 for ( row
= top
; row
< top
+ num
; row
++ )
1100 index
= row
* gc_buffer_columns
;
1102 for ( column
= 0 ; column
< gc_buffer_columns
; index
++, column
++ )
1104 if ( gc_buffer_attributes
[index
] != ATTR_NONE
||
1105 gc_buffer_characters
[index
] != ' ' ||
1106 gc_buffer_colorcodes
[index
] != gc_color_code
)
1108 if ( gc_buffer_colorcodes
[index
] != gc_color_code
)
1110 gc_ops
.paint_char( /* xx */ column
,
1113 /* attrs */ ATTR_NONE
,
1114 /* ch_previous */ 0,
1115 /* attrs_previous */ 0 );
1119 gc_ops
.paint_char( /* xx */ column
,
1122 /* attrs */ ATTR_NONE
,
1123 /* ch_previous */ gc_buffer_characters
[index
],
1124 /* attrs_previous */ gc_buffer_attributes
[index
] );
1127 gc_buffer_attributes
[index
] = ATTR_NONE
;
1128 gc_buffer_characters
[index
] = ' ';
1129 gc_buffer_colorcodes
[index
] = gc_color_code
;
1136 gc_ops
.scroll_down(num
, top
, bottom
);
1138 /* Now set the freed up lines to the background colour */
1140 gc_clear_screen(vinfo
.v_columns
- 1, top
+ num
- 1, top
, bottom
, 1);
1145 gc_scroll_up(int num
, unsigned int top
, unsigned int bottom
)
1147 if (!gc_buffer_size
) return;
1149 if ( bottom
<= gc_buffer_rows
)
1151 unsigned char colorcodesave
= gc_color_code
;
1152 uint32_t column
, row
;
1153 uint32_t index
, jump
;
1155 jump
= num
* gc_buffer_columns
;
1157 for ( row
= top
; row
< bottom
- num
; row
++ )
1159 index
= row
* gc_buffer_columns
;
1161 for ( column
= 0 ; column
< gc_buffer_columns
; index
++, column
++ )
1163 if ( gc_buffer_attributes
[index
] != gc_buffer_attributes
[index
+ jump
] ||
1164 gc_buffer_characters
[index
] != gc_buffer_characters
[index
+ jump
] ||
1165 gc_buffer_colorcodes
[index
] != gc_buffer_colorcodes
[index
+ jump
] )
1167 if ( gc_color_code
!= gc_buffer_colorcodes
[index
+ jump
] )
1169 gc_update_color(COLOR_CODE_GET(gc_buffer_colorcodes
[index
+ jump
], TRUE
), TRUE
);
1170 gc_update_color(COLOR_CODE_GET(gc_buffer_colorcodes
[index
+ jump
], FALSE
), FALSE
);
1173 if ( gc_buffer_colorcodes
[index
] != gc_buffer_colorcodes
[index
+ jump
] )
1175 gc_ops
.paint_char( /* xx */ column
,
1177 /* ch */ gc_buffer_characters
[index
+ jump
],
1178 /* attrs */ gc_buffer_attributes
[index
+ jump
],
1179 /* ch_previous */ 0,
1180 /* attrs_previous */ 0 );
1184 gc_ops
.paint_char( /* xx */ column
,
1186 /* ch */ gc_buffer_characters
[index
+ jump
],
1187 /* attrs */ gc_buffer_attributes
[index
+ jump
],
1188 /* ch_previous */ gc_buffer_characters
[index
],
1189 /* attrs_previous */ gc_buffer_attributes
[index
] );
1192 gc_buffer_attributes
[index
] = gc_buffer_attributes
[index
+ jump
];
1193 gc_buffer_characters
[index
] = gc_buffer_characters
[index
+ jump
];
1194 gc_buffer_colorcodes
[index
] = gc_buffer_colorcodes
[index
+ jump
];
1199 if ( colorcodesave
!= gc_color_code
)
1201 gc_update_color(COLOR_CODE_GET(colorcodesave
, TRUE
), TRUE
);
1202 gc_update_color(COLOR_CODE_GET(colorcodesave
, FALSE
), FALSE
);
1205 /* Now set the freed up lines to the background colour */
1207 for ( row
= bottom
- num
; row
< bottom
; row
++ )
1209 index
= row
* gc_buffer_columns
;
1211 for ( column
= 0 ; column
< gc_buffer_columns
; index
++, column
++ )
1213 if ( gc_buffer_attributes
[index
] != ATTR_NONE
||
1214 gc_buffer_characters
[index
] != ' ' ||
1215 gc_buffer_colorcodes
[index
] != gc_color_code
)
1217 if ( gc_buffer_colorcodes
[index
] != gc_color_code
)
1219 gc_ops
.paint_char( /* xx */ column
,
1222 /* attrs */ ATTR_NONE
,
1223 /* ch_previous */ 0,
1224 /* attrs_previous */ 0 );
1228 gc_ops
.paint_char( /* xx */ column
,
1231 /* attrs */ ATTR_NONE
,
1232 /* ch_previous */ gc_buffer_characters
[index
],
1233 /* attrs_previous */ gc_buffer_attributes
[index
] );
1236 gc_buffer_attributes
[index
] = ATTR_NONE
;
1237 gc_buffer_characters
[index
] = ' ';
1238 gc_buffer_colorcodes
[index
] = gc_color_code
;
1245 gc_ops
.scroll_up(num
, top
, bottom
);
1247 /* Now set the freed up lines to the background colour */
1249 gc_clear_screen(0, bottom
- num
, top
, bottom
, 0);
1254 gc_show_cursor(unsigned int xx
, unsigned int yy
)
1256 if ( xx
< gc_buffer_columns
&& yy
< gc_buffer_rows
)
1258 uint32_t index
= (yy
* gc_buffer_columns
) + xx
;
1259 unsigned char attribute
= gc_buffer_attributes
[index
];
1260 unsigned char character
= gc_buffer_characters
[index
];
1261 unsigned char colorcode
= gc_buffer_colorcodes
[index
];
1262 unsigned char colorcodesave
= gc_color_code
;
1264 gc_update_color(COLOR_CODE_GET(colorcode
, FALSE
), TRUE
);
1265 gc_update_color(COLOR_CODE_GET(colorcode
, TRUE
), FALSE
);
1267 gc_ops
.paint_char(xx
, yy
, character
, attribute
, 0, 0);
1269 gc_update_color(COLOR_CODE_GET(colorcodesave
, TRUE
), TRUE
);
1270 gc_update_color(COLOR_CODE_GET(colorcodesave
, FALSE
), FALSE
);
1274 gc_ops
.show_cursor(xx
, yy
);
1279 gc_update_color(int color
, boolean_t fore
)
1281 assert(gc_ops
.update_color
);
1283 gc_color_code
= COLOR_CODE_SET(gc_color_code
, color
, fore
);
1284 gc_ops
.update_color(color
, fore
);
1288 vcputc(__unused
int l
, __unused
int u
, int c
)
1290 if ( gc_initialized
&& ( gc_enabled
|| debug_mode
) )
1295 #if defined(__i386__) || defined(__x86_64__)
1296 x86_filter_TLB_coherency_interrupts(TRUE
);
1299 if ( gc_enabled
|| debug_mode
)
1301 gc_hide_cursor(gc_x
, gc_y
);
1303 gc_show_cursor(gc_x
, gc_y
);
1305 VCPUTC_LOCK_UNLOCK();
1306 #if defined(__i386__) || defined(__x86_64__)
1307 x86_filter_TLB_coherency_interrupts(FALSE
);
1314 * Video Console (Back-End)
1315 * ------------------------
1319 * For the color support (Michel Pollet)
1321 static unsigned char vc_color_index_table
[33] =
1322 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1323 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 2 };
1325 static uint32_t vc_colors
[8][4] = {
1326 { 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000 }, /* black */
1327 { 0x23232323, 0x7C007C00, 0x00FF0000, 0x3FF00000 }, /* red */
1328 { 0xb9b9b9b9, 0x03e003e0, 0x0000FF00, 0x000FFC00 }, /* green */
1329 { 0x05050505, 0x7FE07FE0, 0x00FFFF00, 0x3FFFFC00 }, /* yellow */
1330 { 0xd2d2d2d2, 0x001f001f, 0x000000FF, 0x000003FF }, /* blue */
1331 // { 0x80808080, 0x31933193, 0x00666699, 0x00000000 }, /* blue */
1332 { 0x18181818, 0x7C1F7C1F, 0x00FF00FF, 0x3FF003FF }, /* magenta */
1333 { 0xb4b4b4b4, 0x03FF03FF, 0x0000FFFF, 0x000FFFFF }, /* cyan */
1334 { 0x00000000, 0x7FFF7FFF, 0x00FFFFFF, 0x3FFFFFFF } /* white */
1337 static uint32_t vc_color_fore
= 0;
1338 static uint32_t vc_color_back
= 0;
1341 * New Rendering code from Michel Pollet
1344 /* Rendered Font Buffer */
1345 static unsigned char *vc_rendered_font
= NULL
;
1347 /* Rendered Font Size */
1348 static uint32_t vc_rendered_font_size
= 0;
1350 /* Size of a character in the table (bytes) */
1351 static int vc_rendered_char_size
= 0;
1353 #define REN_MAX_DEPTH 32
1354 static unsigned char vc_rendered_char
[ISO_CHAR_HEIGHT
* ((REN_MAX_DEPTH
/ 8) * ISO_CHAR_WIDTH
)];
1357 internal_set_progressmeter(int new_value
);
1359 internal_enable_progressmeter(int new_value
);
1363 kProgressMeterOff
= FALSE
,
1364 kProgressMeterUser
= TRUE
,
1365 kProgressMeterKernel
= 3,
1369 kProgressMeterMax
= 1024,
1370 kProgressMeterEnd
= 512,
1374 static boolean_t vc_progress_white
=
1375 #ifdef CONFIG_VC_PROGRESS_WHITE
1377 #else /* !CONFIG_VC_PROGRESS_WHITE */
1379 #endif /* !CONFIG_VC_PROGRESS_WHITE */
1381 static int vc_acquire_delay
= kProgressAcquireDelay
;
1384 vc_clear_screen(unsigned int xx
, unsigned int yy
, unsigned int scrreg_top
,
1385 unsigned int scrreg_bottom
, int which
)
1387 uint32_t *p
, *endp
, *row
;
1389 int rowline
, rowlongs
;
1394 linelongs
= vinfo
.v_rowbytes
* (ISO_CHAR_HEIGHT
>> 2);
1395 rowline
= vinfo
.v_rowscanbytes
>> 2;
1396 rowlongs
= vinfo
.v_rowbytes
>> 2;
1398 p
= (uint32_t*) vinfo
.v_baseaddr
;
1399 endp
= (uint32_t*) vinfo
.v_baseaddr
;
1402 case 0: /* To end of screen */
1403 gc_clear_line(xx
, yy
, 0);
1404 if (yy
< scrreg_bottom
- 1) {
1405 p
+= (yy
+ 1) * linelongs
;
1406 endp
+= scrreg_bottom
* linelongs
;
1409 case 1: /* To start of screen */
1410 gc_clear_line(xx
, yy
, 1);
1411 if (yy
> scrreg_top
) {
1412 p
+= scrreg_top
* linelongs
;
1413 endp
+= yy
* linelongs
;
1416 case 2: /* Whole screen */
1417 p
+= scrreg_top
* linelongs
;
1418 if (scrreg_bottom
== vinfo
.v_rows
) {
1419 endp
+= rowlongs
* vinfo
.v_height
;
1421 endp
+= scrreg_bottom
* linelongs
;
1426 for (row
= p
; row
< endp
; row
+= rowlongs
) {
1427 for (col
= 0; col
< rowline
; col
++)
1428 *(row
+col
) = vc_color_back
;
1433 vc_render_char(unsigned char ch
, unsigned char *renderptr
, short newdepth
)
1436 unsigned char *charptr
;
1437 unsigned short *shortptr
;
1439 } current
; /* current place in rendered font, multiple types. */
1440 unsigned char *theChar
; /* current char in iso_font */
1443 current
.charptr
= renderptr
;
1444 theChar
= iso_font
+ (ch
* ISO_CHAR_HEIGHT
);
1446 for (line
= 0; line
< ISO_CHAR_HEIGHT
; line
++) {
1447 unsigned char mask
= 1;
1451 *current
.charptr
++ = (*theChar
& mask
) ? 0xFF : 0;
1454 *current
.shortptr
++ = (*theChar
& mask
) ? 0xFFFF : 0;
1459 *current
.longptr
++ = (*theChar
& mask
) ? 0xFFFFFFFF : 0;
1463 } while (mask
); /* while the single bit drops to the right */
1469 vc_paint_char_8(unsigned int xx
, unsigned int yy
, unsigned char ch
, int attrs
,
1470 __unused
unsigned char ch_previous
, __unused
int attrs_previous
)
1476 if (vc_rendered_font
) {
1477 theChar
= (uint32_t*)(vc_rendered_font
+ (ch
* vc_rendered_char_size
));
1479 vc_render_char(ch
, vc_rendered_char
, 8);
1480 theChar
= (uint32_t*)(vc_rendered_char
);
1482 where
= (uint32_t*)(vinfo
.v_baseaddr
+
1483 (yy
* ISO_CHAR_HEIGHT
* vinfo
.v_rowbytes
) +
1484 (xx
* ISO_CHAR_WIDTH
));
1486 if (!attrs
) for (i
= 0; i
< ISO_CHAR_HEIGHT
; i
++) { /* No attr? FLY !*/
1487 uint32_t *store
= where
;
1489 for (x
= 0; x
< 2; x
++) {
1490 uint32_t val
= *theChar
++;
1491 val
= (vc_color_back
& ~val
) | (vc_color_fore
& val
);
1495 where
= (uint32_t*)(((unsigned char*)where
)+vinfo
.v_rowbytes
);
1496 } else for (i
= 0; i
< ISO_CHAR_HEIGHT
; i
++) { /* a little slower */
1497 uint32_t *store
= where
, lastpixel
= 0;
1499 for (x
= 0 ; x
< 2; x
++) {
1500 uint32_t val
= *theChar
++, save
= val
;
1501 if (attrs
& ATTR_BOLD
) { /* bold support */
1502 if (lastpixel
&& !(save
& 0xFF000000))
1504 if ((save
& 0xFFFF0000) == 0xFF000000)
1506 if ((save
& 0x00FFFF00) == 0x00FF0000)
1508 if ((save
& 0x0000FFFF) == 0x0000FF00)
1511 if (attrs
& ATTR_REVERSE
) val
= ~val
;
1512 if (attrs
& ATTR_UNDER
&& i
== ISO_CHAR_HEIGHT
-1) val
= ~val
;
1514 val
= (vc_color_back
& ~val
) | (vc_color_fore
& val
);
1516 lastpixel
= save
& 0xff;
1519 where
= (uint32_t*)(((unsigned char*)where
)+vinfo
.v_rowbytes
);
1525 vc_paint_char_16(unsigned int xx
, unsigned int yy
, unsigned char ch
, int attrs
,
1526 __unused
unsigned char ch_previous
,
1527 __unused
int attrs_previous
)
1533 if (vc_rendered_font
) {
1534 theChar
= (uint32_t*)(vc_rendered_font
+ (ch
* vc_rendered_char_size
));
1536 vc_render_char(ch
, vc_rendered_char
, 16);
1537 theChar
= (uint32_t*)(vc_rendered_char
);
1539 where
= (uint32_t*)(vinfo
.v_baseaddr
+
1540 (yy
* ISO_CHAR_HEIGHT
* vinfo
.v_rowbytes
) +
1541 (xx
* ISO_CHAR_WIDTH
* 2));
1543 if (!attrs
) for (i
= 0; i
< ISO_CHAR_HEIGHT
; i
++) { /* No attrs ? FLY ! */
1544 uint32_t *store
= where
;
1546 for (x
= 0; x
< 4; x
++) {
1547 uint32_t val
= *theChar
++;
1548 val
= (vc_color_back
& ~val
) | (vc_color_fore
& val
);
1552 where
= (uint32_t*)(((unsigned char*)where
)+vinfo
.v_rowbytes
);
1553 } else for (i
= 0; i
< ISO_CHAR_HEIGHT
; i
++) { /* a little bit slower */
1554 uint32_t *store
= where
, lastpixel
= 0;
1556 for (x
= 0 ; x
< 4; x
++) {
1557 uint32_t val
= *theChar
++, save
= val
;
1558 if (attrs
& ATTR_BOLD
) { /* bold support */
1559 if (save
== 0xFFFF0000) val
|= 0xFFFF;
1560 else if (lastpixel
&& !(save
& 0xFFFF0000))
1563 if (attrs
& ATTR_REVERSE
) val
= ~val
;
1564 if (attrs
& ATTR_UNDER
&& i
== ISO_CHAR_HEIGHT
-1) val
= ~val
;
1566 val
= (vc_color_back
& ~val
) | (vc_color_fore
& val
);
1569 lastpixel
= save
& 0x7fff;
1572 where
= (uint32_t*)(((unsigned char*)where
)+vinfo
.v_rowbytes
);
1578 vc_paint_char_32(unsigned int xx
, unsigned int yy
, unsigned char ch
, int attrs
,
1579 unsigned char ch_previous
, int attrs_previous
)
1582 uint32_t *theCharPrevious
;
1586 if (vc_rendered_font
) {
1587 theChar
= (uint32_t*)(vc_rendered_font
+ (ch
* vc_rendered_char_size
));
1588 theCharPrevious
= (uint32_t*)(vc_rendered_font
+ (ch_previous
* vc_rendered_char_size
));
1590 vc_render_char(ch
, vc_rendered_char
, 32);
1591 theChar
= (uint32_t*)(vc_rendered_char
);
1592 theCharPrevious
= NULL
;
1595 theCharPrevious
= NULL
;
1597 if (attrs_previous
) {
1598 theCharPrevious
= NULL
;
1600 where
= (uint32_t*)(vinfo
.v_baseaddr
+
1601 (yy
* ISO_CHAR_HEIGHT
* vinfo
.v_rowbytes
) +
1602 (xx
* ISO_CHAR_WIDTH
* 4));
1604 if (!attrs
) for (i
= 0; i
< ISO_CHAR_HEIGHT
; i
++) { /* No attrs ? FLY ! */
1605 uint32_t *store
= where
;
1607 for (x
= 0; x
< 8; x
++) {
1608 uint32_t val
= *theChar
++;
1609 if (theCharPrevious
== NULL
|| val
!= *theCharPrevious
++ ) {
1610 val
= (vc_color_back
& ~val
) | (vc_color_fore
& val
);
1617 where
= (uint32_t *)(((unsigned char*)where
)+vinfo
.v_rowbytes
);
1618 } else for (i
= 0; i
< ISO_CHAR_HEIGHT
; i
++) { /* a little slower */
1619 uint32_t *store
= where
, lastpixel
= 0;
1621 for (x
= 0 ; x
< 8; x
++) {
1622 uint32_t val
= *theChar
++, save
= val
;
1623 if (attrs
& ATTR_BOLD
) { /* bold support */
1624 if (lastpixel
&& !save
)
1627 if (attrs
& ATTR_REVERSE
) val
= ~val
;
1628 if (attrs
& ATTR_UNDER
&& i
== ISO_CHAR_HEIGHT
-1) val
= ~val
;
1630 val
= (vc_color_back
& ~val
) | (vc_color_fore
& val
);
1635 where
= (uint32_t*)(((unsigned char*)where
)+vinfo
.v_rowbytes
);
1641 vc_paint_char(unsigned int xx
, unsigned int yy
, unsigned char ch
, int attrs
,
1642 unsigned char ch_previous
, int attrs_previous
)
1647 switch(vinfo
.v_depth
) {
1649 vc_paint_char_8(xx
, yy
, ch
, attrs
, ch_previous
, attrs_previous
);
1652 vc_paint_char_16(xx
, yy
, ch
, attrs
, ch_previous
,
1657 vc_paint_char_32(xx
, yy
, ch
, attrs
, ch_previous
,
1664 vc_render_font(short newdepth
)
1666 static short olddepth
= 0;
1668 int charindex
; /* index in ISO font */
1669 unsigned char *rendered_font
;
1670 unsigned int rendered_font_size
;
1671 int rendered_char_size
;
1674 if (vm_initialized
== FALSE
) {
1675 return; /* nothing to do */
1677 if (olddepth
== newdepth
&& vc_rendered_font
) {
1678 return; /* nothing to do */
1684 rendered_font
= vc_rendered_font
;
1685 rendered_font_size
= vc_rendered_font_size
;
1686 rendered_char_size
= vc_rendered_char_size
;
1688 vc_rendered_font
= NULL
;
1689 vc_rendered_font_size
= 0;
1690 vc_rendered_char_size
= 0;
1692 VCPUTC_LOCK_UNLOCK();
1695 if (rendered_font
) {
1696 kfree(rendered_font
, rendered_font_size
);
1697 rendered_font
= NULL
;
1701 rendered_char_size
= ISO_CHAR_HEIGHT
* (((newdepth
+ 7) / 8) * ISO_CHAR_WIDTH
);
1702 rendered_font_size
= (ISO_CHAR_MAX
-ISO_CHAR_MIN
+1) * rendered_char_size
;
1703 rendered_font
= (unsigned char *) kalloc(rendered_font_size
);
1706 if (rendered_font
== NULL
) {
1710 for (charindex
= ISO_CHAR_MIN
; charindex
<= ISO_CHAR_MAX
; charindex
++) {
1711 vc_render_char(charindex
, rendered_font
+ (charindex
* rendered_char_size
), newdepth
);
1714 olddepth
= newdepth
;
1719 vc_rendered_font
= rendered_font
;
1720 vc_rendered_font_size
= rendered_font_size
;
1721 vc_rendered_char_size
= rendered_char_size
;
1723 VCPUTC_LOCK_UNLOCK();
1728 vc_enable(boolean_t enable
)
1730 vc_render_font(enable
? vinfo
.v_depth
: 0);
1734 vc_reverse_cursor(unsigned int xx
, unsigned int yy
)
1742 where
= (uint32_t*)(vinfo
.v_baseaddr
+
1743 (yy
* ISO_CHAR_HEIGHT
* vinfo
.v_rowbytes
) +
1744 (xx
/** ISO_CHAR_WIDTH*/ * vinfo
.v_depth
));
1745 for (line
= 0; line
< ISO_CHAR_HEIGHT
; line
++) {
1746 switch (vinfo
.v_depth
) {
1748 where
[0] = ~where
[0];
1749 where
[1] = ~where
[1];
1752 for (col
= 0; col
< 4; col
++)
1753 where
[col
] = ~where
[col
];
1756 for (col
= 0; col
< 8; col
++)
1757 where
[col
] = ~where
[col
];
1760 where
= (uint32_t*)(((unsigned char*)where
)+vinfo
.v_rowbytes
);
1765 vc_scroll_down(int num
, unsigned int scrreg_top
, unsigned int scrreg_bottom
)
1767 uint32_t *from
, *to
, linelongs
, i
, line
, rowline
, rowscanline
;
1772 linelongs
= vinfo
.v_rowbytes
* (ISO_CHAR_HEIGHT
>> 2);
1773 rowline
= vinfo
.v_rowbytes
>> 2;
1774 rowscanline
= vinfo
.v_rowscanbytes
>> 2;
1776 to
= (uint32_t *) vinfo
.v_baseaddr
+ (linelongs
* scrreg_bottom
)
1777 - (rowline
- rowscanline
);
1778 from
= to
- (linelongs
* num
); /* handle multiple line scroll (Michel Pollet) */
1780 i
= (scrreg_bottom
- scrreg_top
) - num
;
1783 for (line
= 0; line
< ISO_CHAR_HEIGHT
; line
++) {
1785 * Only copy what is displayed
1787 video_scroll_down(from
,
1788 (from
-(vinfo
.v_rowscanbytes
>> 2)),
1798 vc_scroll_up(int num
, unsigned int scrreg_top
, unsigned int scrreg_bottom
)
1800 uint32_t *from
, *to
, linelongs
, i
, line
, rowline
, rowscanline
;
1805 linelongs
= vinfo
.v_rowbytes
* (ISO_CHAR_HEIGHT
>> 2);
1806 rowline
= vinfo
.v_rowbytes
>> 2;
1807 rowscanline
= vinfo
.v_rowscanbytes
>> 2;
1809 to
= (uint32_t *) vinfo
.v_baseaddr
+ (scrreg_top
* linelongs
);
1810 from
= to
+ (linelongs
* num
); /* handle multiple line scroll (Michel Pollet) */
1812 i
= (scrreg_bottom
- scrreg_top
) - num
;
1815 for (line
= 0; line
< ISO_CHAR_HEIGHT
; line
++) {
1817 * Only copy what is displayed
1819 video_scroll_up(from
,
1820 (from
+(vinfo
.v_rowscanbytes
>> 2)),
1830 vc_update_color(int color
, boolean_t fore
)
1835 vc_color_fore
= vc_colors
[color
][vc_color_index_table
[vinfo
.v_depth
]];
1837 vc_color_back
= vc_colors
[color
][vc_color_index_table
[vinfo
.v_depth
]];
1842 * Video Console (Back-End): Icon Control
1843 * --------------------------------------
1846 static vc_progress_element
* vc_progress
;
1847 enum { kMaxProgressData
= 3 };
1848 static const unsigned char * vc_progress_data
[kMaxProgressData
];
1849 static const unsigned char * vc_progress_alpha
;
1850 static boolean_t vc_progress_enable
;
1851 static const unsigned char * vc_clut
;
1852 static const unsigned char * vc_clut8
;
1853 static unsigned char vc_revclut8
[256];
1854 static uint32_t vc_progress_interval
;
1855 static uint32_t vc_progress_count
;
1856 static uint32_t vc_progress_angle
;
1857 static uint64_t vc_progress_deadline
;
1858 static thread_call_data_t vc_progress_call
;
1859 static boolean_t vc_needsave
;
1860 static void * vc_saveunder
;
1861 static vm_size_t vc_saveunder_len
;
1862 static int8_t vc_uiscale
= 1;
1863 vc_progress_user_options vc_progress_options
;
1864 vc_progress_user_options vc_user_options
;
1866 decl_simple_lock_data(,vc_progress_lock
)
1868 static int vc_progress_withmeter
= 3;
1869 int vc_progressmeter_enable
;
1870 static int vc_progressmeter_drawn
;
1871 int vc_progressmeter_value
;
1872 static uint32_t vc_progressmeter_count
;
1873 static uint32_t vc_progress_meter_start
;
1874 static uint32_t vc_progress_meter_end
;
1875 static uint64_t vc_progressmeter_interval
;
1876 static uint64_t vc_progressmeter_deadline
;
1877 static thread_call_data_t vc_progressmeter_call
;
1878 static void * vc_progressmeter_backbuffer
;
1879 static boolean_t vc_progressmeter_hold
;
1880 static uint32_t vc_progressmeter_diskspeed
= 256;
1885 kDataIndexed
= 0x20,
1895 static void vc_blit_rect(int x
, int y
, int bx
,
1896 int width
, int height
,
1897 int sourceRow
, int backRow
,
1898 const unsigned char * dataPtr
,
1900 unsigned int flags
);
1901 static void vc_blit_rect_8(int x
, int y
, int bx
,
1902 int width
, int height
,
1903 int sourceRow
, int backRow
,
1904 const unsigned char * dataPtr
,
1905 unsigned char * backBuffer
,
1906 unsigned int flags
);
1907 static void vc_blit_rect_16(int x
, int y
, int bx
,
1908 int width
, int height
,
1909 int sourceRow
, int backRow
,
1910 const unsigned char * dataPtr
,
1911 unsigned short * backBuffer
,
1912 unsigned int flags
);
1913 static void vc_blit_rect_32(int x
, int y
, int bx
,
1914 int width
, int height
,
1915 int sourceRow
, int backRow
,
1916 const unsigned char * dataPtr
,
1917 unsigned int * backBuffer
,
1918 unsigned int flags
);
1919 static void vc_blit_rect_30(int x
, int y
, int bx
,
1920 int width
, int height
,
1921 int sourceRow
, int backRow
,
1922 const unsigned char * dataPtr
,
1923 unsigned int * backBuffer
,
1924 unsigned int flags
);
1925 static void vc_progress_task( void * arg0
, void * arg
);
1926 static void vc_progressmeter_task( void * arg0
, void * arg
);
1928 static void vc_blit_rect(int x
, int y
, int bx
,
1929 int width
, int height
,
1930 int sourceRow
, int backRow
,
1931 const unsigned char * dataPtr
,
1935 if (!vinfo
.v_depth
) return;
1936 if (((unsigned int)(x
+ width
)) > vinfo
.v_width
) return;
1937 if (((unsigned int)(y
+ height
)) > vinfo
.v_height
) return;
1939 switch( vinfo
.v_depth
) {
1941 if( vc_clut8
== vc_clut
)
1942 vc_blit_rect_8( x
, y
, bx
, width
, height
, sourceRow
, backRow
, dataPtr
, (unsigned char *) backBuffer
, flags
);
1945 vc_blit_rect_16( x
, y
, bx
, width
, height
, sourceRow
, backRow
, dataPtr
, (unsigned short *) backBuffer
, flags
);
1948 vc_blit_rect_32( x
, y
, bx
, width
, height
, sourceRow
, backRow
, dataPtr
, (unsigned int *) backBuffer
, flags
);
1951 vc_blit_rect_30( x
, y
, bx
, width
, height
, sourceRow
, backRow
, dataPtr
, (unsigned int *) backBuffer
, flags
);
1957 vc_blit_rect_8(int x
, int y
, __unused
int bx
,
1958 int width
, int height
,
1959 int sourceRow
, __unused
int backRow
,
1960 const unsigned char * dataPtr
,
1961 __unused
unsigned char * backBuffer
,
1962 __unused
unsigned int flags
)
1964 volatile unsigned short * dst
;
1966 unsigned int data
= 0, out
= 0;
1967 int sx
, sy
, a
, b
, c
, d
;
1968 int scale
= 0x10000;
1970 a
= vc_rotate_matr
[kDataRotate
& flags
][0][0] * scale
;
1971 b
= vc_rotate_matr
[kDataRotate
& flags
][0][1] * scale
;
1972 c
= vc_rotate_matr
[kDataRotate
& flags
][1][0] * scale
;
1973 d
= vc_rotate_matr
[kDataRotate
& flags
][1][1] * scale
;
1974 sx
= ((a
+ b
) < 0) ? ((width
* scale
) - 0x8000) : 0;
1975 sy
= ((c
+ d
) < 0) ? ((height
* scale
) - 0x8000) : 0;
1977 if (!sourceRow
) data
= (unsigned int)(uintptr_t)dataPtr
;
1978 else if (1 == sourceRow
) a
= 0;
1980 dst
= (volatile unsigned short *) (vinfo
.v_baseaddr
+
1981 (y
* vinfo
.v_rowbytes
) +
1984 for( line
= 0; line
< height
; line
++)
1986 for( col
= 0; col
< width
; col
++)
1988 if (sourceRow
) data
= dataPtr
[((sx
+ (col
* a
) + (line
* b
)) >> 16)
1989 + sourceRow
* (((sy
+ (col
* c
) + (line
* d
)) >> 16))];
1990 if (kDataAlpha
& flags
)
1991 out
= vc_revclut8
[data
];
1996 dst
= (volatile unsigned short *) (((volatile char*)dst
) + vinfo
.v_rowbytes
);
2000 /* For ARM, 16-bit is 565 (RGB); it is 1555 (XRGB) on other platforms */
2002 #define CLUT_MASK_R 0xf8
2003 #define CLUT_MASK_G 0xf8
2004 #define CLUT_MASK_B 0xf8
2005 #define CLUT_SHIFT_R << 7
2006 #define CLUT_SHIFT_G << 2
2007 #define CLUT_SHIFT_B >> 3
2008 #define MASK_R 0x7c00
2009 #define MASK_G 0x03e0
2010 #define MASK_B 0x001f
2011 #define MASK_R_8 0x3fc00
2012 #define MASK_G_8 0x01fe0
2013 #define MASK_B_8 0x000ff
2015 static void vc_blit_rect_16( int x
, int y
, int bx
,
2016 int width
, int height
,
2017 int sourceRow
, int backRow
,
2018 const unsigned char * dataPtr
,
2019 unsigned short * backPtr
,
2022 volatile unsigned short * dst
;
2024 unsigned int data
= 0, out
= 0, back
= 0;
2025 int sx
, sy
, a
, b
, c
, d
;
2026 int scale
= 0x10000;
2028 a
= vc_rotate_matr
[kDataRotate
& flags
][0][0] * scale
;
2029 b
= vc_rotate_matr
[kDataRotate
& flags
][0][1] * scale
;
2030 c
= vc_rotate_matr
[kDataRotate
& flags
][1][0] * scale
;
2031 d
= vc_rotate_matr
[kDataRotate
& flags
][1][1] * scale
;
2032 sx
= ((a
+ b
) < 0) ? ((width
* scale
) - 0x8000) : 0;
2033 sy
= ((c
+ d
) < 0) ? ((height
* scale
) - 0x8000) : 0;
2035 if (!sourceRow
) data
= (unsigned int)(uintptr_t)dataPtr
;
2036 else if (1 == sourceRow
) a
= 0;
2040 dst
= (volatile unsigned short *) (vinfo
.v_baseaddr
+
2041 (y
* vinfo
.v_rowbytes
) +
2044 for( line
= 0; line
< height
; line
++)
2046 for( col
= 0; col
< width
; col
++)
2048 if (sourceRow
) data
= dataPtr
[((sx
+ (col
* a
) + (line
* b
)) >> 16)
2049 + sourceRow
* (((sy
+ (col
* c
) + (line
* d
)) >> 16))];
2051 if (kSave
& flags
) {
2052 back
= *(dst
+ col
);
2057 if (kDataIndexed
& flags
) {
2058 out
= ( (CLUT_MASK_R
& (vc_clut
[data
*3 + 0])) CLUT_SHIFT_R
)
2059 | ( (CLUT_MASK_G
& (vc_clut
[data
*3 + 1])) CLUT_SHIFT_G
)
2060 | ( (CLUT_MASK_B
& (vc_clut
[data
*3 + 2])) CLUT_SHIFT_B
);
2061 } else if (kDataAlpha
& flags
) {
2062 out
= (((((back
& MASK_R
) * data
) + MASK_R_8
) >> 8) & MASK_R
)
2063 | (((((back
& MASK_G
) * data
) + MASK_G_8
) >> 8) & MASK_G
)
2064 | (((((back
& MASK_B
) * data
) + MASK_B_8
) >> 8) & MASK_B
);
2065 if (vc_progress_white
) out
+= (((0xff - data
) & CLUT_MASK_R
) CLUT_SHIFT_R
)
2066 | (((0xff - data
) & CLUT_MASK_G
) CLUT_SHIFT_G
)
2067 | (((0xff - data
) & CLUT_MASK_B
) CLUT_SHIFT_B
);
2068 } else if (kDataBack
& flags
)
2074 dst
= (volatile unsigned short *) (((volatile char*)dst
) + vinfo
.v_rowbytes
);
2076 backPtr
+= backRow
- width
;
2081 static void vc_blit_rect_32(int x
, int y
, int bx
,
2082 int width
, int height
,
2083 int sourceRow
, int backRow
,
2084 const unsigned char * dataPtr
,
2085 unsigned int * backPtr
,
2088 volatile unsigned int * dst
;
2090 unsigned int data
= 0, out
= 0, back
= 0;
2091 int sx
, sy
, a
, b
, c
, d
;
2092 int scale
= 0x10000;
2094 a
= vc_rotate_matr
[kDataRotate
& flags
][0][0] * scale
;
2095 b
= vc_rotate_matr
[kDataRotate
& flags
][0][1] * scale
;
2096 c
= vc_rotate_matr
[kDataRotate
& flags
][1][0] * scale
;
2097 d
= vc_rotate_matr
[kDataRotate
& flags
][1][1] * scale
;
2098 sx
= ((a
+ b
) < 0) ? ((width
* scale
) - 0x8000) : 0;
2099 sy
= ((c
+ d
) < 0) ? ((height
* scale
) - 0x8000) : 0;
2101 if (!sourceRow
) data
= (unsigned int)(uintptr_t)dataPtr
;
2102 else if (1 == sourceRow
) a
= 0;
2106 dst
= (volatile unsigned int *) (vinfo
.v_baseaddr
+
2107 (y
* vinfo
.v_rowbytes
) +
2110 for( line
= 0; line
< height
; line
++)
2112 for( col
= 0; col
< width
; col
++)
2114 if (sourceRow
) data
= dataPtr
[((sx
+ (col
* a
) + (line
* b
)) >> 16)
2115 + sourceRow
* (((sy
+ (col
* c
) + (line
* d
)) >> 16))];
2117 if (kSave
& flags
) {
2118 back
= *(dst
+ col
);
2123 if (kDataIndexed
& flags
) {
2124 out
= (vc_clut
[data
*3 + 0] << 16)
2125 | (vc_clut
[data
*3 + 1] << 8)
2126 | (vc_clut
[data
*3 + 2]);
2127 } else if (kDataAlpha
& flags
) {
2128 out
= (((((back
& 0x00ff00ff) * data
) + 0x00ff00ff) >> 8) & 0x00ff00ff)
2129 | (((((back
& 0x0000ff00) * data
) + 0x0000ff00) >> 8) & 0x0000ff00);
2130 if (vc_progress_white
) out
+= ((0xff - data
) << 16)
2131 | ((0xff - data
) << 8)
2133 } else if (kDataBack
& flags
)
2139 dst
= (volatile unsigned int *) (((volatile char*)dst
) + vinfo
.v_rowbytes
);
2141 backPtr
+= backRow
- width
;
2145 static void vc_blit_rect_30(int x
, int y
, int bx
,
2146 int width
, int height
,
2147 int sourceRow
, int backRow
,
2148 const unsigned char * dataPtr
,
2149 unsigned int * backPtr
,
2152 volatile unsigned int * dst
;
2154 unsigned int data
= 0, out
= 0, back
= 0;
2155 unsigned long long exp
;
2156 int sx
, sy
, a
, b
, c
, d
;
2157 int scale
= 0x10000;
2159 a
= vc_rotate_matr
[kDataRotate
& flags
][0][0] * scale
;
2160 b
= vc_rotate_matr
[kDataRotate
& flags
][0][1] * scale
;
2161 c
= vc_rotate_matr
[kDataRotate
& flags
][1][0] * scale
;
2162 d
= vc_rotate_matr
[kDataRotate
& flags
][1][1] * scale
;
2163 sx
= ((a
+ b
) < 0) ? ((width
* scale
) - 0x8000) : 0;
2164 sy
= ((c
+ d
) < 0) ? ((height
* scale
) - 0x8000) : 0;
2166 if (!sourceRow
) data
= (unsigned int)(uintptr_t)dataPtr
;
2167 else if (1 == sourceRow
) a
= 0;
2171 dst
= (volatile unsigned int *) (vinfo
.v_baseaddr
+
2172 (y
* vinfo
.v_rowbytes
) +
2175 for( line
= 0; line
< height
; line
++)
2177 for( col
= 0; col
< width
; col
++)
2179 if (sourceRow
) data
= dataPtr
[((sx
+ (col
* a
) + (line
* b
)) >> 16)
2180 + sourceRow
* (((sy
+ (col
* c
) + (line
* d
)) >> 16))];
2182 if (kSave
& flags
) {
2183 back
= *(dst
+ col
);
2188 if (kDataIndexed
& flags
) {
2189 out
= (vc_clut
[data
*3 + 0] << 22)
2190 | (vc_clut
[data
*3 + 1] << 12)
2191 | (vc_clut
[data
*3 + 2] << 2);
2192 } else if (kDataAlpha
& flags
) {
2194 exp
= (((((exp
& 0x3FF003FF) * data
) + 0x0FF000FF) >> 8) & 0x3FF003FF)
2195 | (((((exp
& 0x000FFC00) * data
) + 0x0003FC00) >> 8) & 0x000FFC00);
2196 out
= (unsigned int)exp
;
2197 if (vc_progress_white
) out
+= ((0xFF - data
) << 22)
2198 | ((0xFF - data
) << 12)
2199 | ((0xFF - data
) << 2);
2200 } else if (kDataBack
& flags
)
2206 dst
= (volatile unsigned int *) (((volatile char*)dst
) + vinfo
.v_rowbytes
);
2208 backPtr
+= backRow
- width
;
2212 static void vc_clean_boot_graphics(void)
2214 // clean up possible FDE login graphics
2215 vc_progress_set(FALSE
, 0);
2216 const unsigned char *
2217 color
= (typeof(color
))(uintptr_t)(vc_progress_white
? 0x00000000 : 0xBFBFBFBF);
2218 vc_blit_rect(0, 0, 0, vinfo
.v_width
, vinfo
.v_height
, 0, 0, color
, NULL
, 0);
2222 * Routines to render the lzss image format
2225 struct lzss_image_state
{
2230 uint32_t bytes_per_row
;
2231 volatile uint32_t * row_start
;
2232 const uint8_t* clut
;
2234 typedef struct lzss_image_state lzss_image_state
;
2236 // returns 0 if OK, 1 if error
2238 vc_decompress_lzss_next_pixel (int next_data
, lzss_image_state
* state
)
2240 uint32_t palette_index
= 0;
2241 uint32_t pixel_value
= 0;
2243 palette_index
= next_data
* 3;
2245 pixel_value
= ( (uint32_t) state
->clut
[palette_index
+ 0] << 16)
2246 | ( (uint32_t) state
->clut
[palette_index
+ 1] << 8)
2247 | ( (uint32_t) state
->clut
[palette_index
+ 2]);
2249 *(state
->row_start
+ state
->col
) = pixel_value
;
2251 if (++state
->col
>= state
->width
) {
2253 if (++state
->row
>= state
->height
) {
2256 state
->row_start
= (volatile uint32_t *) (((uintptr_t)state
->row_start
) + state
->bytes_per_row
);
2263 * Blit an lzss compressed image to the framebuffer
2264 * Assumes 32 bit screen (which is everything we ship at the moment)
2265 * The function vc_display_lzss_icon was copied from libkern/mkext.c, then modified.
2269 * TODO: Does lzss use too much stack? 4096 plus bytes...
2270 * Can probably chop it down by 1/2.
2273 /**************************************************************
2274 LZSS.C -- A Data Compression Program
2275 ***************************************************************
2276 4/6/1989 Haruhiko Okumura
2277 Use, distribute, and modify this program freely.
2278 Please send me your improved versions.
2280 NIFTY-Serve PAF01022
2281 CompuServe 74050,1022
2283 **************************************************************/
2285 #define N 4096 /* size of ring buffer - must be power of 2 */
2286 #define F 18 /* upper limit for match_length */
2287 #define THRESHOLD 2 /* encode string into position and length
2288 if match_length is greater than this */
2290 // returns 0 if OK, 1 if error
2291 // x and y indicate upper left corner of image location on screen
2293 vc_display_lzss_icon(uint32_t dst_x
, uint32_t dst_y
,
2294 uint32_t image_width
, uint32_t image_height
,
2295 const uint8_t *compressed_image
,
2296 uint32_t compressed_size
,
2297 const uint8_t *clut
)
2299 uint32_t* image_start
;
2300 uint32_t bytes_per_pixel
= 4;
2301 uint32_t bytes_per_row
= vinfo
.v_rowbytes
;
2303 vc_clean_boot_graphics();
2305 image_start
= (uint32_t *) (vinfo
.v_baseaddr
+ (dst_y
* bytes_per_row
) + (dst_x
* bytes_per_pixel
));
2307 lzss_image_state state
= {0, 0, image_width
, image_height
, bytes_per_row
, image_start
, clut
};
2311 const uint8_t *src
= compressed_image
;
2312 uint32_t srclen
= compressed_size
;
2314 /* ring buffer of size N, with extra F-1 bytes to aid string comparison */
2315 uint8_t text_buf
[N
+ F
- 1];
2316 const uint8_t *srcend
= src
+ srclen
;
2320 srcend
= src
+ srclen
;
2321 for (i
= 0; i
< N
- F
; i
++)
2326 if (((flags
>>= 1) & 0x100) == 0) {
2327 if (src
< srcend
) c
= *src
++; else break;
2328 flags
= c
| 0xFF00; /* uses higher byte cleverly */
2329 } /* to count eight */
2331 if (src
< srcend
) c
= *src
++; else break;
2332 rval
= vc_decompress_lzss_next_pixel(c
, &state
);
2338 if (src
< srcend
) i
= *src
++; else break;
2339 if (src
< srcend
) j
= *src
++; else break;
2340 i
|= ((j
& 0xF0) << 4);
2341 j
= (j
& 0x0F) + THRESHOLD
;
2342 for (k
= 0; k
<= j
; k
++) {
2343 c
= text_buf
[(i
+ k
) & (N
- 1)];
2344 rval
= vc_decompress_lzss_next_pixel(c
, &state
);
2355 void noroot_icon_test(void) {
2356 boolean_t o_vc_progress_enable
= vc_progress_enable
;
2358 vc_progress_enable
= 1;
2360 PE_display_icon( 0, "noroot");
2362 vc_progress_enable
= o_vc_progress_enable
;
2366 void vc_display_icon( vc_progress_element
* desc
,
2367 const unsigned char * data
)
2369 int x
, y
, width
, height
;
2371 if( vc_progress_enable
&& vc_clut
) {
2373 vc_clean_boot_graphics();
2375 width
= desc
->width
;
2376 height
= desc
->height
;
2379 if( 1 & desc
->flags
) {
2380 x
+= ((vinfo
.v_width
- width
) / 2);
2381 y
+= ((vinfo
.v_height
- height
) / 2);
2383 vc_blit_rect( x
, y
, 0, width
, height
, width
, 0, data
, NULL
, kDataIndexed
);
2388 vc_progress_initialize( vc_progress_element
* desc
,
2389 const unsigned char * data1x
,
2390 const unsigned char * data2x
,
2391 const unsigned char * data3x
,
2392 const unsigned char * clut
)
2396 if( (!clut
) || (!desc
) || (!data1x
))
2402 vc_progress_data
[0] = data1x
;
2403 vc_progress_data
[1] = data2x
;
2404 vc_progress_data
[2] = data3x
;
2405 if( 2 & vc_progress
->flags
)
2406 vc_progress_alpha
= data1x
2407 + vc_progress
->count
* vc_progress
->width
* vc_progress
->height
;
2409 vc_progress_alpha
= NULL
;
2411 thread_call_setup(&vc_progress_call
, vc_progress_task
, NULL
);
2412 clock_interval_to_absolutetime_interval(vc_progress
->time
, 1000 * 1000, &abstime
);
2413 vc_progress_interval
= (uint32_t)abstime
;
2415 thread_call_setup(&vc_progressmeter_call
, vc_progressmeter_task
, NULL
);
2416 clock_interval_to_absolutetime_interval(1000 / 8, 1000 * 1000, &abstime
);
2417 vc_progressmeter_interval
= (uint32_t)abstime
;
2422 vc_progress_set(boolean_t enable
, uint32_t vc_delay
)
2425 void *saveBuf
= NULL
;
2426 vm_size_t saveLen
= 0;
2429 unsigned char pdata8
;
2430 unsigned short pdata16
;
2431 unsigned short * buf16
;
2432 unsigned int pdata32
;
2433 unsigned int * buf32
;
2436 if (kBootArgsFlagBlack
& ((boot_args
*) PE_state
.bootArgs
)->flags
) return;
2438 if (1 & vc_progress_withmeter
)
2440 if (enable
) internal_enable_progressmeter(kProgressMeterKernel
);
2443 simple_lock(&vc_progress_lock
);
2445 if( vc_progress_enable
!= enable
) {
2446 vc_progress_enable
= enable
;
2449 vc_progressmeter_count
= 0;
2450 clock_interval_to_deadline(vc_delay
,
2451 1000 * 1000 * 1000 /*second scale*/,
2452 &vc_progressmeter_deadline
);
2453 thread_call_enter_delayed(&vc_progressmeter_call
, vc_progressmeter_deadline
);
2455 else thread_call_cancel(&vc_progressmeter_call
);
2458 simple_unlock(&vc_progress_lock
);
2461 if (!enable
) internal_enable_progressmeter(kProgressMeterOff
);
2466 if(!vc_progress
) return;
2469 saveLen
= (vc_progress
->width
* vc_uiscale
) * (vc_progress
->height
* vc_uiscale
) * vinfo
.v_depth
/ 8;
2470 saveBuf
= kalloc( saveLen
);
2472 switch( vinfo
.v_depth
) {
2474 for( count
= 0; count
< 256; count
++) {
2475 vc_revclut8
[count
] = vc_clut
[0x01 * 3];
2476 pdata8
= (vc_clut
[0x01 * 3] * count
+ 0x0ff) >> 8;
2477 for( index
= 0; index
< 256; index
++) {
2478 if( (pdata8
== vc_clut
[index
* 3 + 0]) &&
2479 (pdata8
== vc_clut
[index
* 3 + 1]) &&
2480 (pdata8
== vc_clut
[index
* 3 + 2])) {
2481 vc_revclut8
[count
] = index
;
2486 memset( saveBuf
, 0x01, saveLen
);
2490 buf16
= (unsigned short *) saveBuf
;
2491 pdata16
= ((vc_clut
[0x01 * 3 + 0] & CLUT_MASK_R
) CLUT_SHIFT_R
)
2492 | ((vc_clut
[0x01 * 3 + 0] & CLUT_MASK_G
) CLUT_SHIFT_G
)
2493 | ((vc_clut
[0x01 * 3 + 0] & CLUT_MASK_B
) CLUT_SHIFT_B
);
2494 for( count
= 0; count
< saveLen
/ 2; count
++)
2495 buf16
[count
] = pdata16
;
2499 buf32
= (unsigned int *) saveBuf
;
2500 pdata32
= ((vc_clut
[0x01 * 3 + 0] & 0xff) << 16)
2501 | ((vc_clut
[0x01 * 3 + 1] & 0xff) << 8)
2502 | ((vc_clut
[0x01 * 3 + 2] & 0xff) << 0);
2503 for( count
= 0; count
< saveLen
/ 4; count
++)
2504 buf32
[count
] = pdata32
;
2510 simple_lock(&vc_progress_lock
);
2512 if( vc_progress_enable
!= enable
) {
2513 vc_progress_enable
= enable
;
2516 vc_saveunder
= saveBuf
;
2517 vc_saveunder_len
= saveLen
;
2520 vc_progress_count
= 0;
2521 vc_progress_angle
= 0;
2523 clock_interval_to_deadline(vc_delay
,
2524 1000 * 1000 * 1000 /*second scale*/,
2525 &vc_progress_deadline
);
2526 thread_call_enter_delayed(&vc_progress_call
, vc_progress_deadline
);
2530 saveBuf
= vc_saveunder
;
2531 saveLen
= vc_saveunder_len
;
2532 vc_saveunder
= NULL
;
2533 vc_saveunder_len
= 0;
2536 thread_call_cancel(&vc_progress_call
);
2540 simple_unlock(&vc_progress_lock
);
2544 kfree( saveBuf
, saveLen
);
2548 static uint32_t vc_progressmeter_range(uint32_t pos
)
2552 if (pos
> kProgressMeterEnd
) pos
= kProgressMeterEnd
;
2553 ret
= vc_progress_meter_start
2554 + ((pos
* (vc_progress_meter_end
- vc_progress_meter_start
)) / kProgressMeterEnd
);
2560 vc_progressmeter_task(__unused
void *arg0
, __unused
void *arg
)
2566 simple_lock(&vc_progress_lock
);
2567 if (vc_progressmeter_enable
)
2569 uint32_t pos
= (vc_progressmeter_count
>> 13);
2570 internal_set_progressmeter(vc_progressmeter_range(pos
));
2571 if (pos
< kProgressMeterEnd
)
2573 static uint16_t incr
[8] = { 10000, 10000, 8192, 4096, 2048, 384, 384, 64 };
2574 vc_progressmeter_count
+= incr
[(pos
* 8) / kProgressMeterEnd
];
2576 interval
= vc_progressmeter_interval
;
2577 interval
= ((interval
* 256) / vc_progressmeter_diskspeed
);
2579 clock_deadline_for_periodic_event(interval
, mach_absolute_time(), &vc_progressmeter_deadline
);
2580 thread_call_enter_delayed(&vc_progressmeter_call
, vc_progressmeter_deadline
);
2583 simple_unlock(&vc_progress_lock
);
2587 void vc_progress_setdiskspeed(uint32_t speed
)
2589 vc_progressmeter_diskspeed
= speed
;
2594 vc_progress_task(__unused
void *arg0
, __unused
void *arg
)
2597 int x
, y
, width
, height
;
2598 uint64_t x_pos
, y_pos
;
2599 const unsigned char * data
;
2602 simple_lock(&vc_progress_lock
);
2604 if( vc_progress_enable
) do {
2606 vc_progress_count
++;
2607 if( vc_progress_count
>= vc_progress
->count
) {
2608 vc_progress_count
= 0;
2609 vc_progress_angle
++;
2612 width
= (vc_progress
->width
* vc_uiscale
);
2613 height
= (vc_progress
->height
* vc_uiscale
);
2614 data
= vc_progress_data
[vc_uiscale
- 1];
2617 if (kVCUsePosition
& vc_progress_options
.options
) {
2618 /* Rotation: 0:normal, 1:right 90, 2:left 180, 3:left 90 */
2619 switch (3 & vinfo
.v_rotate
) {
2621 x_pos
= vc_progress_options
.x_pos
;
2622 y_pos
= vc_progress_options
.y_pos
;
2625 x_pos
= 0xFFFFFFFF - vc_progress_options
.x_pos
;
2626 y_pos
= 0xFFFFFFFF - vc_progress_options
.y_pos
;
2629 x_pos
= 0xFFFFFFFF - vc_progress_options
.y_pos
;
2630 y_pos
= vc_progress_options
.x_pos
;
2633 x_pos
= vc_progress_options
.y_pos
;
2634 y_pos
= 0xFFFFFFFF - vc_progress_options
.x_pos
;
2637 x
= (uint32_t)((x_pos
* (uint64_t) vinfo
.v_width
) / 0xFFFFFFFFULL
);
2638 y
= (uint32_t)((y_pos
* (uint64_t) vinfo
.v_height
) / 0xFFFFFFFFULL
);
2642 x
= (vc_progress
->dx
* vc_uiscale
);
2643 y
= (vc_progress
->dy
* vc_uiscale
);
2644 if( 1 & vc_progress
->flags
) {
2645 x
+= ((vinfo
.v_width
- width
) / 2);
2646 y
+= ((vinfo
.v_height
- height
) / 2);
2650 if ((x
+ width
) > (int)vinfo
.v_width
) break;
2651 if ((y
+ height
) > (int)vinfo
.v_height
) break;
2653 data
+= vc_progress_count
* width
* height
;
2655 vc_blit_rect( x
, y
, 0,
2656 width
, height
, width
, width
,
2659 | (vc_progress_angle
& kDataRotate
)
2660 | (vc_needsave
? kSave
: 0) );
2661 vc_needsave
= FALSE
;
2663 clock_deadline_for_periodic_event(vc_progress_interval
, mach_absolute_time(), &vc_progress_deadline
);
2664 thread_call_enter_delayed(&vc_progress_call
, vc_progress_deadline
);
2667 simple_unlock(&vc_progress_lock
);
2672 * Generic Console (Front-End): Master Control
2673 * -------------------------------------------
2676 #if defined (__i386__) || defined (__x86_64__)
2677 #include <pexpert/i386/boot.h>
2680 static boolean_t gc_acquired
= FALSE
;
2681 static boolean_t gc_graphics_boot
= FALSE
;
2682 static boolean_t gc_desire_text
= FALSE
;
2683 static boolean_t gc_paused_progress
;
2685 static vm_offset_t lastVideoVirt
= 0;
2686 static vm_size_t lastVideoMapSize
= 0;
2687 static boolean_t lastVideoMapKmap
= FALSE
;
2690 gc_pause( boolean_t pause
, boolean_t graphics_now
)
2695 VCPUTC_LOCK_LOCK( );
2697 disableConsoleOutput
= (pause
&& !console_is_serial());
2698 gc_enabled
= (!pause
&& !graphics_now
);
2700 VCPUTC_LOCK_UNLOCK( );
2702 simple_lock(&vc_progress_lock
);
2706 gc_paused_progress
= vc_progress_enable
;
2707 vc_progress_enable
= FALSE
;
2709 else vc_progress_enable
= gc_paused_progress
;
2711 if (vc_progress_enable
)
2713 if (1 & vc_progress_withmeter
) thread_call_enter_delayed(&vc_progressmeter_call
, vc_progressmeter_deadline
);
2715 thread_call_enter_delayed(&vc_progress_call
, vc_progress_deadline
);
2718 simple_unlock(&vc_progress_lock
);
2723 vc_initialize(__unused
struct vc_info
* vinfo_p
)
2726 vinfo
.v_rows
= vinfo
.v_height
/ ISO_CHAR_HEIGHT
;
2727 vinfo
.v_columns
= vinfo
.v_width
/ ISO_CHAR_WIDTH
;
2728 vinfo
.v_rowscanbytes
= ((vinfo
.v_depth
+ 7) / 8) * vinfo
.v_width
;
2729 vc_uiscale
= vinfo
.v_scale
;
2730 if (vc_uiscale
> kMaxProgressData
) vc_uiscale
= kMaxProgressData
;
2731 else if (!vc_uiscale
) vc_uiscale
= 1;
2735 initialize_screen(PE_Video
* boot_vinfo
, unsigned int op
)
2737 unsigned int newMapSize
= 0;
2738 vm_offset_t newVideoVirt
= 0;
2739 boolean_t graphics_now
;
2744 struct vc_info new_vinfo
= vinfo
;
2745 boolean_t makeMapping
= FALSE
;
2750 if (kPEBaseAddressChange
!= op
)
2752 new_vinfo
.v_width
= (unsigned int)boot_vinfo
->v_width
;
2753 new_vinfo
.v_height
= (unsigned int)boot_vinfo
->v_height
;
2754 new_vinfo
.v_depth
= (unsigned int)boot_vinfo
->v_depth
;
2755 new_vinfo
.v_rowbytes
= (unsigned int)boot_vinfo
->v_rowBytes
;
2756 if (kernel_map
== VM_MAP_NULL
) {
2757 // only booter supplies HW rotation
2758 new_vinfo
.v_rotate
= (unsigned int)boot_vinfo
->v_rotate
;
2760 #if defined(__i386__) || defined(__x86_64__)
2761 new_vinfo
.v_type
= (unsigned int)boot_vinfo
->v_display
;
2763 new_vinfo
.v_type
= 0;
2765 unsigned int scale
= (unsigned int)boot_vinfo
->v_scale
;
2766 if (scale
== kPEScaleFactor1x
)
2767 new_vinfo
.v_scale
= kPEScaleFactor1x
;
2768 else if (scale
== kPEScaleFactor2x
)
2769 new_vinfo
.v_scale
= kPEScaleFactor2x
;
2770 else /* Scale factor not set, default to 1x */
2771 new_vinfo
.v_scale
= kPEScaleFactor1x
;
2773 new_vinfo
.v_name
[0] = 0;
2774 new_vinfo
.v_physaddr
= 0;
2777 * Check if we are have to map the framebuffer
2778 * If VM is up, we are given a virtual address, unless b0 is set to indicate physical.
2780 newVideoVirt
= boot_vinfo
->v_baseAddr
;
2781 makeMapping
= (kernel_map
== VM_MAP_NULL
) || (0 != (1 & newVideoVirt
));
2785 new_vinfo
.v_physaddr
= boot_vinfo
->v_baseAddr
& ~3UL; /* Get the physical address */
2787 new_vinfo
.v_physaddr
|= (((uint64_t) boot_vinfo
->v_baseAddrHigh
) << 32);
2789 kprintf("initialize_screen: b=%08llX, w=%08X, h=%08X, r=%08X, d=%08X\n", /* (BRINGUP) */
2790 new_vinfo
.v_physaddr
, new_vinfo
.v_width
, new_vinfo
.v_height
, new_vinfo
.v_rowbytes
, new_vinfo
.v_type
); /* (BRINGUP) */
2793 if (!newVideoVirt
&& !new_vinfo
.v_physaddr
) /* Check to see if we have a framebuffer */
2795 kprintf("initialize_screen: No video - forcing serial mode\n"); /* (BRINGUP) */
2796 new_vinfo
.v_depth
= 0; /* vc routines are nop */
2797 (void)switch_to_serial_console(); /* Switch into serial mode */
2798 gc_graphics_boot
= FALSE
; /* Say we are not in graphics mode */
2799 disableConsoleOutput
= FALSE
; /* Allow printfs to happen */
2806 unsigned int flags
= VM_WIMG_IO
;
2807 if (boot_vinfo
->v_length
!= 0)
2808 newMapSize
= (unsigned int) round_page(boot_vinfo
->v_length
);
2810 newMapSize
= (unsigned int) round_page(new_vinfo
.v_height
* new_vinfo
.v_rowbytes
); /* Remember size */
2811 newVideoVirt
= io_map_spec((vm_map_offset_t
)new_vinfo
.v_physaddr
, newMapSize
, flags
); /* Allocate address space for framebuffer */
2813 new_vinfo
.v_baseaddr
= newVideoVirt
+ boot_vinfo
->v_offset
; /* Set the new framebuffer address */
2816 #if defined(__x86_64__)
2817 // Adjust the video buffer pointer to point to where it is in high virtual (above the hole)
2818 new_vinfo
.v_baseaddr
|= (VM_MIN_KERNEL_ADDRESS
& ~LOW_4GB_MASK
);
2821 /* Update the vinfo structure atomically with respect to the vc_progress task if running */
2824 simple_lock(&vc_progress_lock
);
2826 simple_unlock(&vc_progress_lock
);
2833 // If we changed the virtual address, remove the old mapping
2834 if (newVideoVirt
!= 0)
2836 if (lastVideoVirt
&& lastVideoMapSize
) /* Was the framebuffer mapped before? */
2838 /* XXX why only !4K? */
2839 if (!TEST_PAGE_SIZE_4K
&& lastVideoMapSize
)
2841 pmap_remove(kernel_pmap
, trunc_page_64(lastVideoVirt
),
2842 round_page_64(lastVideoVirt
+ lastVideoMapSize
)); /* Toss mappings */
2844 /* Was this not a special pre-VM mapping? */
2845 if (lastVideoMapKmap
)
2847 kmem_free(kernel_map
, lastVideoVirt
, lastVideoMapSize
); /* Toss kernel addresses */
2850 lastVideoMapKmap
= (NULL
!= kernel_map
); /* Remember how mapped */
2851 lastVideoMapSize
= newMapSize
; /* Remember the size */
2852 lastVideoVirt
= newVideoVirt
; /* Remember the virtual framebuffer address */
2855 if (kPEBaseAddressChange
!= op
)
2857 // Graphics mode setup by the booter.
2859 gc_ops
.initialize
= vc_initialize
;
2860 gc_ops
.enable
= vc_enable
;
2861 gc_ops
.paint_char
= vc_paint_char
;
2862 gc_ops
.scroll_down
= vc_scroll_down
;
2863 gc_ops
.scroll_up
= vc_scroll_up
;
2864 gc_ops
.clear_screen
= vc_clear_screen
;
2865 gc_ops
.hide_cursor
= vc_reverse_cursor
;
2866 gc_ops
.show_cursor
= vc_reverse_cursor
;
2867 gc_ops
.update_color
= vc_update_color
;
2868 gc_initialize(&vinfo
);
2872 graphics_now
= gc_graphics_boot
&& !gc_desire_text
;
2875 case kPEGraphicsMode
:
2876 gc_graphics_boot
= TRUE
;
2877 gc_desire_text
= FALSE
;
2881 disable_debug_output
= FALSE
;
2882 gc_graphics_boot
= FALSE
;
2885 case kPEAcquireScreen
:
2886 if ( gc_acquired
) break;
2888 vc_progress_options
= vc_user_options
;
2889 bzero(&vc_user_options
, sizeof(vc_user_options
));
2891 if (kVCAcquireImmediate
& vc_progress_options
.options
) delay
= 0;
2892 else if (kVCDarkReboot
& vc_progress_options
.options
) delay
= 120;
2893 else delay
= vc_acquire_delay
;
2895 if (kVCDarkBackground
& vc_progress_options
.options
) vc_progress_white
= TRUE
;
2896 else if (kVCLightBackground
& vc_progress_options
.options
) vc_progress_white
= FALSE
;
2898 vc_progress_set( graphics_now
, delay
);
2899 gc_enable( !graphics_now
);
2901 gc_desire_text
= FALSE
;
2904 case kPEDisableScreen
:
2907 gc_pause( TRUE
, graphics_now
);
2911 case kPEEnableScreen
:
2914 gc_pause( FALSE
, graphics_now
);
2919 if ( console_is_serial() ) break;
2921 disable_debug_output
= FALSE
;
2922 if ( gc_acquired
== FALSE
)
2924 gc_desire_text
= TRUE
;
2927 if ( gc_graphics_boot
== FALSE
) break;
2929 vc_progress_set( FALSE
, 0 );
2930 vc_enable_progressmeter( FALSE
);
2934 case kPEReleaseScreen
:
2935 gc_acquired
= FALSE
;
2936 gc_desire_text
= FALSE
;
2938 if ( gc_graphics_boot
== FALSE
) break;
2940 vc_progress_set( FALSE
, 0 );
2941 vc_acquire_delay
= kProgressReacquireDelay
;
2942 vc_progress_white
= TRUE
;
2943 vc_enable_progressmeter(FALSE
);
2944 vc_progress_withmeter
&= ~1;
2949 case kPERefreshBootGraphics
:
2954 if (kBootArgsFlagBlack
& ((boot_args
*) PE_state
.bootArgs
)->flags
) break;
2956 save
= vc_progress_white
;
2957 vc_progress_white
= (0 != (kBootArgsFlagBlackBg
& ((boot_args
*) PE_state
.bootArgs
)->flags
));
2959 internal_enable_progressmeter(kProgressMeterKernel
);
2962 simple_lock(&vc_progress_lock
);
2964 vc_progressmeter_drawn
= 0;
2965 internal_set_progressmeter(vc_progressmeter_range(vc_progressmeter_count
>> 13));
2967 simple_unlock(&vc_progress_lock
);
2970 internal_enable_progressmeter(kProgressMeterOff
);
2971 vc_progress_white
= save
;
2979 unsigned int *p
, *endp
, *row
;
2980 int col
, rowline
, rowlongs
;
2981 register unsigned int mask
;
2986 if ( vinfo
.v_depth
== 32 )
2988 else if ( vinfo
.v_depth
== 30 )
2989 mask
= (0x1ff<<20) | (0x1ff<<10) | 0x1ff;
2990 else if ( vinfo
.v_depth
== 16 )
2995 rowline
= (int)(vinfo
.v_rowscanbytes
/ 4);
2996 rowlongs
= (int)(vinfo
.v_rowbytes
/ 4);
2998 p
= (unsigned int*) vinfo
.v_baseaddr
;
2999 endp
= p
+ (rowlongs
* vinfo
.v_height
);
3001 for (row
= p
; row
< endp
; row
+= rowlongs
) {
3002 for (p
= &row
[0], col
= 0; col
< rowline
; col
++) {
3003 *p
= (*p
>> 1) & mask
;
3009 void vcattach(void); /* XXX gcc 4 warning cleanup */
3014 vm_initialized
= TRUE
;
3016 const boot_args
* bootargs
= (typeof(bootargs
)) PE_state
.bootArgs
;
3018 vc_progress_white
= (0 != ((kBootArgsFlagBlackBg
| kBootArgsFlagLoginUI
)
3019 & bootargs
->flags
));
3020 PE_parse_boot_argn("meter", &vc_progress_withmeter
, sizeof(vc_progress_withmeter
));
3022 if (kBootArgsFlagInstallUI
& bootargs
->flags
)
3024 vc_progress_meter_start
= (bootargs
->bootProgressMeterStart
* kProgressMeterMax
) / 65535;
3025 vc_progress_meter_end
= (bootargs
->bootProgressMeterEnd
* kProgressMeterMax
) / 65535;
3029 vc_progress_meter_start
= 0;
3030 vc_progress_meter_end
= kProgressMeterMax
;
3032 simple_lock_init(&vc_progress_lock
, 0);
3034 if ( gc_graphics_boot
== FALSE
)
3040 initialize_screen(NULL
, kPEReleaseScreen
);
3043 initialize_screen(NULL
, kPEAcquireScreen
);
3045 for ( index
= 0 ; index
< msgbufp
->msg_bufx
; index
++ )
3047 if (msgbufp
->msg_bufc
[index
] == '\0') {
3051 vcputc( 0, 0, msgbufp
->msg_bufc
[index
] );
3053 if ( msgbufp
->msg_bufc
[index
] == '\n' )
3055 vcputc( 0, 0,'\r' );
3062 // redraw progress meter between pixels x1, x2, position at x3
3064 vc_draw_progress_meter(unsigned int flags
, int x1
, int x2
, int x3
)
3066 const unsigned char * data
;
3071 // 1 rounded fill, 0 square end
3072 int style
= (0 == (2 & vc_progress_withmeter
));
3074 ox
= ((vinfo
.v_width
- (kProgressBarWidth
* vc_uiscale
)) / 2);
3075 oy
= vinfo
.v_height
- (vinfo
.v_height
/ 3) - ((kProgressBarHeight
* vc_uiscale
) / 2);
3077 if (kDataBack
== flags
)
3079 // restore back bits
3080 vc_blit_rect(ox
+ x1
, oy
, x1
,
3081 x2
, (kProgressBarHeight
* vc_uiscale
), 0, (kProgressBarWidth
* vc_uiscale
),
3082 NULL
, vc_progressmeter_backbuffer
, flags
);
3086 for (x
= x1
; x
< x2
; x
+= w
)
3089 endCapPos
= ((style
&& onoff
) ? x3
: (kProgressBarWidth
* vc_uiscale
));
3090 if (x
< (kProgressBarCapWidth
* vc_uiscale
))
3092 if (x2
< (kProgressBarCapWidth
* vc_uiscale
))
3095 w
= (kProgressBarCapWidth
* vc_uiscale
) - x
;
3096 data
= progressmeter_leftcap
[vc_uiscale
>= 2][onoff
];
3098 vc_blit_rect(ox
+ x
, oy
, x
, w
,
3099 (kProgressBarHeight
* vc_uiscale
),
3100 (kProgressBarCapWidth
* vc_uiscale
),
3101 (kProgressBarWidth
* vc_uiscale
),
3102 data
, vc_progressmeter_backbuffer
, flags
);
3104 else if (x
< (endCapPos
- (kProgressBarCapWidth
* vc_uiscale
)))
3106 if (x2
< (endCapPos
- (kProgressBarCapWidth
* vc_uiscale
)))
3109 w
= (endCapPos
- (kProgressBarCapWidth
* vc_uiscale
)) - x
;
3110 data
= progressmeter_middle
[vc_uiscale
>= 2][onoff
];
3111 vc_blit_rect(ox
+ x
, oy
, x
, w
,
3112 (kProgressBarHeight
* vc_uiscale
),
3114 (kProgressBarWidth
* vc_uiscale
),
3115 data
, vc_progressmeter_backbuffer
, flags
);
3120 data
= progressmeter_rightcap
[vc_uiscale
>= 2][onoff
];
3121 data
+= x
- (endCapPos
- (kProgressBarCapWidth
* vc_uiscale
));
3122 vc_blit_rect(ox
+ x
, oy
, x
, w
,
3123 (kProgressBarHeight
* vc_uiscale
),
3124 (kProgressBarCapWidth
* vc_uiscale
),
3125 (kProgressBarWidth
* vc_uiscale
),
3126 data
, vc_progressmeter_backbuffer
, flags
);
3131 extern void IORecordProgressBackbuffer(void * buffer
, size_t size
, uint32_t theme
);
3134 internal_enable_progressmeter(int new_value
)
3138 boolean_t stashBackbuffer
;
3140 stashBackbuffer
= FALSE
;
3144 new_buffer
= kalloc((kProgressBarWidth
* vc_uiscale
)
3145 * (kProgressBarHeight
* vc_uiscale
) * sizeof(int));
3149 simple_lock(&vc_progress_lock
);
3151 if (kProgressMeterUser
== new_value
)
3153 if (gc_enabled
|| !gc_acquired
|| !gc_graphics_boot
3154 || (kProgressMeterKernel
== vc_progressmeter_enable
)) new_value
= vc_progressmeter_enable
;
3157 if (new_value
!= vc_progressmeter_enable
)
3161 if (kProgressMeterOff
== vc_progressmeter_enable
)
3163 vc_progressmeter_backbuffer
= new_buffer
;
3164 vc_draw_progress_meter(kDataAlpha
| kSave
, 0, (kProgressBarWidth
* vc_uiscale
), 0);
3166 vc_progressmeter_drawn
= 0;
3168 vc_progressmeter_enable
= new_value
;
3170 else if (vc_progressmeter_backbuffer
)
3172 if (kProgressMeterUser
== vc_progressmeter_enable
)
3174 vc_draw_progress_meter(kDataBack
, 0, (kProgressBarWidth
* vc_uiscale
), vc_progressmeter_drawn
);
3176 else stashBackbuffer
= TRUE
;
3177 new_buffer
= vc_progressmeter_backbuffer
;
3178 vc_progressmeter_backbuffer
= NULL
;
3179 vc_progressmeter_enable
= FALSE
;
3183 simple_unlock(&vc_progress_lock
);
3188 if (stashBackbuffer
) IORecordProgressBackbuffer(new_buffer
,
3189 (kProgressBarWidth
* vc_uiscale
)
3190 * (kProgressBarHeight
* vc_uiscale
)
3193 kfree(new_buffer
, (kProgressBarWidth
* vc_uiscale
)
3194 * (kProgressBarHeight
* vc_uiscale
) * sizeof(int));
3199 internal_set_progressmeter(int new_value
)
3203 // 1 rounded fill, 0 square end
3204 int style
= (0 == (2 & vc_progress_withmeter
));
3206 if ((new_value
< 0) || (new_value
> kProgressMeterMax
)) return;
3208 if (vc_progressmeter_enable
)
3210 vc_progressmeter_value
= new_value
;
3212 capRedraw
= (style
? (kProgressBarCapWidth
* vc_uiscale
) : 0);
3213 x3
= (((kProgressBarWidth
* vc_uiscale
) - 2 * capRedraw
) * vc_progressmeter_value
) / kProgressMeterMax
;
3214 x3
+= (2 * capRedraw
);
3216 if (x3
> vc_progressmeter_drawn
)
3219 if (x1
> vc_progressmeter_drawn
) x1
= vc_progressmeter_drawn
;
3220 vc_draw_progress_meter(kDataAlpha
, vc_progressmeter_drawn
- x1
, x3
, x3
);
3224 vc_draw_progress_meter(kDataAlpha
, x3
- capRedraw
, vc_progressmeter_drawn
, x3
);
3226 vc_progressmeter_drawn
= x3
;
3231 vc_enable_progressmeter(int new_value
)
3233 if (kProgressMeterKernel
== vc_progressmeter_enable
)
3235 vc_progressmeter_hold
= new_value
;
3239 internal_enable_progressmeter(new_value
? kProgressMeterUser
: kProgressMeterOff
);
3244 vc_set_progressmeter(int new_value
)
3249 simple_lock(&vc_progress_lock
);
3251 if (vc_progressmeter_enable
&& (kProgressMeterKernel
!= vc_progressmeter_enable
))
3253 internal_set_progressmeter((new_value
* kProgressMeterMax
) / 100);
3256 simple_unlock(&vc_progress_lock
);