xref: /titanic_44/usr/src/uts/i86pc/boot/boot_vga.c (revision 62a1b812a0c45c0d4c10ef645dda42bf71080108)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * Miniature VGA driver for bootstrap.
31  */
32 
33 #include <sys/archsystm.h>
34 #include <sys/vgareg.h>
35 
36 #include "boot_vga.h"
37 
38 #if defined(_BOOT)
39 #include "../dboot/dboot_xboot.h"
40 #endif
41 
42 #define	VGA_COLOR_CRTC_INDEX	0x3d4
43 #define	VGA_COLOR_CRTC_DATA	0x3d5
44 #define	VGA_SCREEN		((unsigned short *)0xb8000)
45 
46 static void vga_set_crtc(int index, unsigned char val);
47 static unsigned char vga_get_crtc(int index);
48 
49 void
50 vga_clear(int color)
51 {
52 	unsigned short val;
53 	int i;
54 
55 	val = (color << 8) | ' ';
56 
57 	for (i = 0; i < VGA_TEXT_ROWS * VGA_TEXT_COLS; i++) {
58 		VGA_SCREEN[i] = val;
59 	}
60 }
61 
62 void
63 vga_drawc(int c, int color)
64 {
65 	int row;
66 	int col;
67 
68 	vga_getpos(&row, &col);
69 	VGA_SCREEN[row*VGA_TEXT_COLS + col] = (color << 8) | c;
70 }
71 
72 void
73 vga_scroll(int color)
74 {
75 	unsigned short val;
76 	int i;
77 
78 	val = (color << 8) | ' ';
79 
80 	for (i = 0; i < (VGA_TEXT_ROWS-1)*VGA_TEXT_COLS; i++) {
81 		VGA_SCREEN[i] = VGA_SCREEN[i + VGA_TEXT_COLS];
82 	}
83 	for (; i < VGA_TEXT_ROWS * VGA_TEXT_COLS; i++) {
84 		VGA_SCREEN[i] = val;
85 	}
86 }
87 
88 void
89 vga_setpos(int row, int col)
90 {
91 	int off;
92 
93 	off = row * VGA_TEXT_COLS + col;
94 	vga_set_crtc(VGA_CRTC_CLAH, off >> 8);
95 	vga_set_crtc(VGA_CRTC_CLAL, off & 0xff);
96 }
97 
98 void
99 vga_getpos(int *row, int *col)
100 {
101 	int off;
102 
103 	off = (vga_get_crtc(VGA_CRTC_CLAH) << 8) +
104 		vga_get_crtc(VGA_CRTC_CLAL);
105 	*row = off / VGA_TEXT_COLS;
106 	*col = off % VGA_TEXT_COLS;
107 }
108 
109 static void
110 vga_set_crtc(int index, unsigned char val)
111 {
112 	outb(VGA_COLOR_CRTC_INDEX, index);
113 	outb(VGA_COLOR_CRTC_DATA, val);
114 }
115 
116 
117 static unsigned char
118 vga_get_crtc(int index)
119 {
120 	outb(VGA_COLOR_CRTC_INDEX, index);
121 	return (inb(VGA_COLOR_CRTC_DATA));
122 }
123