Subversion Repositories Kolibri OS

Rev

Rev 6311 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6246 serge 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
3
;; Copyright (C) KolibriOS team 2004-2016. All rights reserved. ;;
4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;; Synhronization for MenuetOS.                                 ;;
7
;; Author: Halyavin Andrey, halyavin@land.ru                    ;;
8
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9
 
10
$Revision: 6240 $
11
 
12
struct FRB
13
        list            LHEAD
14
        magic           rd 1
15
        handle          rd 1
16
        destroy         rd 1
17
 
18
        width           rd 1
19
        height          rd 1
20
        pitch           rd 1
21
        format          rd 1
22
        private         rd 1
6339 serge 23
        pde             rd 16*2
6246 serge 24
ends
25
 
26
align 4
27
create_framebuffer:
28
        mov     ecx, sizeof.FRB
29
        call    create_object
30
        test    eax, eax
6311 serge 31
        jz      .fail
6246 serge 32
 
33
        mov     [eax+FRB.magic], 'FRMB'
34
        mov     [eax+FRB.destroy], 0
35
.fail:
36
        ret
37
 
38
 
39
align 4
40
init_video:
41
        mov     ebp, bios_fb
42
 
43
        movzx   eax, byte [BOOT_VARS+BOOT_BPP]      ; bpp
44
        mov     [_display.bits_per_pixel], eax
45
        mov     [_display.vrefresh], 60
46
 
47
        movzx   eax, word [BOOT_VARS+BOOT_X_RES]; X max
48
        mov     [_display.width], eax
49
        mov     [ebp+FRB.width], eax
50
        mov     [display_width_standard], eax
51
        dec     eax
52
        mov     [screen_workarea.right], eax
53
 
54
        movzx   eax, word [BOOT_VARS+BOOT_Y_RES]; Y max
55
        mov     [_display.height], eax
56
        mov     [ebp+FRB.height], eax
57
        mov     [display_height_standard], eax
58
        dec     eax
59
        mov     [screen_workarea.bottom], eax
60
 
61
        movzx   eax, word [BOOT_VARS+BOOT_VESA_MODE]    ; screen mode
62
        mov     dword [SCR_MODE], eax
63
        mov     eax, 640 *4                             ; Bytes PerScanLine
64
        cmp     [SCR_MODE], word 0x13                   ; 320x200
65
        je      @f
66
        cmp     [SCR_MODE], word 0x12                   ; VGA 640x480
67
        je      @f
68
        movzx   eax, word[BOOT_VARS+BOOT_PITCH]         ; for other modes
69
@@:
70
        mov     [_display.lfb_pitch], eax
71
        mov     [ebp+FRB.pitch], eax
72
 
73
        mov     eax, [BOOT_VARS+BOOT_LFB]
74
        mov     [LFBAddress], eax
75
 
76
        mov     eax, [_display.width]
77
        mul     [_display.height]
78
        mov     [_display.win_map_size], eax
79
 
80
        cmp     word [SCR_MODE], 0x0012                 ; VGA (640x480 16 colors)
81
        je      .vga
82
        cmp     word [SCR_MODE], 0x0013                 ; MCGA (320*200 256 colors)
83
        je      .32bpp
84
        cmp     byte [_display.bits_per_pixel], 32
85
        je      .32bpp
86
        cmp     byte [_display.bits_per_pixel], 24
87
        je      .24bpp
88
        cmp     byte [_display.bits_per_pixel], 16
89
        je      .16bpp
90
 
91
.vga:
92
        mov     [PUTPIXEL], VGA_putpixel
93
        mov     [GETPIXEL], Vesa20_getpixel32           ; Conversion buffer is 32 bpp
94
        mov     [_display.bytes_per_pixel], 4           ; Conversion buffer is 32 bpp
95
        jmp     .finish
96
 
97
.16bpp:
98
        mov     [PUTPIXEL], Vesa20_putpixel16
99
        mov     [GETPIXEL], Vesa20_getpixel16
100
        mov     [_display.bytes_per_pixel], 2
101
        jmp     .finish
102
 
103
.24bpp:
104
        mov     [PUTPIXEL], Vesa20_putpixel24
105
        mov     [GETPIXEL], Vesa20_getpixel24
106
        mov     [_display.bytes_per_pixel], 3
107
        jmp     .finish
108
 
109
.32bpp:
110
        mov     [PUTPIXEL], Vesa20_putpixel32
111
        mov     [GETPIXEL], Vesa20_getpixel32
112
        mov     [_display.bytes_per_pixel], 4
113
 
114
.finish:
115
        mov     [MOUSE_PICTURE], mousepointer
116
        mov     [_display.check_mouse], check_mouse_area_for_putpixel
117
        mov     [_display.check_m_pixel], check_mouse_area_for_getpixel
118
 
119
        mov     ax, word [SCR_MODE]
120
        cmp     ax, 0x0012
121
        je      .fake
