Rev 6263 | Rev 7132 | Go to most recent revision | Details | Compare with Previous | 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 |
||
6275 | serge | 130 | or esi, PG_GLOBAL+PAT_WC+PG_UWR |
6263 | serge | 131 | and esi, [pte_valid_mask] |
6275 | serge | 132 | or esi, PDE_LARGE |
6263 | serge | 133 | mov [ebp+FRB.pde], esi |
134 | add esi, edx |
||
135 | mov [ebp+FRB.pde+4], esi |
||
136 | add esi, edx |
||
137 | mov [ebp+FRB.pde+8], esi |
||
138 | add esi, edx |
||
139 | mov [ebp+FRB.pde+12], esi |
||
140 | add esi, edx |
||
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 |
||
157 | mov ebx, 4 |
||
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 |
||
167 | mov ecx, 1024 |
||
168 | @@: |
||
169 | stosd |
||
170 | add eax, 0x1000 |
||
171 | loop @B |
||
172 | |||
173 | add esi, 0x400000 |
||
174 | add ebp, 4 |
||
175 | sub edi, 4096 |
||
176 | dec ebx |
||
177 | jnz .new_pd |
||
178 | stdcall free_kernel_space, edi |
||
179 | jmp .ok |
||
180 | |||
181 | .fake: |
||
182 | mov [BOOT_VARS+BOOT_MTRR], byte 2 |
||
183 | |||
184 | stdcall alloc_kernel_space, 0x1000 |
||
185 | push eax ;store in stack for subsequent |
||
186 | mov edi, eax ;free_kernel_space call |
||
187 | |||
188 | call alloc_page |
||
189 | lea edx, [eax+PG_UWR] |
||
190 | mov [ebp+FRB.pde], edx |
||
191 | |||
192 | stdcall map_page, edi, eax, PG_SWR |
||
193 | |||
194 | ; max VGA=640*480*4=1228800 bytes |
||
195 | ; + 32*640*4=81920 bytes for mouse pointer |
||
196 | stdcall alloc_pages, ((1228800+81920)/4096) |
||
197 | or eax, PG_GLOBAL+PG_UWR |
||
198 | and eax, [pte_valid_mask] |
||
199 | mov ecx, (1228800+81920)/4096 |
||
200 | @@: |
||
201 | stosd |
||
202 | add eax, 0x1000 |
||
203 | loop @B |
||
204 | |||
205 | call free_kernel_space |
||
206 | jmp .ok |
||
207 | |||
208 | align 4 |
||
209 | set_framebuffer: |
||
210 | push esi |
||
211 | push edi |
||
212 | lea esi, [ecx+FRB.pde] |
||
213 | mov eax, sys_proc |
||
214 | |||
215 | cld |
||
216 | pushfd |
||
217 | cli |
||
218 | mov [_display.current_lfb], ecx |
||
219 | .patch_pde: |
||
220 | lea edi, [eax+PROC.pdt_0+4096-32] ;last 8 pd entries up to 32Mb framebuffer |
||
221 | mov ecx, 4 |
||
222 | rep movsd ;patch pde |
||
223 | sub esi, 16 |
||
224 | mov eax, [eax+PROC.list.next] ;next process/address space |
||
225 | cmp eax, sys_proc |
||
226 | jne .patch_pde |
||
227 | |||
228 | bt [cpu_caps], CAPS_PGE |
||
229 | jnc .cr3_flush |
||
230 | |||
231 | mov eax, cr4 |
||
232 | btr eax, 7 ;clear cr4.PGE |
||
233 | mov cr4, eax ;flush TLB |
||
234 | bts eax, 7 |
||
235 | mov cr4, eax ;flush TLB |
||
236 | .exit: |
||
237 | popfd |
||
238 | pop edi |
||
239 | pop esi |
||
240 | ret |
||
241 | |||
242 | .cr3_flush: |
||
243 | mov eax, cr3 |
||
244 | mov cr3, eax ;flush TLB |
||
245 | jmp .exit |
||
246 |