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"
112 #include "progress_meter_data.c"
114 #include "sys/msgbuf.h"
117 * Generic Console (Front-End)
118 * ---------------------------
121 struct vc_info vinfo
;
123 void noroot_icon_test(void);
126 extern int disableConsoleOutput
;
127 static boolean_t gc_enabled
= FALSE
;
128 static boolean_t gc_initialized
= FALSE
;
129 static boolean_t vm_initialized
= FALSE
;
132 void (*initialize
)(struct vc_info
* info
);
133 void (*enable
)(boolean_t enable
);
134 void (*paint_char
)(unsigned int xx
, unsigned int yy
, unsigned char ch
,
135 int attrs
, unsigned char ch_previous
,
137 void (*clear_screen
)(unsigned int xx
, unsigned int yy
, unsigned int top
,
138 unsigned int bottom
, int which
);
139 void (*scroll_down
)(int num
, unsigned int top
, unsigned int bottom
);
140 void (*scroll_up
)(int num
, unsigned int top
, unsigned int bottom
);
141 void (*hide_cursor
)(unsigned int xx
, unsigned int yy
);
142 void (*show_cursor
)(unsigned int xx
, unsigned int yy
);
143 void (*update_color
)(int color
, boolean_t fore
);
146 static unsigned char *gc_buffer_attributes
;
147 static unsigned char *gc_buffer_characters
;
148 static unsigned char *gc_buffer_colorcodes
;
149 static unsigned char *gc_buffer_tab_stops
;
150 static uint32_t gc_buffer_columns
;
151 static uint32_t gc_buffer_rows
;
152 static uint32_t gc_buffer_size
;
154 #if defined(__i386__) || defined(__x86_64__)
155 decl_simple_lock_data(static, vcputc_lock
);
157 #define VCPUTC_LOCK_INIT() \
159 simple_lock_init(&vcputc_lock, 0); \
162 #define VCPUTC_LOCK_LOCK() \
164 boolean_t istate = ml_get_interrupts_enabled(); \
165 while (!simple_lock_try(&vcputc_lock)) \
168 handle_pending_TLB_flushes(); \
173 #define VCPUTC_LOCK_UNLOCK() \
175 simple_unlock(&vcputc_lock); \
178 static hw_lock_data_t vcputc_lock
;
180 #define VCPUTC_LOCK_INIT() \
182 hw_lock_init(&vcputc_lock); \
185 #define VCPUTC_LOCK_LOCK() \
187 if (!hw_lock_to(&vcputc_lock, ~0U))\
189 panic("VCPUTC_LOCK_LOCK"); \
193 #define VCPUTC_LOCK_UNLOCK() \
195 hw_lock_unlock(&vcputc_lock); \
201 # 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
203 # 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
204 # Background color codes:
205 # 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
211 #define ATTR_REVERSE 4
213 #define COLOR_BACKGROUND 0
214 #define COLOR_FOREGROUND 7
216 #define COLOR_CODE_GET(code, fore) (((code) & ((fore) ? 0xF0 : 0x0F)) >> ((fore) ? 4 : 0))
217 #define COLOR_CODE_SET(code, color, fore) (((code) & ((fore) ? 0x0F : 0xF0)) | ((color) << ((fore) ? 4 : 0)))
219 static unsigned char gc_color_code
;
223 static unsigned int gc_x
, gc_y
, gc_savex
, gc_savey
;
224 static unsigned int gc_par
[MAXPARS
], gc_numpars
, gc_hanging_cursor
, gc_attr
, gc_saveattr
;
226 /* VT100 scroll region */
227 static unsigned int gc_scrreg_top
, gc_scrreg_bottom
;
230 ESnormal
, /* Nothing yet */
232 ESsquare
, /* Got ESC [ */
233 ESgetpars
, /* About to get or getting the parameters */
234 ESgotpars
, /* Finished getting the parameters */
235 ESfunckey
, /* Function key */
236 EShash
, /* DEC-specific stuff (screen align, etc.) */
237 ESsetG0
, /* Specify the G0 character set */
238 ESsetG1
, /* Specify the G1 character set */
241 ESignore
/* Ignore this sequence */
242 } gc_vt100state
= ESnormal
;
245 #ifdef CONFIG_VC_PROGRESS_WHITE
246 enum { kProgressAcquireDelay
= 0 /* secs */ };
248 enum { kProgressAcquireDelay
= 5 /* secs */ };
251 static int8_t vc_rotate_matr
[4][2][2] = {
262 static int gc_wrap_mode
= 1, gc_relative_origin
= 0;
263 static int gc_charset_select
= 0, gc_save_charset_s
= 0;
264 static int gc_charset
[2] = { 0, 0 };
265 static int gc_charset_save
[2] = { 0, 0 };
267 static void gc_clear_line(unsigned int xx
, unsigned int yy
, int which
);
268 static void gc_clear_screen(unsigned int xx
, unsigned int yy
, int top
,
269 unsigned int bottom
, int which
);
270 static void gc_enable(boolean_t enable
);
271 static void gc_hide_cursor(unsigned int xx
, unsigned int yy
);
272 static void gc_initialize(struct vc_info
* info
);
273 static boolean_t
gc_is_tab_stop(unsigned int column
);
274 static void gc_paint_char(unsigned int xx
, unsigned int yy
, unsigned char ch
,
276 static void gc_putchar(char ch
);
277 static void gc_putc_askcmd(unsigned char ch
);
278 static void gc_putc_charsetcmd(int charset
, unsigned char ch
);
279 static void gc_putc_charsizecmd(unsigned char ch
);
280 static void gc_putc_esc(unsigned char ch
);
281 static void gc_putc_getpars(unsigned char ch
);
282 static void gc_putc_gotpars(unsigned char ch
);
283 static void gc_putc_normal(unsigned char ch
);
284 static void gc_putc_square(unsigned char ch
);
285 static void gc_reset_screen(void);
286 static void gc_reset_tabs(void);
287 static void gc_reset_vt100(void);
288 static void gc_scroll_down(int num
, unsigned int top
, unsigned int bottom
);
289 static void gc_scroll_up(int num
, unsigned int top
, unsigned int bottom
);
290 static void gc_set_tab_stop(unsigned int column
, boolean_t enabled
);
291 static void gc_show_cursor(unsigned int xx
, unsigned int yy
);
292 static void gc_update_color(int color
, boolean_t fore
);
295 gc_clear_line(unsigned int xx
, unsigned int yy
, int which
)
297 unsigned int start
, end
, i
;
300 * This routine runs extremely slowly. I don't think it's
301 * used all that often, except for To end of line. I'll go
302 * back and speed this up when I speed up the whole vc
307 case 0: /* To end of line */
309 end
= vinfo
.v_columns
-1;
311 case 1: /* To start of line */
315 case 2: /* Whole line */
317 end
= vinfo
.v_columns
-1;
323 for (i
= start
; i
<= end
; i
++) {
324 gc_paint_char(i
, yy
, ' ', ATTR_NONE
);
329 gc_clear_screen(unsigned int xx
, unsigned int yy
, int top
, unsigned int bottom
,
332 if (!gc_buffer_size
) return;
334 if ( xx
< gc_buffer_columns
&& yy
< gc_buffer_rows
&& bottom
<= gc_buffer_rows
)
339 case 0: /* To end of screen */
340 start
= (yy
* gc_buffer_columns
) + xx
;
341 end
= (bottom
* gc_buffer_columns
) - 1;
343 case 1: /* To start of screen */
344 start
= (top
* gc_buffer_columns
);
345 end
= (yy
* gc_buffer_columns
) + xx
;
347 case 2: /* Whole screen */
348 start
= (top
* gc_buffer_columns
);
349 end
= (bottom
* gc_buffer_columns
) - 1;
357 memset(gc_buffer_attributes
+ start
, ATTR_NONE
, end
- start
+ 1);
358 memset(gc_buffer_characters
+ start
, ' ', end
- start
+ 1);
359 memset(gc_buffer_colorcodes
+ start
, gc_color_code
, end
- start
+ 1);
362 gc_ops
.clear_screen(xx
, yy
, top
, bottom
, which
);
366 gc_enable( boolean_t enable
)
368 unsigned char *buffer_attributes
= NULL
;
369 unsigned char *buffer_characters
= NULL
;
370 unsigned char *buffer_colorcodes
= NULL
;
371 unsigned char *buffer_tab_stops
= NULL
;
372 uint32_t buffer_columns
= 0;
373 uint32_t buffer_rows
= 0;
374 uint32_t buffer_size
= 0;
377 if ( enable
== FALSE
)
379 // only disable console output if it goes to the graphics console
380 if ( console_is_serial() == FALSE
)
381 disableConsoleOutput
= TRUE
;
383 gc_ops
.enable(FALSE
);
389 if ( gc_buffer_size
)
391 buffer_attributes
= gc_buffer_attributes
;
392 buffer_characters
= gc_buffer_characters
;
393 buffer_colorcodes
= gc_buffer_colorcodes
;
394 buffer_tab_stops
= gc_buffer_tab_stops
;
395 buffer_columns
= gc_buffer_columns
;
396 buffer_rows
= gc_buffer_rows
;
397 buffer_size
= gc_buffer_size
;
399 gc_buffer_attributes
= NULL
;
400 gc_buffer_characters
= NULL
;
401 gc_buffer_colorcodes
= NULL
;
402 gc_buffer_tab_stops
= NULL
;
403 gc_buffer_columns
= 0;
407 VCPUTC_LOCK_UNLOCK( );
410 kfree( buffer_attributes
, buffer_size
);
411 kfree( buffer_characters
, buffer_size
);
412 kfree( buffer_colorcodes
, buffer_size
);
413 kfree( buffer_tab_stops
, buffer_columns
);
417 VCPUTC_LOCK_UNLOCK( );
423 if ( vm_initialized
)
425 buffer_columns
= vinfo
.v_columns
;
426 buffer_rows
= vinfo
.v_rows
;
427 buffer_size
= buffer_columns
* buffer_rows
;
431 buffer_attributes
= (unsigned char *) kalloc( buffer_size
);
432 buffer_characters
= (unsigned char *) kalloc( buffer_size
);
433 buffer_colorcodes
= (unsigned char *) kalloc( buffer_size
);
434 buffer_tab_stops
= (unsigned char *) kalloc( buffer_columns
);
436 if ( buffer_attributes
== NULL
||
437 buffer_characters
== NULL
||
438 buffer_colorcodes
== NULL
||
439 buffer_tab_stops
== NULL
)
441 if ( buffer_attributes
) kfree( buffer_attributes
, buffer_size
);
442 if ( buffer_characters
) kfree( buffer_characters
, buffer_size
);
443 if ( buffer_colorcodes
) kfree( buffer_colorcodes
, buffer_size
);
444 if ( buffer_tab_stops
) kfree( buffer_tab_stops
, buffer_columns
);
452 memset( buffer_attributes
, ATTR_NONE
, buffer_size
);
453 memset( buffer_characters
, ' ', buffer_size
);
454 memset( buffer_colorcodes
, COLOR_CODE_SET( 0, COLOR_FOREGROUND
, TRUE
), buffer_size
);
455 memset( buffer_tab_stops
, 0, buffer_columns
);
463 gc_buffer_attributes
= buffer_attributes
;
464 gc_buffer_characters
= buffer_characters
;
465 gc_buffer_colorcodes
= buffer_colorcodes
;
466 gc_buffer_tab_stops
= buffer_tab_stops
;
467 gc_buffer_columns
= buffer_columns
;
468 gc_buffer_rows
= buffer_rows
;
469 gc_buffer_size
= buffer_size
;
473 VCPUTC_LOCK_UNLOCK( );
476 gc_ops
.clear_screen(gc_x
, gc_y
, 0, vinfo
.v_rows
, 2);
477 gc_ops
.show_cursor(gc_x
, gc_y
);
481 disableConsoleOutput
= FALSE
;
486 gc_hide_cursor(unsigned int xx
, unsigned int yy
)
488 if ( xx
< gc_buffer_columns
&& yy
< gc_buffer_rows
)
490 uint32_t index
= (yy
* gc_buffer_columns
) + xx
;
491 unsigned char attribute
= gc_buffer_attributes
[index
];
492 unsigned char character
= gc_buffer_characters
[index
];
493 unsigned char colorcode
= gc_buffer_colorcodes
[index
];
494 unsigned char colorcodesave
= gc_color_code
;
496 gc_update_color(COLOR_CODE_GET(colorcode
, TRUE
), TRUE
);
497 gc_update_color(COLOR_CODE_GET(colorcode
, FALSE
), FALSE
);
499 gc_ops
.paint_char(xx
, yy
, character
, attribute
, 0, 0);
501 gc_update_color(COLOR_CODE_GET(colorcodesave
, TRUE
), TRUE
);
502 gc_update_color(COLOR_CODE_GET(colorcodesave
, FALSE
), FALSE
);
506 gc_ops
.hide_cursor(xx
, yy
);
511 gc_initialize(struct vc_info
* info
)
513 if ( gc_initialized
== FALSE
)
518 gc_initialized
= TRUE
;
521 gc_ops
.initialize(info
);
528 gc_paint_char(unsigned int xx
, unsigned int yy
, unsigned char ch
, int attrs
)
530 if ( xx
< gc_buffer_columns
&& yy
< gc_buffer_rows
)
532 uint32_t index
= (yy
* gc_buffer_columns
) + xx
;
534 gc_buffer_attributes
[index
] = attrs
;
535 gc_buffer_characters
[index
] = ch
;
536 gc_buffer_colorcodes
[index
] = gc_color_code
;
539 gc_ops
.paint_char(xx
, yy
, ch
, attrs
, 0, 0);
546 return; /* ignore null characters */
548 switch (gc_vt100state
) {
549 default:gc_vt100state
= ESnormal
; /* FALLTHROUGH */
569 gc_putc_charsizecmd(ch
);
572 gc_putc_charsetcmd(0, ch
);
575 gc_putc_charsetcmd(1, ch
);
579 if (gc_x
>= vinfo
.v_columns
) {
580 if (0 == vinfo
.v_columns
)
583 gc_x
= vinfo
.v_columns
- 1;
585 if (gc_y
>= vinfo
.v_rows
) {
586 if (0 == vinfo
.v_rows
)
589 gc_y
= vinfo
.v_rows
- 1;
594 gc_putc_askcmd(unsigned char ch
)
596 if (ch
>= '0' && ch
<= '9') {
597 gc_par
[gc_numpars
] = (10*gc_par
[gc_numpars
]) + (ch
-'0');
600 gc_vt100state
= ESnormal
;
604 gc_relative_origin
= ch
== 'h';
606 case 7: /* wrap around mode h=1, l=0*/
607 gc_wrap_mode
= ch
== 'h';
616 gc_putc_charsetcmd(int charset
, unsigned char ch
)
618 gc_vt100state
= ESnormal
;
624 gc_charset
[charset
] = 0;
626 case '0' : /* Graphic characters */
628 gc_charset
[charset
] = 0x21;
635 gc_putc_charsizecmd(unsigned char ch
)
637 gc_vt100state
= ESnormal
;
645 case '8' : /* fill 'E's */
648 for (yy
= 0; yy
< vinfo
.v_rows
; yy
++)
649 for (xx
= 0; xx
< vinfo
.v_columns
; xx
++)
650 gc_paint_char(xx
, yy
, 'E', ATTR_NONE
);
658 gc_putc_esc(unsigned char ch
)
660 gc_vt100state
= ESnormal
;
664 gc_vt100state
= ESsquare
;
666 case 'c': /* Reset terminal */
668 gc_clear_screen(gc_x
, gc_y
, 0, vinfo
.v_rows
, 2);
671 case 'D': /* Line feed */
673 if (gc_y
>= gc_scrreg_bottom
-1) {
674 gc_scroll_up(1, gc_scrreg_top
, gc_scrreg_bottom
);
675 gc_y
= gc_scrreg_bottom
- 1;
679 if (ch
== 'E') gc_x
= 0;
681 case 'H': /* Set tab stop */
682 gc_set_tab_stop(gc_x
, TRUE
);
684 case 'M': /* Cursor up */
685 if (gc_y
<= gc_scrreg_top
) {
686 gc_scroll_down(1, gc_scrreg_top
, gc_scrreg_bottom
);
687 gc_y
= gc_scrreg_top
;
695 case '7': /* Save cursor */
698 gc_saveattr
= gc_attr
;
699 gc_save_charset_s
= gc_charset_select
;
700 gc_charset_save
[0] = gc_charset
[0];
701 gc_charset_save
[1] = gc_charset
[1];
703 case '8': /* Restore cursor */
706 gc_attr
= gc_saveattr
;
707 gc_charset_select
= gc_save_charset_s
;
708 gc_charset
[0] = gc_charset_save
[0];
709 gc_charset
[1] = gc_charset_save
[1];
711 case 'Z': /* return terminal ID */
713 case '#': /* change characters height */
714 gc_vt100state
= EScharsize
;
717 gc_vt100state
= ESsetG0
;
719 case ')': /* character set sequence */
720 gc_vt100state
= ESsetG1
;
725 /* Rest not supported */
732 gc_putc_getpars(unsigned char ch
)
735 gc_vt100state
= ESask
;
739 gc_vt100state
= ESnormal
;
743 if (ch
== ';' && gc_numpars
< MAXPARS
- 1) {
746 if (ch
>= '0' && ch
<= '9') {
747 gc_par
[gc_numpars
] *= 10;
748 gc_par
[gc_numpars
] += ch
- '0';
751 gc_vt100state
= ESgotpars
;
757 gc_putc_gotpars(unsigned char ch
)
762 /* special case for vttest for handling cursor
763 movement in escape sequences */
765 gc_vt100state
= ESgotpars
;
768 gc_vt100state
= ESnormal
;
771 gc_y
-= gc_par
[0] ? gc_par
[0] : 1;
772 if (gc_y
< gc_scrreg_top
)
773 gc_y
= gc_scrreg_top
;
776 gc_y
+= gc_par
[0] ? gc_par
[0] : 1;
777 if (gc_y
>= gc_scrreg_bottom
)
778 gc_y
= gc_scrreg_bottom
- 1;
780 case 'C': /* Right */
781 gc_x
+= gc_par
[0] ? gc_par
[0] : 1;
782 if (gc_x
>= vinfo
.v_columns
)
783 gc_x
= vinfo
.v_columns
-1;
786 if (gc_par
[0] > gc_x
)
793 case 'H': /* Set cursor position */
795 gc_x
= gc_par
[1] ? gc_par
[1] - 1 : 0;
796 gc_y
= gc_par
[0] ? gc_par
[0] - 1 : 0;
797 if (gc_relative_origin
)
798 gc_y
+= gc_scrreg_top
;
799 gc_hanging_cursor
= 0;
801 case 'X': /* clear p1 characters */
803 for (i
= gc_x
; i
< gc_x
+ gc_par
[0]; i
++)
804 gc_paint_char(i
, gc_y
, ' ', ATTR_NONE
);
807 case 'J': /* Clear part of screen */
808 gc_clear_screen(gc_x
, gc_y
, 0, vinfo
.v_rows
, gc_par
[0]);
810 case 'K': /* Clear part of line */
811 gc_clear_line(gc_x
, gc_y
, gc_par
[0]);
813 case 'g': /* tab stops */
816 case 2: /* reset tab stops */
817 /* gc_reset_tabs(); */
819 case 3: /* Clear every tabs */
821 for (i
= 0; i
<= vinfo
.v_columns
; i
++)
822 gc_set_tab_stop(i
, FALSE
);
826 gc_set_tab_stop(gc_x
, FALSE
);
830 case 'm': /* Set attribute */
831 for (i
= 0; i
< gc_numpars
; i
++) {
835 gc_update_color(COLOR_BACKGROUND
, FALSE
);
836 gc_update_color(COLOR_FOREGROUND
, TRUE
);
839 gc_attr
|= ATTR_BOLD
;
842 gc_attr
|= ATTR_UNDER
;
845 gc_attr
|= ATTR_REVERSE
;
848 gc_attr
&= ~ATTR_BOLD
;
851 gc_attr
&= ~ATTR_UNDER
;
854 gc_attr
&= ~ATTR_REVERSE
;
857 case 25: /* blink/no blink */
860 if (gc_par
[i
] >= 30 && gc_par
[i
] <= 37)
861 gc_update_color(gc_par
[i
] - 30, TRUE
);
862 if (gc_par
[i
] >= 40 && gc_par
[i
] <= 47)
863 gc_update_color(gc_par
[i
] - 40, FALSE
);
868 case 'r': /* Set scroll region */
870 /* ensure top < bottom, and both within limits */
871 if ((gc_numpars
> 0) && (gc_par
[0] < vinfo
.v_rows
)) {
872 gc_scrreg_top
= gc_par
[0] ? gc_par
[0] - 1 : 0;
876 if ((gc_numpars
> 1) && (gc_par
[1] <= vinfo
.v_rows
) && (gc_par
[1] > gc_par
[0])) {
877 gc_scrreg_bottom
= gc_par
[1];
878 if (gc_scrreg_bottom
> vinfo
.v_rows
)
879 gc_scrreg_bottom
= vinfo
.v_rows
;
881 gc_scrreg_bottom
= vinfo
.v_rows
;
883 if (gc_relative_origin
)
884 gc_y
= gc_scrreg_top
;
891 gc_putc_normal(unsigned char ch
)
894 case '\a': /* Beep */
896 case 127: /* Delete */
897 case '\b': /* Backspace */
898 if (gc_hanging_cursor
) {
899 gc_hanging_cursor
= 0;
906 if (gc_buffer_tab_stops
) while (gc_x
< vinfo
.v_columns
&& !gc_is_tab_stop(++gc_x
));
908 if (gc_x
>= vinfo
.v_columns
)
909 gc_x
= vinfo
.v_columns
-1;
913 case '\n': /* Line feed */
914 if (gc_y
>= gc_scrreg_bottom
-1 ) {
915 gc_scroll_up(1, gc_scrreg_top
, gc_scrreg_bottom
);
916 gc_y
= gc_scrreg_bottom
- 1;
921 case '\r': /* Carriage return */
923 gc_hanging_cursor
= 0;
925 case 0x0e: /* Select G1 charset (Control-N) */
926 gc_charset_select
= 1;
928 case 0x0f: /* Select G0 charset (Control-O) */
929 gc_charset_select
= 0;
931 case 0x18 : /* CAN : cancel */
932 case 0x1A : /* like cancel */
933 /* well, i do nothing here, may be later */
935 case '\033': /* Escape */
936 gc_vt100state
= ESesc
;
937 gc_hanging_cursor
= 0;
941 if (gc_hanging_cursor
) {
943 if (gc_y
>= gc_scrreg_bottom
-1 ) {
944 gc_scroll_up(1, gc_scrreg_top
, gc_scrreg_bottom
);
945 gc_y
= gc_scrreg_bottom
- 1;
949 gc_hanging_cursor
= 0;
951 gc_paint_char(gc_x
, gc_y
, (ch
>= 0x60 && ch
<= 0x7f) ? ch
+ gc_charset
[gc_charset_select
]
953 if (gc_x
== vinfo
.v_columns
- 1) {
954 gc_hanging_cursor
= gc_wrap_mode
;
965 gc_putc_square(unsigned char ch
)
969 for (i
= 0; i
< MAXPARS
; i
++) {
974 gc_vt100state
= ESgetpars
;
981 gc_reset_screen(void)
992 if (!gc_buffer_tab_stops
) return;
994 for (i
= 0; i
< vinfo
.v_columns
; i
++) {
995 gc_buffer_tab_stops
[i
] = ((i
% 8) == 0);
1001 gc_set_tab_stop(unsigned int column
, boolean_t enabled
)
1003 if (gc_buffer_tab_stops
&& (column
< vinfo
.v_columns
)) {
1004 gc_buffer_tab_stops
[column
] = enabled
;
1008 static boolean_t
gc_is_tab_stop(unsigned int column
)
1010 if (gc_buffer_tab_stops
== NULL
)
1011 return ((column
% 8) == 0);
1012 if (column
< vinfo
.v_columns
)
1013 return gc_buffer_tab_stops
[column
];
1019 gc_reset_vt100(void)
1023 gc_scrreg_bottom
= vinfo
.v_rows
;
1024 gc_attr
= ATTR_NONE
;
1025 gc_charset
[0] = gc_charset
[1] = 0;
1026 gc_charset_select
= 0;
1028 gc_relative_origin
= 0;
1029 gc_update_color(COLOR_BACKGROUND
, FALSE
);
1030 gc_update_color(COLOR_FOREGROUND
, TRUE
);
1034 gc_scroll_down(int num
, unsigned int top
, unsigned int bottom
)
1036 if (!gc_buffer_size
) return;
1038 if ( bottom
<= gc_buffer_rows
)
1040 unsigned char colorcodesave
= gc_color_code
;
1041 uint32_t column
, row
;
1042 uint32_t index
, jump
;
1044 jump
= num
* gc_buffer_columns
;
1046 for ( row
= bottom
- 1 ; row
>= top
+ num
; row
-- )
1048 index
= row
* gc_buffer_columns
;
1050 for ( column
= 0 ; column
< gc_buffer_columns
; index
++, column
++ )
1052 if ( gc_buffer_attributes
[index
] != gc_buffer_attributes
[index
- jump
] ||
1053 gc_buffer_characters
[index
] != gc_buffer_characters
[index
- jump
] ||
1054 gc_buffer_colorcodes
[index
] != gc_buffer_colorcodes
[index
- jump
] )
1056 if ( gc_color_code
!= gc_buffer_colorcodes
[index
- jump
] )
1058 gc_update_color(COLOR_CODE_GET(gc_buffer_colorcodes
[index
- jump
], TRUE
), TRUE
);
1059 gc_update_color(COLOR_CODE_GET(gc_buffer_colorcodes
[index
- jump
], FALSE
), FALSE
);
1062 if ( gc_buffer_colorcodes
[index
] != gc_buffer_colorcodes
[index
- jump
] )
1064 gc_ops
.paint_char( /* xx */ column
,
1066 /* ch */ gc_buffer_characters
[index
- jump
],
1067 /* attrs */ gc_buffer_attributes
[index
- jump
],
1068 /* ch_previous */ 0,
1069 /* attrs_previous */ 0 );
1073 gc_ops
.paint_char( /* xx */ column
,
1075 /* ch */ gc_buffer_characters
[index
- jump
],
1076 /* attrs */ gc_buffer_attributes
[index
- jump
],
1077 /* ch_previous */ gc_buffer_characters
[index
],
1078 /* attrs_previous */ gc_buffer_attributes
[index
] );
1081 gc_buffer_attributes
[index
] = gc_buffer_attributes
[index
- jump
];
1082 gc_buffer_characters
[index
] = gc_buffer_characters
[index
- jump
];
1083 gc_buffer_colorcodes
[index
] = gc_buffer_colorcodes
[index
- jump
];
1088 if ( colorcodesave
!= gc_color_code
)
1090 gc_update_color(COLOR_CODE_GET(colorcodesave
, TRUE
), TRUE
);
1091 gc_update_color(COLOR_CODE_GET(colorcodesave
, FALSE
), FALSE
);
1094 /* Now set the freed up lines to the background colour */
1096 for ( row
= top
; row
< top
+ num
; row
++ )
1098 index
= row
* gc_buffer_columns
;
1100 for ( column
= 0 ; column
< gc_buffer_columns
; index
++, column
++ )
1102 if ( gc_buffer_attributes
[index
] != ATTR_NONE
||
1103 gc_buffer_characters
[index
] != ' ' ||
1104 gc_buffer_colorcodes
[index
] != gc_color_code
)
1106 if ( gc_buffer_colorcodes
[index
] != gc_color_code
)
1108 gc_ops
.paint_char( /* xx */ column
,
1111 /* attrs */ ATTR_NONE
,
1112 /* ch_previous */ 0,
1113 /* attrs_previous */ 0 );
1117 gc_ops
.paint_char( /* xx */ column
,
1120 /* attrs */ ATTR_NONE
,
1121 /* ch_previous */ gc_buffer_characters
[index
],
1122 /* attrs_previous */ gc_buffer_attributes
[index
] );
1125 gc_buffer_attributes
[index
] = ATTR_NONE
;
1126 gc_buffer_characters
[index
] = ' ';
1127 gc_buffer_colorcodes
[index
] = gc_color_code
;
1134 gc_ops
.scroll_down(num
, top
, bottom
);
1136 /* Now set the freed up lines to the background colour */
1138 gc_clear_screen(vinfo
.v_columns
- 1, top
+ num
- 1, top
, bottom
, 1);
1143 gc_scroll_up(int num
, unsigned int top
, unsigned int bottom
)
1145 if (!gc_buffer_size
) return;
1147 if ( bottom
<= gc_buffer_rows
)
1149 unsigned char colorcodesave
= gc_color_code
;
1150 uint32_t column
, row
;
1151 uint32_t index
, jump
;
1153 jump
= num
* gc_buffer_columns
;
1155 for ( row
= top
; row
< bottom
- num
; row
++ )
1157 index
= row
* gc_buffer_columns
;
1159 for ( column
= 0 ; column
< gc_buffer_columns
; index
++, column
++ )
1161 if ( gc_buffer_attributes
[index
] != gc_buffer_attributes
[index
+ jump
] ||
1162 gc_buffer_characters
[index
] != gc_buffer_characters
[index
+ jump
] ||
1163 gc_buffer_colorcodes
[index
] != gc_buffer_colorcodes
[index
+ jump
] )
1165 if ( gc_color_code
!= gc_buffer_colorcodes
[index
+ jump
] )
1167 gc_update_color(COLOR_CODE_GET(gc_buffer_colorcodes
[index
+ jump
], TRUE
), TRUE
);
1168 gc_update_color(COLOR_CODE_GET(gc_buffer_colorcodes
[index
+ jump
], FALSE
), FALSE
);
1171 if ( gc_buffer_colorcodes
[index
] != gc_buffer_colorcodes
[index
+ jump
] )
1173 gc_ops
.paint_char( /* xx */ column
,
1175 /* ch */ gc_buffer_characters
[index
+ jump
],
1176 /* attrs */ gc_buffer_attributes
[index
+ jump
],
1177 /* ch_previous */ 0,
1178 /* attrs_previous */ 0 );
1182 gc_ops
.paint_char( /* xx */ column
,
1184 /* ch */ gc_buffer_characters
[index
+ jump
],
1185 /* attrs */ gc_buffer_attributes
[index
+ jump
],
1186 /* ch_previous */ gc_buffer_characters
[index
],
1187 /* attrs_previous */ gc_buffer_attributes
[index
] );
1190 gc_buffer_attributes
[index
] = gc_buffer_attributes
[index
+ jump
];
1191 gc_buffer_characters
[index
] = gc_buffer_characters
[index
+ jump
];
1192 gc_buffer_colorcodes
[index
] = gc_buffer_colorcodes
[index
+ jump
];
1197 if ( colorcodesave
!= gc_color_code
)
1199 gc_update_color(COLOR_CODE_GET(colorcodesave
, TRUE
), TRUE
);
1200 gc_update_color(COLOR_CODE_GET(colorcodesave
, FALSE
), FALSE
);
1203 /* Now set the freed up lines to the background colour */
1205 for ( row
= bottom
- num
; row
< bottom
; row
++ )
1207 index
= row
* gc_buffer_columns
;
1209 for ( column
= 0 ; column
< gc_buffer_columns
; index
++, column
++ )
1211 if ( gc_buffer_attributes
[index
] != ATTR_NONE
||
1212 gc_buffer_characters
[index
] != ' ' ||
1213 gc_buffer_colorcodes
[index
] != gc_color_code
)
1215 if ( gc_buffer_colorcodes
[index
] != gc_color_code
)
1217 gc_ops
.paint_char( /* xx */ column
,
1220 /* attrs */ ATTR_NONE
,
1221 /* ch_previous */ 0,
1222 /* attrs_previous */ 0 );
1226 gc_ops
.paint_char( /* xx */ column
,
1229 /* attrs */ ATTR_NONE
,
1230 /* ch_previous */ gc_buffer_characters
[index
],
1231 /* attrs_previous */ gc_buffer_attributes
[index
] );
1234 gc_buffer_attributes
[index
] = ATTR_NONE
;
1235 gc_buffer_characters
[index
] = ' ';
1236 gc_buffer_colorcodes
[index
] = gc_color_code
;
1243 gc_ops
.scroll_up(num
, top
, bottom
);
1245 /* Now set the freed up lines to the background colour */
1247 gc_clear_screen(0, bottom
- num
, top
, bottom
, 0);
1252 gc_show_cursor(unsigned int xx
, unsigned int yy
)
1254 if ( xx
< gc_buffer_columns
&& yy
< gc_buffer_rows
)
1256 uint32_t index
= (yy
* gc_buffer_columns
) + xx
;
1257 unsigned char attribute
= gc_buffer_attributes
[index
];
1258 unsigned char character
= gc_buffer_characters
[index
];
1259 unsigned char colorcode
= gc_buffer_colorcodes
[index
];
1260 unsigned char colorcodesave
= gc_color_code
;
1262 gc_update_color(COLOR_CODE_GET(colorcode
, FALSE
), TRUE
);
1263 gc_update_color(COLOR_CODE_GET(colorcode
, TRUE
), FALSE
);
1265 gc_ops
.paint_char(xx
, yy
, character
, attribute
, 0, 0);
1267 gc_update_color(COLOR_CODE_GET(colorcodesave
, TRUE
), TRUE
);
1268 gc_update_color(COLOR_CODE_GET(colorcodesave
, FALSE
), FALSE
);
1272 gc_ops
.show_cursor(xx
, yy
);
1277 gc_update_color(int color
, boolean_t fore
)
1279 assert(gc_ops
.update_color
);
1281 gc_color_code
= COLOR_CODE_SET(gc_color_code
, color
, fore
);
1282 gc_ops
.update_color(color
, fore
);
1286 vcputc(__unused
int l
, __unused
int u
, int c
)
1288 if ( gc_initialized
&& ( gc_enabled
|| debug_mode
) )
1293 #if defined(__i386__) || defined(__x86_64__)
1294 x86_filter_TLB_coherency_interrupts(TRUE
);
1297 if ( gc_enabled
|| debug_mode
)
1299 gc_hide_cursor(gc_x
, gc_y
);
1301 gc_show_cursor(gc_x
, gc_y
);
1303 VCPUTC_LOCK_UNLOCK();
1304 #if defined(__i386__) || defined(__x86_64__)
1305 x86_filter_TLB_coherency_interrupts(FALSE
);
1312 * Video Console (Back-End)
1313 * ------------------------
1317 * For the color support (Michel Pollet)
1319 static unsigned char vc_color_index_table
[33] =
1320 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1321 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 2 };
1323 static uint32_t vc_colors
[8][4] = {
1324 { 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000 }, /* black */
1325 { 0x23232323, 0x7C007C00, 0x00FF0000, 0x3FF00000 }, /* red */
1326 { 0xb9b9b9b9, 0x03e003e0, 0x0000FF00, 0x000FFC00 }, /* green */
1327 { 0x05050505, 0x7FE07FE0, 0x00FFFF00, 0x3FFFFC00 }, /* yellow */
1328 { 0xd2d2d2d2, 0x001f001f, 0x000000FF, 0x000003FF }, /* blue */
1329 // { 0x80808080, 0x31933193, 0x00666699, 0x00000000 }, /* blue */
1330 { 0x18181818, 0x7C1F7C1F, 0x00FF00FF, 0x3FF003FF }, /* magenta */
1331 { 0xb4b4b4b4, 0x03FF03FF, 0x0000FFFF, 0x000FFFFF }, /* cyan */
1332 { 0x00000000, 0x7FFF7FFF, 0x00FFFFFF, 0x3FFFFFFF } /* white */
1335 static uint32_t vc_color_fore
= 0;
1336 static uint32_t vc_color_back
= 0;
1339 * New Rendering code from Michel Pollet
1342 /* Rendered Font Buffer */
1343 static unsigned char *vc_rendered_font
= NULL
;
1345 /* Rendered Font Size */
1346 static uint32_t vc_rendered_font_size
= 0;
1348 /* Size of a character in the table (bytes) */
1349 static int vc_rendered_char_size
= 0;
1351 #define REN_MAX_DEPTH 32
1352 static unsigned char vc_rendered_char
[ISO_CHAR_HEIGHT
* ((REN_MAX_DEPTH
/ 8) * ISO_CHAR_WIDTH
)];
1355 vc_clear_screen(unsigned int xx
, unsigned int yy
, unsigned int scrreg_top
,
1356 unsigned int scrreg_bottom
, int which
)
1358 uint32_t *p
, *endp
, *row
;
1360 int rowline
, rowlongs
;
1365 linelongs
= vinfo
.v_rowbytes
* (ISO_CHAR_HEIGHT
>> 2);
1366 rowline
= vinfo
.v_rowscanbytes
>> 2;
1367 rowlongs
= vinfo
.v_rowbytes
>> 2;
1369 p
= (uint32_t*) vinfo
.v_baseaddr
;
1370 endp
= (uint32_t*) vinfo
.v_baseaddr
;
1373 case 0: /* To end of screen */
1374 gc_clear_line(xx
, yy
, 0);
1375 if (yy
< scrreg_bottom
- 1) {
1376 p
+= (yy
+ 1) * linelongs
;
1377 endp
+= scrreg_bottom
* linelongs
;
1380 case 1: /* To start of screen */
1381 gc_clear_line(xx
, yy
, 1);
1382 if (yy
> scrreg_top
) {
1383 p
+= scrreg_top
* linelongs
;
1384 endp
+= yy
* linelongs
;
1387 case 2: /* Whole screen */
1388 p
+= scrreg_top
* linelongs
;
1389 if (scrreg_bottom
== vinfo
.v_rows
) {
1390 endp
+= rowlongs
* vinfo
.v_height
;
1392 endp
+= scrreg_bottom
* linelongs
;
1397 for (row
= p
; row
< endp
; row
+= rowlongs
) {
1398 for (col
= 0; col
< rowline
; col
++)
1399 *(row
+col
) = vc_color_back
;
1404 vc_render_char(unsigned char ch
, unsigned char *renderptr
, short newdepth
)
1407 unsigned char *charptr
;
1408 unsigned short *shortptr
;
1410 } current
; /* current place in rendered font, multiple types. */
1411 unsigned char *theChar
; /* current char in iso_font */
1414 current
.charptr
= renderptr
;
1415 theChar
= iso_font
+ (ch
* ISO_CHAR_HEIGHT
);
1417 for (line
= 0; line
< ISO_CHAR_HEIGHT
; line
++) {
1418 unsigned char mask
= 1;
1422 *current
.charptr
++ = (*theChar
& mask
) ? 0xFF : 0;
1425 *current
.shortptr
++ = (*theChar
& mask
) ? 0xFFFF : 0;
1430 *current
.longptr
++ = (*theChar
& mask
) ? 0xFFFFFFFF : 0;
1434 } while (mask
); /* while the single bit drops to the right */
1440 vc_paint_char_8(unsigned int xx
, unsigned int yy
, unsigned char ch
, int attrs
,
1441 __unused
unsigned char ch_previous
, __unused
int attrs_previous
)
1447 if (vc_rendered_font
) {
1448 theChar
= (uint32_t*)(vc_rendered_font
+ (ch
* vc_rendered_char_size
));
1450 vc_render_char(ch
, vc_rendered_char
, 8);
1451 theChar
= (uint32_t*)(vc_rendered_char
);
1453 where
= (uint32_t*)(vinfo
.v_baseaddr
+
1454 (yy
* ISO_CHAR_HEIGHT
* vinfo
.v_rowbytes
) +
1455 (xx
* ISO_CHAR_WIDTH
));
1457 if (!attrs
) for (i
= 0; i
< ISO_CHAR_HEIGHT
; i
++) { /* No attr? FLY !*/
1458 uint32_t *store
= where
;
1460 for (x
= 0; x
< 2; x
++) {
1461 uint32_t val
= *theChar
++;
1462 val
= (vc_color_back
& ~val
) | (vc_color_fore
& val
);
1466 where
= (uint32_t*)(((unsigned char*)where
)+vinfo
.v_rowbytes
);
1467 } else for (i
= 0; i
< ISO_CHAR_HEIGHT
; i
++) { /* a little slower */
1468 uint32_t *store
= where
, lastpixel
= 0;
1470 for (x
= 0 ; x
< 2; x
++) {
1471 uint32_t val
= *theChar
++, save
= val
;
1472 if (attrs
& ATTR_BOLD
) { /* bold support */
1473 if (lastpixel
&& !(save
& 0xFF000000))
1475 if ((save
& 0xFFFF0000) == 0xFF000000)
1477 if ((save
& 0x00FFFF00) == 0x00FF0000)
1479 if ((save
& 0x0000FFFF) == 0x0000FF00)
1482 if (attrs
& ATTR_REVERSE
) val
= ~val
;
1483 if (attrs
& ATTR_UNDER
&& i
== ISO_CHAR_HEIGHT
-1) val
= ~val
;
1485 val
= (vc_color_back
& ~val
) | (vc_color_fore
& val
);
1487 lastpixel
= save
& 0xff;
1490 where
= (uint32_t*)(((unsigned char*)where
)+vinfo
.v_rowbytes
);
1496 vc_paint_char_16(unsigned int xx
, unsigned int yy
, unsigned char ch
, int attrs
,
1497 __unused
unsigned char ch_previous
,
1498 __unused
int attrs_previous
)
1504 if (vc_rendered_font
) {
1505 theChar
= (uint32_t*)(vc_rendered_font
+ (ch
* vc_rendered_char_size
));
1507 vc_render_char(ch
, vc_rendered_char
, 16);
1508 theChar
= (uint32_t*)(vc_rendered_char
);
1510 where
= (uint32_t*)(vinfo
.v_baseaddr
+
1511 (yy
* ISO_CHAR_HEIGHT
* vinfo
.v_rowbytes
) +
1512 (xx
* ISO_CHAR_WIDTH
* 2));
1514 if (!attrs
) for (i
= 0; i
< ISO_CHAR_HEIGHT
; i
++) { /* No attrs ? FLY ! */
1515 uint32_t *store
= where
;
1517 for (x
= 0; x
< 4; x
++) {
1518 uint32_t val
= *theChar
++;
1519 val
= (vc_color_back
& ~val
) | (vc_color_fore
& val
);
1523 where
= (uint32_t*)(((unsigned char*)where
)+vinfo
.v_rowbytes
);
1524 } else for (i
= 0; i
< ISO_CHAR_HEIGHT
; i
++) { /* a little bit slower */
1525 uint32_t *store
= where
, lastpixel
= 0;
1527 for (x
= 0 ; x
< 4; x
++) {
1528 uint32_t val
= *theChar
++, save
= val
;
1529 if (attrs
& ATTR_BOLD
) { /* bold support */
1530 if (save
== 0xFFFF0000) val
|= 0xFFFF;
1531 else if (lastpixel
&& !(save
& 0xFFFF0000))
1534 if (attrs
& ATTR_REVERSE
) val
= ~val
;
1535 if (attrs
& ATTR_UNDER
&& i
== ISO_CHAR_HEIGHT
-1) val
= ~val
;
1537 val
= (vc_color_back
& ~val
) | (vc_color_fore
& val
);
1540 lastpixel
= save
& 0x7fff;
1543 where
= (uint32_t*)(((unsigned char*)where
)+vinfo
.v_rowbytes
);
1549 vc_paint_char_32(unsigned int xx
, unsigned int yy
, unsigned char ch
, int attrs
,
1550 unsigned char ch_previous
, int attrs_previous
)
1553 uint32_t *theCharPrevious
;
1557 if (vc_rendered_font
) {
1558 theChar
= (uint32_t*)(vc_rendered_font
+ (ch
* vc_rendered_char_size
));
1559 theCharPrevious
= (uint32_t*)(vc_rendered_font
+ (ch_previous
* vc_rendered_char_size
));
1561 vc_render_char(ch
, vc_rendered_char
, 32);
1562 theChar
= (uint32_t*)(vc_rendered_char
);
1563 theCharPrevious
= NULL
;
1566 theCharPrevious
= NULL
;
1568 if (attrs_previous
) {
1569 theCharPrevious
= NULL
;
1571 where
= (uint32_t*)(vinfo
.v_baseaddr
+
1572 (yy
* ISO_CHAR_HEIGHT
* vinfo
.v_rowbytes
) +
1573 (xx
* ISO_CHAR_WIDTH
* 4));
1575 if (!attrs
) for (i
= 0; i
< ISO_CHAR_HEIGHT
; i
++) { /* No attrs ? FLY ! */
1576 uint32_t *store
= where
;
1578 for (x
= 0; x
< 8; x
++) {
1579 uint32_t val
= *theChar
++;
1580 if (theCharPrevious
== NULL
|| val
!= *theCharPrevious
++ ) {
1581 val
= (vc_color_back
& ~val
) | (vc_color_fore
& val
);
1588 where
= (uint32_t *)(((unsigned char*)where
)+vinfo
.v_rowbytes
);
1589 } else for (i
= 0; i
< ISO_CHAR_HEIGHT
; i
++) { /* a little slower */
1590 uint32_t *store
= where
, lastpixel
= 0;
1592 for (x
= 0 ; x
< 8; x
++) {
1593 uint32_t val
= *theChar
++, save
= val
;
1594 if (attrs
& ATTR_BOLD
) { /* bold support */
1595 if (lastpixel
&& !save
)
1598 if (attrs
& ATTR_REVERSE
) val
= ~val
;
1599 if (attrs
& ATTR_UNDER
&& i
== ISO_CHAR_HEIGHT
-1) val
= ~val
;
1601 val
= (vc_color_back
& ~val
) | (vc_color_fore
& val
);
1606 where
= (uint32_t*)(((unsigned char*)where
)+vinfo
.v_rowbytes
);
1612 vc_paint_char(unsigned int xx
, unsigned int yy
, unsigned char ch
, int attrs
,
1613 unsigned char ch_previous
, int attrs_previous
)
1618 switch(vinfo
.v_depth
) {
1620 vc_paint_char_8(xx
, yy
, ch
, attrs
, ch_previous
, attrs_previous
);
1623 vc_paint_char_16(xx
, yy
, ch
, attrs
, ch_previous
,
1628 vc_paint_char_32(xx
, yy
, ch
, attrs
, ch_previous
,
1635 vc_render_font(short newdepth
)
1637 static short olddepth
= 0;
1639 int charindex
; /* index in ISO font */
1640 unsigned char *rendered_font
;
1641 unsigned int rendered_font_size
;
1642 int rendered_char_size
;
1645 if (vm_initialized
== FALSE
) {
1646 return; /* nothing to do */
1648 if (olddepth
== newdepth
&& vc_rendered_font
) {
1649 return; /* nothing to do */
1655 rendered_font
= vc_rendered_font
;
1656 rendered_font_size
= vc_rendered_font_size
;
1657 rendered_char_size
= vc_rendered_char_size
;
1659 vc_rendered_font
= NULL
;
1660 vc_rendered_font_size
= 0;
1661 vc_rendered_char_size
= 0;
1663 VCPUTC_LOCK_UNLOCK();
1666 if (rendered_font
) {
1667 kfree(rendered_font
, rendered_font_size
);
1668 rendered_font
= NULL
;
1672 rendered_char_size
= ISO_CHAR_HEIGHT
* (((newdepth
+ 7) / 8) * ISO_CHAR_WIDTH
);
1673 rendered_font_size
= (ISO_CHAR_MAX
-ISO_CHAR_MIN
+1) * rendered_char_size
;
1674 rendered_font
= (unsigned char *) kalloc(rendered_font_size
);
1677 if (rendered_font
== NULL
) {
1681 for (charindex
= ISO_CHAR_MIN
; charindex
<= ISO_CHAR_MAX
; charindex
++) {
1682 vc_render_char(charindex
, rendered_font
+ (charindex
* rendered_char_size
), newdepth
);
1685 olddepth
= newdepth
;
1690 vc_rendered_font
= rendered_font
;
1691 vc_rendered_font_size
= rendered_font_size
;
1692 vc_rendered_char_size
= rendered_char_size
;
1694 VCPUTC_LOCK_UNLOCK();
1699 vc_enable(boolean_t enable
)
1701 vc_render_font(enable
? vinfo
.v_depth
: 0);
1705 vc_reverse_cursor(unsigned int xx
, unsigned int yy
)
1713 where
= (uint32_t*)(vinfo
.v_baseaddr
+
1714 (yy
* ISO_CHAR_HEIGHT
* vinfo
.v_rowbytes
) +
1715 (xx
/** ISO_CHAR_WIDTH*/ * vinfo
.v_depth
));
1716 for (line
= 0; line
< ISO_CHAR_HEIGHT
; line
++) {
1717 switch (vinfo
.v_depth
) {
1719 where
[0] = ~where
[0];
1720 where
[1] = ~where
[1];
1723 for (col
= 0; col
< 4; col
++)
1724 where
[col
] = ~where
[col
];
1727 for (col
= 0; col
< 8; col
++)
1728 where
[col
] = ~where
[col
];
1731 where
= (uint32_t*)(((unsigned char*)where
)+vinfo
.v_rowbytes
);
1736 vc_scroll_down(int num
, unsigned int scrreg_top
, unsigned int scrreg_bottom
)
1738 uint32_t *from
, *to
, linelongs
, i
, line
, rowline
, rowscanline
;
1743 linelongs
= vinfo
.v_rowbytes
* (ISO_CHAR_HEIGHT
>> 2);
1744 rowline
= vinfo
.v_rowbytes
>> 2;
1745 rowscanline
= vinfo
.v_rowscanbytes
>> 2;
1747 to
= (uint32_t *) vinfo
.v_baseaddr
+ (linelongs
* scrreg_bottom
)
1748 - (rowline
- rowscanline
);
1749 from
= to
- (linelongs
* num
); /* handle multiple line scroll (Michel Pollet) */
1751 i
= (scrreg_bottom
- scrreg_top
) - num
;
1754 for (line
= 0; line
< ISO_CHAR_HEIGHT
; line
++) {
1756 * Only copy what is displayed
1758 video_scroll_down(from
,
1759 (from
-(vinfo
.v_rowscanbytes
>> 2)),
1769 vc_scroll_up(int num
, unsigned int scrreg_top
, unsigned int scrreg_bottom
)
1771 uint32_t *from
, *to
, linelongs
, i
, line
, rowline
, rowscanline
;
1776 linelongs
= vinfo
.v_rowbytes
* (ISO_CHAR_HEIGHT
>> 2);
1777 rowline
= vinfo
.v_rowbytes
>> 2;
1778 rowscanline
= vinfo
.v_rowscanbytes
>> 2;
1780 to
= (uint32_t *) vinfo
.v_baseaddr
+ (scrreg_top
* linelongs
);
1781 from
= to
+ (linelongs
* num
); /* handle multiple line scroll (Michel Pollet) */
1783 i
= (scrreg_bottom
- scrreg_top
) - num
;
1786 for (line
= 0; line
< ISO_CHAR_HEIGHT
; line
++) {
1788 * Only copy what is displayed
1790 video_scroll_up(from
,
1791 (from
+(vinfo
.v_rowscanbytes
>> 2)),
1801 vc_update_color(int color
, boolean_t fore
)
1806 vc_color_fore
= vc_colors
[color
][vc_color_index_table
[vinfo
.v_depth
]];
1808 vc_color_back
= vc_colors
[color
][vc_color_index_table
[vinfo
.v_depth
]];
1813 * Video Console (Back-End): Icon Control
1814 * --------------------------------------
1817 static vc_progress_element
* vc_progress
;
1818 static const unsigned char * vc_progress_data
[2];
1819 static const unsigned char * vc_progress_alpha
;
1820 static boolean_t vc_progress_enable
;
1821 static const unsigned char * vc_clut
;
1822 static const unsigned char * vc_clut8
;
1823 static unsigned char vc_revclut8
[256];
1824 static uint32_t vc_progress_interval
;
1825 static uint32_t vc_progress_count
;
1826 static uint32_t vc_progress_angle
;
1827 static uint64_t vc_progress_deadline
;
1828 static thread_call_data_t vc_progress_call
;
1829 static boolean_t vc_needsave
;
1830 static void * vc_saveunder
;
1831 static vm_size_t vc_saveunder_len
;
1832 static int8_t vc_uiselect
= 0;
1833 decl_simple_lock_data(,vc_progress_lock
)
1837 kDataIndexed
= 0x20,
1847 static void vc_blit_rect(int x
, int y
, int bx
,
1848 int width
, int height
,
1849 int sourceRow
, int backRow
,
1850 const unsigned char * dataPtr
,
1852 unsigned int flags
);
1853 static void vc_blit_rect_8(int x
, int y
, int bx
,
1854 int width
, int height
,
1855 int sourceRow
, int backRow
,
1856 const unsigned char * dataPtr
,
1857 unsigned char * backBuffer
,
1858 unsigned int flags
);
1859 static void vc_blit_rect_16(int x
, int y
, int bx
,
1860 int width
, int height
,
1861 int sourceRow
, int backRow
,
1862 const unsigned char * dataPtr
,
1863 unsigned short * backBuffer
,
1864 unsigned int flags
);
1865 static void vc_blit_rect_32(int x
, int y
, int bx
,
1866 int width
, int height
,
1867 int sourceRow
, int backRow
,
1868 const unsigned char * dataPtr
,
1869 unsigned int * backBuffer
,
1870 unsigned int flags
);
1871 static void vc_blit_rect_30(int x
, int y
, int bx
,
1872 int width
, int height
,
1873 int sourceRow
, int backRow
,
1874 const unsigned char * dataPtr
,
1875 unsigned int * backBuffer
,
1876 unsigned int flags
);
1877 static void vc_progress_task( void * arg0
, void * arg
);
1879 static void vc_blit_rect(int x
, int y
, int bx
,
1880 int width
, int height
,
1881 int sourceRow
, int backRow
,
1882 const unsigned char * dataPtr
,
1889 switch( vinfo
.v_depth
) {
1891 if( vc_clut8
== vc_clut
)
1892 vc_blit_rect_8( x
, y
, bx
, width
, height
, sourceRow
, backRow
, dataPtr
, (unsigned char *) backBuffer
, flags
);
1895 vc_blit_rect_16( x
, y
, bx
, width
, height
, sourceRow
, backRow
, dataPtr
, (unsigned short *) backBuffer
, flags
);
1898 vc_blit_rect_32( x
, y
, bx
, width
, height
, sourceRow
, backRow
, dataPtr
, (unsigned int *) backBuffer
, flags
);
1901 vc_blit_rect_30( x
, y
, bx
, width
, height
, sourceRow
, backRow
, dataPtr
, (unsigned int *) backBuffer
, flags
);
1907 vc_blit_rect_8(int x
, int y
, __unused
int bx
,
1908 int width
, int height
,
1909 int sourceRow
, __unused
int backRow
,
1910 const unsigned char * dataPtr
,
1911 __unused
unsigned char * backBuffer
,
1912 __unused
unsigned int flags
)
1914 volatile unsigned short * dst
;
1916 unsigned int data
= 0, out
= 0;
1917 int sx
, sy
, a
, b
, c
, d
;
1918 int scale
= 0x10000;
1920 a
= vc_rotate_matr
[kDataRotate
& flags
][0][0] * scale
;
1921 b
= vc_rotate_matr
[kDataRotate
& flags
][0][1] * scale
;
1922 c
= vc_rotate_matr
[kDataRotate
& flags
][1][0] * scale
;
1923 d
= vc_rotate_matr
[kDataRotate
& flags
][1][1] * scale
;
1924 sx
= ((a
+ b
) < 0) ? ((width
* scale
) - 0x8000) : 0;
1925 sy
= ((c
+ d
) < 0) ? ((height
* scale
) - 0x8000) : 0;
1927 if (!sourceRow
) data
= (unsigned int)(uintptr_t)dataPtr
;
1928 else if (1 == sourceRow
) a
= 0;
1930 dst
= (volatile unsigned short *) (vinfo
.v_baseaddr
+
1931 (y
* vinfo
.v_rowbytes
) +
1934 for( line
= 0; line
< height
; line
++)
1936 for( col
= 0; col
< width
; col
++)
1938 if (sourceRow
) data
= dataPtr
[((sx
+ (col
* a
) + (line
* b
)) >> 16)
1939 + sourceRow
* (((sy
+ (col
* c
) + (line
* d
)) >> 16))];
1940 if (kDataAlpha
& flags
)
1941 out
= vc_revclut8
[data
];
1946 dst
= (volatile unsigned short *) (((volatile char*)dst
) + vinfo
.v_rowbytes
);
1950 /* For ARM, 16-bit is 565 (RGB); it is 1555 (XRGB) on other platforms */
1952 #define CLUT_MASK_R 0xf8
1953 #define CLUT_MASK_G 0xf8
1954 #define CLUT_MASK_B 0xf8
1955 #define CLUT_SHIFT_R << 7
1956 #define CLUT_SHIFT_G << 2
1957 #define CLUT_SHIFT_B >> 3
1958 #define MASK_R 0x7c00
1959 #define MASK_G 0x03e0
1960 #define MASK_B 0x001f
1961 #define MASK_R_8 0x3fc00
1962 #define MASK_G_8 0x01fe0
1963 #define MASK_B_8 0x000ff
1965 static void vc_blit_rect_16( int x
, int y
, int bx
,
1966 int width
, int height
,
1967 int sourceRow
, int backRow
,
1968 const unsigned char * dataPtr
,
1969 unsigned short * backPtr
,
1972 volatile unsigned short * dst
;
1974 unsigned int data
= 0, out
= 0, back
= 0;
1975 int sx
, sy
, a
, b
, c
, d
;
1976 int scale
= 0x10000;
1978 a
= vc_rotate_matr
[kDataRotate
& flags
][0][0] * scale
;
1979 b
= vc_rotate_matr
[kDataRotate
& flags
][0][1] * scale
;
1980 c
= vc_rotate_matr
[kDataRotate
& flags
][1][0] * scale
;
1981 d
= vc_rotate_matr
[kDataRotate
& flags
][1][1] * scale
;
1982 sx
= ((a
+ b
) < 0) ? ((width
* scale
) - 0x8000) : 0;
1983 sy
= ((c
+ d
) < 0) ? ((height
* scale
) - 0x8000) : 0;
1985 if (!sourceRow
) data
= (unsigned int)(uintptr_t)dataPtr
;
1986 else if (1 == sourceRow
) a
= 0;
1990 dst
= (volatile unsigned short *) (vinfo
.v_baseaddr
+
1991 (y
* vinfo
.v_rowbytes
) +
1994 for( line
= 0; line
< height
; line
++)
1996 for( col
= 0; col
< width
; col
++)
1998 if (sourceRow
) data
= dataPtr
[((sx
+ (col
* a
) + (line
* b
)) >> 16)
1999 + sourceRow
* (((sy
+ (col
* c
) + (line
* d
)) >> 16))];
2001 if (kSave
& flags
) {
2002 back
= *(dst
+ col
);
2007 if (kDataIndexed
& flags
) {
2008 out
= ( (CLUT_MASK_R
& (vc_clut
[data
*3 + 0])) CLUT_SHIFT_R
)
2009 | ( (CLUT_MASK_G
& (vc_clut
[data
*3 + 1])) CLUT_SHIFT_G
)
2010 | ( (CLUT_MASK_B
& (vc_clut
[data
*3 + 2])) CLUT_SHIFT_B
);
2011 } else if (kDataAlpha
& flags
) {
2012 out
= (((((back
& MASK_R
) * data
) + MASK_R_8
) >> 8) & MASK_R
)
2013 | (((((back
& MASK_G
) * data
) + MASK_G_8
) >> 8) & MASK_G
)
2014 | (((((back
& MASK_B
) * data
) + MASK_B_8
) >> 8) & MASK_B
);
2015 #ifdef CONFIG_VC_PROGRESS_WHITE
2016 out
+= (((0xff - data
) & CLUT_MASK_R
) CLUT_SHIFT_R
)
2017 | (((0xff - data
) & CLUT_MASK_G
) CLUT_SHIFT_G
)
2018 | (((0xff - data
) & CLUT_MASK_B
) CLUT_SHIFT_B
);
2024 dst
= (volatile unsigned short *) (((volatile char*)dst
) + vinfo
.v_rowbytes
);
2026 backPtr
+= backRow
- width
;
2031 static void vc_blit_rect_32(int x
, int y
, int bx
,
2032 int width
, int height
,
2033 int sourceRow
, int backRow
,
2034 const unsigned char * dataPtr
,
2035 unsigned int * backPtr
,
2038 volatile unsigned int * dst
;
2040 unsigned int data
= 0, out
= 0, back
= 0;
2041 int sx
, sy
, a
, b
, c
, d
;
2042 int scale
= 0x10000;
2044 a
= vc_rotate_matr
[kDataRotate
& flags
][0][0] * scale
;
2045 b
= vc_rotate_matr
[kDataRotate
& flags
][0][1] * scale
;
2046 c
= vc_rotate_matr
[kDataRotate
& flags
][1][0] * scale
;
2047 d
= vc_rotate_matr
[kDataRotate
& flags
][1][1] * scale
;
2048 sx
= ((a
+ b
) < 0) ? ((width
* scale
) - 0x8000) : 0;
2049 sy
= ((c
+ d
) < 0) ? ((height
* scale
) - 0x8000) : 0;
2051 if (!sourceRow
) data
= (unsigned int)(uintptr_t)dataPtr
;
2052 else if (1 == sourceRow
) a
= 0;
2056 dst
= (volatile unsigned int *) (vinfo
.v_baseaddr
+
2057 (y
* vinfo
.v_rowbytes
) +
2060 for( line
= 0; line
< height
; line
++)
2062 for( col
= 0; col
< width
; col
++)
2064 if (sourceRow
) data
= dataPtr
[((sx
+ (col
* a
) + (line
* b
)) >> 16)
2065 + sourceRow
* (((sy
+ (col
* c
) + (line
* d
)) >> 16))];
2067 if (kSave
& flags
) {
2068 back
= *(dst
+ col
);
2073 if (kDataIndexed
& flags
) {
2074 out
= (vc_clut
[data
*3 + 0] << 16)
2075 | (vc_clut
[data
*3 + 1] << 8)
2076 | (vc_clut
[data
*3 + 2]);
2077 } else if (kDataAlpha
& flags
) {
2078 out
= (((((back
& 0x00ff00ff) * data
) + 0x00ff00ff) >> 8) & 0x00ff00ff)
2079 | (((((back
& 0x0000ff00) * data
) + 0x0000ff00) >> 8) & 0x0000ff00);
2080 #ifdef CONFIG_VC_PROGRESS_WHITE
2081 out
+= ((0xff - data
) << 16)
2082 | ((0xff - data
) << 8)
2089 dst
= (volatile unsigned int *) (((volatile char*)dst
) + vinfo
.v_rowbytes
);
2091 backPtr
+= backRow
- width
;
2095 static void vc_blit_rect_30(int x
, int y
, int bx
,
2096 int width
, int height
,
2097 int sourceRow
, int backRow
,
2098 const unsigned char * dataPtr
,
2099 unsigned int * backPtr
,
2102 volatile unsigned int * dst
;
2104 unsigned int data
= 0, out
= 0, back
= 0;
2105 unsigned long long exp
;
2106 int sx
, sy
, a
, b
, c
, d
;
2107 int scale
= 0x10000;
2109 a
= vc_rotate_matr
[kDataRotate
& flags
][0][0] * scale
;
2110 b
= vc_rotate_matr
[kDataRotate
& flags
][0][1] * scale
;
2111 c
= vc_rotate_matr
[kDataRotate
& flags
][1][0] * scale
;
2112 d
= vc_rotate_matr
[kDataRotate
& flags
][1][1] * scale
;
2113 sx
= ((a
+ b
) < 0) ? ((width
* scale
) - 0x8000) : 0;
2114 sy
= ((c
+ d
) < 0) ? ((height
* scale
) - 0x8000) : 0;
2116 if (!sourceRow
) data
= (unsigned int)(uintptr_t)dataPtr
;
2117 else if (1 == sourceRow
) a
= 0;
2121 dst
= (volatile unsigned int *) (vinfo
.v_baseaddr
+
2122 (y
* vinfo
.v_rowbytes
) +
2125 for( line
= 0; line
< height
; line
++)
2127 for( col
= 0; col
< width
; col
++)
2129 if (col
< sourceRow
)
2133 if (kSave
& flags
) {
2134 back
= *(dst
+ col
);
2139 if (kDataIndexed
& flags
) {
2140 out
= (vc_clut
[data
*3 + 0] << 22)
2141 | (vc_clut
[data
*3 + 1] << 12)
2142 | (vc_clut
[data
*3 + 2] << 2);
2143 } else if (kDataAlpha
& flags
) {
2145 exp
= (((((exp
& 0x3FF003FF) * data
) + 0x0FF000FF) >> 8) & 0x3FF003FF)
2146 | (((((exp
& 0x000FFC00) * data
) + 0x0003FC00) >> 8) & 0x000FFC00);
2147 out
= (unsigned int)exp
;
2148 #ifdef CONFIG_VC_PROGRESS_WHITE
2149 out
+= ((0xFF - data
) << 22)
2150 | ((0xFF - data
) << 12)
2151 | ((0xFF - data
) << 2);
2157 dst
= (volatile unsigned int *) (((volatile char*)dst
) + vinfo
.v_rowbytes
);
2159 backPtr
+= backRow
- width
;
2165 * Routines to render the lzss image format
2168 struct lzss_image_state
{
2173 uint32_t bytes_per_row
;
2174 volatile uint32_t * row_start
;
2175 const uint8_t* clut
;
2177 typedef struct lzss_image_state lzss_image_state
;
2179 // returns 0 if OK, 1 if error
2181 vc_decompress_lzss_next_pixel (int next_data
, lzss_image_state
* state
)
2183 uint32_t palette_index
= 0;
2184 uint32_t pixel_value
= 0;
2186 palette_index
= next_data
* 3;
2188 pixel_value
= ( (uint32_t) state
->clut
[palette_index
+ 0] << 16)
2189 | ( (uint32_t) state
->clut
[palette_index
+ 1] << 8)
2190 | ( (uint32_t) state
->clut
[palette_index
+ 2]);
2192 *(state
->row_start
+ state
->col
) = pixel_value
;
2194 if (++state
->col
>= state
->width
) {
2196 if (++state
->row
>= state
->height
) {
2199 state
->row_start
= (volatile uint32_t *) (((uintptr_t)state
->row_start
) + state
->bytes_per_row
);
2206 * Blit an lzss compressed image to the framebuffer
2207 * Assumes 32 bit screen (which is everything we ship at the moment)
2208 * The function vc_display_lzss_icon was copied from libkern/mkext.c, then modified.
2212 * TODO: Does lzss use too much stack? 4096 plus bytes...
2213 * Can probably chop it down by 1/2.
2216 /**************************************************************
2217 LZSS.C -- A Data Compression Program
2218 ***************************************************************
2219 4/6/1989 Haruhiko Okumura
2220 Use, distribute, and modify this program freely.
2221 Please send me your improved versions.
2223 NIFTY-Serve PAF01022
2224 CompuServe 74050,1022
2226 **************************************************************/
2228 #define N 4096 /* size of ring buffer - must be power of 2 */
2229 #define F 18 /* upper limit for match_length */
2230 #define THRESHOLD 2 /* encode string into position and length
2231 if match_length is greater than this */
2233 // returns 0 if OK, 1 if error
2234 // x and y indicate upper left corner of image location on screen
2236 vc_display_lzss_icon(uint32_t dst_x
, uint32_t dst_y
,
2237 uint32_t image_width
, uint32_t image_height
,
2238 const uint8_t *compressed_image
,
2239 uint32_t compressed_size
,
2240 const uint8_t *clut
)
2242 uint32_t* image_start
;
2243 uint32_t bytes_per_pixel
= 4;
2244 uint32_t bytes_per_row
= vinfo
.v_rowbytes
;
2246 image_start
= (uint32_t *) (vinfo
.v_baseaddr
+ (dst_y
* bytes_per_row
) + (dst_x
* bytes_per_pixel
));
2248 lzss_image_state state
= {0, 0, image_width
, image_height
, bytes_per_row
, image_start
, clut
};
2252 const uint8_t *src
= compressed_image
;
2253 uint32_t srclen
= compressed_size
;
2255 /* ring buffer of size N, with extra F-1 bytes to aid string comparison */
2256 uint8_t text_buf
[N
+ F
- 1];
2257 const uint8_t *srcend
= src
+ srclen
;
2261 srcend
= src
+ srclen
;
2262 for (i
= 0; i
< N
- F
; i
++)
2267 if (((flags
>>= 1) & 0x100) == 0) {
2268 if (src
< srcend
) c
= *src
++; else break;
2269 flags
= c
| 0xFF00; /* uses higher byte cleverly */
2270 } /* to count eight */
2272 if (src
< srcend
) c
= *src
++; else break;
2273 rval
= vc_decompress_lzss_next_pixel(c
, &state
);
2279 if (src
< srcend
) i
= *src
++; else break;
2280 if (src
< srcend
) j
= *src
++; else break;
2281 i
|= ((j
& 0xF0) << 4);
2282 j
= (j
& 0x0F) + THRESHOLD
;
2283 for (k
= 0; k
<= j
; k
++) {
2284 c
= text_buf
[(i
+ k
) & (N
- 1)];
2285 rval
= vc_decompress_lzss_next_pixel(c
, &state
);
2296 void noroot_icon_test(void) {
2297 boolean_t o_vc_progress_enable
= vc_progress_enable
;
2299 vc_progress_enable
= 1;
2301 PE_display_icon( 0, "noroot");
2303 vc_progress_enable
= o_vc_progress_enable
;
2307 void vc_display_icon( vc_progress_element
* desc
,
2308 const unsigned char * data
)
2310 int x
, y
, width
, height
;
2312 if( vc_progress_enable
&& vc_clut
) {
2314 width
= desc
->width
;
2315 height
= desc
->height
;
2318 if( 1 & desc
->flags
) {
2319 x
+= ((vinfo
.v_width
- width
) / 2);
2320 y
+= ((vinfo
.v_height
- height
) / 2);
2322 vc_blit_rect( x
, y
, 0, width
, height
, width
, 0, data
, NULL
, kDataIndexed
);
2327 vc_progress_initialize( vc_progress_element
* desc
,
2328 const unsigned char * data1x
,
2329 const unsigned char * data2x
,
2330 const unsigned char * clut
)
2334 if( (!clut
) || (!desc
) || (!data1x
))
2339 simple_lock_init(&vc_progress_lock
, 0);
2342 vc_progress_data
[0] = data1x
;
2343 vc_progress_data
[1] = data2x
;
2344 if( 2 & vc_progress
->flags
)
2345 vc_progress_alpha
= data1x
2346 + vc_progress
->count
* vc_progress
->width
* vc_progress
->height
;
2348 vc_progress_alpha
= NULL
;
2350 thread_call_setup(&vc_progress_call
, vc_progress_task
, NULL
);
2352 clock_interval_to_absolutetime_interval(vc_progress
->time
, 1000 * 1000, &abstime
);
2353 vc_progress_interval
= (uint32_t)abstime
;
2357 vc_progress_set(boolean_t enable
, uint32_t vc_delay
)
2360 void *saveBuf
= NULL
;
2361 vm_size_t saveLen
= 0;
2364 unsigned char pdata8
;
2365 unsigned short pdata16
;
2366 unsigned short * buf16
;
2367 unsigned int pdata32
;
2368 unsigned int * buf32
;
2374 saveLen
= (vc_progress
->width
<< vc_uiselect
) * (vc_progress
->height
<< vc_uiselect
) * vinfo
.v_depth
/ 8;
2375 saveBuf
= kalloc( saveLen
);
2377 switch( vinfo
.v_depth
) {
2379 for( count
= 0; count
< 256; count
++) {
2380 vc_revclut8
[count
] = vc_clut
[0x01 * 3];
2381 pdata8
= (vc_clut
[0x01 * 3] * count
+ 0x0ff) >> 8;
2382 for( index
= 0; index
< 256; index
++) {
2383 if( (pdata8
== vc_clut
[index
* 3 + 0]) &&
2384 (pdata8
== vc_clut
[index
* 3 + 1]) &&
2385 (pdata8
== vc_clut
[index
* 3 + 2])) {
2386 vc_revclut8
[count
] = index
;
2391 memset( saveBuf
, 0x01, saveLen
);
2395 buf16
= (unsigned short *) saveBuf
;
2396 pdata16
= ((vc_clut
[0x01 * 3 + 0] & CLUT_MASK_R
) CLUT_SHIFT_R
)
2397 | ((vc_clut
[0x01 * 3 + 0] & CLUT_MASK_G
) CLUT_SHIFT_G
)
2398 | ((vc_clut
[0x01 * 3 + 0] & CLUT_MASK_B
) CLUT_SHIFT_B
);
2399 for( count
= 0; count
< saveLen
/ 2; count
++)
2400 buf16
[count
] = pdata16
;
2404 buf32
= (unsigned int *) saveBuf
;
2405 pdata32
= ((vc_clut
[0x01 * 3 + 0] & 0xff) << 16)
2406 | ((vc_clut
[0x01 * 3 + 1] & 0xff) << 8)
2407 | ((vc_clut
[0x01 * 3 + 2] & 0xff) << 0);
2408 for( count
= 0; count
< saveLen
/ 4; count
++)
2409 buf32
[count
] = pdata32
;
2415 simple_lock(&vc_progress_lock
);
2417 if( vc_progress_enable
!= enable
) {
2418 vc_progress_enable
= enable
;
2421 vc_saveunder
= saveBuf
;
2422 vc_saveunder_len
= saveLen
;
2425 vc_progress_count
= 0;
2426 vc_progress_angle
= 0;
2428 clock_interval_to_deadline(vc_delay
,
2429 1000 * 1000 * 1000 /*second scale*/,
2430 &vc_progress_deadline
);
2431 thread_call_enter_delayed(&vc_progress_call
, vc_progress_deadline
);
2435 saveBuf
= vc_saveunder
;
2436 saveLen
= vc_saveunder_len
;
2437 vc_saveunder
= NULL
;
2438 vc_saveunder_len
= 0;
2441 thread_call_cancel(&vc_progress_call
);
2445 simple_unlock(&vc_progress_lock
);
2449 kfree( saveBuf
, saveLen
);
2454 vc_progress_task(__unused
void *arg0
, __unused
void *arg
)
2457 int x
, y
, width
, height
;
2458 const unsigned char * data
;
2461 simple_lock(&vc_progress_lock
);
2463 if( vc_progress_enable
) {
2465 vc_progress_count
++;
2466 if( vc_progress_count
>= vc_progress
->count
) {
2467 vc_progress_count
= 0;
2468 vc_progress_angle
++;
2471 width
= (vc_progress
->width
<< vc_uiselect
);
2472 height
= (vc_progress
->height
<< vc_uiselect
);
2473 x
= (vc_progress
->dx
<< vc_uiselect
);
2474 y
= (vc_progress
->dy
<< vc_uiselect
);
2475 data
= vc_progress_data
[vc_uiselect
];
2476 data
+= vc_progress_count
* width
* height
;
2477 if( 1 & vc_progress
->flags
) {
2478 x
+= ((vinfo
.v_width
- width
) / 2);
2479 y
+= ((vinfo
.v_height
- height
) / 2);
2481 vc_blit_rect( x
, y
, 0,
2482 width
, height
, width
, width
,
2485 | (vc_progress_angle
& kDataRotate
)
2486 | (vc_needsave
? kSave
: 0) );
2487 vc_needsave
= FALSE
;
2489 clock_deadline_for_periodic_event(vc_progress_interval
, mach_absolute_time(), &vc_progress_deadline
);
2490 thread_call_enter_delayed(&vc_progress_call
, vc_progress_deadline
);
2492 simple_unlock(&vc_progress_lock
);
2497 * Generic Console (Front-End): Master Control
2498 * -------------------------------------------
2501 #if defined (__i386__) || defined (__x86_64__)
2502 #include <pexpert/i386/boot.h>
2505 static boolean_t gc_acquired
= FALSE
;
2506 static boolean_t gc_graphics_boot
= FALSE
;
2507 static boolean_t gc_desire_text
= FALSE
;
2509 static uint64_t lastVideoPhys
= 0;
2510 static vm_offset_t lastVideoVirt
= 0;
2511 static vm_size_t lastVideoSize
= 0;
2512 static boolean_t lastVideoMapped
= FALSE
;
2515 gc_pause( boolean_t pause
, boolean_t graphics_now
)
2520 VCPUTC_LOCK_LOCK( );
2522 disableConsoleOutput
= (pause
&& !console_is_serial());
2523 gc_enabled
= (!pause
&& !graphics_now
);
2525 VCPUTC_LOCK_UNLOCK( );
2527 simple_lock(&vc_progress_lock
);
2529 vc_progress_enable
= gc_graphics_boot
&& !gc_desire_text
&& !pause
;
2530 if (vc_progress_enable
)
2531 thread_call_enter_delayed(&vc_progress_call
, vc_progress_deadline
);
2533 simple_unlock(&vc_progress_lock
);
2538 vc_initialize(__unused
struct vc_info
* vinfo_p
)
2541 vinfo
.v_rows
= vinfo
.v_height
/ ISO_CHAR_HEIGHT
;
2542 vinfo
.v_columns
= vinfo
.v_width
/ ISO_CHAR_WIDTH
;
2543 vinfo
.v_rowscanbytes
= ((vinfo
.v_depth
+ 7) / 8) * vinfo
.v_width
;
2544 vc_uiselect
= (2 == vinfo
.v_scale
) ? 1 : 0;
2548 initialize_screen(PE_Video
* boot_vinfo
, unsigned int op
)
2550 unsigned int fbsize
= 0;
2551 vm_offset_t newVideoVirt
= 0;
2552 boolean_t graphics_now
;
2557 struct vc_info new_vinfo
= vinfo
;
2559 * First, check if we are changing the size and/or location of the framebuffer
2561 new_vinfo
.v_name
[0] = 0;
2562 new_vinfo
.v_physaddr
= boot_vinfo
->v_baseAddr
& ~3; /* Get the physical address */
2564 new_vinfo
.v_physaddr
|= (((uint64_t) boot_vinfo
->v_baseAddrHigh
) << 32);
2566 if (kPEBaseAddressChange
!= op
)
2568 new_vinfo
.v_width
= (unsigned int)boot_vinfo
->v_width
;
2569 new_vinfo
.v_height
= (unsigned int)boot_vinfo
->v_height
;
2570 new_vinfo
.v_depth
= (unsigned int)boot_vinfo
->v_depth
;
2571 new_vinfo
.v_rowbytes
= (unsigned int)boot_vinfo
->v_rowBytes
;
2572 #if defined(__i386__) || defined(__x86_64__)
2573 new_vinfo
.v_type
= (unsigned int)boot_vinfo
->v_display
;
2575 new_vinfo
.v_type
= 0;
2577 unsigned int scale
= (unsigned int)boot_vinfo
->v_scale
;
2578 if (scale
== kPEScaleFactor1x
)
2579 new_vinfo
.v_scale
= kPEScaleFactor1x
;
2580 else if (scale
== kPEScaleFactor2x
)
2581 new_vinfo
.v_scale
= kPEScaleFactor2x
;
2582 else /* Scale factor not set, default to 1x */
2583 new_vinfo
.v_scale
= kPEScaleFactor1x
;
2587 if (!lastVideoMapped
)
2588 kprintf("initialize_screen: b=%08llX, w=%08X, h=%08X, r=%08X, d=%08X\n", /* (BRINGUP) */
2589 new_vinfo
.v_physaddr
, new_vinfo
.v_width
, new_vinfo
.v_height
, new_vinfo
.v_rowbytes
, new_vinfo
.v_type
); /* (BRINGUP) */
2591 if (!new_vinfo
.v_physaddr
) /* Check to see if we have a framebuffer */
2593 kprintf("initialize_screen: No video - forcing serial mode\n"); /* (BRINGUP) */
2594 new_vinfo
.v_depth
= 0; /* vc routines are nop */
2595 (void)switch_to_serial_console(); /* Switch into serial mode */
2596 gc_graphics_boot
= FALSE
; /* Say we are not in graphics mode */
2597 disableConsoleOutput
= FALSE
; /* Allow printfs to happen */
2603 * If VM is up, we are given a virtual address, unless b0 is set to indicate physical.
2605 if ((kernel_map
!= VM_MAP_NULL
) && (0 == (1 & boot_vinfo
->v_baseAddr
)))
2607 fbppage
= pmap_find_phys(kernel_pmap
, (addr64_t
)boot_vinfo
->v_baseAddr
); /* Get the physical address of frame buffer */
2608 if(!fbppage
) /* Did we find it? */
2610 panic("initialize_screen: Strange framebuffer - addr = %08X\n", (uint32_t)boot_vinfo
->v_baseAddr
);
2612 new_vinfo
.v_physaddr
= (((uint64_t)fbppage
) << 12) | (boot_vinfo
->v_baseAddr
& PAGE_MASK
); /* Get the physical address */
2615 if (boot_vinfo
->v_length
!= 0)
2616 fbsize
= (unsigned int) round_page(boot_vinfo
->v_length
);
2618 fbsize
= (unsigned int) round_page(new_vinfo
.v_height
* new_vinfo
.v_rowbytes
); /* Remember size */
2621 if ((lastVideoPhys
!= new_vinfo
.v_physaddr
) || (fbsize
> lastVideoSize
)) /* Did framebuffer change location or get bigger? */
2623 unsigned int flags
= VM_WIMG_IO
;
2624 newVideoVirt
= io_map_spec((vm_map_offset_t
)new_vinfo
.v_physaddr
, fbsize
, flags
); /* Allocate address space for framebuffer */
2628 if (newVideoVirt
!= 0)
2629 new_vinfo
.v_baseaddr
= newVideoVirt
+ boot_vinfo
->v_offset
; /* Set the new framebuffer address */
2631 new_vinfo
.v_baseaddr
= lastVideoVirt
+ boot_vinfo
->v_offset
; /* Set the new framebuffer address */
2633 #if defined(__x86_64__)
2634 // Adjust the video buffer pointer to point to where it is in high virtual (above the hole)
2635 new_vinfo
.v_baseaddr
|= (VM_MIN_KERNEL_ADDRESS
& ~LOW_4GB_MASK
);
2638 /* Update the vinfo structure atomically with respect to the vc_progress task if running */
2641 simple_lock(&vc_progress_lock
);
2643 simple_unlock(&vc_progress_lock
);
2650 // If we changed the virtual address, remove the old mapping
2651 if (newVideoVirt
!= 0)
2653 if (lastVideoVirt
) /* Was the framebuffer mapped before? */
2656 if(lastVideoMapped
) /* Was this not a special pre-VM mapping? */
2659 pmap_remove(kernel_pmap
, trunc_page_64(lastVideoVirt
),
2660 round_page_64(lastVideoVirt
+ lastVideoSize
)); /* Toss mappings */
2662 if(lastVideoMapped
) /* Was this not a special pre-VM mapping? */
2664 kmem_free(kernel_map
, lastVideoVirt
, lastVideoSize
); /* Toss kernel addresses */
2667 lastVideoPhys
= new_vinfo
.v_physaddr
; /* Remember the framebuffer address */
2668 lastVideoSize
= fbsize
; /* Remember the size */
2669 lastVideoVirt
= newVideoVirt
; /* Remember the virtual framebuffer address */
2670 lastVideoMapped
= (NULL
!= kernel_map
);
2673 if (kPEBaseAddressChange
!= op
)
2675 // Graphics mode setup by the booter.
2677 gc_ops
.initialize
= vc_initialize
;
2678 gc_ops
.enable
= vc_enable
;
2679 gc_ops
.paint_char
= vc_paint_char
;
2680 gc_ops
.scroll_down
= vc_scroll_down
;
2681 gc_ops
.scroll_up
= vc_scroll_up
;
2682 gc_ops
.clear_screen
= vc_clear_screen
;
2683 gc_ops
.hide_cursor
= vc_reverse_cursor
;
2684 gc_ops
.show_cursor
= vc_reverse_cursor
;
2685 gc_ops
.update_color
= vc_update_color
;
2686 gc_initialize(&vinfo
);
2689 #ifdef GRATEFULDEBUGGER
2690 GratefulDebInit((bootBumbleC
*)boot_vinfo
); /* Re-initialize GratefulDeb */
2691 #endif /* GRATEFULDEBUGGER */
2694 graphics_now
= gc_graphics_boot
&& !gc_desire_text
;
2697 case kPEGraphicsMode
:
2698 gc_graphics_boot
= TRUE
;
2699 gc_desire_text
= 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 disable_debug_output
= FALSE
;
2733 if ( gc_acquired
== FALSE
)
2735 gc_desire_text
= TRUE
;
2738 if ( gc_graphics_boot
== FALSE
) break;
2740 vc_progress_set( FALSE
, 0 );
2741 vc_enable_progressmeter( FALSE
);
2745 case kPEReleaseScreen
:
2746 gc_acquired
= FALSE
;
2747 gc_desire_text
= FALSE
;
2749 if ( gc_graphics_boot
== FALSE
) break;
2751 vc_progress_set( FALSE
, 0 );
2752 vc_enable_progressmeter( FALSE
);
2755 #ifdef GRATEFULDEBUGGER
2756 GratefulDebInit(0); /* Stop grateful debugger */
2757 #endif /* GRATEFULDEBUGGER */
2760 #ifdef GRATEFULDEBUGGER
2761 if ( boot_vinfo
) GratefulDebInit((bootBumbleC
*)boot_vinfo
); /* Re initialize GratefulDeb */
2762 #endif /* GRATEFULDEBUGGER */
2768 unsigned int *p
, *endp
, *row
;
2769 int col
, rowline
, rowlongs
;
2770 register unsigned int mask
;
2775 if ( vinfo
.v_depth
== 32 )
2777 else if ( vinfo
.v_depth
== 30 )
2778 mask
= (0x1ff<<20) | (0x1ff<<10) | 0x1ff;
2779 else if ( vinfo
.v_depth
== 16 )
2784 rowline
= (int)(vinfo
.v_rowscanbytes
/ 4);
2785 rowlongs
= (int)(vinfo
.v_rowbytes
/ 4);
2787 p
= (unsigned int*) vinfo
.v_baseaddr
;
2788 endp
= p
+ (rowlongs
* vinfo
.v_height
);
2790 for (row
= p
; row
< endp
; row
+= rowlongs
) {
2791 for (p
= &row
[0], col
= 0; col
< rowline
; col
++) {
2792 *p
= (*p
>> 1) & mask
;
2798 void vcattach(void); /* XXX gcc 4 warning cleanup */
2803 vm_initialized
= TRUE
;
2805 if ( gc_graphics_boot
== FALSE
)
2811 initialize_screen(NULL
, kPEReleaseScreen
);
2814 initialize_screen(NULL
, kPEAcquireScreen
);
2816 for ( index
= 0 ; index
< msgbufp
->msg_bufx
; index
++ )
2818 if (msgbufp
->msg_bufc
[index
] == '\0') {
2822 vcputc( 0, 0, msgbufp
->msg_bufc
[index
] );
2824 if ( msgbufp
->msg_bufc
[index
] == '\n' )
2826 vcputc( 0, 0,'\r' );
2833 int vc_progress_meter_enable
;
2834 int vc_progress_meter_value
;
2836 static void * vc_progress_meter_backbuffer
;
2837 static int vc_progress_meter_drawn
;
2840 vc_draw_progress_meter(int select
, unsigned int flags
, int x1
, int x2
)
2842 const unsigned char * data
;
2846 ox
= ((vinfo
.v_width
- (kProgressBarWidth
<< vc_uiselect
)) / 2);
2847 oy
= vinfo
.v_height
- (((vinfo
.v_height
/ 2) - ((vc_progress
->dy
+ kProgressBarHeight
) << vc_uiselect
)) / 2);
2849 if (kDataBack
== flags
)
2851 // restore back bits
2852 vc_blit_rect(ox
+ x1
, oy
, x1
,
2853 x2
, (kProgressBarHeight
<< vc_uiselect
), 0, (kProgressBarWidth
<< vc_uiselect
),
2854 NULL
, vc_progress_meter_backbuffer
, flags
);
2858 for (x
= x1
; x
< x2
; x
+= w
)
2860 if (x
< (kProgressBarCapWidth
<< vc_uiselect
))
2862 if (x2
< (kProgressBarCapWidth
<< vc_uiselect
))
2865 w
= (kProgressBarCapWidth
<< vc_uiselect
) - x
;
2866 data
= progressmeter_leftcap
[vc_uiselect
& 1][select
& 1];
2868 vc_blit_rect(ox
+ x
, oy
, x
, w
,
2869 (kProgressBarHeight
<< vc_uiselect
),
2870 (kProgressBarCapWidth
<< vc_uiselect
),
2871 (kProgressBarWidth
<< vc_uiselect
),
2872 data
, vc_progress_meter_backbuffer
, flags
);
2874 else if (x
< ((kProgressBarWidth
- kProgressBarCapWidth
) << vc_uiselect
))
2876 if (x2
< ((kProgressBarWidth
- kProgressBarCapWidth
) << vc_uiselect
))
2879 w
= ((kProgressBarWidth
- kProgressBarCapWidth
) << vc_uiselect
) - x
;
2880 data
= progressmeter_middle
[vc_uiselect
& 1][select
& 1];
2881 vc_blit_rect(ox
+ x
, oy
, x
, w
,
2882 (kProgressBarHeight
<< vc_uiselect
),
2884 (kProgressBarWidth
<< vc_uiselect
),
2885 data
, vc_progress_meter_backbuffer
, flags
);
2890 data
= progressmeter_rightcap
[vc_uiselect
& 1][select
& 1];
2891 data
+= x
- ((kProgressBarWidth
- kProgressBarCapWidth
) << vc_uiselect
);
2892 vc_blit_rect(ox
+ x
, oy
, x
, w
,
2893 (kProgressBarHeight
<< vc_uiselect
),
2894 (kProgressBarCapWidth
<< vc_uiselect
),
2895 (kProgressBarWidth
<< vc_uiselect
),
2896 data
, vc_progress_meter_backbuffer
, flags
);
2902 vc_enable_progressmeter(int new_value
)
2905 void * new_buffer
= NULL
;
2908 new_buffer
= kalloc((kProgressBarWidth
<< vc_uiselect
)
2909 * (kProgressBarHeight
<< vc_uiselect
) * sizeof(int));
2912 simple_lock(&vc_progress_lock
);
2914 if (gc_enabled
|| !gc_acquired
|| !gc_graphics_boot
)
2917 if (new_value
!= vc_progress_meter_enable
)
2921 vc_progress_meter_backbuffer
= new_buffer
;
2922 vc_draw_progress_meter(FALSE
, kDataAlpha
| kSave
, 0, (kProgressBarWidth
<< vc_uiselect
));
2923 vc_progress_meter_enable
= TRUE
;
2925 vc_progress_meter_drawn
= 0;
2927 else if (vc_progress_meter_backbuffer
)
2929 vc_draw_progress_meter(0, kDataBack
, 0, (kProgressBarWidth
<< vc_uiselect
));
2930 new_buffer
= vc_progress_meter_backbuffer
;
2931 vc_progress_meter_backbuffer
= NULL
;
2932 vc_progress_meter_enable
= FALSE
;
2936 simple_unlock(&vc_progress_lock
);
2940 kfree(new_buffer
, (kProgressBarWidth
<< vc_uiselect
)
2941 * (kProgressBarHeight
<< vc_uiselect
) * sizeof(int));
2945 vc_set_progressmeter(int new_value
)
2950 if ((new_value
< 0) | (new_value
> 100))
2954 simple_lock(&vc_progress_lock
);
2956 if (vc_progress_meter_enable
)
2958 vc_progress_meter_value
= new_value
;
2959 x2
= ((kProgressBarWidth
<< vc_uiselect
) * new_value
) / 100;
2960 if (x2
> vc_progress_meter_drawn
)
2961 vc_draw_progress_meter(TRUE
, kDataAlpha
, vc_progress_meter_drawn
, x2
);
2963 vc_draw_progress_meter(FALSE
, kDataAlpha
, x2
, vc_progress_meter_drawn
);
2964 vc_progress_meter_drawn
= x2
;
2967 simple_unlock(&vc_progress_lock
);