1 | #ifdef CONFIG_FB
|
---|
2 |
|
---|
3 | #include <macros.h>
|
---|
4 |
|
---|
5 | #define VESA_INFO_SIZE 1024
|
---|
6 |
|
---|
7 | #define VESA_MODE_ATTRIBUTES_OFFSET 0
|
---|
8 | #define VESA_MODE_LIST_PTR_OFFSET 14
|
---|
9 | #define VESA_MODE_SCANLINE_OFFSET 16
|
---|
10 | #define VESA_MODE_WIDTH_OFFSET 18
|
---|
11 | #define VESA_MODE_HEIGHT_OFFSET 20
|
---|
12 | #define VESA_MODE_BPP_OFFSET 25
|
---|
13 | #define VESA_MODE_RED_MASK_OFFSET 31
|
---|
14 | #define VESA_MODE_RED_POS_OFFSET 32
|
---|
15 | #define VESA_MODE_GREEN_MASK_OFFSET 33
|
---|
16 | #define VESA_MODE_GREEN_POS_OFFSET 34
|
---|
17 | #define VESA_MODE_BLUE_MASK_OFFSET 35
|
---|
18 | #define VESA_MODE_BLUE_POS_OFFSET 36
|
---|
19 | #define VESA_MODE_PHADDR_OFFSET 40
|
---|
20 |
|
---|
21 | #define VESA_END_OF_MODES 0xffff
|
---|
22 |
|
---|
23 | #define VESA_OK 0x4f
|
---|
24 |
|
---|
25 | #define VESA_GET_INFO 0x4f00
|
---|
26 | #define VESA_GET_MODE_INFO 0x4f01
|
---|
27 | #define VESA_SET_MODE 0x4f02
|
---|
28 | #define VESA_SET_PALETTE 0x4f09
|
---|
29 |
|
---|
30 | .code32
|
---|
31 | vesa_init:
|
---|
32 | jmp $gdtselector(VESA_INIT_DES), $vesa_init_real - vesa_init
|
---|
33 |
|
---|
34 | .code16
|
---|
35 | vesa_init_real:
|
---|
36 |
|
---|
37 | mov %cr0, %eax
|
---|
38 | and $~1, %eax
|
---|
39 | mov %eax, %cr0
|
---|
40 |
|
---|
41 | jmp $VESA_INIT_SEGMENT, $vesa_init_real2 - vesa_init
|
---|
42 |
|
---|
43 | vesa_init_real2:
|
---|
44 | mov $VESA_INIT_SEGMENT, %bx
|
---|
45 |
|
---|
46 | mov %bx, %es
|
---|
47 | mov %bx, %fs
|
---|
48 | mov %bx, %gs
|
---|
49 | mov %bx, %ds
|
---|
50 | mov %bx, %ss
|
---|
51 |
|
---|
52 | movl %esp, %eax
|
---|
53 | movl $0x0000fffc, %esp
|
---|
54 | movl $0x0000fffc, %ebp
|
---|
55 | pushl %eax
|
---|
56 |
|
---|
57 | /* Parse default mode string */
|
---|
58 |
|
---|
59 | mov $default_mode - vesa_init, %di
|
---|
60 | xor %eax, %eax
|
---|
61 | xor %ebx, %ebx
|
---|
62 |
|
---|
63 | mov $8, %ecx
|
---|
64 | parse_width:
|
---|
65 | mov (%di), %al
|
---|
66 |
|
---|
67 | /* Check for digit */
|
---|
68 |
|
---|
69 | cmp $'0', %al
|
---|
70 | jb parse_width_done
|
---|
71 |
|
---|
72 | cmp $'9', %al
|
---|
73 | ja parse_width_done
|
---|
74 |
|
---|
75 | sub $'0', %al
|
---|
76 |
|
---|
77 | /* Multiply default_width by 10 and add digit */
|
---|
78 |
|
---|
79 | mov default_width - vesa_init, %bx
|
---|
80 | lea (%ebx, %ebx, 4), %ebx
|
---|
81 | shl $1, %ebx
|
---|
82 | add %ax, %bx
|
---|
83 | mov %bx, default_width - vesa_init
|
---|
84 |
|
---|
85 | inc %di
|
---|
86 | loop parse_width
|
---|
87 | parse_width_done:
|
---|
88 |
|
---|
89 | mov (%di), %al
|
---|
90 | cmp $0, %al
|
---|
91 | jz parse_done
|
---|
92 | inc %di
|
---|
93 |
|
---|
94 | mov $8, %ecx
|
---|
95 | parse_height:
|
---|
96 | mov (%di), %al
|
---|
97 |
|
---|
98 | /* Check for digit */
|
---|
99 |
|
---|
100 | cmp $'0', %al
|
---|
101 | jb parse_height_done
|
---|
102 |
|
---|
103 | cmp $'9', %al
|
---|
104 | ja parse_height_done
|
---|
105 |
|
---|
106 | sub $'0', %al
|
---|
107 |
|
---|
108 | /* Multiply default_height by 10 and add digit */
|
---|
109 |
|
---|
110 | mov default_height - vesa_init, %bx
|
---|
111 | lea (%ebx, %ebx, 4), %ebx
|
---|
112 | shl $1, %ebx
|
---|
113 | add %ax, %bx
|
---|
114 | mov %bx, default_height - vesa_init
|
---|
115 |
|
---|
116 | inc %di
|
---|
117 | loop parse_height
|
---|
118 | parse_height_done:
|
---|
119 |
|
---|
120 | mov (%di), %al
|
---|
121 | cmp $0, %al
|
---|
122 | jz parse_done
|
---|
123 | inc %di
|
---|
124 |
|
---|
125 | mov $4, %ecx
|
---|
126 | parse_bpp:
|
---|
127 | mov (%di), %al
|
---|
128 |
|
---|
129 | /* Check for digit */
|
---|
130 |
|
---|
131 | cmp $'0', %al
|
---|
132 | jb parse_bpp_done
|
---|
133 |
|
---|
134 | cmp $'9', %al
|
---|
135 | ja parse_bpp_done
|
---|
136 |
|
---|
137 | sub $'0', %al
|
---|
138 |
|
---|
139 | /* Multiply default_bpp by 10 and add digit */
|
---|
140 |
|
---|
141 | mov default_bpp - vesa_init, %bx
|
---|
142 | lea (%ebx, %ebx, 4), %ebx
|
---|
143 | shl $1, %ebx
|
---|
144 | add %ax, %bx
|
---|
145 | mov %bx, default_bpp - vesa_init
|
---|
146 |
|
---|
147 | inc %di
|
---|
148 | loop parse_bpp
|
---|
149 | parse_bpp_done:
|
---|
150 |
|
---|
151 | parse_done:
|
---|
152 |
|
---|
153 | mov $VESA_GET_INFO, %ax
|
---|
154 | mov $e_vesa_init - vesa_init, %di
|
---|
155 | push %di
|
---|
156 | int $0x10
|
---|
157 |
|
---|
158 | pop %di
|
---|
159 | cmp $VESA_OK, %al
|
---|
160 | jnz no_mode
|
---|
161 |
|
---|
162 | mov 2 + VESA_MODE_LIST_PTR_OFFSET(%di), %si
|
---|
163 | mov %si, %gs
|
---|
164 | mov VESA_MODE_LIST_PTR_OFFSET(%di), %si
|
---|
165 |
|
---|
166 | add $VESA_INFO_SIZE, %di
|
---|
167 |
|
---|
168 | next_mode:
|
---|
169 | /* Try next mode */
|
---|
170 |
|
---|
171 | mov %gs:(%si), %cx
|
---|
172 | cmp $VESA_END_OF_MODES, %cx
|
---|
173 | je no_mode
|
---|
174 |
|
---|
175 | inc %si
|
---|
176 | inc %si
|
---|
177 | push %cx
|
---|
178 | push %di
|
---|
179 | push %si
|
---|
180 | mov $VESA_GET_MODE_INFO, %ax
|
---|
181 | int $0x10
|
---|
182 |
|
---|
183 | pop %si
|
---|
184 | pop %di
|
---|
185 | pop %cx
|
---|
186 | cmp $VESA_OK, %al
|
---|
187 | jne no_mode
|
---|
188 |
|
---|
189 | /*
|
---|
190 | * Check for proper attributes (supported,
|
---|
191 | * color, graphics, linear framebuffer).
|
---|
192 | */
|
---|
193 |
|
---|
194 | mov VESA_MODE_ATTRIBUTES_OFFSET(%di), %ax
|
---|
195 | and $0x99, %ax
|
---|
196 | cmp $0x99, %ax
|
---|
197 | jne next_mode
|
---|
198 |
|
---|
199 | /* Check for proper resolution */
|
---|
200 |
|
---|
201 | mov default_width - vesa_init, %ax
|
---|
202 | cmp VESA_MODE_WIDTH_OFFSET(%di), %ax
|
---|
203 | jne next_mode
|
---|
204 |
|
---|
205 | mov default_height - vesa_init, %ax
|
---|
206 | cmp VESA_MODE_HEIGHT_OFFSET(%di), %ax
|
---|
207 | jne next_mode
|
---|
208 |
|
---|
209 | /* Check for proper bpp */
|
---|
210 |
|
---|
211 | mov default_bpp - vesa_init, %al
|
---|
212 | cmp VESA_MODE_BPP_OFFSET(%di), %al
|
---|
213 | je set_mode
|
---|
214 |
|
---|
215 | mov $24, %al
|
---|
216 | cmp default_bpp - vesa_init, %al
|
---|
217 | jne next_mode
|
---|
218 |
|
---|
219 | /* For 24 bpp modes accept also 32 bit bpp */
|
---|
220 |
|
---|
221 | mov $32, %al
|
---|
222 | cmp VESA_MODE_BPP_OFFSET(%di), %al
|
---|
223 | jne next_mode
|
---|
224 |
|
---|
225 | set_mode:
|
---|
226 | mov %cx, %bx
|
---|
227 | or $0xc000, %bx
|
---|
228 | push %di
|
---|
229 | mov $VESA_SET_MODE, %ax
|
---|
230 | int $0x10
|
---|
231 |
|
---|
232 | pop %di
|
---|
233 | cmp $VESA_OK, %al
|
---|
234 | jnz no_mode
|
---|
235 |
|
---|
236 | /* Set 3:2:3 VGA palette */
|
---|
237 |
|
---|
238 | mov VESA_MODE_BPP_OFFSET(%di), %al
|
---|
239 | cmp $8, %al
|
---|
240 | jnz vga_not_set
|
---|
241 |
|
---|
242 | mov VESA_MODE_ATTRIBUTES_OFFSET(%di), %ax
|
---|
243 | push %di
|
---|
244 | mov $vga323 - vesa_init, %di
|
---|
245 | mov $0x100, %ecx
|
---|
246 |
|
---|
247 | /* Test if VGA compatible registers are present */
|
---|
248 | bt $5, %ax
|
---|
249 | jnc vga_compat
|
---|
250 |
|
---|
251 | /* Use VESA routine to set the palette */
|
---|
252 |
|
---|
253 | mov $VESA_SET_PALETTE, %ax
|
---|
254 | xor %bl, %bl
|
---|
255 | xor %dx, %dx
|
---|
256 | int $0x10
|
---|
257 |
|
---|
258 | cmp $0x00, %ah
|
---|
259 | je vga_not_compat
|
---|
260 |
|
---|
261 | vga_compat:
|
---|
262 |
|
---|
263 | /* Use VGA registers to set the palette */
|
---|
264 |
|
---|
265 | movw $0x3c6, %dx /* set palette mask */
|
---|
266 | movb $0xff, %al
|
---|
267 | outb %al, %dx
|
---|
268 |
|
---|
269 | movw $0x3c8, %dx /* first index to set */
|
---|
270 | xor %al, %al
|
---|
271 | outb %al, %dx
|
---|
272 |
|
---|
273 | movw $0x3c9, %dx /* data port */
|
---|
274 |
|
---|
275 | vga_loop:
|
---|
276 | movb %es:2(%di), %al
|
---|
277 | outb %al, %dx
|
---|
278 |
|
---|
279 | movb %es:1(%di), %al
|
---|
280 | outb %al, %dx
|
---|
281 |
|
---|
282 | movb %es:(%di), %al
|
---|
283 | outb %al, %dx
|
---|
284 |
|
---|
285 | addw $4, %di
|
---|
286 | loop vga_loop
|
---|
287 |
|
---|
288 | vga_not_compat:
|
---|
289 |
|
---|
290 | pop %di
|
---|
291 |
|
---|
292 | vga_not_set:
|
---|
293 |
|
---|
294 | /*
|
---|
295 | * Store mode parameters:
|
---|
296 | * eax = bpp[8] scanline[16]
|
---|
297 | * ebx = width[16] height[16]
|
---|
298 | * edx = red_mask[8] red_pos[8] green_mask[8] green_pos[8]
|
---|
299 | * esi = blue_mask[8] blue_pos[8]
|
---|
300 | * edi = linear frame buffer
|
---|
301 | */
|
---|
302 |
|
---|
303 | mov VESA_MODE_BPP_OFFSET(%di), %al
|
---|
304 | xor %ah, %ah
|
---|
305 | shl $16, %eax
|
---|
306 | mov VESA_MODE_SCANLINE_OFFSET(%di), %ax
|
---|
307 |
|
---|
308 | mov VESA_MODE_WIDTH_OFFSET(%di), %bx
|
---|
309 | shl $16, %ebx
|
---|
310 | mov VESA_MODE_HEIGHT_OFFSET(%di), %bx
|
---|
311 |
|
---|
312 | mov VESA_MODE_BLUE_MASK_OFFSET(%di), %dl
|
---|
313 | shl $8, %edx
|
---|
314 | mov VESA_MODE_BLUE_POS_OFFSET(%di), %dl
|
---|
315 | mov %edx, %esi
|
---|
316 |
|
---|
317 | mov VESA_MODE_RED_MASK_OFFSET(%di), %dl
|
---|
318 | shl $8, %edx
|
---|
319 | mov VESA_MODE_RED_POS_OFFSET(%di), %dl
|
---|
320 | shl $8, %edx
|
---|
321 | mov VESA_MODE_GREEN_MASK_OFFSET(%di), %dl
|
---|
322 | shl $8, %edx
|
---|
323 | mov VESA_MODE_GREEN_POS_OFFSET(%di), %dl
|
---|
324 |
|
---|
325 | mov VESA_MODE_PHADDR_OFFSET(%di), %edi
|
---|
326 |
|
---|
327 | vesa_leave_real:
|
---|
328 |
|
---|
329 | mov %cr0, %ecx
|
---|
330 | or $1, %ecx
|
---|
331 | mov %ecx, %cr0
|
---|
332 |
|
---|
333 | jmp vesa_leave_real2
|
---|
334 |
|
---|
335 | vesa_leave_real2:
|
---|
336 |
|
---|
337 | ljmpl $gdtselector(KTEXT32_DES), $(vesa_init_protected - vesa_init + VESA_INIT_SEGMENT << 4)
|
---|
338 |
|
---|
339 | no_mode:
|
---|
340 |
|
---|
341 | /* No prefered mode found */
|
---|
342 |
|
---|
343 | mov $0x111, %cx
|
---|
344 | push %di
|
---|
345 | push %cx
|
---|
346 | mov $VESA_GET_MODE_INFO, %ax
|
---|
347 | int $0x10
|
---|
348 |
|
---|
349 | pop %cx
|
---|
350 | pop %di
|
---|
351 | cmp $VESA_OK, %al
|
---|
352 | jnz text_mode
|
---|
353 | jz set_mode /* force relative jump */
|
---|
354 |
|
---|
355 | text_mode:
|
---|
356 |
|
---|
357 | /* Reset to EGA text mode (because of problems with VESA) */
|
---|
358 |
|
---|
359 | mov $0x0003, %ax
|
---|
360 | int $0x10
|
---|
361 | mov $0xffffffff, %edi
|
---|
362 | xor %ax, %ax
|
---|
363 | jz vesa_leave_real /* force relative jump */
|
---|
364 |
|
---|
365 | vga323:
|
---|
366 | #include "vga323.pal"
|
---|
367 |
|
---|
368 | default_width:
|
---|
369 | .word 0
|
---|
370 |
|
---|
371 | default_height:
|
---|
372 | .word 0
|
---|
373 |
|
---|
374 | default_bpp:
|
---|
375 | .byte 0
|
---|
376 |
|
---|
377 | default_mode:
|
---|
378 | .ascii STRING(CONFIG_VESA_MODE)
|
---|
379 | .ascii "-"
|
---|
380 | .asciz STRING(CONFIG_VESA_BPP)
|
---|
381 | .fill 24
|
---|
382 |
|
---|
383 | #include "vesa_ret.inc"
|
---|
384 |
|
---|
385 | .align 4
|
---|
386 | e_vesa_init:
|
---|
387 | #endif
|
---|