Debian Codegraph @

purgatory/arch/i386/vga.c

raw
1 #include <sys/io.h>
2 #include <purgatory.h>
3 #include "purgatory-x86.h"
4
5 /* Crudely reset a VGA card to text mode 3, by writing plausible default */
6 /* values into its registers. */
7 /* Tim Deegan (tjd21 at cl.cam.ac.uk), March 2003 */
8 /* Based on Keir Fraser's start-of-day reset code from the Xen hypervisor */
9 /* Converted from Assembly 20 December 2004 -- Eric Biederman */
10
11 void x86_reset_vga(void)
12 {
13 /* Hello */
14 inb(0x3da);
15 outb(0, 0x3c0);
16
17 /* Sequencer registers */
18 outw(0x0300, 0x3c4);
19 outw(0x0001, 0x3c4);
20 outw(0x0302, 0x3c4);
21 outw(0x0003, 0x3c4);
22 outw(0x0204, 0x3c4);
23
24 /* Ensure CRTC regs 0-7 are unlocked by clearing bit 7 of CRTC[17] */
25 outw(0x0e11, 0x3d4);
26 /* CRTC registers */
27 outw(0x5f00, 0x3d4);
28 outw(0x4f01, 0x3d4);
29 outw(0x5002, 0x3d4);
30 outw(0x8203, 0x3d4);
31 outw(0x5504, 0x3d4);
32 outw(0x8105, 0x3d4);
33 outw(0xbf06, 0x3d4);
34 outw(0x1f07, 0x3d4);
35 outw(0x0008, 0x3d4);
36 outw(0x4f09, 0x3d4);
37 outw(0x200a, 0x3d4);
38 outw(0x0e0b, 0x3d4);
39 outw(0x000c, 0x3d4);
40 outw(0x000d, 0x3d4);
41 outw(0x010e, 0x3d4);
42 outw(0xe00f, 0x3d4);
43 outw(0x9c10, 0x3d4);
44 outw(0x8e11, 0x3d4);
45 outw(0x8f12, 0x3d4);
46 outw(0x2813, 0x3d4);
47 outw(0x1f14, 0x3d4);
48 outw(0x9615, 0x3d4);
49 outw(0xb916, 0x3d4);
50 outw(0xa317, 0x3d4);
51 outw(0xff18, 0x3d4);
52
53 /* Graphic registers */
54 outw(0x0000, 0x3ce);
55 outw(0x0001, 0x3ce);
56 outw(0x0002, 0x3ce);
57 outw(0x0003, 0x3ce);
58 outw(0x0004, 0x3ce);
59 outw(0x1005, 0x3ce);
60 outw(0x0e06, 0x3ce);
61 outw(0x0007, 0x3ce);
62 outw(0xff08, 0x3ce);
63
64 /* Attribute registers */
65 inb(0x3da);
66 outb(0x00, 0x3c0);
67 outb(0x00, 0x3c0);
68
69 inb(0x3da);
70 outb(0x01, 0x3c0);
71 outb(0x01, 0x3c0);
72
73 inb(0x3da);
74 outb(0x02, 0x3c0);
75 outb(0x02, 0x3c0);
76
77 inb(0x3da);
78 outb(0x03, 0x3c0);
79 outb(0x03, 0x3c0);
80
81 inb(0x3da);
82 outb(0x04, 0x3c0);
83 outb(0x04, 0x3c0);
84
85 inb(0x3da);
86 outb(0x05, 0x3c0);
87 outb(0x05, 0x3c0);
88
89 inb(0x3da);
90 outb(0x06, 0x3c0);
91 outb(0x14, 0x3c0);
92
93 inb(0x3da);
94 outb(0x07, 0x3c0);
95 outb(0x07, 0x3c0);
96
97 inb(0x3da);
98 outb(0x08, 0x3c0);
99 outb(0x38, 0x3c0);
100
101 inb(0x3da);
102 outb(0x09, 0x3c0);
103 outb(0x39, 0x3c0);
104
105 inb(0x3da);
106 outb(0x0a, 0x3c0);
107 outb(0x3a, 0x3c0);
108
109 inb(0x3da);
110 outb(0x0b, 0x3c0);
111 outb(0x3b, 0x3c0);
112
113 inb(0x3da);
114 outb(0x0c, 0x3c0);
115 outb(0x3c, 0x3c0);
116
117 inb(0x3da);
118 outb(0x0d, 0x3c0);
119 outb(0x3d, 0x3c0);
120
121 inb(0x3da);
122 outb(0x0e, 0x3c0);
123 outb(0x3e, 0x3c0);
124
125 inb(0x3da);
126 outb(0x0f, 0x3c0);
127 outb(0x3f, 0x3c0);
128
129 inb(0x3da);
130 outb(0x10, 0x3c0);
131 outb(0x0c, 0x3c0);
132
133 inb(0x3da);
134 outb(0x11, 0x3c0);
135 outb(0x00, 0x3c0);
136
137 inb(0x3da);
138 outb(0x12, 0x3c0);
139 outb(0x0f, 0x3c0);
140
141 inb(0x3da);
142 outb(0x13, 0x3c0);
143 outb(0x08, 0x3c0);
144
145 inb(0x3da);
146 outb(0x14, 0x3c0);
147 outb(0x00, 0x3c0);
148
149 /* Goodbye */
150 inb(0x3da);
151 outb(0x20, 0x3c0);
152 }