122
        cmp     ax, 0x0013
123
        je      .fake
124
 
125
        mov     esi, [LFBAddress]
126
        bt      [cpu_caps], CAPS_PSE
127
        jnc     .create_page_tables
6261 serge 128
 
6339 serge 129
        mov     edx, 0x00200000
6311 serge 130
        or      esi, PG_GLOBAL+PAT_WC+PG_UWR
6246 serge 131
        and     esi, [pte_valid_mask]
6311 serge 132
        or      esi, PDE_LARGE
6246 serge 133
        mov     [ebp+FRB.pde], esi
134
        add     esi, edx
135
        mov     [ebp+FRB.pde+8], esi
136
        add     esi, edx
6339 serge 137
        mov     [ebp+FRB.pde+16], esi
6246 serge 138
        add     esi, edx
6339 serge 139
        mov     [ebp+FRB.pde+24], esi
140
        add     esi, edx
6246 serge 141
.ok:
142
        call    calculate_fast_getting_offset_for_WinMapAddress
143
; for Qemu or non standart video cards
144
; Unfortunately [BytesPerScanLine] does not always
145
; equal to [_display.width] * [ScreenBPP] / 8
146
        call    calculate_fast_getting_offset_for_LFB
147
        ret
148
 
149
.create_page_tables:
150
 
151
        add     ebp, FRB.pde
152
        or      esi, PG_GLOBAL+PAT_WC+PG_UWR
153
        and     esi, [pte_valid_mask]
154
 
155
        stdcall alloc_kernel_space, 0x1000
156
        mov     edi, eax
6339 serge 157
        mov     ebx, 8
6246 serge 158
 
159
.new_pd:
160
        call    alloc_page
161
        lea     edx, [eax+PG_UWR]
162
        mov     [ebp], edx
163
 
164
        stdcall map_page, edi, eax, PG_SWR
165
 
166
        mov     eax, esi
6339 serge 167
        mov     ecx, 512
6246 serge 168
@@:
6339 serge 169
        mov     [edi], eax
170
        mov     [edi+4], dword 0
6246 serge 171
        add     eax, 0x1000
6339 serge 172
        add     edi, 8
6246 serge 173
        loop    @B
174
 
6339 serge 175
        add     esi, 0x200000
6246 serge 176
        add     ebp, 4
177
        sub     edi, 4096
178
        dec     ebx
179
        jnz     .new_pd
180
        stdcall free_kernel_space, edi
181
        jmp     .ok
182
 
183
.fake:
184
        mov     [BOOT_VARS+BOOT_MTRR], byte 2
185
 
186
        stdcall alloc_kernel_space, 0x1000
187
        push    eax                            ;store in stack for subsequent
188
        mov     edi, eax                       ;free_kernel_space call
189
 
190
        call    alloc_page
191
        lea     edx, [eax+PG_UWR]
192
        mov     [ebp+FRB.pde], edx
193
 
6311 serge 194
        stdcall map_page, edi, eax, PG_SWR
195
 
6246 serge 196
; max VGA=640*480*4=1228800 bytes
197
; + 32*640*4=81920 bytes for mouse pointer
198
        stdcall alloc_pages, ((1228800+81920)/4096)
199
        or      eax, PG_GLOBAL+PG_UWR
200
        and     eax, [pte_valid_mask]
201
        mov     ecx, (1228800+81920)/4096
202
@@:
6339 serge 203
        mov     [edi], eax
204
        mov     [edi+4],dword 0
6246 serge 205
        add     eax, 0x1000
6339 serge 206
        add     edi, 8
6246 serge 207
        loop    @B
208
 
209
        call free_kernel_space
210
        jmp     .ok
211
 
212
align 4
213
set_framebuffer:
6252 serge 214
        push    esi
215
        push    edi
216
        lea     esi, [ecx+FRB.pde]
6339 serge 217
        mov     edi, sys_pml2+OS_BASE+8192-16*8
6252 serge 218
 
6261 serge 219
        cld
6252 serge 220
        pushfd
221
        cli
6339 serge 222
 
6252 serge 223
        mov     [_display.current_lfb], ecx
6339 serge 224
 
6252 serge 225
.patch_pde:
6339 serge 226
        mov     ecx, 16*2
227
        rep movsd
6252 serge 228
 
229
        bt      [cpu_caps], CAPS_PGE
230
        jnc     .cr3_flush
231
 
232
        mov     eax, cr4
233
        btr     eax, 7                          ;clear cr4.PGE
234
        mov     cr4, eax                        ;flush TLB
235
        bts     eax, 7
236
        mov     cr4, eax                        ;flush TLB
237
.exit:
238
        popfd
239
        pop     edi
240
        pop     esi
6246 serge 241
        ret
242
 
6252 serge 243
.cr3_flush:
244
        mov     eax, cr3
245
        mov     cr3, eax                        ;flush TLB
246
        jmp     .exit
247