source: mainline/kernel/arch/ia32/src/boot/vesa_real.inc@ 3bacee1

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 3bacee1 was f1380b7, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 8 years ago

style: Remove trailing whitespace on _all_ lines, including empty ones, remaining files.

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