Subversion Repositories Kolibri OS

Rev

Rev 9941 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2023. 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: 9948 $
  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.bpp]      ; bpp
  44.         mov     [_display.bits_per_pixel], eax
  45.         mov     [_display.vrefresh], 60
  46.  
  47.         movzx   eax, word [BOOT.x_res]; X max
  48.         cmp     eax, MAX_SCREEN_WIDTH
  49.         ja      $
  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.  
  56.         movzx   eax, word [BOOT.y_res]; Y max
  57.         cmp     eax, MAX_SCREEN_HEIGHT
  58.         ja      $
  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.  
  65.         movzx   eax, word [BOOT.vesa_mode]    ; screen mode
  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
  72.         movzx   eax, word[BOOT.pitch]         ; for other modes
  73. @@:
  74.         mov     [_display.lfb_pitch], eax
  75.         mov     [ebp + FRB.pitch], eax
  76.  
  77.         mov     eax, [BOOT.lfb]
  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_new
  103.         mov     [GETPIXEL], Vesa20_getpixel16
  104.         mov     [_display.bytes_per_pixel], 2
  105.         jmp     .finish
  106.  
  107. .24bpp:
  108.         mov     [PUTPIXEL], Vesa20_putpixel24_new
  109.         mov     [GETPIXEL], Vesa20_getpixel24
  110.         mov     [_display.bytes_per_pixel], 3
  111.         jmp     .finish
  112.  
  113. .32bpp:
  114.         mov     [PUTPIXEL], Vesa20_putpixel32_new
  115.         mov     [GETPIXEL], Vesa20_getpixel32
  116.         mov     [_display.bytes_per_pixel], 4
  117.  
  118. .finish:
  119.         mov     [_display.check_mouse], check_mouse_area_for_putpixel_new
  120.         mov     [_display.check_m_pixel], check_mouse_area_for_getpixel_new
  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
  133.         or      esi, PG_GLOBAL + PAT_WC + PG_UWR
  134.         and     esi, [pte_valid_mask]
  135.         or      esi, PDE_LARGE
  136.         mov     [ebp + FRB.pde], esi
  137.         add     esi, edx
  138.         mov     [ebp + FRB.pde + 4], esi
  139.         add     esi, edx
  140.         mov     [ebp + FRB.pde + 8], esi
  141.         add     esi, edx
  142.         mov     [ebp + FRB.pde + 12], esi
  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
  155.         or      esi, PG_GLOBAL + PAT_WC + PG_UWR
  156.         and     esi, [pte_valid_mask]
  157.  
  158.         stdcall alloc_kernel_space, PAGE_SIZE
  159.         mov     edi, eax
  160.         mov     ebx, 4
  161.  
  162. .new_pd:
  163.         call    alloc_page
  164.         lea     edx, [eax + PG_UWR]
  165.         mov     [ebp], edx
  166.  
  167.         stdcall map_page, edi, eax, PG_SWR
  168.  
  169.         mov     eax, esi
  170.         mov     ecx, PAGE_SIZE/4
  171. @@:
  172.         stosd
  173.         add     eax, PAGE_SIZE
  174.         loop    @B
  175.  
  176.         add     esi, 0x400000
  177.         add     ebp, 4
  178.         sub     edi, PAGE_SIZE
  179.         dec     ebx
  180.         jnz     .new_pd
  181.         stdcall free_kernel_space, edi
  182.         jmp     .ok
  183.  
  184. .fake:
  185.         mov     [BOOT.mtrr], byte 2
  186.  
  187.         stdcall alloc_kernel_space, PAGE_SIZE
  188.         push    eax                            ;store in stack for subsequent
  189.         mov     edi, eax                       ;free_kernel_space call
  190.  
  191.         call    alloc_page
  192.         lea     edx, [eax + PG_UWR]
  193.         mov     [ebp + FRB.pde], edx
  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
  199.         stdcall alloc_pages, ((1228800+81920)/PAGE_SIZE)
  200.         or      eax, PG_GLOBAL+PG_UWR
  201.         and     eax, [pte_valid_mask]
  202.         mov     ecx, (1228800+81920)/PAGE_SIZE
  203. @@:
  204.         stosd
  205.         add     eax, PAGE_SIZE
  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
  215.         lea     esi, [ecx + FRB.pde]
  216.         mov     eax, sys_proc
  217.  
  218.         cld
  219.         pushfd
  220.         cli
  221.         mov     [_display.current_lfb], ecx
  222. .patch_pde:
  223.         lea     edi, [eax + PROC.pdt_0 + (LFB_BASE shr 20)] ;last 8 pd entries up to 32Mb framebuffer
  224.         mov     ecx, 4
  225.         rep movsd                               ;patch pde
  226.         sub     esi, 16
  227.         mov     eax, [eax + PROC.list.next]       ;next process/address space
  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.  
  250.