Rev 9941 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6263 | serge | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
||
9941 | Doczom | 3 | ;; Copyright (C) KolibriOS team 2004-2023. All rights reserved. ;; |
6263 | serge | 4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
||
6 | ;; Synhronization for MenuetOS. ;; |
||
7 | ;; Author: Halyavin Andrey, halyavin@land.ru ;; |
||
8 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
||
9 | |||
8224 | dunkaist | 10 | $Revision: 9948 $ |
6263 | serge | 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 | |||
9715 | Doczom | 33 | mov [eax + FRB.magic], 'FRMB' |
34 | mov [eax + FRB.destroy], 0 |
||
6263 | serge | 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 |
9715 | Doczom | 51 | mov [ebp + FRB.width], eax |
6263 | serge | 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 |
9715 | Doczom | 60 | mov [ebp + FRB.height], eax |
6263 | serge | 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 |
||
9715 | Doczom | 75 | mov [ebp + FRB.pitch], eax |
6263 | serge | 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: |
||
9941 | Doczom | 102 | mov [PUTPIXEL], Vesa20_putpixel16_new |
6263 | serge | 103 | mov [GETPIXEL], Vesa20_getpixel16 |
104 | mov [_display.bytes_per_pixel], 2 |
||
105 | jmp .finish |
||
106 | |||
107 | .24bpp: |
||
9941 | Doczom | 108 | mov [PUTPIXEL], Vesa20_putpixel24_new |
6263 | serge | 109 | mov [GETPIXEL], Vesa20_getpixel24 |
110 | mov [_display.bytes_per_pixel], 3 |
||
111 | jmp .finish |
||
112 | |||
113 | .32bpp: |
||
9941 | Doczom | 114 | mov [PUTPIXEL], Vesa20_putpixel32_new |
6263 | serge | 115 | mov [GETPIXEL], Vesa20_getpixel32 |
116 | mov [_display.bytes_per_pixel], 4 |
||
117 | |||
118 | .finish: |
||
9941 | Doczom | 119 | mov [_display.check_mouse], check_mouse_area_for_putpixel_new |
120 | mov [_display.check_m_pixel], check_mouse_area_for_getpixel_new |
||
6263 | serge | 121 | |
122 | mov ax, word [SCR_MODE] |
||
123 | cmp ax, 0x0012 |
||
124 | je .fake |
||
125 | cmp ax, 0x0013 |
||
126 | je .fake |
||
127 | |||
128 | mov esi, [LFBAddress] |
||
129 | bt [cpu_caps], CAPS_PSE |
||
130 | jnc .create_page_tables |
||
131 | |||
132 | mov edx, 0x00400000 |
||
9715 | Doczom | 133 | or esi, PG_GLOBAL + PAT_WC + PG_UWR |
6263 | serge | 134 | and esi, [pte_valid_mask] |
6275 | serge | 135 | or esi, PDE_LARGE |
9715 | Doczom | 136 | mov [ebp + FRB.pde], esi |
6263 | serge | 137 | add esi, edx |
9715 | Doczom | 138 | mov [ebp + FRB.pde + 4], esi |
6263 | serge | 139 | add esi, edx |
9715 | Doczom | 140 | mov [ebp + FRB.pde + 8], esi |
6263 | serge | 141 | add esi, edx |
9715 | Doczom | 142 | mov [ebp + FRB.pde + 12], esi |
6263 | serge | 143 | add esi, edx |
144 | .ok: |
||
145 | call calculate_fast_getting_offset_for_WinMapAddress |
||
146 | ; for Qemu or non standart video cards |
||
147 | ; Unfortunately [BytesPerScanLine] does not always |
||
148 | ; equal to [_display.width] * [ScreenBPP] / 8 |
||
149 | call calculate_fast_getting_offset_for_LFB |
||
150 | ret |
||
151 | |||
152 | .create_page_tables: |
||
153 | |||
154 | add ebp, FRB.pde |
||
9715 | Doczom | 155 | or esi, PG_GLOBAL + PAT_WC + PG_UWR |
6263 | serge | 156 | and esi, [pte_valid_mask] |
157 | |||
9926 | Doczom | 158 | stdcall alloc_kernel_space, PAGE_SIZE |
6263 | serge | 159 | mov edi, eax |
160 | mov ebx, 4 |
||
161 | |||
162 | .new_pd: |
||
163 | call alloc_page |
||
9715 | Doczom | 164 | lea edx, [eax + PG_UWR] |
6263 | serge | 165 | mov [ebp], edx |
166 | |||
167 | stdcall map_page, edi, eax, PG_SWR |
||
168 | |||
169 | mov eax, esi |
||
9926 | Doczom | 170 | mov ecx, PAGE_SIZE/4 |
6263 | serge | 171 | @@: |
172 | stosd |
||
9926 | Doczom | 173 | add eax, PAGE_SIZE |
6263 | serge | 174 | loop @B |
175 | |||
176 | add esi, 0x400000 |
||
177 | add ebp, 4 |
||
9926 | Doczom | 178 | sub edi, PAGE_SIZE |
6263 | serge | 179 | dec ebx |
180 | jnz .new_pd |
||
181 | stdcall free_kernel_space, edi |
||
182 | jmp .ok |
||
183 | |||
184 | .fake: |
||
7132 | dunkaist | 185 | mov [BOOT.mtrr], byte 2 |
6263 | serge | 186 | |
9926 | Doczom | 187 | stdcall alloc_kernel_space, PAGE_SIZE |
6263 | serge | 188 | push eax ;store in stack for subsequent |
189 | mov edi, eax ;free_kernel_space call |
||
190 | |||
191 | call alloc_page |
||
9715 | Doczom | 192 | lea edx, [eax + PG_UWR] |
193 | mov [ebp + FRB.pde], edx |
||
6263 | serge | 194 | |
195 | stdcall map_page, edi, eax, PG_SWR |
||
196 | |||
197 | ; max VGA=640*480*4=1228800 bytes |
||
198 | ; + 32*640*4=81920 bytes for mouse pointer |
||
9926 | Doczom | 199 | stdcall alloc_pages, ((1228800+81920)/PAGE_SIZE) |
6263 | serge | 200 | or eax, PG_GLOBAL+PG_UWR |
201 | and eax, [pte_valid_mask] |
||
9926 | Doczom | 202 | mov ecx, (1228800+81920)/PAGE_SIZE |
6263 | serge | 203 | @@: |
204 | stosd |
||
9926 | Doczom | 205 | add eax, PAGE_SIZE |
6263 | serge | 206 | loop @B |
207 | |||
208 | call free_kernel_space |
||
209 | jmp .ok |
||
210 | |||
211 | align 4 |
||
212 | set_framebuffer: |
||
213 | push esi |
||
214 | push edi |
||
9715 | Doczom | 215 | lea esi, [ecx + FRB.pde] |
6263 | serge | 216 | mov eax, sys_proc |
217 | |||
218 | cld |
||
219 | pushfd |
||
220 | cli |
||
221 | mov [_display.current_lfb], ecx |
||
222 | .patch_pde: |
||
9948 | Doczom | 223 | lea edi, [eax + PROC.pdt_0 + (LFB_BASE shr 20)] ;last 8 pd entries up to 32Mb framebuffer |
6263 | serge | 224 | mov ecx, 4 |
225 | rep movsd ;patch pde |
||
226 | sub esi, 16 |
||
9715 | Doczom | 227 | mov eax, [eax + PROC.list.next] ;next process/address space |
6263 | serge | 228 | cmp eax, sys_proc |
229 | jne .patch_pde |
||
230 | |||
231 | bt [cpu_caps], CAPS_PGE |
||
232 | jnc .cr3_flush |
||
233 | |||
234 | mov eax, cr4 |
||
235 | btr eax, 7 ;clear cr4.PGE |
||
236 | mov cr4, eax ;flush TLB |
||
237 | bts eax, 7 |
||
238 | mov cr4, eax ;flush TLB |
||
239 | .exit: |
||
240 | popfd |
||
241 | pop edi |
||
242 | pop esi |
||
243 | ret |
||
244 | |||
245 | .cr3_flush: |
||
246 | mov eax, cr3 |
||
247 | mov cr3, eax ;flush TLB |
||
248 | jmp .exit |
||
249 |