Subversion Repositories Kolibri OS

Rev

Rev 7522 | Rev 9715 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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