Subversion Repositories Kolibri OS

Rev

Rev 6275 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6263 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
23
        pde             rd 8
24
ends
25
 
26
align 4
27
create_framebuffer:
28
        mov     ecx, sizeof.FRB
29
        call    create_object
30
        test    eax, eax
31
        jz      .fail
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
128
 
129
        mov     edx, 0x00400000
130
        or      esi, PG_GLOBAL+PDE_LARGE+PAT_WC+PG_UWR
131
        and     esi, [pte_valid_mask]
132
        mov     [ebp+FRB.pde], esi
133
        add     esi, edx
134
        mov     [ebp+FRB.pde+4], esi
135
        add     esi, edx
136
        mov     [ebp+FRB.pde+8], esi
137
        add     esi, edx
138
        mov     [ebp+FRB.pde+12], esi
139
        add     esi, edx
140
.ok:
141
        call    calculate_fast_getting_offset_for_WinMapAddress
142
; for Qemu or non standart video cards
143
; Unfortunately [BytesPerScanLine] does not always
144
; equal to [_display.width] * [ScreenBPP] / 8
145
        call    calculate_fast_getting_offset_for_LFB
146
        ret
147
 
148
.create_page_tables:
149
 
150
        add     ebp, FRB.pde
151
        or      esi, PG_GLOBAL+PAT_WC+PG_UWR
152
        and     esi, [pte_valid_mask]
153
 
154
        stdcall alloc_kernel_space, 0x1000
155
        mov     edi, eax
156
        mov     ebx, 4
157
 
158
.new_pd:
159
        call    alloc_page
160
        lea     edx, [eax+PG_UWR]
161
        mov     [ebp], edx
162
 
163
        stdcall map_page, edi, eax, PG_SWR
164
 
165
        mov     eax, esi
166
        mov     ecx, 1024
167
@@:
168
        stosd
169
        add     eax, 0x1000
170
        loop    @B
171
 
172
        add     esi, 0x400000
173
        add     ebp, 4
174
        sub     edi, 4096
175
        dec     ebx
176
        jnz     .new_pd
177
        stdcall free_kernel_space, edi
178
        jmp     .ok
179
 
180
.fake:
181
        mov     [BOOT_VARS+BOOT_MTRR], byte 2
182
 
183
        stdcall alloc_kernel_space, 0x1000
184
        push    eax                            ;store in stack for subsequent
185
        mov     edi, eax                       ;free_kernel_space call
186
 
187
        call    alloc_page
188
        lea     edx, [eax+PG_UWR]
189
        mov     [ebp+FRB.pde], edx
190
 
191
        stdcall map_page, edi, eax, PG_SWR
192
 
193
; max VGA=640*480*4=1228800 bytes
194
; + 32*640*4=81920 bytes for mouse pointer
195
        stdcall alloc_pages, ((1228800+81920)/4096)
196
        or      eax, PG_GLOBAL+PG_UWR
197
        and     eax, [pte_valid_mask]
198
        mov     ecx, (1228800+81920)/4096
199
@@:
200
        stosd
201
        add     eax, 0x1000
202
        loop    @B
203
 
204
        call    free_kernel_space
205
        jmp     .ok
206
 
207
align 4
208
set_framebuffer:
209
        push    esi
210
        push    edi
211
        lea     esi, [ecx+FRB.pde]
212
        mov     eax, sys_proc
213
 
214
        cld
215
        pushfd
216
        cli
217
        mov     [_display.current_lfb], ecx
218
.patch_pde:
219
        lea     edi, [eax+PROC.pdt_0+4096-32]   ;last 8 pd entries up to 32Mb framebuffer
220
        mov     ecx, 4
221
        rep movsd                               ;patch pde
222
        sub     esi, 16
223
        mov     eax, [eax+PROC.list.next]       ;next process/address space
224
        cmp     eax, sys_proc
225
        jne     .patch_pde
226
 
227
        bt      [cpu_caps], CAPS_PGE
228
        jnc     .cr3_flush
229
 
230
        mov     eax, cr4
231
        btr     eax, 7                          ;clear cr4.PGE
232
        mov     cr4, eax                        ;flush TLB
233
        bts     eax, 7
234
        mov     cr4, eax                        ;flush TLB
235
.exit:
236
        popfd
237
        pop     edi
238
        pop     esi
239
        ret
240
 
241
.cr3_flush:
242
        mov     eax, cr3
243
        mov     cr3, eax                        ;flush TLB
244
        jmp     .exit
245