2016-02-20 10:57:44 +01:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;; ;;
|
2023-09-22 18:31:40 +02:00
|
|
|
;; Copyright (C) KolibriOS team 2004-2023. All rights reserved. ;;
|
2016-02-20 10:57:44 +01:00
|
|
|
;; Distributed under terms of the GNU General Public License ;;
|
|
|
|
;; ;;
|
|
|
|
;; Synhronization for MenuetOS. ;;
|
|
|
|
;; Author: Halyavin Andrey, halyavin@land.ru ;;
|
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
|
2020-11-20 04:45:41 +01:00
|
|
|
$Revision$
|
2016-02-20 10:57:44 +01:00
|
|
|
|
|
|
|
struct FRB
|
|
|
|
list LHEAD
|
|
|
|
magic rd 1
|
|
|
|
handle rd 1
|
|
|
|
destroy rd 1
|
|
|
|
|
|
|
|
width rd 1
|
|
|
|
height rd 1
|
|
|
|
pitch rd 1
|
|
|
|
format rd 1
|
|
|
|
private rd 1
|
|
|
|
pde rd 8
|
|
|
|
ends
|
|
|
|
|
|
|
|
align 4
|
|
|
|
create_framebuffer:
|
|
|
|
mov ecx, sizeof.FRB
|
|
|
|
call create_object
|
|
|
|
test eax, eax
|
|
|
|
jz .fail
|
|
|
|
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [eax + FRB.magic], 'FRMB'
|
|
|
|
mov [eax + FRB.destroy], 0
|
2016-02-20 10:57:44 +01:00
|
|
|
.fail:
|
|
|
|
ret
|
|
|
|
|
|
|
|
|
|
|
|
align 4
|
|
|
|
init_video:
|
|
|
|
mov ebp, bios_fb
|
|
|
|
|
2017-12-17 03:12:53 +01:00
|
|
|
movzx eax, byte [BOOT.bpp] ; bpp
|
2016-02-20 10:57:44 +01:00
|
|
|
mov [_display.bits_per_pixel], eax
|
|
|
|
mov [_display.vrefresh], 60
|
|
|
|
|
2017-12-17 03:12:53 +01:00
|
|
|
movzx eax, word [BOOT.x_res]; X max
|
2018-11-02 01:14:46 +01:00
|
|
|
cmp eax, MAX_SCREEN_WIDTH
|
|
|
|
ja $
|
2016-02-20 10:57:44 +01:00
|
|
|
mov [_display.width], eax
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [ebp + FRB.width], eax
|
2016-02-20 10:57:44 +01:00
|
|
|
mov [display_width_standard], eax
|
|
|
|
dec eax
|
|
|
|
mov [screen_workarea.right], eax
|
|
|
|
|
2017-12-17 03:12:53 +01:00
|
|
|
movzx eax, word [BOOT.y_res]; Y max
|
2018-11-02 01:14:46 +01:00
|
|
|
cmp eax, MAX_SCREEN_HEIGHT
|
|
|
|
ja $
|
2016-02-20 10:57:44 +01:00
|
|
|
mov [_display.height], eax
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [ebp + FRB.height], eax
|
2016-02-20 10:57:44 +01:00
|
|
|
mov [display_height_standard], eax
|
|
|
|
dec eax
|
|
|
|
mov [screen_workarea.bottom], eax
|
|
|
|
|
2017-12-17 03:12:53 +01:00
|
|
|
movzx eax, word [BOOT.vesa_mode] ; screen mode
|
2016-02-20 10:57:44 +01:00
|
|
|
mov dword [SCR_MODE], eax
|
|
|
|
mov eax, 640 *4 ; Bytes PerScanLine
|
|
|
|
cmp [SCR_MODE], word 0x13 ; 320x200
|
|
|
|
je @f
|
|
|
|
cmp [SCR_MODE], word 0x12 ; VGA 640x480
|
|
|
|
je @f
|
2017-12-17 03:12:53 +01:00
|
|
|
movzx eax, word[BOOT.pitch] ; for other modes
|
2016-02-20 10:57:44 +01:00
|
|
|
@@:
|
|
|
|
mov [_display.lfb_pitch], eax
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [ebp + FRB.pitch], eax
|
2016-02-20 10:57:44 +01:00
|
|
|
|
2017-12-17 03:12:53 +01:00
|
|
|
mov eax, [BOOT.lfb]
|
2016-02-20 10:57:44 +01:00
|
|
|
mov [LFBAddress], eax
|
|
|
|
|
|
|
|
mov eax, [_display.width]
|
|
|
|
mul [_display.height]
|
|
|
|
mov [_display.win_map_size], eax
|
|
|
|
|
|
|
|
cmp word [SCR_MODE], 0x0012 ; VGA (640x480 16 colors)
|
|
|
|
je .vga
|
|
|
|
cmp word [SCR_MODE], 0x0013 ; MCGA (320*200 256 colors)
|
|
|
|
je .32bpp
|
|
|
|
cmp byte [_display.bits_per_pixel], 32
|
|
|
|
je .32bpp
|
|
|
|
cmp byte [_display.bits_per_pixel], 24
|
|
|
|
je .24bpp
|
|
|
|
cmp byte [_display.bits_per_pixel], 16
|
|
|
|
je .16bpp
|
|
|
|
|
|
|
|
.vga:
|
|
|
|
mov [PUTPIXEL], VGA_putpixel
|
|
|
|
mov [GETPIXEL], Vesa20_getpixel32 ; Conversion buffer is 32 bpp
|
|
|
|
mov [_display.bytes_per_pixel], 4 ; Conversion buffer is 32 bpp
|
|
|
|
jmp .finish
|
|
|
|
|
|
|
|
.16bpp:
|
2023-09-22 18:31:40 +02:00
|
|
|
mov [PUTPIXEL], Vesa20_putpixel16_new
|
2016-02-20 10:57:44 +01:00
|
|
|
mov [GETPIXEL], Vesa20_getpixel16
|
|
|
|
mov [_display.bytes_per_pixel], 2
|
|
|
|
jmp .finish
|
|
|
|
|
|
|
|
.24bpp:
|
2023-09-22 18:31:40 +02:00
|
|
|
mov [PUTPIXEL], Vesa20_putpixel24_new
|
2016-02-20 10:57:44 +01:00
|
|
|
mov [GETPIXEL], Vesa20_getpixel24
|
|
|
|
mov [_display.bytes_per_pixel], 3
|
|
|
|
jmp .finish
|
|
|
|
|
|
|
|
.32bpp:
|
2023-09-22 18:31:40 +02:00
|
|
|
mov [PUTPIXEL], Vesa20_putpixel32_new
|
2016-02-20 10:57:44 +01:00
|
|
|
mov [GETPIXEL], Vesa20_getpixel32
|
|
|
|
mov [_display.bytes_per_pixel], 4
|
|
|
|
|
|
|
|
.finish:
|
2023-09-22 18:31:40 +02:00
|
|
|
mov [_display.check_mouse], check_mouse_area_for_putpixel_new
|
|
|
|
mov [_display.check_m_pixel], check_mouse_area_for_getpixel_new
|
2016-02-20 10:57:44 +01:00
|
|
|
|
|
|
|
mov ax, word [SCR_MODE]
|
|
|
|
cmp ax, 0x0012
|
|
|
|
je .fake
|
|
|
|
cmp ax, 0x0013
|
|
|
|
je .fake
|
|
|
|
|
|
|
|
mov esi, [LFBAddress]
|
|
|
|
bt [cpu_caps], CAPS_PSE
|
|
|
|
jnc .create_page_tables
|
|
|
|
|
|
|
|
mov edx, 0x00400000
|
2022-02-12 18:27:41 +01:00
|
|
|
or esi, PG_GLOBAL + PAT_WC + PG_UWR
|
2016-02-20 10:57:44 +01:00
|
|
|
and esi, [pte_valid_mask]
|
2016-02-21 18:29:58 +01:00
|
|
|
or esi, PDE_LARGE
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [ebp + FRB.pde], esi
|
2016-02-20 10:57:44 +01:00
|
|
|
add esi, edx
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [ebp + FRB.pde + 4], esi
|
2016-02-20 10:57:44 +01:00
|
|
|
add esi, edx
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [ebp + FRB.pde + 8], esi
|
2016-02-20 10:57:44 +01:00
|
|
|
add esi, edx
|
2022-02-12 18:27:41 +01:00
|
|
|
mov [ebp + FRB.pde + 12], esi
|
2016-02-20 10:57:44 +01:00
|
|
|
add esi, edx
|
|
|
|
.ok:
|
|
|
|
call calculate_fast_getting_offset_for_WinMapAddress
|
|
|
|
; for Qemu or non standart video cards
|
|
|
|
; Unfortunately [BytesPerScanLine] does not always
|
|
|
|
; equal to [_display.width] * [ScreenBPP] / 8
|
|
|
|
call calculate_fast_getting_offset_for_LFB
|
|
|
|
ret
|
|
|
|
|
|
|
|
.create_page_tables:
|
|
|
|
|
|
|
|
add ebp, FRB.pde
|
2022-02-12 18:27:41 +01:00
|
|
|
or esi, PG_GLOBAL + PAT_WC + PG_UWR
|
2016-02-20 10:57:44 +01:00
|
|
|
and esi, [pte_valid_mask]
|
|
|
|
|
2023-06-25 18:42:10 +02:00
|
|
|
stdcall alloc_kernel_space, PAGE_SIZE
|
2016-02-20 10:57:44 +01:00
|
|
|
mov edi, eax
|
|
|
|
mov ebx, 4
|
|
|
|
|
|
|
|
.new_pd:
|
|
|
|
call alloc_page
|
2022-02-12 18:27:41 +01:00
|
|
|
lea edx, [eax + PG_UWR]
|
2016-02-20 10:57:44 +01:00
|
|
|
mov [ebp], edx
|
|
|
|
|
|
|
|
stdcall map_page, edi, eax, PG_SWR
|
|
|
|
|
|
|
|
mov eax, esi
|
2023-06-25 18:42:10 +02:00
|
|
|
mov ecx, PAGE_SIZE/4
|
2016-02-20 10:57:44 +01:00
|
|
|
@@:
|
|
|
|
stosd
|
2023-06-25 18:42:10 +02:00
|
|
|
add eax, PAGE_SIZE
|
2016-02-20 10:57:44 +01:00
|
|
|
loop @B
|
|
|
|
|
|
|
|
add esi, 0x400000
|
|
|
|
add ebp, 4
|
2023-06-25 18:42:10 +02:00
|
|
|
sub edi, PAGE_SIZE
|
2016-02-20 10:57:44 +01:00
|
|
|
dec ebx
|
|
|
|
jnz .new_pd
|
|
|
|
stdcall free_kernel_space, edi
|
|
|
|
jmp .ok
|
|
|
|
|
|
|
|
.fake:
|
2017-12-17 03:12:53 +01:00
|
|
|
mov [BOOT.mtrr], byte 2
|
2016-02-20 10:57:44 +01:00
|
|
|
|
2023-06-25 18:42:10 +02:00
|
|
|
stdcall alloc_kernel_space, PAGE_SIZE
|
2016-02-20 10:57:44 +01:00
|
|
|
push eax ;store in stack for subsequent
|
|
|
|
mov edi, eax ;free_kernel_space call
|
|
|
|
|
|
|
|
call alloc_page
|
2022-02-12 18:27:41 +01:00
|
|
|
lea edx, [eax + PG_UWR]
|
|
|
|
mov [ebp + FRB.pde], edx
|
2016-02-20 10:57:44 +01:00
|
|
|
|
|
|
|
stdcall map_page, edi, eax, PG_SWR
|
|
|
|
|
|
|
|
; max VGA=640*480*4=1228800 bytes
|
|
|
|
; + 32*640*4=81920 bytes for mouse pointer
|
2023-06-25 18:42:10 +02:00
|
|
|
stdcall alloc_pages, ((1228800+81920)/PAGE_SIZE)
|
2016-02-20 10:57:44 +01:00
|
|
|
or eax, PG_GLOBAL+PG_UWR
|
|
|
|
and eax, [pte_valid_mask]
|
2023-06-25 18:42:10 +02:00
|
|
|
mov ecx, (1228800+81920)/PAGE_SIZE
|
2016-02-20 10:57:44 +01:00
|
|
|
@@:
|
|
|
|
stosd
|
2023-06-25 18:42:10 +02:00
|
|
|
add eax, PAGE_SIZE
|
2016-02-20 10:57:44 +01:00
|
|
|
loop @B
|
|
|
|
|
|
|
|
call free_kernel_space
|
|
|
|
jmp .ok
|
|
|
|
|
|
|
|
align 4
|
|
|
|
set_framebuffer:
|
|
|
|
push esi
|
|
|
|
push edi
|
2022-02-12 18:27:41 +01:00
|
|
|
lea esi, [ecx + FRB.pde]
|
2016-02-20 10:57:44 +01:00
|
|
|
mov eax, sys_proc
|
|
|
|
|
|
|
|
cld
|
|
|
|
pushfd
|
|
|
|
cli
|
|
|
|
mov [_display.current_lfb], ecx
|
|
|
|
.patch_pde:
|
2023-06-25 18:42:10 +02:00
|
|
|
lea edi, [eax + PROC.pdt_0 + PAGE_SIZE -32] ;last 8 pd entries up to 32Mb framebuffer
|
2016-02-20 10:57:44 +01:00
|
|
|
mov ecx, 4
|
|
|
|
rep movsd ;patch pde
|
|
|
|
sub esi, 16
|
2022-02-12 18:27:41 +01:00
|
|
|
mov eax, [eax + PROC.list.next] ;next process/address space
|
2016-02-20 10:57:44 +01:00
|
|
|
cmp eax, sys_proc
|
|
|
|
jne .patch_pde
|
|
|
|
|
|
|
|
bt [cpu_caps], CAPS_PGE
|
|
|
|
jnc .cr3_flush
|
|
|
|
|
|
|
|
mov eax, cr4
|
|
|
|
btr eax, 7 ;clear cr4.PGE
|
|
|
|
mov cr4, eax ;flush TLB
|
|
|
|
bts eax, 7
|
|
|
|
mov cr4, eax ;flush TLB
|
|
|
|
.exit:
|
|
|
|
popfd
|
|
|
|
pop edi
|
|
|
|
pop esi
|
|
|
|
ret
|
|
|
|
|
|
|
|
.cr3_flush:
|
|
|
|
mov eax, cr3
|
|
|
|
mov cr3, eax ;flush TLB
|
|
|
|
jmp .exit
|
|
|
|
|