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