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
93 #include <console/video_console.h>
94 #include <console/serial_protos.h>
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>
104 #include <vm/vm_kern.h>
105 #include <machine/io_map_entries.h>
106 #include <machine/machine_cpu.h>
108 #include <pexpert/pexpert.h>
109 #include <sys/kdebug.h>
111 #include "iso_font.c"
113 #include "progress_meter_data.c"
116 #include "sys/msgbuf.h"
119 * Generic Console (Front-End)
120 * ---------------------------
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
;
128 void noroot_icon_test(void);
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
;
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
,
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
);
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
;
159 #if defined(__i386__) || defined(__x86_64__)
160 decl_simple_lock_data(static, vcputc_lock
);
162 #define VCPUTC_LOCK_INIT() \
164 simple_lock_init(&vcputc_lock, 0); \
167 #define VCPUTC_LOCK_LOCK() \
169 boolean_t istate = ml_get_interrupts_enabled(); \
170 while (!simple_lock_try(&vcputc_lock)) \
173 handle_pending_TLB_flushes(); \
178 #define VCPUTC_LOCK_UNLOCK() \
180 simple_unlock(&vcputc_lock); \
183 static hw_lock_data_t vcputc_lock
;
185 #define VCPUTC_LOCK_INIT() \
187 hw_lock_init(&vcputc_lock); \
190 #define VCPUTC_LOCK_LOCK() \
192 if (!hw_lock_to(&vcputc_lock, hwLockTimeOut*10))\
194 panic("VCPUTC_LOCK_LOCK"); \
198 #define VCPUTC_LOCK_UNLOCK() \
200 hw_lock_unlock(&vcputc_lock); \
206 # 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
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
216 #define ATTR_REVERSE 4
218 #define COLOR_BACKGROUND 0
219 #define COLOR_FOREGROUND 7
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)))
224 static unsigned char gc_color_code
;
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
;
231 /* VT100 scroll region */
232 static unsigned int gc_scrreg_top
, gc_scrreg_bottom
;
235 ESnormal
, /* Nothing yet */
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 */
246 ESignore
/* Ignore this sequence */
247 } gc_vt100state
= ESnormal
;
250 #ifdef CONFIG_VC_PROGRESS_WHITE
251 enum { kProgressAcquireDelay
= 0 /* secs */ };
253 enum { kProgressAcquireDelay
= 5 /* secs */ };
256 static int8_t vc_rotate_matr
[4][2][2] = {
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 };
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
,
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
);
300 gc_clear_line(unsigned int xx
, unsigned int yy
, int which
)
302 unsigned int start
, end
, i
;
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
312 case 0: /* To end of line */
314 end
= vinfo
.v_columns
-1;
316 case 1: /* To start of line */
320 case 2: /* Whole line */
322 end
= vinfo
.v_columns
-1;
328 for (i
= start
; i
<= end
; i
++) {
329 gc_paint_char(i
, yy
, ' ', ATTR_NONE
);
334 gc_clear_screen(unsigned int xx
, unsigned int yy
, int top
, unsigned int bottom
,
337 if (!gc_buffer_size
) return;
339 if ( xx
< gc_buffer_columns
&& yy
< gc_buffer_rows
&& bottom
<= gc_buffer_rows
)
344 case 0: /* To end of screen */
345 start
= (yy
* gc_buffer_columns
) + xx
;
346 end
= (bottom
* gc_buffer_columns
) - 1;
348 case 1: /* To start of screen */
349 start
= (top
* gc_buffer_columns
);
350 end
= (yy
* gc_buffer_columns
) + xx
;
352 case 2: /* Whole screen */
353 start
= (top
* gc_buffer_columns
);
354 end
= (bottom
* gc_buffer_columns
) - 1;
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);
367 gc_ops
.clear_screen(xx
, yy
, top
, bottom
, which
);
371 gc_enable( boolean_t enable
)
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;
382 if ( enable
== FALSE
)
384 // only disable console output if it goes to the graphics console
385 if ( console_is_serial() == FALSE
)
386 disableConsoleOutput
= TRUE
;
388 gc_ops
.enable(FALSE
);
394 if ( gc_buffer_size
)
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
;
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;
412 VCPUTC_LOCK_UNLOCK( );
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
);
422 VCPUTC_LOCK_UNLOCK( );
428 if ( vm_initialized
)
430 buffer_columns
= vinfo
.v_columns
;
431 buffer_rows
= vinfo
.v_rows
;
432 buffer_size
= buffer_columns
* buffer_rows
;
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
);
441 if ( buffer_attributes
== NULL
||
442 buffer_characters
== NULL
||
443 buffer_colorcodes
== NULL
||
444 buffer_tab_stops
== NULL
)
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
);
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
);
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
;
478 VCPUTC_LOCK_UNLOCK( );
481 gc_ops
.clear_screen(gc_x
, gc_y
, 0, vinfo
.v_rows
, 2);
482 gc_ops
.show_cursor(gc_x
, gc_y
);
486 disableConsoleOutput
= FALSE
;
491 gc_hide_cursor(unsigned int xx
, unsigned int yy
)
493 if ( xx
< gc_buffer_columns
&& yy
< gc_buffer_rows
)
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
;
501 gc_update_color(COLOR_CODE_GET(colorcode
, TRUE
), TRUE
);
502 gc_update_color(COLOR_CODE_GET(colorcode
, FALSE
), FALSE
);
504 gc_ops
.paint_char(xx
, yy
, character
, attribute
, 0, 0);
506 gc_update_color(COLOR_CODE_GET(colorcodesave
, TRUE
), TRUE
);
507 gc_update_color(COLOR_CODE_GET(colorcodesave
, FALSE
), FALSE
);
511 gc_ops
.hide_cursor(xx
, yy
);
516 gc_initialize(struct vc_info
* info
)
518 if ( gc_initialized
== FALSE
)
523 gc_initialized
= TRUE
;
526 gc_ops
.initialize(info
);
533 gc_paint_char(unsigned int xx
, unsigned int yy
, unsigned char ch
, int attrs
)
535 if ( xx
< gc_buffer_columns
&& yy
< gc_buffer_rows
)
537 uint32_t index
= (yy
* gc_buffer_columns
) + xx
;
539 gc_buffer_attributes
[index
] = attrs
;
540 gc_buffer_characters
[index
] = ch
;
541 gc_buffer_colorcodes
[index
] = gc_color_code
;
544 gc_ops
.paint_char(xx
, yy
, ch
, attrs
, 0, 0);
551 return; /* ignore null characters */
553 switch (gc_vt100state
) {
554 default:gc_vt100state
= ESnormal
; /* FALLTHROUGH */
574 gc_putc_charsizecmd(ch
);
577 gc_putc_charsetcmd(0, ch
);
580 gc_putc_charsetcmd(1, ch
);
584 if (gc_x
>= vinfo
.v_columns
) {
585 if (0 == vinfo
.v_columns
)
588 gc_x
= vinfo
.v_columns
- 1;
590 if (gc_y
>= vinfo
.v_rows
) {
591 if (0 == vinfo
.v_rows
)
594 gc_y
= vinfo
.v_rows
- 1;
599 gc_putc_askcmd(unsigned char ch
)
601 if (ch
>= '0' && ch
<= '9') {
602 gc_par
[gc_numpars
] = (10*gc_par
[gc_numpars
]) + (ch
-'0');
605 gc_vt100state
= ESnormal
;
609 gc_relative_origin
= ch
== 'h';
611 case 7: /* wrap around mode h=1, l=0*/
612 gc_wrap_mode
= ch
== 'h';
621 gc_putc_charsetcmd(int charset
, unsigned char ch
)
623 gc_vt100state
= ESnormal
;
629 gc_charset
[charset
] = 0;
631 case '0' : /* Graphic characters */
633 gc_charset
[charset
] = 0x21;
640 gc_putc_charsizecmd(unsigned char ch
)
642 gc_vt100state
= ESnormal
;
650 case '8' : /* fill 'E's */
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
);
663 gc_putc_esc(unsigned char ch
)
665 gc_vt100state
= ESnormal
;
669 gc_vt100state
= ESsquare
;
671 case 'c': /* Reset terminal */
673 gc_clear_screen(gc_x
, gc_y
, 0, vinfo
.v_rows
, 2);
676 case 'D': /* Line feed */
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;
684 if (ch
== 'E') gc_x
= 0;
686 case 'H': /* Set tab stop */
687 gc_set_tab_stop(gc_x
, TRUE
);
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
;
700 case '7': /* Save cursor */
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];
708 case '8': /* Restore cursor */
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];
716 case 'Z': /* return terminal ID */
718 case '#': /* change characters height */
719 gc_vt100state
= EScharsize
;
722 gc_vt100state
= ESsetG0
;
724 case ')': /* character set sequence */
725 gc_vt100state
= ESsetG1
;
730 /* Rest not supported */
737 gc_putc_getpars(unsigned char ch
)
740 gc_vt100state
= ESask
;
744 gc_vt100state
= ESnormal
;
748 if (ch
== ';' && gc_numpars
< MAXPARS
- 1) {
751 if (ch
>= '0' && ch
<= '9') {
752 gc_par
[gc_numpars
] *= 10;
753 gc_par
[gc_numpars
] += ch
- '0';
756 gc_vt100state
= ESgotpars
;
762 gc_putc_gotpars(unsigned char ch
)
767 /* special case for vttest for handling cursor
768 movement in escape sequences */
770 gc_vt100state
= ESgotpars
;
773 gc_vt100state
= ESnormal
;
776 gc_y
-= gc_par
[0] ? gc_par
[0] : 1;
777 if (gc_y
< gc_scrreg_top
)
778 gc_y
= gc_scrreg_top
;
781 gc_y
+= gc_par
[0] ? gc_par
[0] : 1;
782 if (gc_y
>= gc_scrreg_bottom
)
783 gc_y
= gc_scrreg_bottom
- 1;
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;
791 if (gc_par
[0] > gc_x
)
798 case 'H': /* Set cursor position */
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;
806 case 'X': /* clear p1 characters */
808 for (i
= gc_x
; i
< gc_x
+ gc_par
[0]; i
++)
809 gc_paint_char(i
, gc_y
, ' ', ATTR_NONE
);
812 case 'J': /* Clear part of screen */
813 gc_clear_screen(gc_x
, gc_y
, 0, vinfo
.v_rows
, gc_par
[0]);
815 case 'K': /* Clear part of line */
816 gc_clear_line(gc_x
, gc_y
, gc_par
[0]);
818 case 'g': /* tab stops */
821 case 2: /* reset tab stops */
822 /* gc_reset_tabs(); */
824 case 3: /* Clear every tabs */
826 for (i
= 0; i
<= vinfo
.v_columns
; i
++)
827 gc_set_tab_stop(i
, FALSE
);
831 gc_set_tab_stop(gc_x
, FALSE
);
835 case 'm': /* Set attribute */
836 for (i
= 0; i
< gc_numpars
; i
++) {
840 gc_update_color(COLOR_BACKGROUND
, FALSE
);
841 gc_update_color(COLOR_FOREGROUND
, TRUE
);
844 gc_attr
|= ATTR_BOLD
;
847 gc_attr
|= ATTR_UNDER
;
850 gc_attr
|= ATTR_REVERSE
;
853 gc_attr
&= ~ATTR_BOLD
;
856 gc_attr
&= ~ATTR_UNDER
;
859 gc_attr
&= ~ATTR_REVERSE
;
862 case 25: /* blink/no blink */
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
);
873 case 'r': /* Set scroll region */
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;
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
;
886 gc_scrreg_bottom
= vinfo
.v_rows
;
888 if (gc_relative_origin
)
889 gc_y
= gc_scrreg_top
;
896 gc_putc_normal(unsigned char ch
)
899 case '\a': /* Beep */
901 case 127: /* Delete */
902 case '\b': /* Backspace */
903 if (gc_hanging_cursor
) {
904 gc_hanging_cursor
= 0;
911 if (gc_buffer_tab_stops
) while (gc_x
< vinfo
.v_columns
&& !gc_is_tab_stop(++gc_x
));
913 if (gc_x
>= vinfo
.v_columns
)
914 gc_x
= vinfo
.v_columns
-1;
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;
926 case '\r': /* Carriage return */
928 gc_hanging_cursor
= 0;
930 case 0x0e: /* Select G1 charset (Control-N) */
931 gc_charset_select
= 1;
933 case 0x0f: /* Select G0 charset (Control-O) */
934 gc_charset_select
= 0;
936 case 0x18 : /* CAN : cancel */
937 case 0x1A : /* like cancel */
938 /* well, i do nothing here, may be later */
940 case '\033': /* Escape */
941 gc_vt100state
= ESesc
;
942 gc_hanging_cursor
= 0;
946 if (gc_hanging_cursor
) {
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;
954 gc_hanging_cursor
= 0;
956 gc_paint_char(gc_x
, gc_y
, (ch
>= 0x60 && ch
<= 0x7f) ? ch
+ gc_charset
[gc_charset_select
]
958 if (gc_x
== vinfo
.v_columns
- 1) {
959 gc_hanging_cursor
= gc_wrap_mode
;
970 gc_putc_square(unsigned char ch
)
974 for (i
= 0; i
< MAXPARS
; i
++) {
979 gc_vt100state
= ESgetpars
;
986 gc_reset_screen(void)
997 if (!gc_buffer_tab_stops
) return;
999 for (i
= 0; i
< vinfo
.v_columns
; i
++) {
1000 gc_buffer_tab_stops
[i
] = ((i
% 8) == 0);
1006 gc_set_tab_stop(unsigned int column
, boolean_t enabled
)
1008 if (gc_buffer_tab_stops
&& (column
< vinfo
.v_columns
)) {
1009 gc_buffer_tab_stops
[column
] = enabled
;
1013 static boolean_t
gc_is_tab_stop(unsigned int column
)
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
];
1024 gc_reset_vt100(void)
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;
1033 gc_relative_origin
= 0;
1034 gc_update_color(COLOR_BACKGROUND
, FALSE
);
1035 gc_update_color(COLOR_FOREGROUND
, TRUE
);
1039 gc_scroll_down(int num
, unsigned int top
, unsigned int bottom
)
1041 if (!gc_buffer_size
) return;
1043 if ( bottom
<= gc_buffer_rows
)
1045 unsigned char colorcodesave
= gc_color_code
;
1046 uint32_t column
, row
;
1047 uint32_t index
, jump
;
1049 jump
= num
* gc_buffer_columns
;
1051 for ( row
= bottom
- 1 ; row
>= top
+ num
; row
-- )
1053 index
= row
* gc_buffer_columns
;
1055 for ( column
= 0 ; column
< gc_buffer_columns
; index
++, column
++ )
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
] )
1061 if ( gc_color_code
!= gc_buffer_colorcodes
[index
- jump
] )
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
);
1067 if ( gc_buffer_colorcodes
[index
] != gc_buffer_colorcodes
[index
- jump
] )
1069 gc_ops
.paint_char( /* xx */ column
,
1071 /* ch */ gc_buffer_characters
[index
- jump
],
1072 /* attrs */ gc_buffer_attributes
[index
- jump
],
1073 /* ch_previous */ 0,
1074 /* attrs_previous */ 0 );
1078 gc_ops
.paint_char( /* xx */ column
,
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
] );
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
];
1093 if ( colorcodesave
!= gc_color_code
)
1095 gc_update_color(COLOR_CODE_GET(colorcodesave
, TRUE
), TRUE
);
1096 gc_update_color(COLOR_CODE_GET(colorcodesave
, FALSE
), FALSE
);
1099 /* Now set the freed up lines to the background colour */
1101 for ( row
= top
; row
< top
+ num
; row
++ )
1103 index
= row
* gc_buffer_columns
;
1105 for ( column
= 0 ; column
< gc_buffer_columns
; index
++, column
++ )
1107 if ( gc_buffer_attributes
[index
] != ATTR_NONE
||
1108 gc_buffer_characters
[index
] != ' ' ||
1109 gc_buffer_colorcodes
[index
] != gc_color_code
)
1111 if ( gc_buffer_colorcodes
[index
] != gc_color_code
)
1113 gc_ops
.paint_char( /* xx */ column
,
1116 /* attrs */ ATTR_NONE
,
1117 /* ch_previous */ 0,
1118 /* attrs_previous */ 0 );
1122 gc_ops
.paint_char( /* xx */ column
,
1125 /* attrs */ ATTR_NONE
,
1126 /* ch_previous */ gc_buffer_characters
[index
],
1127 /* attrs_previous */ gc_buffer_attributes
[index
] );
1130 gc_buffer_attributes
[index
] = ATTR_NONE
;
1131 gc_buffer_characters
[index
] = ' ';
1132 gc_buffer_colorcodes
[index
] = gc_color_code
;
1139 gc_ops
.scroll_down(num
, top
, bottom
);
1141 /* Now set the freed up lines to the background colour */
1143 gc_clear_screen(vinfo
.v_columns
- 1, top
+ num
- 1, top
, bottom
, 1);
1148 gc_scroll_up(int num
, unsigned int top
, unsigned int bottom
)
1150 if (!gc_buffer_size
) return;
1152 if ( bottom
<= gc_buffer_rows
)
1154 unsigned char colorcodesave
= gc_color_code
;
1155 uint32_t column
, row
;
1156 uint32_t index
, jump
;
1158 jump
= num
* gc_buffer_columns
;
1160 for ( row
= top
; row
< bottom
- num
; row
++ )
1162 index
= row
* gc_buffer_columns
;
1164 for ( column
= 0 ; column
< gc_buffer_columns
; index
++, column
++ )
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
] )
1170 if ( gc_color_code
!= gc_buffer_colorcodes
[index
+ jump
] )
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
);
1176 if ( gc_buffer_colorcodes
[index
] != gc_buffer_colorcodes
[index
+ jump
] )
1178 gc_ops
.paint_char( /* xx */ column
,
1180 /* ch */ gc_buffer_characters
[index
+ jump
],
1181 /* attrs */ gc_buffer_attributes
[index
+ jump
],
1182 /* ch_previous */ 0,
1183 /* attrs_previous */ 0 );
1187 gc_ops
.paint_char( /* xx */ column
,
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
] );
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
];
1202 if ( colorcodesave
!= gc_color_code
)
1204 gc_update_color(COLOR_CODE_GET(colorcodesave
, TRUE
), TRUE
);
1205 gc_update_color(COLOR_CODE_GET(colorcodesave
, FALSE
), FALSE
);
1208 /* Now set the freed up lines to the background colour */
1210 for ( row
= bottom
- num
; row
< bottom
; row
++ )
1212 index
= row
* gc_buffer_columns
;
1214 for ( column
= 0 ; column
< gc_buffer_columns
; index
++, column
++ )
1216 if ( gc_buffer_attributes
[index
] != ATTR_NONE
||
1217 gc_buffer_characters
[index
] != ' ' ||
1218 gc_buffer_colorcodes
[index
] != gc_color_code
)
1220 if ( gc_buffer_colorcodes
[index
] != gc_color_code
)
1222 gc_ops
.paint_char( /* xx */ column
,
1225 /* attrs */ ATTR_NONE
,
1226 /* ch_previous */ 0,
1227 /* attrs_previous */ 0 );
1231 gc_ops
.paint_char( /* xx */ column
,
1234 /* attrs */ ATTR_NONE
,
1235 /* ch_previous */ gc_buffer_characters
[index
],
1236 /* attrs_previous */ gc_buffer_attributes
[index
] );
1239 gc_buffer_attributes
[index
] = ATTR_NONE
;
1240 gc_buffer_characters
[index
] = ' ';
1241 gc_buffer_colorcodes
[index
] = gc_color_code
;
1248 gc_ops
.scroll_up(num
, top
, bottom
);
1250 /* Now set the freed up lines to the background colour */
1252 gc_clear_screen(0, bottom
- num
, top
, bottom
, 0);
1257 gc_show_cursor(unsigned int xx
, unsigned int yy
)
1259 if ( xx
< gc_buffer_columns
&& yy
< gc_buffer_rows
)
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
;
1267 gc_update_color(COLOR_CODE_GET(colorcode
, FALSE
), TRUE
);
1268 gc_update_color(COLOR_CODE_GET(colorcode
, TRUE
), FALSE
);
1270 gc_ops
.paint_char(xx
, yy
, character
, attribute
, 0, 0);
1272 gc_update_color(COLOR_CODE_GET(colorcodesave
, TRUE
), TRUE
);
1273 gc_update_color(COLOR_CODE_GET(colorcodesave
, FALSE
), FALSE
);
1277 gc_ops
.show_cursor(xx
, yy
);
1282 gc_update_color(int color
, boolean_t fore
)
1284 gc_color_code
= COLOR_CODE_SET(gc_color_code
, color
, fore
);
1285 gc_ops
.update_color(color
, fore
);
1289 vcputc(__unused
int l
, __unused
int u
, int c
)
1291 if ( gc_initialized
&& ( gc_enabled
|| debug_mode
) )
1296 #if defined(__i386__) || defined(__x86_64__)
1297 x86_filter_TLB_coherency_interrupts(TRUE
);
1300 if ( gc_enabled
|| debug_mode
)
1302 gc_hide_cursor(gc_x
, gc_y
);
1304 gc_show_cursor(gc_x
, gc_y
);
1306 VCPUTC_LOCK_UNLOCK();
1307 #if defined(__i386__) || defined(__x86_64__)
1308 x86_filter_TLB_coherency_interrupts(FALSE
);
1315 * Video Console (Back-End)
1316 * ------------------------
1320 * For the color support (Michel Pollet)
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 };
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 */
1338 static uint32_t vc_color_fore
= 0;
1339 static uint32_t vc_color_back
= 0;
1342 * New Rendering code from Michel Pollet
1345 /* Rendered Font Buffer */
1346 static unsigned char *vc_rendered_font
= NULL
;
1348 /* Rendered Font Size */
1349 static uint32_t vc_rendered_font_size
= 0;
1351 /* Size of a character in the table (bytes) */
1352 static int vc_rendered_char_size
= 0;
1354 #define REN_MAX_DEPTH 32
1355 static unsigned char vc_rendered_char
[ISO_CHAR_HEIGHT
* ((REN_MAX_DEPTH
/ 8) * ISO_CHAR_WIDTH
)];
1358 vc_clear_screen(unsigned int xx
, unsigned int yy
, unsigned int scrreg_top
,
1359 unsigned int scrreg_bottom
, int which
)
1361 uint32_t *p
, *endp
, *row
;
1363 int rowline
, rowlongs
;
1368 linelongs
= vinfo
.v_rowbytes
* (ISO_CHAR_HEIGHT
>> 2);
1369 rowline
= vinfo
.v_rowscanbytes
>> 2;
1370 rowlongs
= vinfo
.v_rowbytes
>> 2;
1372 p
= (uint32_t*) vinfo
.v_baseaddr
;
1373 endp
= (uint32_t*) vinfo
.v_baseaddr
;
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
;
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
;
1390 case 2: /* Whole screen */
1391 p
+= scrreg_top
* linelongs
;
1392 if (scrreg_bottom
== vinfo
.v_rows
) {
1393 endp
+= rowlongs
* vinfo
.v_height
;
1395 endp
+= scrreg_bottom
* linelongs
;
1400 for (row
= p
; row
< endp
; row
+= rowlongs
) {
1401 for (col
= 0; col
< rowline
; col
++)
1402 *(row
+col
) = vc_color_back
;
1407 vc_render_char(unsigned char ch
, unsigned char *renderptr
, short newdepth
)
1410 unsigned char *charptr
;
1411 unsigned short *shortptr
;
1413 } current
; /* current place in rendered font, multiple types. */
1414 unsigned char *theChar
; /* current char in iso_font */
1417 current
.charptr
= renderptr
;
1418 theChar
= iso_font
+ (ch
* ISO_CHAR_HEIGHT
);
1420 for (line
= 0; line
< ISO_CHAR_HEIGHT
; line
++) {
1421 unsigned char mask
= 1;
1425 *current
.charptr
++ = (*theChar
& mask
) ? 0xFF : 0;
1428 *current
.shortptr
++ = (*theChar
& mask
) ? 0xFFFF : 0;
1433 *current
.longptr
++ = (*theChar
& mask
) ? 0xFFFFFFFF : 0;
1437 } while (mask
); /* while the single bit drops to the right */
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
)
1450 if (vc_rendered_font
) {
1451 theChar
= (uint32_t*)(vc_rendered_font
+ (ch
* vc_rendered_char_size
));
1453 vc_render_char(ch
, vc_rendered_char
, 8);
1454 theChar
= (uint32_t*)(vc_rendered_char
);
1456 where
= (uint32_t*)(vinfo
.v_baseaddr
+
1457 (yy
* ISO_CHAR_HEIGHT
* vinfo
.v_rowbytes
) +
1458 (xx
* ISO_CHAR_WIDTH
));
1460 if (!attrs
) for (i
= 0; i
< ISO_CHAR_HEIGHT
; i
++) { /* No attr? FLY !*/
1461 uint32_t *store
= where
;
1463 for (x
= 0; x
< 2; x
++) {
1464 uint32_t val
= *theChar
++;
1465 val
= (vc_color_back
& ~val
) | (vc_color_fore
& val
);
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;
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))
1478 if ((save
& 0xFFFF0000) == 0xFF000000)
1480 if ((save
& 0x00FFFF00) == 0x00FF0000)
1482 if ((save
& 0x0000FFFF) == 0x0000FF00)
1485 if (attrs
& ATTR_REVERSE
) val
= ~val
;
1486 if (attrs
& ATTR_UNDER
&& i
== ISO_CHAR_HEIGHT
-1) val
= ~val
;
1488 val
= (vc_color_back
& ~val
) | (vc_color_fore
& val
);
1490 lastpixel
= save
& 0xff;
1493 where
= (uint32_t*)(((unsigned char*)where
)+vinfo
.v_rowbytes
);
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
)
1507 if (vc_rendered_font
) {
1508 theChar
= (uint32_t*)(vc_rendered_font
+ (ch
* vc_rendered_char_size
));
1510 vc_render_char(ch
, vc_rendered_char
, 16);
1511 theChar
= (uint32_t*)(vc_rendered_char
);
1513 where
= (uint32_t*)(vinfo
.v_baseaddr
+
1514 (yy
* ISO_CHAR_HEIGHT
* vinfo
.v_rowbytes
) +
1515 (xx
* ISO_CHAR_WIDTH
* 2));
1517 if (!attrs
) for (i
= 0; i
< ISO_CHAR_HEIGHT
; i
++) { /* No attrs ? FLY ! */
1518 uint32_t *store
= where
;
1520 for (x
= 0; x
< 4; x
++) {
1521 uint32_t val
= *theChar
++;
1522 val
= (vc_color_back
& ~val
) | (vc_color_fore
& val
);
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;
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))
1537 if (attrs
& ATTR_REVERSE
) val
= ~val
;
1538 if (attrs
& ATTR_UNDER
&& i
== ISO_CHAR_HEIGHT
-1) val
= ~val
;
1540 val
= (vc_color_back
& ~val
) | (vc_color_fore
& val
);
1543 lastpixel
= save
& 0x7fff;
1546 where
= (uint32_t*)(((unsigned char*)where
)+vinfo
.v_rowbytes
);
1552 vc_paint_char_32(unsigned int xx
, unsigned int yy
, unsigned char ch
, int attrs
,
1553 unsigned char ch_previous
, int attrs_previous
)
1556 uint32_t *theCharPrevious
;
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
));
1564 vc_render_char(ch
, vc_rendered_char
, 32);
1565 theChar
= (uint32_t*)(vc_rendered_char
);
1566 theCharPrevious
= NULL
;
1569 theCharPrevious
= NULL
;
1571 if (attrs_previous
) {
1572 theCharPrevious
= NULL
;
1574 where
= (uint32_t*)(vinfo
.v_baseaddr
+
1575 (yy
* ISO_CHAR_HEIGHT
* vinfo
.v_rowbytes
) +
1576 (xx
* ISO_CHAR_WIDTH
* 4));
1578 if (!attrs
) for (i
= 0; i
< ISO_CHAR_HEIGHT
; i
++) { /* No attrs ? FLY ! */
1579 uint32_t *store
= where
;
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
);
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;
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
)
1601 if (attrs
& ATTR_REVERSE
) val
= ~val
;
1602 if (attrs
& ATTR_UNDER
&& i
== ISO_CHAR_HEIGHT
-1) val
= ~val
;
1604 val
= (vc_color_back
& ~val
) | (vc_color_fore
& val
);
1609 where
= (uint32_t*)(((unsigned char*)where
)+vinfo
.v_rowbytes
);
1615 vc_paint_char(unsigned int xx
, unsigned int yy
, unsigned char ch
, int attrs
,
1616 unsigned char ch_previous
, int attrs_previous
)
1621 switch(vinfo
.v_depth
) {
1623 vc_paint_char_8(xx
, yy
, ch
, attrs
, ch_previous
, attrs_previous
);
1626 vc_paint_char_16(xx
, yy
, ch
, attrs
, ch_previous
,
1631 vc_paint_char_32(xx
, yy
, ch
, attrs
, ch_previous
,
1638 vc_render_font(short newdepth
)
1640 static short olddepth
= 0;
1642 int charindex
; /* index in ISO font */
1643 unsigned char *rendered_font
;
1644 unsigned int rendered_font_size
;
1645 int rendered_char_size
;
1648 if (vm_initialized
== FALSE
) {
1649 return; /* nothing to do */
1651 if (olddepth
== newdepth
&& vc_rendered_font
) {
1652 return; /* nothing to do */
1658 rendered_font
= vc_rendered_font
;
1659 rendered_font_size
= vc_rendered_font_size
;
1660 rendered_char_size
= vc_rendered_char_size
;
1662 vc_rendered_font
= NULL
;
1663 vc_rendered_font_size
= 0;
1664 vc_rendered_char_size
= 0;
1666 VCPUTC_LOCK_UNLOCK();
1669 if (rendered_font
) {
1670 kfree(rendered_font
, rendered_font_size
);
1671 rendered_font
= NULL
;
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
);
1680 if (rendered_font
== NULL
) {
1684 for (charindex
= ISO_CHAR_MIN
; charindex
<= ISO_CHAR_MAX
; charindex
++) {
1685 vc_render_char(charindex
, rendered_font
+ (charindex
* rendered_char_size
), newdepth
);
1688 olddepth
= newdepth
;
1693 vc_rendered_font
= rendered_font
;
1694 vc_rendered_font_size
= rendered_font_size
;
1695 vc_rendered_char_size
= rendered_char_size
;
1697 VCPUTC_LOCK_UNLOCK();
1702 vc_enable(boolean_t enable
)
1704 vc_render_font(enable
? vinfo
.v_depth
: 0);
1708 vc_reverse_cursor(unsigned int xx
, unsigned int yy
)
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
) {
1722 where
[0] = ~where
[0];
1723 where
[1] = ~where
[1];
1726 for (col
= 0; col
< 4; col
++)
1727 where
[col
] = ~where
[col
];
1730 for (col
= 0; col
< 8; col
++)
1731 where
[col
] = ~where
[col
];
1734 where
= (uint32_t*)(((unsigned char*)where
)+vinfo
.v_rowbytes
);
1739 vc_scroll_down(int num
, unsigned int scrreg_top
, unsigned int scrreg_bottom
)
1741 uint32_t *from
, *to
, linelongs
, i
, line
, rowline
, rowscanline
;
1746 linelongs
= vinfo
.v_rowbytes
* (ISO_CHAR_HEIGHT
>> 2);
1747 rowline
= vinfo
.v_rowbytes
>> 2;
1748 rowscanline
= vinfo
.v_rowscanbytes
>> 2;
1750 to
= (uint32_t *) vinfo
.v_baseaddr
+ (linelongs
* scrreg_bottom
)
1751 - (rowline
- rowscanline
);
1752 from
= to
- (linelongs
* num
); /* handle multiple line scroll (Michel Pollet) */
1754 i
= (scrreg_bottom
- scrreg_top
) - num
;
1757 for (line
= 0; line
< ISO_CHAR_HEIGHT
; line
++) {
1759 * Only copy what is displayed
1761 video_scroll_down(from
,
1762 (from
-(vinfo
.v_rowscanbytes
>> 2)),
1772 vc_scroll_up(int num
, unsigned int scrreg_top
, unsigned int scrreg_bottom
)
1774 uint32_t *from
, *to
, linelongs
, i
, line
, rowline
, rowscanline
;
1779 linelongs
= vinfo
.v_rowbytes
* (ISO_CHAR_HEIGHT
>> 2);
1780 rowline
= vinfo
.v_rowbytes
>> 2;
1781 rowscanline
= vinfo
.v_rowscanbytes
>> 2;
1783 to
= (uint32_t *) vinfo
.v_baseaddr
+ (scrreg_top
* linelongs
);
1784 from
= to
+ (linelongs
* num
); /* handle multiple line scroll (Michel Pollet) */
1786 i
= (scrreg_bottom
- scrreg_top
) - num
;
1789 for (line
= 0; line
< ISO_CHAR_HEIGHT
; line
++) {
1791 * Only copy what is displayed
1793 video_scroll_up(from
,
1794 (from
+(vinfo
.v_rowscanbytes
>> 2)),
1804 vc_update_color(int color
, boolean_t fore
)
1809 vc_color_fore
= vc_colors
[color
][vc_color_index_table
[vinfo
.v_depth
]];
1811 vc_color_back
= vc_colors
[color
][vc_color_index_table
[vinfo
.v_depth
]];
1816 * Video Console (Back-End): Icon Control
1817 * --------------------------------------
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
)
1840 kDataIndexed
= 0x20,
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
,
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
);
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
,
1892 switch( vinfo
.v_depth
) {
1894 if( vc_clut8
== vc_clut
)
1895 vc_blit_rect_8( x
, y
, bx
, width
, height
, sourceRow
, backRow
, dataPtr
, (unsigned char *) backBuffer
, flags
);
1898 vc_blit_rect_16( x
, y
, bx
, width
, height
, sourceRow
, backRow
, dataPtr
, (unsigned short *) backBuffer
, flags
);
1901 vc_blit_rect_32( x
, y
, bx
, width
, height
, sourceRow
, backRow
, dataPtr
, (unsigned int *) backBuffer
, flags
);
1904 vc_blit_rect_30( x
, y
, bx
, width
, height
, sourceRow
, backRow
, dataPtr
, (unsigned int *) backBuffer
, flags
);
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
)
1917 volatile unsigned short * dst
;
1919 unsigned int data
= 0, out
= 0;
1920 int sx
, sy
, a
, b
, c
, d
;
1921 int scale
= 0x10000;
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;
1930 if (!sourceRow
) data
= (unsigned int)(uintptr_t)dataPtr
;
1931 else if (1 == sourceRow
) a
= 0;
1933 dst
= (volatile unsigned short *) (vinfo
.v_baseaddr
+
1934 (y
* vinfo
.v_rowbytes
) +
1937 for( line
= 0; line
< height
; line
++)
1939 for( col
= 0; col
< width
; col
++)
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
];
1949 dst
= (volatile unsigned short *) (((volatile char*)dst
) + vinfo
.v_rowbytes
);
1953 /* For ARM, 16-bit is 565 (RGB); it is 1555 (XRGB) on other platforms */
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
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
,
1975 volatile unsigned short * dst
;
1977 unsigned int data
= 0, out
= 0, back
= 0;
1978 int sx
, sy
, a
, b
, c
, d
;
1979 int scale
= 0x10000;
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;
1988 if (!sourceRow
) data
= (unsigned int)(uintptr_t)dataPtr
;
1989 else if (1 == sourceRow
) a
= 0;
1993 dst
= (volatile unsigned short *) (vinfo
.v_baseaddr
+
1994 (y
* vinfo
.v_rowbytes
) +
1997 for( line
= 0; line
< height
; line
++)
1999 for( col
= 0; col
< width
; col
++)
2001 if (sourceRow
) data
= dataPtr
[((sx
+ (col
* a
) + (line
* b
)) >> 16)
2002 + sourceRow
* (((sy
+ (col
* c
) + (line
* d
)) >> 16))];
2004 if (kSave
& flags
) {
2005 back
= *(dst
+ col
);
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
);
2027 dst
= (volatile unsigned short *) (((volatile char*)dst
) + vinfo
.v_rowbytes
);
2029 backPtr
+= backRow
- width
;
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
,
2041 volatile unsigned int * dst
;
2043 unsigned int data
= 0, out
= 0, back
= 0;
2044 int sx
, sy
, a
, b
, c
, d
;
2045 int scale
= 0x10000;
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;
2054 if (!sourceRow
) data
= (unsigned int)(uintptr_t)dataPtr
;
2055 else if (1 == sourceRow
) a
= 0;
2059 dst
= (volatile unsigned int *) (vinfo
.v_baseaddr
+
2060 (y
* vinfo
.v_rowbytes
) +
2063 for( line
= 0; line
< height
; line
++)
2065 for( col
= 0; col
< width
; col
++)
2067 if (sourceRow
) data
= dataPtr
[((sx
+ (col
* a
) + (line
* b
)) >> 16)
2068 + sourceRow
* (((sy
+ (col
* c
) + (line
* d
)) >> 16))];
2070 if (kSave
& flags
) {
2071 back
= *(dst
+ col
);
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)
2092 dst
= (volatile unsigned int *) (((volatile char*)dst
) + vinfo
.v_rowbytes
);
2094 backPtr
+= backRow
- width
;
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
,
2105 volatile unsigned int * dst
;
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;
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;
2119 if (!sourceRow
) data
= (unsigned int)(uintptr_t)dataPtr
;
2120 else if (1 == sourceRow
) a
= 0;
2124 dst
= (volatile unsigned int *) (vinfo
.v_baseaddr
+
2125 (y
* vinfo
.v_rowbytes
) +
2128 for( line
= 0; line
< height
; line
++)
2130 for( col
= 0; col
< width
; col
++)
2132 if (col
< sourceRow
)
2136 if (kSave
& flags
) {
2137 back
= *(dst
+ col
);
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
) {
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);
2160 dst
= (volatile unsigned int *) (((volatile char*)dst
) + vinfo
.v_rowbytes
);
2162 backPtr
+= backRow
- width
;
2168 * Routines to render the lzss image format
2171 struct lzss_image_state
{
2176 uint32_t bytes_per_row
;
2177 volatile uint32_t * row_start
;
2178 const uint8_t* clut
;
2180 typedef struct lzss_image_state lzss_image_state
;
2182 // returns 0 if OK, 1 if error
2184 vc_decompress_lzss_next_pixel (int next_data
, lzss_image_state
* state
)
2186 uint32_t palette_index
= 0;
2187 uint32_t pixel_value
= 0;
2189 palette_index
= next_data
* 3;
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]);
2195 *(state
->row_start
+ state
->col
) = pixel_value
;
2197 if (++state
->col
>= state
->width
) {
2199 if (++state
->row
>= state
->height
) {
2202 state
->row_start
= (volatile uint32_t *) (((uintptr_t)state
->row_start
) + state
->bytes_per_row
);
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.
2215 * TODO: Does lzss use too much stack? 4096 plus bytes...
2216 * Can probably chop it down by 1/2.
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.
2226 NIFTY-Serve PAF01022
2227 CompuServe 74050,1022
2229 **************************************************************/
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 */
2236 // returns 0 if OK, 1 if error
2237 // x and y indicate upper left corner of image location on screen
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
)
2245 uint32_t* image_start
;
2246 uint32_t bytes_per_pixel
= 4;
2247 uint32_t bytes_per_row
= vinfo
.v_rowbytes
;
2249 image_start
= (uint32_t *) (vinfo
.v_baseaddr
+ (dst_y
* bytes_per_row
) + (dst_x
* bytes_per_pixel
));
2251 lzss_image_state state
= {0, 0, image_width
, image_height
, bytes_per_row
, image_start
, clut
};
2255 const uint8_t *src
= compressed_image
;
2256 uint32_t srclen
= compressed_size
;
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
;
2264 srcend
= src
+ srclen
;
2265 for (i
= 0; i
< N
- F
; i
++)
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 */
2275 if (src
< srcend
) c
= *src
++; else break;
2276 rval
= vc_decompress_lzss_next_pixel(c
, &state
);
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
);
2299 void noroot_icon_test(void) {
2300 boolean_t o_vc_progress_enable
= vc_progress_enable
;
2302 vc_progress_enable
= 1;
2304 PE_display_icon( 0, "noroot");
2306 vc_progress_enable
= o_vc_progress_enable
;
2310 void vc_display_icon( vc_progress_element
* desc
,
2311 const unsigned char * data
)
2313 int x
, y
, width
, height
;
2315 if( vc_progress_enable
&& vc_clut
) {
2317 width
= desc
->width
;
2318 height
= desc
->height
;
2321 if( 1 & desc
->flags
) {
2322 x
+= ((vinfo
.v_width
- width
) / 2);
2323 y
+= ((vinfo
.v_height
- height
) / 2);
2325 vc_blit_rect( x
, y
, 0, width
, height
, width
, 0, data
, NULL
, kDataIndexed
);
2330 vc_progress_initialize( vc_progress_element
* desc
,
2331 const unsigned char * data1x
,
2332 const unsigned char * data2x
,
2333 const unsigned char * clut
)
2337 if( (!clut
) || (!desc
) || (!data1x
))
2342 simple_lock_init(&vc_progress_lock
, 0);
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
;
2351 vc_progress_alpha
= NULL
;
2353 thread_call_setup(&vc_progress_call
, vc_progress_task
, NULL
);
2355 clock_interval_to_absolutetime_interval(vc_progress
->time
, 1000 * 1000, &abstime
);
2356 vc_progress_interval
= (uint32_t)abstime
;
2360 vc_progress_set(boolean_t enable
, uint32_t vc_delay
)
2363 void *saveBuf
= NULL
;
2364 vm_size_t saveLen
= 0;
2367 unsigned char pdata8
;
2368 unsigned short pdata16
;
2369 unsigned short * buf16
;
2370 unsigned int pdata32
;
2371 unsigned int * buf32
;
2377 saveLen
= (vc_progress
->width
<< vc_uiselect
) * (vc_progress
->height
<< vc_uiselect
) * vinfo
.v_depth
/ 8;
2378 saveBuf
= kalloc( saveLen
);
2380 switch( vinfo
.v_depth
) {
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
;
2394 memset( saveBuf
, 0x01, saveLen
);
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
;
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
;
2418 simple_lock(&vc_progress_lock
);
2420 if( vc_progress_enable
!= enable
) {
2421 vc_progress_enable
= enable
;
2424 vc_saveunder
= saveBuf
;
2425 vc_saveunder_len
= saveLen
;
2428 vc_progress_count
= 0;
2429 vc_progress_angle
= 0;
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
);
2438 saveBuf
= vc_saveunder
;
2439 saveLen
= vc_saveunder_len
;
2440 vc_saveunder
= NULL
;
2441 vc_saveunder_len
= 0;
2444 thread_call_cancel(&vc_progress_call
);
2448 simple_unlock(&vc_progress_lock
);
2452 kfree( saveBuf
, saveLen
);
2457 vc_progress_task(__unused
void *arg0
, __unused
void *arg
)
2460 int x
, y
, width
, height
;
2461 const unsigned char * data
;
2464 simple_lock(&vc_progress_lock
);
2466 if( vc_progress_enable
) {
2468 KERNEL_DEBUG_CONSTANT(0x7020008, vc_progress_count
, 0, 0, 0, 0);
2470 vc_progress_count
++;
2471 if( vc_progress_count
>= vc_progress
->count
) {
2472 vc_progress_count
= 0;
2473 vc_progress_angle
++;
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);
2486 vc_blit_rect( x
, y
, 0,
2487 width
, height
, width
, width
,
2490 | (vc_progress_angle
& kDataRotate
)
2491 | (vc_needsave
? kSave
: 0) );
2492 vc_needsave
= FALSE
;
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
);
2497 simple_unlock(&vc_progress_lock
);
2502 * Generic Console (Front-End): Master Control
2503 * -------------------------------------------
2506 #if defined (__i386__) || defined (__x86_64__)
2507 #include <pexpert/i386/boot.h>
2510 static boolean_t gc_acquired
= FALSE
;
2511 static boolean_t gc_graphics_boot
= FALSE
;
2512 static boolean_t gc_desire_text
= FALSE
;
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
;
2520 gc_pause( boolean_t pause
, boolean_t graphics_now
)
2525 VCPUTC_LOCK_LOCK( );
2527 disableConsoleOutput
= (pause
&& !console_is_serial());
2528 gc_enabled
= (!pause
&& !graphics_now
);
2530 VCPUTC_LOCK_UNLOCK( );
2532 simple_lock(&vc_progress_lock
);
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
);
2538 simple_unlock(&vc_progress_lock
);
2543 vc_initialize(__unused
struct vc_info
* vinfo_p
)
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;
2553 initialize_screen(PE_Video
* boot_vinfo
, unsigned int op
)
2555 unsigned int fbsize
= 0;
2556 vm_offset_t newVideoVirt
= 0;
2557 boolean_t graphics_now
;
2562 struct vc_info new_vinfo
= vinfo
;
2564 * First, check if we are changing the size and/or location of the framebuffer
2566 new_vinfo
.v_name
[0] = 0;
2567 new_vinfo
.v_physaddr
= boot_vinfo
->v_baseAddr
& ~3; /* Get the physical address */
2569 new_vinfo
.v_physaddr
|= (((uint64_t) boot_vinfo
->v_baseAddrHigh
) << 32);
2571 if (kPEBaseAddressChange
!= op
)
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
;
2580 new_vinfo
.v_type
= 0;
2582 new_vinfo
.v_scale
= boot_vinfo
->v_scale
;
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) */
2589 if (!new_vinfo
.v_physaddr
) /* Check to see if we have a framebuffer */
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 */
2601 * If VM is up, we are given a virtual address, unless b0 is set to indicate physical.
2603 if ((kernel_map
!= VM_MAP_NULL
) && (0 == (1 & boot_vinfo
->v_baseAddr
)))
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? */
2608 panic("initialize_screen: Strange framebuffer - addr = %08X\n", (uint32_t)boot_vinfo
->v_baseAddr
);
2610 new_vinfo
.v_physaddr
= (((uint64_t)fbppage
) << 12) | (boot_vinfo
->v_baseAddr
& PAGE_MASK
); /* Get the physical address */
2613 if (boot_vinfo
->v_length
!= 0)
2614 fbsize
= (unsigned int) round_page(boot_vinfo
->v_length
);
2616 fbsize
= (unsigned int) round_page(new_vinfo
.v_height
* new_vinfo
.v_rowbytes
); /* Remember size */
2619 if ((lastVideoPhys
!= new_vinfo
.v_physaddr
) || (fbsize
> lastVideoSize
)) /* Did framebuffer change location or get bigger? */
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 */
2626 if (newVideoVirt
!= 0)
2627 new_vinfo
.v_baseaddr
= newVideoVirt
+ boot_vinfo
->v_offset
; /* Set the new framebuffer address */
2629 new_vinfo
.v_baseaddr
= lastVideoVirt
+ boot_vinfo
->v_offset
; /* Set the new framebuffer address */
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
);
2636 /* Update the vinfo structure atomically with respect to the vc_progress task if running */
2639 simple_lock(&vc_progress_lock
);
2641 simple_unlock(&vc_progress_lock
);
2648 // If we changed the virtual address, remove the old mapping
2649 if (newVideoVirt
!= 0)
2651 if (lastVideoVirt
) /* Was the framebuffer mapped before? */
2654 if(lastVideoMapped
) /* Was this not a special pre-VM mapping? */
2657 pmap_remove(kernel_pmap
, trunc_page_64(lastVideoVirt
),
2658 round_page_64(lastVideoVirt
+ lastVideoSize
)); /* Toss mappings */
2660 if(lastVideoMapped
) /* Was this not a special pre-VM mapping? */
2662 kmem_free(kernel_map
, lastVideoVirt
, lastVideoSize
); /* Toss kernel addresses */
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
);
2671 if (kPEBaseAddressChange
!= op
)
2673 // Graphics mode setup by the booter.
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
);
2687 #ifdef GRATEFULDEBUGGER
2688 GratefulDebInit((bootBumbleC
*)boot_vinfo
); /* Re-initialize GratefulDeb */
2689 #endif /* GRATEFULDEBUGGER */
2692 graphics_now
= gc_graphics_boot
&& !gc_desire_text
;
2695 case kPEGraphicsMode
:
2696 panicDialogDesired
= TRUE
;
2697 gc_graphics_boot
= TRUE
;
2698 gc_desire_text
= FALSE
;
2702 panicDialogDesired
= FALSE
;
2703 disable_debug_output
= FALSE
;
2704 gc_graphics_boot
= FALSE
;
2707 case kPEAcquireScreen
:
2708 if ( gc_acquired
) break;
2709 vc_progress_set( graphics_now
, kProgressAcquireDelay
);
2710 gc_enable( !graphics_now
);
2712 gc_desire_text
= FALSE
;
2715 case kPEDisableScreen
:
2718 gc_pause( TRUE
, graphics_now
);
2722 case kPEEnableScreen
:
2725 gc_pause( FALSE
, graphics_now
);
2730 if ( console_is_serial() ) break;
2732 panicDialogDesired
= FALSE
;
2733 disable_debug_output
= FALSE
;
2734 if ( gc_acquired
== FALSE
)
2736 gc_desire_text
= TRUE
;
2739 if ( gc_graphics_boot
== FALSE
) break;
2741 vc_progress_set( FALSE
, 0 );
2742 #if !CONFIG_EMBEDDED
2743 vc_enable_progressmeter( FALSE
);
2748 case kPEReleaseScreen
:
2749 gc_acquired
= FALSE
;
2750 gc_desire_text
= FALSE
;
2752 vc_progress_set( FALSE
, 0 );
2753 #if !CONFIG_EMBEDDED
2754 vc_enable_progressmeter( FALSE
);
2758 #ifdef GRATEFULDEBUGGER
2759 GratefulDebInit(0); /* Stop grateful debugger */
2760 #endif /* GRATEFULDEBUGGER */
2763 #ifdef GRATEFULDEBUGGER
2764 if ( boot_vinfo
) GratefulDebInit((bootBumbleC
*)boot_vinfo
); /* Re initialize GratefulDeb */
2765 #endif /* GRATEFULDEBUGGER */
2771 unsigned int *p
, *endp
, *row
;
2772 int col
, rowline
, rowlongs
;
2773 register unsigned int mask
;
2778 if ( vinfo
.v_depth
== 32 )
2780 else if ( vinfo
.v_depth
== 30 )
2781 mask
= (0x1ff<<20) | (0x1ff<<10) | 0x1ff;
2782 else if ( vinfo
.v_depth
== 16 )
2787 rowline
= (int)(vinfo
.v_rowscanbytes
/ 4);
2788 rowlongs
= (int)(vinfo
.v_rowbytes
/ 4);
2790 p
= (unsigned int*) vinfo
.v_baseaddr
;
2791 endp
= p
+ (rowlongs
* vinfo
.v_height
);
2793 for (row
= p
; row
< endp
; row
+= rowlongs
) {
2794 for (p
= &row
[0], col
= 0; col
< rowline
; col
++) {
2795 *p
= (*p
>> 1) & mask
;
2801 void vcattach(void); /* XXX gcc 4 warning cleanup */
2806 vm_initialized
= TRUE
;
2808 if ( gc_graphics_boot
== FALSE
)
2814 initialize_screen(NULL
, kPEReleaseScreen
);
2817 initialize_screen(NULL
, kPEAcquireScreen
);
2819 for ( index
= 0 ; index
< msgbufp
->msg_bufx
; index
++ )
2821 if (msgbufp
->msg_bufc
[index
] == '\0') {
2825 vcputc( 0, 0, msgbufp
->msg_bufc
[index
] );
2827 if ( msgbufp
->msg_bufc
[index
] == '\n' )
2829 vcputc( 0, 0,'\r' );
2835 #if !CONFIG_EMBEDDED
2837 int vc_progress_meter_enable
;
2838 int vc_progress_meter_value
;
2840 static void * vc_progress_meter_backbuffer
;
2841 static int vc_progress_meter_drawn
;
2844 vc_draw_progress_meter(int select
, unsigned int flags
, int x1
, int x2
)
2846 const unsigned char * data
;
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);
2853 if (kDataBack
== flags
)
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
);
2862 for (x
= x1
; x
< x2
; x
+= w
)
2864 if (x
< (kProgressBarCapWidth
<< vc_uiselect
))
2866 if (x2
< (kProgressBarCapWidth
<< vc_uiselect
))
2869 w
= (kProgressBarCapWidth
<< vc_uiselect
) - x
;
2870 data
= progressmeter_leftcap
[vc_uiselect
& 1][select
& 1];
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
);
2878 else if (x
< ((kProgressBarWidth
- kProgressBarCapWidth
) << vc_uiselect
))
2880 if (x2
< ((kProgressBarWidth
- kProgressBarCapWidth
) << vc_uiselect
))
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
),
2888 (kProgressBarWidth
<< vc_uiselect
),
2889 data
, vc_progress_meter_backbuffer
, flags
);
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
);
2906 vc_enable_progressmeter(int new_value
)
2909 void * new_buffer
= NULL
;
2912 new_buffer
= kalloc((kProgressBarWidth
<< vc_uiselect
)
2913 * (kProgressBarHeight
<< vc_uiselect
) * sizeof(int));
2916 simple_lock(&vc_progress_lock
);
2918 if (gc_enabled
|| !gc_acquired
|| !gc_graphics_boot
)
2921 if (new_value
!= vc_progress_meter_enable
)
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
;
2929 vc_progress_meter_drawn
= 0;
2931 else if (vc_progress_meter_backbuffer
)
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
;
2940 simple_unlock(&vc_progress_lock
);
2944 kfree(new_buffer
, (kProgressBarWidth
<< vc_uiselect
)
2945 * (kProgressBarHeight
<< vc_uiselect
) * sizeof(int));
2949 vc_set_progressmeter(int new_value
)
2954 if ((new_value
< 0) | (new_value
> 100))
2958 simple_lock(&vc_progress_lock
);
2960 if (vc_progress_meter_enable
)
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
);
2967 vc_draw_progress_meter(FALSE
, kDataAlpha
, x2
, vc_progress_meter_drawn
);
2968 vc_progress_meter_drawn
= x2
;
2971 simple_unlock(&vc_progress_lock
);
2975 #endif /* !CONFIG_EMBEDDED */