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
;
129 extern int disableConsoleOutput
;
130 static boolean_t gc_enabled
= FALSE
;
131 static boolean_t gc_initialized
= FALSE
;
132 static boolean_t vm_initialized
= FALSE
;
135 void (*initialize
)(struct vc_info
* info
);
136 void (*enable
)(boolean_t enable
);
137 void (*paint_char
)(unsigned int xx
, unsigned int yy
, unsigned char ch
,
138 int attrs
, unsigned char ch_previous
,
140 void (*clear_screen
)(unsigned int xx
, unsigned int yy
, unsigned int top
,
141 unsigned int bottom
, int which
);
142 void (*scroll_down
)(int num
, unsigned int top
, unsigned int bottom
);
143 void (*scroll_up
)(int num
, unsigned int top
, unsigned int bottom
);
144 void (*hide_cursor
)(unsigned int xx
, unsigned int yy
);
145 void (*show_cursor
)(unsigned int xx
, unsigned int yy
);
146 void (*update_color
)(int color
, boolean_t fore
);
149 static unsigned char *gc_buffer_attributes
;
150 static unsigned char *gc_buffer_characters
;
151 static unsigned char *gc_buffer_colorcodes
;
152 static unsigned char *gc_buffer_tab_stops
;
153 static uint32_t gc_buffer_columns
;
154 static uint32_t gc_buffer_rows
;
155 static uint32_t gc_buffer_size
;
157 #if defined(__i386__) || defined(__x86_64__)
158 decl_simple_lock_data(static, vcputc_lock
);
160 #define VCPUTC_LOCK_INIT() \
162 simple_lock_init(&vcputc_lock, 0); \
165 #define VCPUTC_LOCK_LOCK() \
167 boolean_t istate = ml_get_interrupts_enabled(); \
168 while (!simple_lock_try(&vcputc_lock)) \
171 handle_pending_TLB_flushes(); \
176 #define VCPUTC_LOCK_UNLOCK() \
178 simple_unlock(&vcputc_lock); \
181 static hw_lock_data_t vcputc_lock
;
183 #define VCPUTC_LOCK_INIT() \
185 hw_lock_init(&vcputc_lock); \
188 #define VCPUTC_LOCK_LOCK() \
190 if (!hw_lock_to(&vcputc_lock, hwLockTimeOut*10))\
192 panic("VCPUTC_LOCK_LOCK"); \
196 #define VCPUTC_LOCK_UNLOCK() \
198 hw_lock_unlock(&vcputc_lock); \
204 # 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
206 # 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
207 # Background color codes:
208 # 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
214 #define ATTR_REVERSE 4
216 #define COLOR_BACKGROUND 0
217 #define COLOR_FOREGROUND 7
219 #define COLOR_CODE_GET(code, fore) (((code) & ((fore) ? 0xF0 : 0x0F)) >> ((fore) ? 4 : 0))
220 #define COLOR_CODE_SET(code, color, fore) (((code) & ((fore) ? 0x0F : 0xF0)) | ((color) << ((fore) ? 4 : 0)))
222 static unsigned char gc_color_code
;
226 static unsigned int gc_x
, gc_y
, gc_savex
, gc_savey
;
227 static unsigned int gc_par
[MAXPARS
], gc_numpars
, gc_hanging_cursor
, gc_attr
, gc_saveattr
;
229 /* VT100 scroll region */
230 static unsigned int gc_scrreg_top
, gc_scrreg_bottom
;
232 #ifdef CONFIG_VC_PROGRESS_WHITE
233 enum { kProgressAcquireDelay
= 0 /* secs */ };
235 enum { kProgressAcquireDelay
= 5 /* secs */ };
239 ESnormal
, /* Nothing yet */
241 ESsquare
, /* Got ESC [ */
242 ESgetpars
, /* About to get or getting the parameters */
243 ESgotpars
, /* Finished getting the parameters */
244 ESfunckey
, /* Function key */
245 EShash
, /* DEC-specific stuff (screen align, etc.) */
246 ESsetG0
, /* Specify the G0 character set */
247 ESsetG1
, /* Specify the G1 character set */
250 ESignore
/* Ignore this sequence */
251 } gc_vt100state
= ESnormal
;
253 static int gc_wrap_mode
= 1, gc_relative_origin
= 0;
254 static int gc_charset_select
= 0, gc_save_charset_s
= 0;
255 static int gc_charset
[2] = { 0, 0 };
256 static int gc_charset_save
[2] = { 0, 0 };
258 static void gc_clear_line(unsigned int xx
, unsigned int yy
, int which
);
259 static void gc_clear_screen(unsigned int xx
, unsigned int yy
, int top
,
260 unsigned int bottom
, int which
);
261 static void gc_enable(boolean_t enable
);
262 static void gc_hide_cursor(unsigned int xx
, unsigned int yy
);
263 static void gc_initialize(struct vc_info
* info
);
264 static boolean_t
gc_is_tab_stop(unsigned int column
);
265 static void gc_paint_char(unsigned int xx
, unsigned int yy
, unsigned char ch
,
267 static void gc_putchar(char ch
);
268 static void gc_putc_askcmd(unsigned char ch
);
269 static void gc_putc_charsetcmd(int charset
, unsigned char ch
);
270 static void gc_putc_charsizecmd(unsigned char ch
);
271 static void gc_putc_esc(unsigned char ch
);
272 static void gc_putc_getpars(unsigned char ch
);
273 static void gc_putc_gotpars(unsigned char ch
);
274 static void gc_putc_normal(unsigned char ch
);
275 static void gc_putc_square(unsigned char ch
);
276 static void gc_reset_screen(void);
277 static void gc_reset_tabs(void);
278 static void gc_reset_vt100(void);
279 static void gc_scroll_down(int num
, unsigned int top
, unsigned int bottom
);
280 static void gc_scroll_up(int num
, unsigned int top
, unsigned int bottom
);
281 static void gc_set_tab_stop(unsigned int column
, boolean_t enabled
);
282 static void gc_show_cursor(unsigned int xx
, unsigned int yy
);
283 static void gc_update_color(int color
, boolean_t fore
);
286 gc_clear_line(unsigned int xx
, unsigned int yy
, int which
)
288 unsigned int start
, end
, i
;
291 * This routine runs extremely slowly. I don't think it's
292 * used all that often, except for To end of line. I'll go
293 * back and speed this up when I speed up the whole vc
298 case 0: /* To end of line */
300 end
= vinfo
.v_columns
-1;
302 case 1: /* To start of line */
306 case 2: /* Whole line */
308 end
= vinfo
.v_columns
-1;
314 for (i
= start
; i
<= end
; i
++) {
315 gc_paint_char(i
, yy
, ' ', ATTR_NONE
);
320 gc_clear_screen(unsigned int xx
, unsigned int yy
, int top
, unsigned int bottom
,
323 if (!gc_buffer_size
) return;
325 if ( xx
< gc_buffer_columns
&& yy
< gc_buffer_rows
&& bottom
<= gc_buffer_rows
)
330 case 0: /* To end of screen */
331 start
= (yy
* gc_buffer_columns
) + xx
;
332 end
= (bottom
* gc_buffer_columns
) - 1;
334 case 1: /* To start of screen */
335 start
= (top
* gc_buffer_columns
);
336 end
= (yy
* gc_buffer_columns
) + xx
;
338 case 2: /* Whole screen */
339 start
= (top
* gc_buffer_columns
);
340 end
= (bottom
* gc_buffer_columns
) - 1;
348 memset(gc_buffer_attributes
+ start
, ATTR_NONE
, end
- start
+ 1);
349 memset(gc_buffer_characters
+ start
, ' ', end
- start
+ 1);
350 memset(gc_buffer_colorcodes
+ start
, gc_color_code
, end
- start
+ 1);
353 gc_ops
.clear_screen(xx
, yy
, top
, bottom
, which
);
357 gc_enable( boolean_t enable
)
359 unsigned char *buffer_attributes
= NULL
;
360 unsigned char *buffer_characters
= NULL
;
361 unsigned char *buffer_colorcodes
= NULL
;
362 unsigned char *buffer_tab_stops
= NULL
;
363 uint32_t buffer_columns
= 0;
364 uint32_t buffer_rows
= 0;
365 uint32_t buffer_size
= 0;
368 if ( enable
== FALSE
)
370 // only disable console output if it goes to the graphics console
371 if ( console_is_serial() == FALSE
)
372 disableConsoleOutput
= TRUE
;
374 gc_ops
.enable(FALSE
);
380 if ( gc_buffer_size
)
382 buffer_attributes
= gc_buffer_attributes
;
383 buffer_characters
= gc_buffer_characters
;
384 buffer_colorcodes
= gc_buffer_colorcodes
;
385 buffer_tab_stops
= gc_buffer_tab_stops
;
386 buffer_columns
= gc_buffer_columns
;
387 buffer_rows
= gc_buffer_rows
;
388 buffer_size
= gc_buffer_size
;
390 gc_buffer_attributes
= NULL
;
391 gc_buffer_characters
= NULL
;
392 gc_buffer_colorcodes
= NULL
;
393 gc_buffer_tab_stops
= NULL
;
394 gc_buffer_columns
= 0;
398 VCPUTC_LOCK_UNLOCK( );
401 kfree( buffer_attributes
, buffer_size
);
402 kfree( buffer_characters
, buffer_size
);
403 kfree( buffer_colorcodes
, buffer_size
);
404 kfree( buffer_tab_stops
, buffer_columns
);
408 VCPUTC_LOCK_UNLOCK( );
414 if ( vm_initialized
)
416 buffer_columns
= vinfo
.v_columns
;
417 buffer_rows
= vinfo
.v_rows
;
418 buffer_size
= buffer_columns
* buffer_rows
;
422 buffer_attributes
= (unsigned char *) kalloc( buffer_size
);
423 buffer_characters
= (unsigned char *) kalloc( buffer_size
);
424 buffer_colorcodes
= (unsigned char *) kalloc( buffer_size
);
425 buffer_tab_stops
= (unsigned char *) kalloc( buffer_columns
);
427 if ( buffer_attributes
== NULL
||
428 buffer_characters
== NULL
||
429 buffer_colorcodes
== NULL
||
430 buffer_tab_stops
== NULL
)
432 if ( buffer_attributes
) kfree( buffer_attributes
, buffer_size
);
433 if ( buffer_characters
) kfree( buffer_characters
, buffer_size
);
434 if ( buffer_colorcodes
) kfree( buffer_colorcodes
, buffer_size
);
435 if ( buffer_tab_stops
) kfree( buffer_tab_stops
, buffer_columns
);
443 memset( buffer_attributes
, ATTR_NONE
, buffer_size
);
444 memset( buffer_characters
, ' ', buffer_size
);
445 memset( buffer_colorcodes
, COLOR_CODE_SET( 0, COLOR_FOREGROUND
, TRUE
), buffer_size
);
446 memset( buffer_tab_stops
, 0, buffer_columns
);
454 gc_buffer_attributes
= buffer_attributes
;
455 gc_buffer_characters
= buffer_characters
;
456 gc_buffer_colorcodes
= buffer_colorcodes
;
457 gc_buffer_tab_stops
= buffer_tab_stops
;
458 gc_buffer_columns
= buffer_columns
;
459 gc_buffer_rows
= buffer_rows
;
460 gc_buffer_size
= buffer_size
;
464 VCPUTC_LOCK_UNLOCK( );
467 gc_ops
.clear_screen(gc_x
, gc_y
, 0, vinfo
.v_rows
, 2);
468 gc_ops
.show_cursor(gc_x
, gc_y
);
472 disableConsoleOutput
= FALSE
;
477 gc_hide_cursor(unsigned int xx
, unsigned int yy
)
479 if ( xx
< gc_buffer_columns
&& yy
< gc_buffer_rows
)
481 uint32_t index
= (yy
* gc_buffer_columns
) + xx
;
482 unsigned char attribute
= gc_buffer_attributes
[index
];
483 unsigned char character
= gc_buffer_characters
[index
];
484 unsigned char colorcode
= gc_buffer_colorcodes
[index
];
485 unsigned char colorcodesave
= gc_color_code
;
487 gc_update_color(COLOR_CODE_GET(colorcode
, TRUE
), TRUE
);
488 gc_update_color(COLOR_CODE_GET(colorcode
, FALSE
), FALSE
);
490 gc_ops
.paint_char(xx
, yy
, character
, attribute
, 0, 0);
492 gc_update_color(COLOR_CODE_GET(colorcodesave
, TRUE
), TRUE
);
493 gc_update_color(COLOR_CODE_GET(colorcodesave
, FALSE
), FALSE
);
497 gc_ops
.hide_cursor(xx
, yy
);
502 gc_initialize(struct vc_info
* info
)
504 if ( gc_initialized
== FALSE
)
509 gc_initialized
= TRUE
;
512 gc_ops
.initialize(info
);
519 gc_paint_char(unsigned int xx
, unsigned int yy
, unsigned char ch
, int attrs
)
521 if ( xx
< gc_buffer_columns
&& yy
< gc_buffer_rows
)
523 uint32_t index
= (yy
* gc_buffer_columns
) + xx
;
525 gc_buffer_attributes
[index
] = attrs
;
526 gc_buffer_characters
[index
] = ch
;
527 gc_buffer_colorcodes
[index
] = gc_color_code
;
530 gc_ops
.paint_char(xx
, yy
, ch
, attrs
, 0, 0);
537 return; /* ignore null characters */
539 switch (gc_vt100state
) {
540 default:gc_vt100state
= ESnormal
; /* FALLTHROUGH */
560 gc_putc_charsizecmd(ch
);
563 gc_putc_charsetcmd(0, ch
);
566 gc_putc_charsetcmd(1, ch
);
570 if (gc_x
>= vinfo
.v_columns
) {
571 if (0 == vinfo
.v_columns
)
574 gc_x
= vinfo
.v_columns
- 1;
576 if (gc_y
>= vinfo
.v_rows
) {
577 if (0 == vinfo
.v_rows
)
580 gc_y
= vinfo
.v_rows
- 1;
585 gc_putc_askcmd(unsigned char ch
)
587 if (ch
>= '0' && ch
<= '9') {
588 gc_par
[gc_numpars
] = (10*gc_par
[gc_numpars
]) + (ch
-'0');
591 gc_vt100state
= ESnormal
;
595 gc_relative_origin
= ch
== 'h';
597 case 7: /* wrap around mode h=1, l=0*/
598 gc_wrap_mode
= ch
== 'h';
607 gc_putc_charsetcmd(int charset
, unsigned char ch
)
609 gc_vt100state
= ESnormal
;
615 gc_charset
[charset
] = 0;
617 case '0' : /* Graphic characters */
619 gc_charset
[charset
] = 0x21;
626 gc_putc_charsizecmd(unsigned char ch
)
628 gc_vt100state
= ESnormal
;
636 case '8' : /* fill 'E's */
639 for (yy
= 0; yy
< vinfo
.v_rows
; yy
++)
640 for (xx
= 0; xx
< vinfo
.v_columns
; xx
++)
641 gc_paint_char(xx
, yy
, 'E', ATTR_NONE
);
649 gc_putc_esc(unsigned char ch
)
651 gc_vt100state
= ESnormal
;
655 gc_vt100state
= ESsquare
;
657 case 'c': /* Reset terminal */
659 gc_clear_screen(gc_x
, gc_y
, 0, vinfo
.v_rows
, 2);
662 case 'D': /* Line feed */
664 if (gc_y
>= gc_scrreg_bottom
-1) {
665 gc_scroll_up(1, gc_scrreg_top
, gc_scrreg_bottom
);
666 gc_y
= gc_scrreg_bottom
- 1;
670 if (ch
== 'E') gc_x
= 0;
672 case 'H': /* Set tab stop */
673 gc_set_tab_stop(gc_x
, TRUE
);
675 case 'M': /* Cursor up */
676 if (gc_y
<= gc_scrreg_top
) {
677 gc_scroll_down(1, gc_scrreg_top
, gc_scrreg_bottom
);
678 gc_y
= gc_scrreg_top
;
686 case '7': /* Save cursor */
689 gc_saveattr
= gc_attr
;
690 gc_save_charset_s
= gc_charset_select
;
691 gc_charset_save
[0] = gc_charset
[0];
692 gc_charset_save
[1] = gc_charset
[1];
694 case '8': /* Restore cursor */
697 gc_attr
= gc_saveattr
;
698 gc_charset_select
= gc_save_charset_s
;
699 gc_charset
[0] = gc_charset_save
[0];
700 gc_charset
[1] = gc_charset_save
[1];
702 case 'Z': /* return terminal ID */
704 case '#': /* change characters height */
705 gc_vt100state
= EScharsize
;
708 gc_vt100state
= ESsetG0
;
710 case ')': /* character set sequence */
711 gc_vt100state
= ESsetG1
;
716 /* Rest not supported */
723 gc_putc_getpars(unsigned char ch
)
726 gc_vt100state
= ESask
;
730 gc_vt100state
= ESnormal
;
734 if (ch
== ';' && gc_numpars
< MAXPARS
- 1) {
737 if (ch
>= '0' && ch
<= '9') {
738 gc_par
[gc_numpars
] *= 10;
739 gc_par
[gc_numpars
] += ch
- '0';
742 gc_vt100state
= ESgotpars
;
748 gc_putc_gotpars(unsigned char ch
)
753 /* special case for vttest for handling cursor
754 movement in escape sequences */
756 gc_vt100state
= ESgotpars
;
759 gc_vt100state
= ESnormal
;
762 gc_y
-= gc_par
[0] ? gc_par
[0] : 1;
763 if (gc_y
< gc_scrreg_top
)
764 gc_y
= gc_scrreg_top
;
767 gc_y
+= gc_par
[0] ? gc_par
[0] : 1;
768 if (gc_y
>= gc_scrreg_bottom
)
769 gc_y
= gc_scrreg_bottom
- 1;
771 case 'C': /* Right */
772 gc_x
+= gc_par
[0] ? gc_par
[0] : 1;
773 if (gc_x
>= vinfo
.v_columns
)
774 gc_x
= vinfo
.v_columns
-1;
777 if (gc_par
[0] > gc_x
)
784 case 'H': /* Set cursor position */
786 gc_x
= gc_par
[1] ? gc_par
[1] - 1 : 0;
787 gc_y
= gc_par
[0] ? gc_par
[0] - 1 : 0;
788 if (gc_relative_origin
)
789 gc_y
+= gc_scrreg_top
;
790 gc_hanging_cursor
= 0;
792 case 'X': /* clear p1 characters */
794 for (i
= gc_x
; i
< gc_x
+ gc_par
[0]; i
++)
795 gc_paint_char(i
, gc_y
, ' ', ATTR_NONE
);
798 case 'J': /* Clear part of screen */
799 gc_clear_screen(gc_x
, gc_y
, 0, vinfo
.v_rows
, gc_par
[0]);
801 case 'K': /* Clear part of line */
802 gc_clear_line(gc_x
, gc_y
, gc_par
[0]);
804 case 'g': /* tab stops */
807 case 2: /* reset tab stops */
808 /* gc_reset_tabs(); */
810 case 3: /* Clear every tabs */
812 for (i
= 0; i
<= vinfo
.v_columns
; i
++)
813 gc_set_tab_stop(i
, FALSE
);
817 gc_set_tab_stop(gc_x
, FALSE
);
821 case 'm': /* Set attribute */
822 for (i
= 0; i
< gc_numpars
; i
++) {
826 gc_update_color(COLOR_BACKGROUND
, FALSE
);
827 gc_update_color(COLOR_FOREGROUND
, TRUE
);
830 gc_attr
|= ATTR_BOLD
;
833 gc_attr
|= ATTR_UNDER
;
836 gc_attr
|= ATTR_REVERSE
;
839 gc_attr
&= ~ATTR_BOLD
;
842 gc_attr
&= ~ATTR_UNDER
;
845 gc_attr
&= ~ATTR_REVERSE
;
848 case 25: /* blink/no blink */
851 if (gc_par
[i
] >= 30 && gc_par
[i
] <= 37)
852 gc_update_color(gc_par
[i
] - 30, TRUE
);
853 if (gc_par
[i
] >= 40 && gc_par
[i
] <= 47)
854 gc_update_color(gc_par
[i
] - 40, FALSE
);
859 case 'r': /* Set scroll region */
861 /* ensure top < bottom, and both within limits */
862 if ((gc_numpars
> 0) && (gc_par
[0] < vinfo
.v_rows
)) {
863 gc_scrreg_top
= gc_par
[0] ? gc_par
[0] - 1 : 0;
867 if ((gc_numpars
> 1) && (gc_par
[1] <= vinfo
.v_rows
) && (gc_par
[1] > gc_par
[0])) {
868 gc_scrreg_bottom
= gc_par
[1];
869 if (gc_scrreg_bottom
> vinfo
.v_rows
)
870 gc_scrreg_bottom
= vinfo
.v_rows
;
872 gc_scrreg_bottom
= vinfo
.v_rows
;
874 if (gc_relative_origin
)
875 gc_y
= gc_scrreg_top
;
882 gc_putc_normal(unsigned char ch
)
885 case '\a': /* Beep */
887 case 127: /* Delete */
888 case '\b': /* Backspace */
889 if (gc_hanging_cursor
) {
890 gc_hanging_cursor
= 0;
897 if (gc_buffer_tab_stops
) while (gc_x
< vinfo
.v_columns
&& !gc_is_tab_stop(++gc_x
));
899 if (gc_x
>= vinfo
.v_columns
)
900 gc_x
= vinfo
.v_columns
-1;
904 case '\n': /* Line feed */
905 if (gc_y
>= gc_scrreg_bottom
-1 ) {
906 gc_scroll_up(1, gc_scrreg_top
, gc_scrreg_bottom
);
907 gc_y
= gc_scrreg_bottom
- 1;
912 case '\r': /* Carriage return */
914 gc_hanging_cursor
= 0;
916 case 0x0e: /* Select G1 charset (Control-N) */
917 gc_charset_select
= 1;
919 case 0x0f: /* Select G0 charset (Control-O) */
920 gc_charset_select
= 0;
922 case 0x18 : /* CAN : cancel */
923 case 0x1A : /* like cancel */
924 /* well, i do nothing here, may be later */
926 case '\033': /* Escape */
927 gc_vt100state
= ESesc
;
928 gc_hanging_cursor
= 0;
932 if (gc_hanging_cursor
) {
934 if (gc_y
>= gc_scrreg_bottom
-1 ) {
935 gc_scroll_up(1, gc_scrreg_top
, gc_scrreg_bottom
);
936 gc_y
= gc_scrreg_bottom
- 1;
940 gc_hanging_cursor
= 0;
942 gc_paint_char(gc_x
, gc_y
, (ch
>= 0x60 && ch
<= 0x7f) ? ch
+ gc_charset
[gc_charset_select
]
944 if (gc_x
== vinfo
.v_columns
- 1) {
945 gc_hanging_cursor
= gc_wrap_mode
;
956 gc_putc_square(unsigned char ch
)
960 for (i
= 0; i
< MAXPARS
; i
++) {
965 gc_vt100state
= ESgetpars
;
972 gc_reset_screen(void)
983 if (!gc_buffer_tab_stops
) return;
985 for (i
= 0; i
< vinfo
.v_columns
; i
++) {
986 gc_buffer_tab_stops
[i
] = ((i
% 8) == 0);
992 gc_set_tab_stop(unsigned int column
, boolean_t enabled
)
994 if (gc_buffer_tab_stops
&& (column
< vinfo
.v_columns
)) {
995 gc_buffer_tab_stops
[column
] = enabled
;
999 static boolean_t
gc_is_tab_stop(unsigned int column
)
1001 if (gc_buffer_tab_stops
== NULL
)
1002 return ((column
% 8) == 0);
1003 if (column
< vinfo
.v_columns
)
1004 return gc_buffer_tab_stops
[column
];
1010 gc_reset_vt100(void)
1014 gc_scrreg_bottom
= vinfo
.v_rows
;
1015 gc_attr
= ATTR_NONE
;
1016 gc_charset
[0] = gc_charset
[1] = 0;
1017 gc_charset_select
= 0;
1019 gc_relative_origin
= 0;
1020 gc_update_color(COLOR_BACKGROUND
, FALSE
);
1021 gc_update_color(COLOR_FOREGROUND
, TRUE
);
1025 gc_scroll_down(int num
, unsigned int top
, unsigned int bottom
)
1027 if (!gc_buffer_size
) return;
1029 if ( bottom
<= gc_buffer_rows
)
1031 unsigned char colorcodesave
= gc_color_code
;
1032 uint32_t column
, row
;
1033 uint32_t index
, jump
;
1035 jump
= num
* gc_buffer_columns
;
1037 for ( row
= bottom
- 1 ; row
>= top
+ num
; row
-- )
1039 index
= row
* gc_buffer_columns
;
1041 for ( column
= 0 ; column
< gc_buffer_columns
; index
++, column
++ )
1043 if ( gc_buffer_attributes
[index
] != gc_buffer_attributes
[index
- jump
] ||
1044 gc_buffer_characters
[index
] != gc_buffer_characters
[index
- jump
] ||
1045 gc_buffer_colorcodes
[index
] != gc_buffer_colorcodes
[index
- jump
] )
1047 if ( gc_color_code
!= gc_buffer_colorcodes
[index
- jump
] )
1049 gc_update_color(COLOR_CODE_GET(gc_buffer_colorcodes
[index
- jump
], TRUE
), TRUE
);
1050 gc_update_color(COLOR_CODE_GET(gc_buffer_colorcodes
[index
- jump
], FALSE
), FALSE
);
1053 if ( gc_buffer_colorcodes
[index
] != gc_buffer_colorcodes
[index
- jump
] )
1055 gc_ops
.paint_char( /* xx */ column
,
1057 /* ch */ gc_buffer_characters
[index
- jump
],
1058 /* attrs */ gc_buffer_attributes
[index
- jump
],
1059 /* ch_previous */ 0,
1060 /* attrs_previous */ 0 );
1064 gc_ops
.paint_char( /* xx */ column
,
1066 /* ch */ gc_buffer_characters
[index
- jump
],
1067 /* attrs */ gc_buffer_attributes
[index
- jump
],
1068 /* ch_previous */ gc_buffer_characters
[index
],
1069 /* attrs_previous */ gc_buffer_attributes
[index
] );
1072 gc_buffer_attributes
[index
] = gc_buffer_attributes
[index
- jump
];
1073 gc_buffer_characters
[index
] = gc_buffer_characters
[index
- jump
];
1074 gc_buffer_colorcodes
[index
] = gc_buffer_colorcodes
[index
- jump
];
1079 if ( colorcodesave
!= gc_color_code
)
1081 gc_update_color(COLOR_CODE_GET(colorcodesave
, TRUE
), TRUE
);
1082 gc_update_color(COLOR_CODE_GET(colorcodesave
, FALSE
), FALSE
);
1085 /* Now set the freed up lines to the background colour */
1087 for ( row
= top
; row
< top
+ num
; row
++ )
1089 index
= row
* gc_buffer_columns
;
1091 for ( column
= 0 ; column
< gc_buffer_columns
; index
++, column
++ )
1093 if ( gc_buffer_attributes
[index
] != ATTR_NONE
||
1094 gc_buffer_characters
[index
] != ' ' ||
1095 gc_buffer_colorcodes
[index
] != gc_color_code
)
1097 if ( gc_buffer_colorcodes
[index
] != gc_color_code
)
1099 gc_ops
.paint_char( /* xx */ column
,
1102 /* attrs */ ATTR_NONE
,
1103 /* ch_previous */ 0,
1104 /* attrs_previous */ 0 );
1108 gc_ops
.paint_char( /* xx */ column
,
1111 /* attrs */ ATTR_NONE
,
1112 /* ch_previous */ gc_buffer_characters
[index
],
1113 /* attrs_previous */ gc_buffer_attributes
[index
] );
1116 gc_buffer_attributes
[index
] = ATTR_NONE
;
1117 gc_buffer_characters
[index
] = ' ';
1118 gc_buffer_colorcodes
[index
] = gc_color_code
;
1125 gc_ops
.scroll_down(num
, top
, bottom
);
1127 /* Now set the freed up lines to the background colour */
1129 gc_clear_screen(vinfo
.v_columns
- 1, top
+ num
- 1, top
, bottom
, 1);
1134 gc_scroll_up(int num
, unsigned int top
, unsigned int bottom
)
1136 if (!gc_buffer_size
) return;
1138 if ( bottom
<= gc_buffer_rows
)
1140 unsigned char colorcodesave
= gc_color_code
;
1141 uint32_t column
, row
;
1142 uint32_t index
, jump
;
1144 jump
= num
* gc_buffer_columns
;
1146 for ( row
= top
; row
< bottom
- num
; row
++ )
1148 index
= row
* gc_buffer_columns
;
1150 for ( column
= 0 ; column
< gc_buffer_columns
; index
++, column
++ )
1152 if ( gc_buffer_attributes
[index
] != gc_buffer_attributes
[index
+ jump
] ||
1153 gc_buffer_characters
[index
] != gc_buffer_characters
[index
+ jump
] ||
1154 gc_buffer_colorcodes
[index
] != gc_buffer_colorcodes
[index
+ jump
] )
1156 if ( gc_color_code
!= gc_buffer_colorcodes
[index
+ jump
] )
1158 gc_update_color(COLOR_CODE_GET(gc_buffer_colorcodes
[index
+ jump
], TRUE
), TRUE
);
1159 gc_update_color(COLOR_CODE_GET(gc_buffer_colorcodes
[index
+ jump
], FALSE
), FALSE
);
1162 if ( gc_buffer_colorcodes
[index
] != gc_buffer_colorcodes
[index
+ jump
] )
1164 gc_ops
.paint_char( /* xx */ column
,
1166 /* ch */ gc_buffer_characters
[index
+ jump
],
1167 /* attrs */ gc_buffer_attributes
[index
+ jump
],
1168 /* ch_previous */ 0,
1169 /* attrs_previous */ 0 );
1173 gc_ops
.paint_char( /* xx */ column
,
1175 /* ch */ gc_buffer_characters
[index
+ jump
],
1176 /* attrs */ gc_buffer_attributes
[index
+ jump
],
1177 /* ch_previous */ gc_buffer_characters
[index
],
1178 /* attrs_previous */ gc_buffer_attributes
[index
] );
1181 gc_buffer_attributes
[index
] = gc_buffer_attributes
[index
+ jump
];
1182 gc_buffer_characters
[index
] = gc_buffer_characters
[index
+ jump
];
1183 gc_buffer_colorcodes
[index
] = gc_buffer_colorcodes
[index
+ jump
];
1188 if ( colorcodesave
!= gc_color_code
)
1190 gc_update_color(COLOR_CODE_GET(colorcodesave
, TRUE
), TRUE
);
1191 gc_update_color(COLOR_CODE_GET(colorcodesave
, FALSE
), FALSE
);
1194 /* Now set the freed up lines to the background colour */
1196 for ( row
= bottom
- num
; row
< bottom
; row
++ )
1198 index
= row
* gc_buffer_columns
;
1200 for ( column
= 0 ; column
< gc_buffer_columns
; index
++, column
++ )
1202 if ( gc_buffer_attributes
[index
] != ATTR_NONE
||
1203 gc_buffer_characters
[index
] != ' ' ||
1204 gc_buffer_colorcodes
[index
] != gc_color_code
)
1206 if ( gc_buffer_colorcodes
[index
] != gc_color_code
)
1208 gc_ops
.paint_char( /* xx */ column
,
1211 /* attrs */ ATTR_NONE
,
1212 /* ch_previous */ 0,
1213 /* attrs_previous */ 0 );
1217 gc_ops
.paint_char( /* xx */ column
,
1220 /* attrs */ ATTR_NONE
,
1221 /* ch_previous */ gc_buffer_characters
[index
],
1222 /* attrs_previous */ gc_buffer_attributes
[index
] );
1225 gc_buffer_attributes
[index
] = ATTR_NONE
;
1226 gc_buffer_characters
[index
] = ' ';
1227 gc_buffer_colorcodes
[index
] = gc_color_code
;
1234 gc_ops
.scroll_up(num
, top
, bottom
);
1236 /* Now set the freed up lines to the background colour */
1238 gc_clear_screen(0, bottom
- num
, top
, bottom
, 0);
1243 gc_show_cursor(unsigned int xx
, unsigned int yy
)
1245 if ( xx
< gc_buffer_columns
&& yy
< gc_buffer_rows
)
1247 uint32_t index
= (yy
* gc_buffer_columns
) + xx
;
1248 unsigned char attribute
= gc_buffer_attributes
[index
];
1249 unsigned char character
= gc_buffer_characters
[index
];
1250 unsigned char colorcode
= gc_buffer_colorcodes
[index
];
1251 unsigned char colorcodesave
= gc_color_code
;
1253 gc_update_color(COLOR_CODE_GET(colorcode
, FALSE
), TRUE
);
1254 gc_update_color(COLOR_CODE_GET(colorcode
, TRUE
), FALSE
);
1256 gc_ops
.paint_char(xx
, yy
, character
, attribute
, 0, 0);
1258 gc_update_color(COLOR_CODE_GET(colorcodesave
, TRUE
), TRUE
);
1259 gc_update_color(COLOR_CODE_GET(colorcodesave
, FALSE
), FALSE
);
1263 gc_ops
.show_cursor(xx
, yy
);
1268 gc_update_color(int color
, boolean_t fore
)
1270 gc_color_code
= COLOR_CODE_SET(gc_color_code
, color
, fore
);
1271 gc_ops
.update_color(color
, fore
);
1275 vcputc(__unused
int l
, __unused
int u
, int c
)
1277 if ( gc_initialized
&& ( gc_enabled
|| debug_mode
) )
1282 #if defined(__i386__) || defined(__x86_64__)
1283 x86_filter_TLB_coherency_interrupts(TRUE
);
1286 if ( gc_enabled
|| debug_mode
)
1288 gc_hide_cursor(gc_x
, gc_y
);
1290 gc_show_cursor(gc_x
, gc_y
);
1292 VCPUTC_LOCK_UNLOCK();
1293 #if defined(__i386__) || defined(__x86_64__)
1294 x86_filter_TLB_coherency_interrupts(FALSE
);
1301 * Video Console (Back-End)
1302 * ------------------------
1306 * For the color support (Michel Pollet)
1308 static unsigned char vc_color_index_table
[33] =
1309 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1310 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 2 };
1312 static uint32_t vc_colors
[8][4] = {
1313 { 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000 }, /* black */
1314 { 0x23232323, 0x7C007C00, 0x00FF0000, 0x3FF00000 }, /* red */
1315 { 0xb9b9b9b9, 0x03e003e0, 0x0000FF00, 0x000FFC00 }, /* green */
1316 { 0x05050505, 0x7FE07FE0, 0x00FFFF00, 0x3FFFFC00 }, /* yellow */
1317 { 0xd2d2d2d2, 0x001f001f, 0x000000FF, 0x000003FF }, /* blue */
1318 // { 0x80808080, 0x31933193, 0x00666699, 0x00000000 }, /* blue */
1319 { 0x18181818, 0x7C1F7C1F, 0x00FF00FF, 0x3FF003FF }, /* magenta */
1320 { 0xb4b4b4b4, 0x03FF03FF, 0x0000FFFF, 0x000FFFFF }, /* cyan */
1321 { 0x00000000, 0x7FFF7FFF, 0x00FFFFFF, 0x3FFFFFFF } /* white */
1324 static uint32_t vc_color_fore
= 0;
1325 static uint32_t vc_color_back
= 0;
1328 * New Rendering code from Michel Pollet
1331 /* Rendered Font Buffer */
1332 static unsigned char *vc_rendered_font
= NULL
;
1334 /* Rendered Font Size */
1335 static uint32_t vc_rendered_font_size
= 0;
1337 /* Size of a character in the table (bytes) */
1338 static int vc_rendered_char_size
= 0;
1340 #define REN_MAX_DEPTH 32
1341 static unsigned char vc_rendered_char
[ISO_CHAR_HEIGHT
* ((REN_MAX_DEPTH
/ 8) * ISO_CHAR_WIDTH
)];
1344 vc_clear_screen(unsigned int xx
, unsigned int yy
, unsigned int scrreg_top
,
1345 unsigned int scrreg_bottom
, int which
)
1347 uint32_t *p
, *endp
, *row
;
1349 int rowline
, rowlongs
;
1354 linelongs
= vinfo
.v_rowbytes
* (ISO_CHAR_HEIGHT
>> 2);
1355 rowline
= vinfo
.v_rowscanbytes
>> 2;
1356 rowlongs
= vinfo
.v_rowbytes
>> 2;
1358 p
= (uint32_t*) vinfo
.v_baseaddr
;
1359 endp
= (uint32_t*) vinfo
.v_baseaddr
;
1362 case 0: /* To end of screen */
1363 gc_clear_line(xx
, yy
, 0);
1364 if (yy
< scrreg_bottom
- 1) {
1365 p
+= (yy
+ 1) * linelongs
;
1366 endp
+= scrreg_bottom
* linelongs
;
1369 case 1: /* To start of screen */
1370 gc_clear_line(xx
, yy
, 1);
1371 if (yy
> scrreg_top
) {
1372 p
+= scrreg_top
* linelongs
;
1373 endp
+= yy
* linelongs
;
1376 case 2: /* Whole screen */
1377 p
+= scrreg_top
* linelongs
;
1378 if (scrreg_bottom
== vinfo
.v_rows
) {
1379 endp
+= rowlongs
* vinfo
.v_height
;
1381 endp
+= scrreg_bottom
* linelongs
;
1386 for (row
= p
; row
< endp
; row
+= rowlongs
) {
1387 for (col
= 0; col
< rowline
; col
++)
1388 *(row
+col
) = vc_color_back
;
1393 vc_initialize(__unused
struct vc_info
* vinfo_p
)
1396 vinfo
.v_rows
= vinfo
.v_height
/ ISO_CHAR_HEIGHT
;
1397 vinfo
.v_columns
= vinfo
.v_width
/ ISO_CHAR_WIDTH
;
1398 vinfo
.v_rowscanbytes
= ((vinfo
.v_depth
+ 7) / 8) * vinfo
.v_width
;
1402 vc_render_char(unsigned char ch
, unsigned char *renderptr
, short newdepth
)
1405 unsigned char *charptr
;
1406 unsigned short *shortptr
;
1408 } current
; /* current place in rendered font, multiple types. */
1409 unsigned char *theChar
; /* current char in iso_font */
1412 current
.charptr
= renderptr
;
1413 theChar
= iso_font
+ (ch
* ISO_CHAR_HEIGHT
);
1415 for (line
= 0; line
< ISO_CHAR_HEIGHT
; line
++) {
1416 unsigned char mask
= 1;
1420 *current
.charptr
++ = (*theChar
& mask
) ? 0xFF : 0;
1423 *current
.shortptr
++ = (*theChar
& mask
) ? 0xFFFF : 0;
1428 *current
.longptr
++ = (*theChar
& mask
) ? 0xFFFFFFFF : 0;
1432 } while (mask
); /* while the single bit drops to the right */
1438 vc_paint_char_8(unsigned int xx
, unsigned int yy
, unsigned char ch
, int attrs
,
1439 __unused
unsigned char ch_previous
, __unused
int attrs_previous
)
1445 if (vc_rendered_font
) {
1446 theChar
= (uint32_t*)(vc_rendered_font
+ (ch
* vc_rendered_char_size
));
1448 vc_render_char(ch
, vc_rendered_char
, 8);
1449 theChar
= (uint32_t*)(vc_rendered_char
);
1451 where
= (uint32_t*)(vinfo
.v_baseaddr
+
1452 (yy
* ISO_CHAR_HEIGHT
* vinfo
.v_rowbytes
) +
1453 (xx
* ISO_CHAR_WIDTH
));
1455 if (!attrs
) for (i
= 0; i
< ISO_CHAR_HEIGHT
; i
++) { /* No attr? FLY !*/
1456 uint32_t *store
= where
;
1458 for (x
= 0; x
< 2; x
++) {
1459 uint32_t val
= *theChar
++;
1460 val
= (vc_color_back
& ~val
) | (vc_color_fore
& val
);
1464 where
= (uint32_t*)(((unsigned char*)where
)+vinfo
.v_rowbytes
);
1465 } else for (i
= 0; i
< ISO_CHAR_HEIGHT
; i
++) { /* a little slower */
1466 uint32_t *store
= where
, lastpixel
= 0;
1468 for (x
= 0 ; x
< 2; x
++) {
1469 uint32_t val
= *theChar
++, save
= val
;
1470 if (attrs
& ATTR_BOLD
) { /* bold support */
1471 if (lastpixel
&& !(save
& 0xFF000000))
1473 if ((save
& 0xFFFF0000) == 0xFF000000)
1475 if ((save
& 0x00FFFF00) == 0x00FF0000)
1477 if ((save
& 0x0000FFFF) == 0x0000FF00)
1480 if (attrs
& ATTR_REVERSE
) val
= ~val
;
1481 if (attrs
& ATTR_UNDER
&& i
== ISO_CHAR_HEIGHT
-1) val
= ~val
;
1483 val
= (vc_color_back
& ~val
) | (vc_color_fore
& val
);
1485 lastpixel
= save
& 0xff;
1488 where
= (uint32_t*)(((unsigned char*)where
)+vinfo
.v_rowbytes
);
1494 vc_paint_char_16(unsigned int xx
, unsigned int yy
, unsigned char ch
, int attrs
,
1495 __unused
unsigned char ch_previous
,
1496 __unused
int attrs_previous
)
1502 if (vc_rendered_font
) {
1503 theChar
= (uint32_t*)(vc_rendered_font
+ (ch
* vc_rendered_char_size
));
1505 vc_render_char(ch
, vc_rendered_char
, 16);
1506 theChar
= (uint32_t*)(vc_rendered_char
);
1508 where
= (uint32_t*)(vinfo
.v_baseaddr
+
1509 (yy
* ISO_CHAR_HEIGHT
* vinfo
.v_rowbytes
) +
1510 (xx
* ISO_CHAR_WIDTH
* 2));
1512 if (!attrs
) for (i
= 0; i
< ISO_CHAR_HEIGHT
; i
++) { /* No attrs ? FLY ! */
1513 uint32_t *store
= where
;
1515 for (x
= 0; x
< 4; x
++) {
1516 uint32_t val
= *theChar
++;
1517 val
= (vc_color_back
& ~val
) | (vc_color_fore
& val
);
1521 where
= (uint32_t*)(((unsigned char*)where
)+vinfo
.v_rowbytes
);
1522 } else for (i
= 0; i
< ISO_CHAR_HEIGHT
; i
++) { /* a little bit slower */
1523 uint32_t *store
= where
, lastpixel
= 0;
1525 for (x
= 0 ; x
< 4; x
++) {
1526 uint32_t val
= *theChar
++, save
= val
;
1527 if (attrs
& ATTR_BOLD
) { /* bold support */
1528 if (save
== 0xFFFF0000) val
|= 0xFFFF;
1529 else if (lastpixel
&& !(save
& 0xFFFF0000))
1532 if (attrs
& ATTR_REVERSE
) val
= ~val
;
1533 if (attrs
& ATTR_UNDER
&& i
== ISO_CHAR_HEIGHT
-1) val
= ~val
;
1535 val
= (vc_color_back
& ~val
) | (vc_color_fore
& val
);
1538 lastpixel
= save
& 0x7fff;
1541 where
= (uint32_t*)(((unsigned char*)where
)+vinfo
.v_rowbytes
);
1547 vc_paint_char_32(unsigned int xx
, unsigned int yy
, unsigned char ch
, int attrs
,
1548 unsigned char ch_previous
, int attrs_previous
)
1551 uint32_t *theCharPrevious
;
1555 if (vc_rendered_font
) {
1556 theChar
= (uint32_t*)(vc_rendered_font
+ (ch
* vc_rendered_char_size
));
1557 theCharPrevious
= (uint32_t*)(vc_rendered_font
+ (ch_previous
* vc_rendered_char_size
));
1559 vc_render_char(ch
, vc_rendered_char
, 32);
1560 theChar
= (uint32_t*)(vc_rendered_char
);
1561 theCharPrevious
= NULL
;
1564 theCharPrevious
= NULL
;
1566 if (attrs_previous
) {
1567 theCharPrevious
= NULL
;
1569 where
= (uint32_t*)(vinfo
.v_baseaddr
+
1570 (yy
* ISO_CHAR_HEIGHT
* vinfo
.v_rowbytes
) +
1571 (xx
* ISO_CHAR_WIDTH
* 4));
1573 if (!attrs
) for (i
= 0; i
< ISO_CHAR_HEIGHT
; i
++) { /* No attrs ? FLY ! */
1574 uint32_t *store
= where
;
1576 for (x
= 0; x
< 8; x
++) {
1577 uint32_t val
= *theChar
++;
1578 if (theCharPrevious
== NULL
|| val
!= *theCharPrevious
++ ) {
1579 val
= (vc_color_back
& ~val
) | (vc_color_fore
& val
);
1586 where
= (uint32_t *)(((unsigned char*)where
)+vinfo
.v_rowbytes
);
1587 } else for (i
= 0; i
< ISO_CHAR_HEIGHT
; i
++) { /* a little slower */
1588 uint32_t *store
= where
, lastpixel
= 0;
1590 for (x
= 0 ; x
< 8; x
++) {
1591 uint32_t val
= *theChar
++, save
= val
;
1592 if (attrs
& ATTR_BOLD
) { /* bold support */
1593 if (lastpixel
&& !save
)
1596 if (attrs
& ATTR_REVERSE
) val
= ~val
;
1597 if (attrs
& ATTR_UNDER
&& i
== ISO_CHAR_HEIGHT
-1) val
= ~val
;
1599 val
= (vc_color_back
& ~val
) | (vc_color_fore
& val
);
1604 where
= (uint32_t*)(((unsigned char*)where
)+vinfo
.v_rowbytes
);
1610 vc_paint_char(unsigned int xx
, unsigned int yy
, unsigned char ch
, int attrs
,
1611 unsigned char ch_previous
, int attrs_previous
)
1616 switch(vinfo
.v_depth
) {
1618 vc_paint_char_8(xx
, yy
, ch
, attrs
, ch_previous
, attrs_previous
);
1621 vc_paint_char_16(xx
, yy
, ch
, attrs
, ch_previous
,
1626 vc_paint_char_32(xx
, yy
, ch
, attrs
, ch_previous
,
1633 vc_render_font(short newdepth
)
1635 static short olddepth
= 0;
1637 int charindex
; /* index in ISO font */
1638 unsigned char *rendered_font
;
1639 unsigned int rendered_font_size
;
1640 int rendered_char_size
;
1643 if (vm_initialized
== FALSE
) {
1644 return; /* nothing to do */
1646 if (olddepth
== newdepth
&& vc_rendered_font
) {
1647 return; /* nothing to do */
1653 rendered_font
= vc_rendered_font
;
1654 rendered_font_size
= vc_rendered_font_size
;
1655 rendered_char_size
= vc_rendered_char_size
;
1657 vc_rendered_font
= NULL
;
1658 vc_rendered_font_size
= 0;
1659 vc_rendered_char_size
= 0;
1661 VCPUTC_LOCK_UNLOCK();
1664 if (rendered_font
) {
1665 kfree(rendered_font
, rendered_font_size
);
1666 rendered_font
= NULL
;
1670 rendered_char_size
= ISO_CHAR_HEIGHT
* (((newdepth
+ 7) / 8) * ISO_CHAR_WIDTH
);
1671 rendered_font_size
= (ISO_CHAR_MAX
-ISO_CHAR_MIN
+1) * rendered_char_size
;
1672 rendered_font
= (unsigned char *) kalloc(rendered_font_size
);
1675 if (rendered_font
== NULL
) {
1679 for (charindex
= ISO_CHAR_MIN
; charindex
<= ISO_CHAR_MAX
; charindex
++) {
1680 vc_render_char(charindex
, rendered_font
+ (charindex
* rendered_char_size
), newdepth
);
1683 olddepth
= newdepth
;
1688 vc_rendered_font
= rendered_font
;
1689 vc_rendered_font_size
= rendered_font_size
;
1690 vc_rendered_char_size
= rendered_char_size
;
1692 VCPUTC_LOCK_UNLOCK();
1697 vc_enable(boolean_t enable
)
1699 vc_render_font(enable
? vinfo
.v_depth
: 0);
1703 vc_reverse_cursor(unsigned int xx
, unsigned int yy
)
1711 where
= (uint32_t*)(vinfo
.v_baseaddr
+
1712 (yy
* ISO_CHAR_HEIGHT
* vinfo
.v_rowbytes
) +
1713 (xx
/** ISO_CHAR_WIDTH*/ * vinfo
.v_depth
));
1714 for (line
= 0; line
< ISO_CHAR_HEIGHT
; line
++) {
1715 switch (vinfo
.v_depth
) {
1717 where
[0] = ~where
[0];
1718 where
[1] = ~where
[1];
1721 for (col
= 0; col
< 4; col
++)
1722 where
[col
] = ~where
[col
];
1725 for (col
= 0; col
< 8; col
++)
1726 where
[col
] = ~where
[col
];
1729 where
= (uint32_t*)(((unsigned char*)where
)+vinfo
.v_rowbytes
);
1734 vc_scroll_down(int num
, unsigned int scrreg_top
, unsigned int scrreg_bottom
)
1736 uint32_t *from
, *to
, linelongs
, i
, line
, rowline
, rowscanline
;
1741 linelongs
= vinfo
.v_rowbytes
* (ISO_CHAR_HEIGHT
>> 2);
1742 rowline
= vinfo
.v_rowbytes
>> 2;
1743 rowscanline
= vinfo
.v_rowscanbytes
>> 2;
1745 to
= (uint32_t *) vinfo
.v_baseaddr
+ (linelongs
* scrreg_bottom
)
1746 - (rowline
- rowscanline
);
1747 from
= to
- (linelongs
* num
); /* handle multiple line scroll (Michel Pollet) */
1749 i
= (scrreg_bottom
- scrreg_top
) - num
;
1752 for (line
= 0; line
< ISO_CHAR_HEIGHT
; line
++) {
1754 * Only copy what is displayed
1756 video_scroll_down(from
,
1757 (from
-(vinfo
.v_rowscanbytes
>> 2)),
1767 vc_scroll_up(int num
, unsigned int scrreg_top
, unsigned int scrreg_bottom
)
1769 uint32_t *from
, *to
, linelongs
, i
, line
, rowline
, rowscanline
;
1774 linelongs
= vinfo
.v_rowbytes
* (ISO_CHAR_HEIGHT
>> 2);
1775 rowline
= vinfo
.v_rowbytes
>> 2;
1776 rowscanline
= vinfo
.v_rowscanbytes
>> 2;
1778 to
= (uint32_t *) vinfo
.v_baseaddr
+ (scrreg_top
* linelongs
);
1779 from
= to
+ (linelongs
* num
); /* handle multiple line scroll (Michel Pollet) */
1781 i
= (scrreg_bottom
- scrreg_top
) - num
;
1784 for (line
= 0; line
< ISO_CHAR_HEIGHT
; line
++) {
1786 * Only copy what is displayed
1788 video_scroll_up(from
,
1789 (from
+(vinfo
.v_rowscanbytes
>> 2)),
1799 vc_update_color(int color
, boolean_t fore
)
1804 vc_color_fore
= vc_colors
[color
][vc_color_index_table
[vinfo
.v_depth
]];
1806 vc_color_back
= vc_colors
[color
][vc_color_index_table
[vinfo
.v_depth
]];
1811 * Video Console (Back-End): Icon Control
1812 * --------------------------------------
1815 struct vc_progress_element
{
1816 unsigned int version
;
1819 unsigned char count
;
1820 unsigned char res
[3];
1826 unsigned int res2
[3];
1827 unsigned char data
[0];
1829 typedef struct vc_progress_element vc_progress_element
;
1831 static vc_progress_element
* vc_progress
;
1832 static const unsigned char * vc_progress_data
;
1833 static const unsigned char * vc_progress_alpha
;
1834 static boolean_t vc_progress_enable
;
1835 static const unsigned char * vc_clut
;
1836 static const unsigned char * vc_clut8
;
1837 static unsigned char vc_revclut8
[256];
1838 static uint32_t vc_progress_interval
;
1839 static uint32_t vc_progress_count
;
1840 static uint64_t vc_progress_deadline
;
1841 static thread_call_data_t vc_progress_call
;
1842 static boolean_t vc_needsave
;
1843 static void * vc_saveunder
;
1844 static vm_size_t vc_saveunder_len
;
1845 decl_simple_lock_data(,vc_progress_lock
)
1849 kDataIndexed
= 0x02,
1854 static void vc_blit_rect(int x
, int y
, int bx
,
1855 int width
, int height
,
1856 int sourceRow
, int backRow
,
1857 const unsigned char * dataPtr
,
1859 unsigned int flags
);
1860 static void vc_blit_rect_8(int x
, int y
, int bx
,
1861 int width
, int height
,
1862 int sourceRow
, int backRow
,
1863 const unsigned char * dataPtr
,
1864 unsigned char * backBuffer
,
1865 unsigned int flags
);
1866 static void vc_blit_rect_16(int x
, int y
, int bx
,
1867 int width
, int height
,
1868 int sourceRow
, int backRow
,
1869 const unsigned char * dataPtr
,
1870 unsigned short * backBuffer
,
1871 unsigned int flags
);
1872 static void vc_blit_rect_32(int x
, int y
, int bx
,
1873 int width
, int height
,
1874 int sourceRow
, int backRow
,
1875 const unsigned char * dataPtr
,
1876 unsigned int * backBuffer
,
1877 unsigned int flags
);
1878 static void vc_blit_rect_30(int x
, int y
, int bx
,
1879 int width
, int height
,
1880 int sourceRow
, int backRow
,
1881 const unsigned char * dataPtr
,
1882 unsigned int * backBuffer
,
1883 unsigned int flags
);
1884 extern void vc_display_icon( vc_progress_element
* desc
, const unsigned char * data
);
1885 extern void vc_progress_initialize( vc_progress_element
* desc
, const unsigned char * data
, const unsigned char * clut
);
1886 void vc_progress_set(boolean_t enable
, uint32_t vc_delay
);
1887 static void vc_progress_task( void * arg0
, void * arg
);
1889 static void vc_blit_rect(int x
, int y
, int bx
,
1890 int width
, int height
,
1891 int sourceRow
, int backRow
,
1892 const unsigned char * dataPtr
,
1899 switch( vinfo
.v_depth
) {
1901 if( vc_clut8
== vc_clut
)
1902 vc_blit_rect_8( x
, y
, bx
, width
, height
, sourceRow
, backRow
, dataPtr
, (unsigned char *) backBuffer
, flags
);
1905 vc_blit_rect_16( x
, y
, bx
, width
, height
, sourceRow
, backRow
, dataPtr
, (unsigned short *) backBuffer
, flags
);
1908 vc_blit_rect_32( x
, y
, bx
, width
, height
, sourceRow
, backRow
, dataPtr
, (unsigned int *) backBuffer
, flags
);
1911 vc_blit_rect_30( x
, y
, bx
, width
, height
, sourceRow
, backRow
, dataPtr
, (unsigned int *) backBuffer
, flags
);
1917 vc_blit_rect_8(int x
, int y
, __unused
int bx
,
1918 int width
, int height
,
1919 int sourceRow
, __unused
int backRow
,
1920 const unsigned char * dataPtr
,
1921 __unused
unsigned char * backBuffer
,
1922 __unused
unsigned int flags
)
1924 volatile unsigned short * dst
;
1926 unsigned int data
= 0, out
= 0;
1929 data
= (unsigned int)(uintptr_t)dataPtr
;
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 (col
< sourceRow
)
1940 if (kDataAlpha
& flags
)
1941 out
= vc_revclut8
[data
];
1946 dst
= (volatile unsigned short *) (((volatile char*)dst
) + vinfo
.v_rowbytes
);
1947 if (sourceRow
> width
)
1948 dataPtr
+= sourceRow
- width
;
1952 /* For ARM, 16-bit is 565 (RGB); it is 1555 (XRGB) on other platforms */
1954 #define CLUT_MASK_R 0xf8
1955 #define CLUT_MASK_G 0xf8
1956 #define CLUT_MASK_B 0xf8
1957 #define CLUT_SHIFT_R << 7
1958 #define CLUT_SHIFT_G << 2
1959 #define CLUT_SHIFT_B >> 3
1960 #define MASK_R 0x7c00
1961 #define MASK_G 0x03e0
1962 #define MASK_B 0x001f
1963 #define MASK_R_8 0x3fc00
1964 #define MASK_G_8 0x01fe0
1965 #define MASK_B_8 0x000ff
1967 static void vc_blit_rect_16( int x
, int y
, int bx
,
1968 int width
, int height
,
1969 int sourceRow
, int backRow
,
1970 const unsigned char * dataPtr
,
1971 unsigned short * backPtr
,
1974 volatile unsigned short * dst
;
1976 unsigned int data
= 0, out
= 0, back
= 0;
1981 data
= (unsigned int)(uintptr_t)dataPtr
;
1982 dst
= (volatile unsigned short *) (vinfo
.v_baseaddr
+
1983 (y
* vinfo
.v_rowbytes
) +
1986 for( line
= 0; line
< height
; line
++)
1988 for( col
= 0; col
< width
; col
++)
1990 if (col
< sourceRow
)
1994 if (kSave
& flags
) {
1995 back
= *(dst
+ col
);
2000 if (kDataIndexed
& flags
) {
2001 out
= ( (CLUT_MASK_R
& (vc_clut
[data
*3 + 0])) CLUT_SHIFT_R
)
2002 | ( (CLUT_MASK_G
& (vc_clut
[data
*3 + 1])) CLUT_SHIFT_G
)
2003 | ( (CLUT_MASK_B
& (vc_clut
[data
*3 + 2])) CLUT_SHIFT_B
);
2004 } else if (kDataAlpha
& flags
) {
2005 out
= (((((back
& MASK_R
) * data
) + MASK_R_8
) >> 8) & MASK_R
)
2006 | (((((back
& MASK_G
) * data
) + MASK_G_8
) >> 8) & MASK_G
)
2007 | (((((back
& MASK_B
) * data
) + MASK_B_8
) >> 8) & MASK_B
);
2008 #ifdef CONFIG_VC_PROGRESS_WHITE
2009 out
+= (((0xff - data
) & CLUT_MASK_R
) CLUT_SHIFT_R
)
2010 | (((0xff - data
) & CLUT_MASK_G
) CLUT_SHIFT_G
)
2011 | (((0xff - data
) & CLUT_MASK_B
) CLUT_SHIFT_B
);
2017 dst
= (volatile unsigned short *) (((volatile char*)dst
) + vinfo
.v_rowbytes
);
2019 backPtr
+= backRow
- width
;
2020 if (sourceRow
> width
)
2021 dataPtr
+= sourceRow
- width
;
2025 static void vc_blit_rect_32(int x
, int y
, int bx
,
2026 int width
, int height
,
2027 int sourceRow
, int backRow
,
2028 const unsigned char * dataPtr
,
2029 unsigned int * backPtr
,
2032 volatile unsigned int * dst
;
2034 unsigned int data
= 0, out
= 0, back
= 0;
2039 data
= (unsigned int)(uintptr_t)dataPtr
;
2040 dst
= (volatile unsigned int *) (vinfo
.v_baseaddr
+
2041 (y
* vinfo
.v_rowbytes
) +
2044 for( line
= 0; line
< height
; line
++)
2046 for( col
= 0; col
< width
; col
++)
2048 if (col
< sourceRow
)
2052 if (kSave
& flags
) {
2053 back
= *(dst
+ col
);
2058 if (kDataIndexed
& flags
) {
2059 out
= (vc_clut
[data
*3 + 0] << 16)
2060 | (vc_clut
[data
*3 + 1] << 8)
2061 | (vc_clut
[data
*3 + 2]);
2062 } else if (kDataAlpha
& flags
) {
2063 out
= (((((back
& 0x00ff00ff) * data
) + 0x00ff00ff) >> 8) & 0x00ff00ff)
2064 | (((((back
& 0x0000ff00) * data
) + 0x0000ff00) >> 8) & 0x0000ff00);
2065 #ifdef CONFIG_VC_PROGRESS_WHITE
2066 out
+= ((0xff - data
) << 16)
2067 | ((0xff - data
) << 8)
2074 dst
= (volatile unsigned int *) (((volatile char*)dst
) + vinfo
.v_rowbytes
);
2076 backPtr
+= backRow
- width
;
2077 if (sourceRow
> width
)
2078 dataPtr
+= sourceRow
- width
;
2082 static void vc_blit_rect_30(int x
, int y
, int bx
,
2083 int width
, int height
,
2084 int sourceRow
, int backRow
,
2085 const unsigned char * dataPtr
,
2086 unsigned int * backPtr
,
2089 volatile unsigned int * dst
;
2091 unsigned int data
= 0, out
= 0, back
= 0;
2092 unsigned long long exp
;
2097 data
= (unsigned int)(uintptr_t)dataPtr
;
2098 dst
= (volatile unsigned int *) (vinfo
.v_baseaddr
+
2099 (y
* vinfo
.v_rowbytes
) +
2102 for( line
= 0; line
< height
; line
++)
2104 for( col
= 0; col
< width
; col
++)
2106 if (col
< sourceRow
)
2110 if (kSave
& flags
) {
2111 back
= *(dst
+ col
);
2116 if (kDataIndexed
& flags
) {
2117 out
= (vc_clut
[data
*3 + 0] << 22)
2118 | (vc_clut
[data
*3 + 1] << 12)
2119 | (vc_clut
[data
*3 + 2] << 2);
2120 } else if (kDataAlpha
& flags
) {
2122 exp
= (((((exp
& 0x3FF003FF) * data
) + 0x0FF000FF) >> 8) & 0x3FF003FF)
2123 | (((((exp
& 0x000FFC00) * data
) + 0x0003FC00) >> 8) & 0x000FFC00);
2124 out
= (unsigned int)exp
;
2125 #ifdef CONFIG_VC_PROGRESS_WHITE
2126 out
+= ((0xFF - data
) << 22)
2127 | ((0xFF - data
) << 12)
2128 | ((0xFF - data
) << 2);
2134 dst
= (volatile unsigned int *) (((volatile char*)dst
) + vinfo
.v_rowbytes
);
2136 backPtr
+= backRow
- width
;
2137 if (sourceRow
> width
)
2138 dataPtr
+= sourceRow
- width
;
2142 void vc_display_icon( vc_progress_element
* desc
,
2143 const unsigned char * data
)
2145 int x
, y
, width
, height
;
2147 if( vc_progress_enable
&& vc_clut
) {
2149 width
= desc
->width
;
2150 height
= desc
->height
;
2153 if( 1 & desc
->flags
) {
2154 x
+= ((vinfo
.v_width
- width
) / 2);
2155 y
+= ((vinfo
.v_height
- height
) / 2);
2157 vc_blit_rect( x
, y
, 0, width
, height
, width
, 0, data
, NULL
, kDataIndexed
);
2162 vc_progress_initialize( vc_progress_element
* desc
,
2163 const unsigned char * data
,
2164 const unsigned char * clut
)
2168 if( (!clut
) || (!desc
) || (!data
))
2173 simple_lock_init(&vc_progress_lock
, 0);
2176 vc_progress_data
= data
;
2177 if( 2 & vc_progress
->flags
)
2178 vc_progress_alpha
= vc_progress_data
2179 + vc_progress
->count
* vc_progress
->width
* vc_progress
->height
;
2181 vc_progress_alpha
= NULL
;
2183 thread_call_setup(&vc_progress_call
, vc_progress_task
, NULL
);
2185 clock_interval_to_absolutetime_interval(vc_progress
->time
, 1000 * 1000, &abstime
);
2186 vc_progress_interval
= (uint32_t)abstime
;
2190 vc_progress_set(boolean_t enable
, uint32_t vc_delay
)
2193 void *saveBuf
= NULL
;
2194 vm_size_t saveLen
= 0;
2197 unsigned char pdata8
;
2198 unsigned short pdata16
;
2199 unsigned short * buf16
;
2200 unsigned int pdata32
;
2201 unsigned int * buf32
;
2207 saveLen
= vc_progress
->width
* vc_progress
->height
* vinfo
.v_depth
/ 8;
2208 saveBuf
= kalloc( saveLen
);
2210 switch( vinfo
.v_depth
) {
2212 for( count
= 0; count
< 256; count
++) {
2213 vc_revclut8
[count
] = vc_clut
[0x01 * 3];
2214 pdata8
= (vc_clut
[0x01 * 3] * count
+ 0x0ff) >> 8;
2215 for( index
= 0; index
< 256; index
++) {
2216 if( (pdata8
== vc_clut
[index
* 3 + 0]) &&
2217 (pdata8
== vc_clut
[index
* 3 + 1]) &&
2218 (pdata8
== vc_clut
[index
* 3 + 2])) {
2219 vc_revclut8
[count
] = index
;
2224 memset( saveBuf
, 0x01, saveLen
);
2228 buf16
= (unsigned short *) saveBuf
;
2229 pdata16
= ((vc_clut
[0x01 * 3 + 0] & CLUT_MASK_R
) CLUT_SHIFT_R
)
2230 | ((vc_clut
[0x01 * 3 + 0] & CLUT_MASK_G
) CLUT_SHIFT_G
)
2231 | ((vc_clut
[0x01 * 3 + 0] & CLUT_MASK_B
) CLUT_SHIFT_B
);
2232 for( count
= 0; count
< saveLen
/ 2; count
++)
2233 buf16
[count
] = pdata16
;
2237 buf32
= (unsigned int *) saveBuf
;
2238 pdata32
= ((vc_clut
[0x01 * 3 + 0] & 0xff) << 16)
2239 | ((vc_clut
[0x01 * 3 + 1] & 0xff) << 8)
2240 | ((vc_clut
[0x01 * 3 + 2] & 0xff) << 0);
2241 for( count
= 0; count
< saveLen
/ 4; count
++)
2242 buf32
[count
] = pdata32
;
2248 simple_lock(&vc_progress_lock
);
2250 if( vc_progress_enable
!= enable
) {
2251 vc_progress_enable
= enable
;
2254 vc_saveunder
= saveBuf
;
2255 vc_saveunder_len
= saveLen
;
2258 vc_progress_count
= 0;
2260 clock_interval_to_deadline(vc_delay
,
2261 1000 * 1000 * 1000 /*second scale*/,
2262 &vc_progress_deadline
);
2263 thread_call_enter_delayed(&vc_progress_call
, vc_progress_deadline
);
2267 saveBuf
= vc_saveunder
;
2268 saveLen
= vc_saveunder_len
;
2269 vc_saveunder
= NULL
;
2270 vc_saveunder_len
= 0;
2273 thread_call_cancel(&vc_progress_call
);
2277 simple_unlock(&vc_progress_lock
);
2281 kfree( saveBuf
, saveLen
);
2286 vc_progress_task(__unused
void *arg0
, __unused
void *arg
)
2289 int x
, y
, width
, height
;
2290 const unsigned char * data
;
2293 simple_lock(&vc_progress_lock
);
2295 if( vc_progress_enable
) {
2297 KERNEL_DEBUG_CONSTANT(0x7020008, vc_progress_count
, 0, 0, 0, 0);
2299 vc_progress_count
++;
2300 if( vc_progress_count
>= vc_progress
->count
)
2301 vc_progress_count
= 0;
2303 width
= vc_progress
->width
;
2304 height
= vc_progress
->height
;
2305 x
= vc_progress
->dx
;
2306 y
= vc_progress
->dy
;
2307 data
= vc_progress_data
;
2308 data
+= vc_progress_count
* width
* height
;
2309 if( 1 & vc_progress
->flags
) {
2310 x
+= ((vinfo
.v_width
- width
) / 2);
2311 y
+= ((vinfo
.v_height
- height
) / 2);
2313 vc_blit_rect( x
, y
, 0,
2314 width
, height
, width
, width
,
2316 kDataAlpha
| (vc_needsave
? kSave
: 0) );
2317 vc_needsave
= FALSE
;
2319 clock_deadline_for_periodic_event(vc_progress_interval
, mach_absolute_time(), &vc_progress_deadline
);
2320 thread_call_enter_delayed(&vc_progress_call
, vc_progress_deadline
);
2322 simple_unlock(&vc_progress_lock
);
2327 * Generic Console (Front-End): Master Control
2328 * -------------------------------------------
2331 #if defined (__i386__) || defined (__x86_64__)
2332 #include <pexpert/i386/boot.h>
2335 static boolean_t gc_acquired
= FALSE
;
2336 static boolean_t gc_graphics_boot
= FALSE
;
2337 static boolean_t gc_desire_text
= FALSE
;
2339 static uint64_t lastVideoPhys
= 0;
2340 static vm_offset_t lastVideoVirt
= 0;
2341 static vm_size_t lastVideoSize
= 0;
2342 static boolean_t lastVideoMapped
= FALSE
;
2345 gc_pause( boolean_t pause
, boolean_t graphics_now
)
2350 VCPUTC_LOCK_LOCK( );
2352 disableConsoleOutput
= (pause
&& !console_is_serial());
2353 gc_enabled
= (!pause
&& !graphics_now
);
2355 VCPUTC_LOCK_UNLOCK( );
2357 simple_lock(&vc_progress_lock
);
2359 vc_progress_enable
= gc_graphics_boot
&& !gc_desire_text
&& !pause
;
2360 if (vc_progress_enable
)
2361 thread_call_enter_delayed(&vc_progress_call
, vc_progress_deadline
);
2363 simple_unlock(&vc_progress_lock
);
2368 initialize_screen(PE_Video
* boot_vinfo
, unsigned int op
)
2370 unsigned int fbsize
= 0;
2371 vm_offset_t newVideoVirt
= 0;
2372 boolean_t graphics_now
;
2377 struct vc_info new_vinfo
= vinfo
;
2379 * First, check if we are changing the size and/or location of the framebuffer
2381 new_vinfo
.v_name
[0] = 0;
2382 new_vinfo
.v_physaddr
= boot_vinfo
->v_baseAddr
& ~3; /* Get the physical address */
2384 new_vinfo
.v_physaddr
|= (((uint64_t) boot_vinfo
->v_baseAddrHigh
) << 32);
2386 if (kPEBaseAddressChange
!= op
)
2388 new_vinfo
.v_width
= (unsigned int)boot_vinfo
->v_width
;
2389 new_vinfo
.v_height
= (unsigned int)boot_vinfo
->v_height
;
2390 new_vinfo
.v_depth
= (unsigned int)boot_vinfo
->v_depth
;
2391 new_vinfo
.v_rowbytes
= (unsigned int)boot_vinfo
->v_rowBytes
;
2392 #if defined(__i386__) || defined(__x86_64__)
2393 new_vinfo
.v_type
= (unsigned int)boot_vinfo
->v_display
;
2395 new_vinfo
.v_type
= 0;
2399 if (!lastVideoMapped
)
2400 kprintf("initialize_screen: b=%08llX, w=%08X, h=%08X, r=%08X, d=%08X\n", /* (BRINGUP) */
2401 new_vinfo
.v_physaddr
, new_vinfo
.v_width
, new_vinfo
.v_height
, new_vinfo
.v_rowbytes
, new_vinfo
.v_type
); /* (BRINGUP) */
2403 if (!new_vinfo
.v_physaddr
) /* Check to see if we have a framebuffer */
2405 kprintf("initialize_screen: No video - forcing serial mode\n"); /* (BRINGUP) */
2406 new_vinfo
.v_depth
= 0; /* vc routines are nop */
2407 (void)switch_to_serial_console(); /* Switch into serial mode */
2408 gc_graphics_boot
= FALSE
; /* Say we are not in graphics mode */
2409 disableConsoleOutput
= FALSE
; /* Allow printfs to happen */
2415 * If VM is up, we are given a virtual address, unless b0 is set to indicate physical.
2417 if ((kernel_map
!= VM_MAP_NULL
) && (0 == (1 & boot_vinfo
->v_baseAddr
)))
2419 fbppage
= pmap_find_phys(kernel_pmap
, (addr64_t
)boot_vinfo
->v_baseAddr
); /* Get the physical address of frame buffer */
2420 if(!fbppage
) /* Did we find it? */
2422 panic("initialize_screen: Strange framebuffer - addr = %08X\n", (uint32_t)boot_vinfo
->v_baseAddr
);
2424 new_vinfo
.v_physaddr
= (((uint64_t)fbppage
) << 12) | (boot_vinfo
->v_baseAddr
& PAGE_MASK
); /* Get the physical address */
2427 if (boot_vinfo
->v_length
!= 0)
2428 fbsize
= (unsigned int) round_page(boot_vinfo
->v_length
);
2430 fbsize
= (unsigned int) round_page(new_vinfo
.v_height
* new_vinfo
.v_rowbytes
); /* Remember size */
2433 if ((lastVideoPhys
!= new_vinfo
.v_physaddr
) || (fbsize
> lastVideoSize
)) /* Did framebuffer change location or get bigger? */
2435 unsigned int flags
= VM_WIMG_IO
;
2436 newVideoVirt
= io_map_spec((vm_map_offset_t
)new_vinfo
.v_physaddr
, fbsize
, flags
); /* Allocate address space for framebuffer */
2440 if (newVideoVirt
!= 0)
2441 new_vinfo
.v_baseaddr
= newVideoVirt
+ boot_vinfo
->v_offset
; /* Set the new framebuffer address */
2443 new_vinfo
.v_baseaddr
= lastVideoVirt
+ boot_vinfo
->v_offset
; /* Set the new framebuffer address */
2445 #if defined(__x86_64__)
2446 // Adjust the video buffer pointer to point to where it is in high virtual (above the hole)
2447 new_vinfo
.v_baseaddr
|= (VM_MIN_KERNEL_ADDRESS
& ~LOW_4GB_MASK
);
2450 /* Update the vinfo structure atomically with respect to the vc_progress task if running */
2453 simple_lock(&vc_progress_lock
);
2455 simple_unlock(&vc_progress_lock
);
2462 // If we changed the virtual address, remove the old mapping
2463 if (newVideoVirt
!= 0)
2465 if (lastVideoVirt
) /* Was the framebuffer mapped before? */
2468 if(lastVideoMapped
) /* Was this not a special pre-VM mapping? */
2471 pmap_remove(kernel_pmap
, trunc_page_64(lastVideoVirt
),
2472 round_page_64(lastVideoVirt
+ lastVideoSize
)); /* Toss mappings */
2474 if(lastVideoMapped
) /* Was this not a special pre-VM mapping? */
2476 kmem_free(kernel_map
, lastVideoVirt
, lastVideoSize
); /* Toss kernel addresses */
2479 lastVideoPhys
= new_vinfo
.v_physaddr
; /* Remember the framebuffer address */
2480 lastVideoSize
= fbsize
; /* Remember the size */
2481 lastVideoVirt
= newVideoVirt
; /* Remember the virtual framebuffer address */
2482 lastVideoMapped
= (NULL
!= kernel_map
);
2485 if (kPEBaseAddressChange
!= op
)
2487 // Graphics mode setup by the booter.
2489 gc_ops
.initialize
= vc_initialize
;
2490 gc_ops
.enable
= vc_enable
;
2491 gc_ops
.paint_char
= vc_paint_char
;
2492 gc_ops
.scroll_down
= vc_scroll_down
;
2493 gc_ops
.scroll_up
= vc_scroll_up
;
2494 gc_ops
.clear_screen
= vc_clear_screen
;
2495 gc_ops
.hide_cursor
= vc_reverse_cursor
;
2496 gc_ops
.show_cursor
= vc_reverse_cursor
;
2497 gc_ops
.update_color
= vc_update_color
;
2498 gc_initialize(&vinfo
);
2501 #ifdef GRATEFULDEBUGGER
2502 GratefulDebInit((bootBumbleC
*)boot_vinfo
); /* Re-initialize GratefulDeb */
2503 #endif /* GRATEFULDEBUGGER */
2506 graphics_now
= gc_graphics_boot
&& !gc_desire_text
;
2509 case kPEGraphicsMode
:
2510 panicDialogDesired
= TRUE
;
2511 gc_graphics_boot
= TRUE
;
2512 gc_desire_text
= FALSE
;
2516 panicDialogDesired
= FALSE
;
2517 disable_debug_output
= FALSE
;
2518 gc_graphics_boot
= FALSE
;
2521 case kPEAcquireScreen
:
2522 if ( gc_acquired
) break;
2523 vc_progress_set( graphics_now
, kProgressAcquireDelay
);
2524 gc_enable( !graphics_now
);
2526 gc_desire_text
= FALSE
;
2529 case kPEDisableScreen
:
2532 gc_pause( TRUE
, graphics_now
);
2536 case kPEEnableScreen
:
2539 gc_pause( FALSE
, graphics_now
);
2544 if ( console_is_serial() ) break;
2546 panicDialogDesired
= FALSE
;
2547 disable_debug_output
= FALSE
;
2548 if ( gc_acquired
== FALSE
)
2550 gc_desire_text
= TRUE
;
2553 if ( gc_graphics_boot
== FALSE
) break;
2555 vc_progress_set( FALSE
, 0 );
2556 #if !CONFIG_EMBEDDED
2557 vc_enable_progressmeter( FALSE
);
2562 case kPEReleaseScreen
:
2563 gc_acquired
= FALSE
;
2564 gc_desire_text
= FALSE
;
2566 vc_progress_set( FALSE
, 0 );
2567 #if !CONFIG_EMBEDDED
2568 vc_enable_progressmeter( FALSE
);
2572 #ifdef GRATEFULDEBUGGER
2573 GratefulDebInit(0); /* Stop grateful debugger */
2574 #endif /* GRATEFULDEBUGGER */
2577 #ifdef GRATEFULDEBUGGER
2578 if ( boot_vinfo
) GratefulDebInit((bootBumbleC
*)boot_vinfo
); /* Re initialize GratefulDeb */
2579 #endif /* GRATEFULDEBUGGER */
2585 unsigned int *p
, *endp
, *row
;
2586 int col
, rowline
, rowlongs
;
2587 register unsigned int mask
;
2592 if ( vinfo
.v_depth
== 32 )
2594 else if ( vinfo
.v_depth
== 30 )
2595 mask
= (0x1ff<<20) | (0x1ff<<10) | 0x1ff;
2596 else if ( vinfo
.v_depth
== 16 )
2601 rowline
= (int)(vinfo
.v_rowscanbytes
/ 4);
2602 rowlongs
= (int)(vinfo
.v_rowbytes
/ 4);
2604 p
= (unsigned int*) vinfo
.v_baseaddr
;
2605 endp
= p
+ (rowlongs
* vinfo
.v_height
);
2607 for (row
= p
; row
< endp
; row
+= rowlongs
) {
2608 for (p
= &row
[0], col
= 0; col
< rowline
; col
++) {
2609 *p
= (*p
>> 1) & mask
;
2615 void vcattach(void); /* XXX gcc 4 warning cleanup */
2620 vm_initialized
= TRUE
;
2622 if ( gc_graphics_boot
== FALSE
)
2628 initialize_screen(NULL
, kPEReleaseScreen
);
2631 initialize_screen(NULL
, kPEAcquireScreen
);
2633 for ( index
= 0 ; index
< msgbufp
->msg_bufx
; index
++ )
2635 if (msgbufp
->msg_bufc
[index
] == '\0') {
2639 vcputc( 0, 0, msgbufp
->msg_bufc
[index
] );
2641 if ( msgbufp
->msg_bufc
[index
] == '\n' )
2643 vcputc( 0, 0,'\r' );
2649 #if !CONFIG_EMBEDDED
2651 int vc_progress_meter_enable
;
2652 int vc_progress_meter_value
;
2654 static void * vc_progress_meter_backbuffer
;
2655 static int vc_progress_meter_drawn
;
2658 vc_draw_progress_meter(int select
, unsigned int flags
, int x1
, int x2
)
2660 const unsigned char * data
;
2664 ox
= ((vinfo
.v_width
- kProgressBarWidth
) / 2);
2665 oy
= vinfo
.v_height
- (((vinfo
.v_height
/ 2) - vc_progress
->dy
+ kProgressBarHeight
) / 2);
2667 if (kDataBack
== flags
)
2669 // restore back bits
2670 vc_blit_rect(ox
+ x1
, oy
, x1
,
2671 x2
, kProgressBarHeight
, 0, kProgressBarWidth
,
2672 NULL
, vc_progress_meter_backbuffer
, flags
);
2676 for (x
= x1
; x
< x2
; x
+= w
)
2678 if (x
< kProgressBarCapWidth
)
2680 if (x2
< kProgressBarCapWidth
)
2683 w
= kProgressBarCapWidth
- x
;
2684 data
= &progressmeter_leftcap
[select
& 1][0];
2686 vc_blit_rect(ox
+ x
, oy
, x
,
2687 w
, kProgressBarHeight
, kProgressBarCapWidth
, kProgressBarWidth
,
2688 data
, vc_progress_meter_backbuffer
, flags
);
2690 else if (x
< (kProgressBarWidth
- kProgressBarCapWidth
))
2692 if (x2
< (kProgressBarWidth
- kProgressBarCapWidth
))
2695 w
= (kProgressBarWidth
- kProgressBarCapWidth
) - x
;
2696 data
= &progressmeter_middle
[select
& 1][0];
2697 vc_blit_rect(ox
+ x
, oy
, x
,
2698 w
, kProgressBarHeight
, 1, kProgressBarWidth
,
2699 data
, vc_progress_meter_backbuffer
, flags
);
2704 data
= &progressmeter_rightcap
[select
& 1][0];
2705 data
+= x
- (kProgressBarWidth
- kProgressBarCapWidth
);
2706 vc_blit_rect(ox
+ x
, oy
, x
,
2707 w
, kProgressBarHeight
, kProgressBarCapWidth
, kProgressBarWidth
,
2708 data
, vc_progress_meter_backbuffer
, flags
);
2714 vc_enable_progressmeter(int new_value
)
2717 void * new_buffer
= NULL
;
2720 new_buffer
= kalloc(kProgressBarWidth
* kProgressBarHeight
* sizeof(int));
2723 simple_lock(&vc_progress_lock
);
2725 if (gc_enabled
|| !gc_acquired
|| !gc_graphics_boot
)
2728 if (new_value
!= vc_progress_meter_enable
)
2732 vc_progress_meter_backbuffer
= new_buffer
;
2733 vc_draw_progress_meter(FALSE
, kDataAlpha
| kSave
, 0, kProgressBarWidth
);
2734 vc_progress_meter_enable
= TRUE
;
2736 vc_progress_meter_drawn
= 0;
2738 else if (vc_progress_meter_backbuffer
)
2740 vc_draw_progress_meter(0, kDataBack
, 0, kProgressBarWidth
);
2741 new_buffer
= vc_progress_meter_backbuffer
;
2742 vc_progress_meter_backbuffer
= NULL
;
2743 vc_progress_meter_enable
= FALSE
;
2748 simple_unlock(&vc_progress_lock
);
2752 kfree(new_buffer
, kProgressBarWidth
* kProgressBarHeight
* sizeof(int));
2756 vc_set_progressmeter(int new_value
)
2761 if ((new_value
< 0) | (new_value
> 100))
2765 simple_lock(&vc_progress_lock
);
2767 if (vc_progress_meter_enable
)
2769 vc_progress_meter_value
= new_value
;
2770 x2
= ((kProgressBarWidth
- 1) * new_value
) / 100;
2771 if (x2
> vc_progress_meter_drawn
)
2772 vc_draw_progress_meter(TRUE
, kDataAlpha
, vc_progress_meter_drawn
, x2
);
2774 vc_draw_progress_meter(FALSE
, kDataAlpha
, x2
, vc_progress_meter_drawn
);
2775 vc_progress_meter_drawn
= x2
;
2778 simple_unlock(&vc_progress_lock
);
2782 #endif /* !CONFIG_EMBEDDED */