Subversion Repositories Kolibri OS

Rev

Rev 34 | Rev 76 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                        ;;
  3. ;;  BOOTCODE.INC                                          ;;
  4. ;;                                                        ;;
  5. ;;  KolibriOS 16-bit loader,                              ;;
  6. ;;                        based on bootcode for MenuetOS  ;;
  7. ;;                                                        ;;
  8. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9.  
  10.  
  11.  
  12. ;==========================================================================
  13. ;
  14. ;                           16 BIT FUNCTIONS
  15. ;
  16. ;==========================================================================
  17.  
  18. putchar:
  19. ; in: al=character
  20.         mov     ah, 0Eh
  21.         mov     bh, 0
  22.         int     10h
  23.         ret
  24.  
  25. print:
  26. ; in: si->string
  27.         mov     al, 186
  28.         call    putchar
  29.         mov     al, ' '
  30.         call    putchar
  31.  
  32. printplain:
  33. ; in: si->string
  34.         pusha
  35.         lodsb
  36. @@:
  37.         call    putchar
  38.         lodsb
  39.         cmp     al, 0
  40.         jnz     @b
  41.         popa
  42.         ret
  43.  
  44. ; Now int 16 is used for keyboard support.
  45. ; This is shorter, simpler and more reliable.
  46. if 0
  47. getkey:      push  ecx
  48.              push  edx
  49.              add   ebx,0x0101
  50.              xor   eax,eax
  51.  
  52.            gk1:
  53.              in    al,0x60
  54.              mov   cl,al
  55.            gk0:
  56.              in    al,0x60
  57.              cmp   al,cl
  58.              je    gk0
  59.              cmp   ax,11
  60.              jg    gk0
  61.              gk0_1:
  62.              mov   cl,al
  63.  
  64. ;             add   al,47
  65. ;             mov   [ds:keyinbs-0x10000],al
  66. ;             mov   si,keyinbs-0x10000
  67. ;             call  printplain
  68.  
  69.            gk12:
  70.              in    al,0x60
  71.              cmp   al,cl
  72.              je    gk12
  73.              cmp   ax,240
  74.              jne   gk13
  75.              mov   al,cl
  76.              jmp   gk14
  77.            gk13:
  78.              add   cl,128
  79.              cmp   al,cl
  80.              jne   gk1
  81.              sub   al,128
  82.            gk14:
  83.  
  84.              movzx edx,bl
  85.              cmp   eax,edx
  86.              jb    gk1
  87.              movzx edx,bh
  88.              cmp   eax,edx
  89.              jg    gk1
  90.              test  ebx,0x010000
  91.              jnz   gk3
  92.              mov   cx,0x1000
  93.              mov   dx,cx
  94.              add   eax,47
  95.              mov   cx,ax
  96.              cmp   cx,58
  97.              jb    gk_nozero
  98.              sub   cx,10
  99.            gk_nozero:
  100.              mov   [ds:keyin-0x10000],cl
  101.              mov   si,keyin-0x10000
  102.              call  printplain
  103.            gk3:
  104.              sub   eax,48
  105.              pop   edx
  106.              pop   ecx
  107.              ret
  108. end if
  109.  
  110. getkey:
  111. ; get number in range [bl,bh] (bl,bh in ['0'..'9'])
  112. ; in: bx=range
  113. ; out: ax=digit (1..9, 10 for 0)
  114.         mov     ah, 0
  115.         int     16h
  116.         cmp     al, bl
  117.         jb      getkey
  118.         cmp     al, bh
  119.         ja      getkey
  120.         push    ax
  121.         call    putchar
  122.         pop     ax
  123.         and     ax, 0Fh
  124.         jnz     @f
  125.         mov     al, 10
  126. @@:
  127.         ret
  128.  
  129. setcursor:
  130. ; in: dl=column, dh=row
  131.         mov     ah, 2
  132.         mov     bh, 0
  133.         int     10h
  134.         ret
  135.  
  136. macro _setcursor row,column
  137. {
  138.         mov     dx, row*256 + column
  139.         call    setcursor
  140. }
  141.  
  142. pagetable_set:
  143.         or      al, 7
  144. @@:
  145.         stosd
  146.         add     eax, 1000h
  147.         loop    @b
  148.         ret
  149.  
  150. ; 16-bit data
  151. ; videomodes table
  152. gr_table:
  153.         dw      0x112+0100000000000000b ,  640 ,  480           ; 1
  154.         dw      0x115+0100000000000000b ,  800 ,  600           ; 2
  155.         dw      0x118+0100000000000000b , 1024 ,  768           ; 3
  156.         dw      0x11B+0100000000000000b , 1280 , 1024           ; 4
  157.         dw      0x112 ,  640 , 480                              ; 5
  158.         dw      0x115 ,  800 , 600                              ; 6
  159.         dw      0x118 , 1024 , 768                              ; 7
  160.         dw      0x11B , 1280 ,1024                              ; 8
  161.         dw      0x13, 320, 200                                  ; 9
  162.         dw      0x12, 640, 480                                  ; 0
  163.  
  164. ; table for move to extended memory (int 15h, ah=87h)
  165.        movedesc:
  166.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  167.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  168.  
  169.         db      0xff,0xff,0x0,0xa0,0x00,0x93,0x0,0x0
  170.         db      0xff,0xff,0x0,0x00,0x10,0x93,0x0,0x0
  171.  
  172.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  173.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  174.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  175.         db      0x00,0x00,0x0,0x00,0x00,0x00,0x0,0x0
  176.  
  177. ;=========================================================================
  178. ;
  179. ;                           16 BIT CODE
  180. ;
  181. ;=========================================================================
  182.  
  183.  
  184. start_of_code:
  185.         cld
  186. ; \begin{diamond}[02.12.2005]
  187.         cmp     ax, 'KL'
  188.         jnz     @f
  189.         mov     word [cs:cfgmanager.loader_block-0x10000], si
  190.         mov     word [cs:cfgmanager.loader_block+2-0x10000], ds
  191. @@:
  192. ; \end{diamond}[02.12.2005]
  193.  
  194. ; set up stack
  195.         mov     ax, 3000h
  196.         mov     ss, ax
  197.         mov     sp, 0EC00h
  198. ; set up segment registers
  199.         push    cs
  200.         pop     ds
  201.         push    cs
  202.         pop     es
  203.  
  204. ; set videomode
  205.         mov     ax, 3
  206.         int  0x10
  207.  
  208.  ; Load & set russian VGA font (RU.INC)
  209.         mov  bp,RU_FNT1-10000h   ; RU_FNT1 - First part
  210.           mov  bx,1000h            ; 768 bytes
  211.           mov  cx,30h              ; 48 symbols
  212.           mov  dx,80h              ; 128 - position of first symbol
  213.         mov  ax,1100h
  214.           int  10h
  215.  
  216.         mov  bp,RU_FNT2-10000h   ; RU_FNT2 -Second part
  217.         mov  bx,1000h            ; 512 bytes
  218.         mov  cx,20h              ; 32 symbols
  219.         mov  dx,0E0h             ; 224 - position of first symbol
  220.         mov  ax,1100h
  221.           int  10h
  222.  ; End set VGA russian font
  223.  
  224. ; draw frames
  225.         push    0xb800
  226.         pop     es
  227.         xor     di, di
  228. ;        mov  si,d80x25-0x10000
  229. ;        mov  cx,80*25
  230. ;        mov  ah,1*16+15
  231. ;       dfl1:
  232. ;        lodsb
  233. ;        stosw
  234. ;        loop dfl1
  235.         mov     ah, 1*16+15
  236. ; draw top
  237.         mov     si, d80x25_top - 0x10000
  238.         mov     cx, d80x25_top_num * 80
  239. @@:
  240.         lodsb
  241.         stosw
  242.         loop    @b
  243. ; draw spaces
  244.         mov     si, space_msg - 0x10000
  245.         mov     cx, 25 - d80x25_top_num - d80x25_bottom_num
  246. dfl1:
  247.         push    cx
  248.         push    si
  249.         mov     cx, 80
  250. @@:
  251.         lodsb
  252.         stosw
  253.         loop    @b
  254.         pop     si
  255.         pop     cx
  256.         loop    dfl1
  257. ; draw bottom
  258.         mov     si, d80x25_bottom - 0x10000
  259.         mov     cx, d80x25_bottom_num * 80
  260. @@:
  261.         lodsb
  262.         stosw
  263.         loop    @b
  264.  
  265.         mov     byte [space_msg-0x10000+80], 0  ; now space_msg is null terminated
  266.  
  267.         _setcursor d80x25_top_num,0
  268.  
  269.  
  270. ; TEST FOR 386+
  271.  
  272.         mov     bx, 0x4000
  273.         pushf
  274.         pop     ax
  275.         mov     dx,ax
  276.         xor     ax,bx
  277.         push    ax
  278.         popf
  279.         pushf
  280.         pop     ax
  281.         and     ax,bx
  282.         and     dx,bx
  283.         cmp     ax,dx
  284.         jnz     cpugood
  285.         mov     si,not386-0x10000
  286. sayerr:
  287.         call    print
  288.         jmp     $
  289.      cpugood:
  290.  
  291. ; set up esp
  292.         movzx   esp, sp
  293.  
  294. ; FLUSH 8042 KEYBOARD CONTROLLER
  295.  
  296. ;// mike.dld [
  297.  ;       mov     al,0xED
  298.  ;       out     0x60,al
  299.  ;       or      cx,-1
  300.  ;     @@:
  301.  ;       in      al,0x64
  302.  ;       test    al,2
  303.  ;       jz      @f
  304.  ;       loop    @b
  305.  ;     @@:
  306.  ;       mov     al,0
  307.  ;       out     0x60,al
  308.  ;       or      cx,-1
  309.  ;     @@:
  310.  ;       in      al,0x64
  311.  ;       test    al,2
  312.  ;       jz      @f
  313.  ;       loop    @b
  314.  ;     @@:
  315. ;// mike.dld ]
  316.  
  317. ;       mov     ecx,10000
  318. ;      fl1:
  319. ;       in      al,0x64
  320. ;       loop    fl1
  321. ;       test    al,1
  322. ;       jz      fl2
  323. ;       in      al,0x60
  324. ;       jmp     fl1
  325. ;      fl2:
  326.  
  327. ;****************************************************************
  328. ; The function is modified Mario79
  329. ;*****************************************************************
  330. ; wait_kbd:        ; variant 1
  331. ;       mov      cx,2500h  ;çàäåðæêà ïîðÿäêà 10 ìñåê
  332. ; test_kbd:
  333. ;       in       al,64h    ;÷èòàåì ñîñòîÿíèå êëàâèàòóðû
  334. ;       test     al,2      ;ïðîâåðêà áèòà ãîòîâíîñòè
  335. ;       loopnz   test_kbd
  336.  
  337.     mov   al,0xf6         ; Ñáðîñ êëàâèàòóðû, ðàçðåøèòü ñêàíèðîâàíèå
  338.     out   0x60,al
  339.     xor   cx,cx
  340. wait_loop:       ; variant 2
  341. ; reading state of port of 8042 controller
  342.         in      al,64h
  343.         and     al,00000010b  ; ready flag
  344. ; wait until 8042 controller is ready
  345.         loopnz  wait_loop
  346.  
  347. ; DISPLAY VESA INFORMATION
  348.  
  349.         push    0
  350.         pop     es
  351.         mov     ax,0x4f00
  352.         mov     di,0xa000
  353.         int     0x10
  354.         cmp     ax,0x004f
  355.         mov     si, novesa-0x10000
  356.         jnz     @f
  357.         mov     ax,[es:di+4]
  358.         add     ax,'0'*256+'0'
  359.         mov     si,vervesa-0x10000
  360.         mov     [si+vervesa_off], ah
  361.         mov     [si+vervesa_off+2], al
  362. @@:     call    print
  363.  
  364. ; \begin{diamond}[30.11.2005]
  365. cfgmanager:
  366. ; settings:
  367. ; a) preboot_graph = graphical mode
  368. ;    preboot_gprobe = probe this mode?
  369. ; b) preboot_mtrr = use hardware acceleration?
  370. ; c) preboot_vrrm = use VRR?
  371. ; d) preboot_device = from what boot?
  372.         mov     di, preboot_graph-0x10000
  373. ; check bootloader block
  374.         cmp     [.loader_block-0x10000], 0
  375.         jz      .noloaderblock
  376.         les     bx, [.loader_block-0x10000]
  377.         cmp     byte [es:bx], 1
  378.         mov     si, loader_block_error-0x10000
  379.         jnz     sayerr
  380.         test    byte [es:bx+1], 1
  381.         jz      @f
  382. ; image in memory present
  383.         cmp     [di+preboot_device-preboot_graph], 0
  384.         jnz     @f
  385.         mov     [di+preboot_device-preboot_graph], 3
  386. @@:
  387. .noloaderblock:
  388. ; determine default settings
  389.         mov     [.bSettingsChanged-0x10000], 0
  390.         cmp     byte [di], 0
  391.         jnz     .preboot_gr_end
  392.         mov     [di+preboot_gprobe-preboot_graph], 0
  393.         mov     al, [vervesa+vervesa_off-0x10000]
  394.         cmp     al, 'x'
  395.         jz      .novesa
  396.         cmp     al, '1'
  397.         jz      .vesa12
  398.         mov     [di+preboot_gprobe-preboot_graph], 2
  399.         mov     al, 3
  400.         jmp     @f
  401. .vesa12:
  402.         mov     al, 7
  403.         jmp     @f
  404. .novesa:
  405.         mov     al, 10
  406. @@:
  407.         mov     [di], al
  408. .preboot_gr_end:
  409.         cmp     [di+preboot_mtrr-preboot_graph], 1
  410.         adc     [di+preboot_mtrr-preboot_graph], 0
  411.         cmp     [di+preboot_vrrm-preboot_graph], 1
  412.         adc     [di+preboot_vrrm-preboot_graph], 0
  413.         cmp     [di+preboot_device-preboot_graph], 1
  414.         adc     [di+preboot_device-preboot_graph], 0
  415. ; notify user
  416.         mov     si, linef-0x10000
  417.         call    print
  418.         mov     si, start_msg-0x10000
  419.         call    print
  420.         mov     si, time_msg-0x10000
  421.         call    print
  422. ; get start time
  423.         call    .gettime
  424.         mov     [.starttime-0x10000], eax
  425.         mov     word [.timer-0x10000], .newtimer-0x10000
  426.         mov     word [.timer-0x10000+2], cs
  427. .printcfg:
  428.         _setcursor 9,0
  429.         mov     si, current_cfg_msg-0x10000
  430.         call    print
  431.         mov     si, curvideo_msg-0x10000
  432.         call    print
  433.         mov     al, [preboot_graph-0x10000]
  434.         cmp     al, 8
  435.         ja      .pnovesa
  436.         mov     dl, al
  437.         and     eax, 3
  438.         mov     si, [modes_msg-0x10000+eax*2]
  439.         call    printplain
  440.         mov     si, modevesa20-0x10000
  441.         cmp     dl, 4
  442.         jbe     @f
  443.         mov     si, modevesa12-0x10000
  444. @@:
  445.         call    printplain
  446.         cmp     dl, 4
  447.         ja      .x
  448.         mov     si, probeno_msg-0x10000
  449.         cmp     [preboot_gprobe-0x10000], 2
  450.         jnz     @f
  451.         mov     si, probeok_msg-0x10000
  452. @@:
  453.         call    printplain
  454. .x:
  455.         jmp     .c
  456. .pnovesa:
  457.         cmp     al, 9
  458.         mov     si, mode9-0x10000
  459.         jz      @b
  460.         mov     si, mode10-0x10000
  461.         jmp     @b
  462. .c:
  463.         mov     si, linef-0x10000
  464.         call    printplain
  465.         mov     si, mtrr_msg-0x10000
  466.         cmp     [preboot_mtrr-0x10000], 1
  467.         call    .say_on_off
  468.         mov     si, vrrm_msg-0x10000
  469.         cmp     [preboot_vrrm-0x10000], 1
  470.         call    .say_on_off
  471.         mov     si, preboot_device_msg-0x10000
  472.         call    print
  473.         mov     al, [preboot_device-0x10000]
  474.         and     eax, 3
  475.         mov     si, [preboot_device_msgs-0x10000+eax*2]
  476.         call    printplain
  477. .wait:
  478.         _setcursor 25,0         ; out of screen
  479. ; set timer interrupt handler
  480.         cli
  481.         push    0
  482.         pop     es
  483.         mov     eax, [es:8*4]
  484.         mov     [.oldtimer-0x10000], eax
  485.         mov     eax, [.timer-0x10000]
  486.         mov     [es:8*4], eax
  487.         sti
  488. ; wait for keypressed
  489.         mov     ah, 0
  490.         int     16h
  491.         push    ax
  492. ; restore timer interrupt
  493.         push    0
  494.         pop     es
  495.         mov     eax, [.oldtimer-0x10000]
  496.         mov     [es:8*4], eax
  497.         mov     [.timer-0x10000], eax
  498.         _setcursor 7,0
  499.         mov     si, space_msg-0x10000
  500.         call    printplain
  501.         pop     ax
  502. ; switch on key
  503.         cmp     al, 13
  504.         jz      .continue
  505.         or      al, 20h
  506.         cmp     al, 'a'
  507.         jz      .change_a
  508.         cmp     al, 'b'
  509.         jz      .change_b
  510.         cmp     al, 'c'
  511.         jz      .change_c
  512.         cmp     al, 'd'
  513.         jnz     .wait
  514.         _setcursor 15,0
  515.         mov     si,bdev-0x10000
  516.         call    print
  517.         mov     bx,'13'
  518.         call    getkey
  519.         mov     [preboot_device-0x10000], al
  520.         _setcursor 13,0
  521. .d:
  522.         mov     [.bSettingsChanged-0x10000], 1
  523.         mov     si, space_msg-0x10000
  524.         call    printplain
  525.         _setcursor 15,0
  526.         mov     cx, 6
  527. @@:
  528.         call    printplain
  529.         loop    @b
  530.         jmp     .printcfg
  531. .change_a:
  532.         _setcursor 15,0
  533.         mov     si, gr_mode-0x10000
  534.         call    printplain
  535.         mov     bx, '09'
  536.         call    getkey
  537.         mov     [preboot_graph-0x10000], al
  538.         cmp     al, 4
  539.         ja      @f
  540.         mov     si, probetext-0x10000
  541.         call    printplain
  542.         mov     bx, '12'
  543.         call    getkey
  544.         mov     [preboot_gprobe-0x10000], al
  545. @@:
  546.         _setcursor 10,0
  547.         jmp     .d
  548. .change_b:
  549.         _setcursor 15,0
  550.         mov     si, gr_acc-0x10000
  551.         call    print
  552.         mov     bx, '12'
  553.         call    getkey
  554.         mov     [preboot_mtrr-0x10000], al
  555.         _setcursor 11,0
  556.         jmp     .d
  557. .change_c:
  558.         _setcursor 15,0
  559.         mov     si, vrrmprint-0x10000
  560.         call    print
  561.         mov     bx, '12'
  562.         call    getkey
  563.         mov     [preboot_vrrm-0x10000], al
  564.         _setcursor 12,0
  565.         jmp     .d
  566. .say_on_off:
  567.         pushf
  568.         call    print
  569.         mov     si, on_msg-0x10000
  570.         popf
  571.         jz      @f
  572.         mov     si, off_msg-0x10000
  573. @@:     call    printplain
  574.         ret
  575. ; novesa and vervesa strings are not used at the moment of executing this code
  576. virtual at novesa
  577. .oldtimer dd ?
  578. .starttime dd ?
  579. .bSettingsChanged db ?
  580. .timer dd ?
  581. end virtual
  582. .loader_block dd 0
  583. .gettime:
  584.         mov     ah, 0
  585.         int     1Ah
  586.         xchg    ax, cx
  587.         shl     eax, 10h
  588.         xchg    ax, dx
  589.         ret
  590. .newtimer:
  591.         push    ds
  592.         push    cs
  593.         pop     ds
  594.         pushf
  595.         call    [.oldtimer-0x10000]
  596.         pushad
  597.         call    .gettime
  598.         sub     eax, [.starttime-0x10000]
  599.         sub     ax, 18*5
  600.         jae     .timergo
  601.         neg     ax
  602.         add     ax, 18-1
  603.         mov     bx, 18
  604.         xor     dx, dx
  605.         div     bx
  606. if lang eq ru
  607. ; ¯®¤®¦¤¨â¥ 5 ᥪ㭤, 4/3/2 ᥪ㭤ë, 1 ᥪ㭤ã
  608.         cmp     al, 5
  609.         mov     cl, ' '
  610.         jae     @f
  611.         cmp     al, 1
  612.         mov     cl, 'ã'
  613.         jz      @f
  614.         mov     cl, 'ë'
  615. @@:     mov     [time_str+9-0x10000], cl
  616. else
  617. ; wait 5/4/3/2 seconds, 1 second
  618.         cmp     al, 1
  619.         mov     cl, 's'
  620.         ja      @f
  621.         mov     cl, ' '
  622. @@:     mov     [time_str+9-0x10000], cl
  623. end if
  624.         add     al, '0'
  625.         mov     [time_str+1-0x10000], al
  626.         mov     si, time_msg-0x10000
  627.         _setcursor 7,0
  628.         call    print
  629.         _setcursor 25,0
  630.         popad
  631.         pop     ds
  632.         iret
  633. .timergo:
  634.         push    0
  635.         pop     es
  636.         mov     eax, [.oldtimer-0x10000]
  637.         mov     [es:8*4], eax
  638.         mov     sp, 0EC00h
  639. .continue:
  640.         sti
  641.         _setcursor 6,0
  642.         mov     si, space_msg-0x10000
  643.         call    printplain
  644.         call    printplain
  645.         _setcursor 6,0
  646.         mov     si, loading_msg-0x10000
  647.         call    print
  648.         _setcursor 15,0
  649.         cmp     [.bSettingsChanged-0x10000], 0
  650.         jz      .load
  651.         cmp     [.loader_block-0x10000], 0
  652.         jz      .load
  653.         les     bx, [.loader_block-0x10000]
  654.         mov     eax, [es:bx+3]
  655.         push    ds
  656.         pop     es
  657.         test    eax, eax
  658.         jz      .load
  659.         push    eax
  660.         mov     si, save_quest-0x10000
  661.         call    print
  662. .waityn:
  663.         mov     ah, 0
  664.         int     16h
  665.         or      al, 20h
  666.         cmp     al, 'n'
  667.         jz      .loadc
  668.         cmp     al, 'y'
  669.         jnz     .waityn
  670.         call    putchar
  671.         mov     byte [space_msg-0x10000+80], 186
  672.         pop     eax
  673.         push    cs
  674.         push    .cont-0x10000
  675.         push    eax
  676.         retf
  677. .loadc:
  678.         pop     eax
  679. .cont:
  680.         push    cs
  681.         pop     ds
  682.         mov     si, space_msg-0x10000
  683.         mov     byte [si+80], 0
  684.         _setcursor 15,0
  685.         call    printplain
  686.         _setcursor 15,0
  687. .load:
  688. ; \end{diamond}[02.12.2005]
  689.  
  690. ; ASK GRAPHICS MODE
  691.  
  692.         movzx   ax, [preboot_graph-0x10000]
  693.         push    0
  694.         pop     es
  695. ; address is gr_table+6*(ax-1)-0x10000
  696.         add     ax, ax
  697.         lea     si, [gr_table-0x10000 + eax + eax*2 - 6]
  698.         mov     bx,[si+0]
  699.         mov     cx,[si+2]
  700.         mov     dx,[si+4]
  701.         cmp     al, 9*2
  702.         mov     al, 32  ; BPP
  703.         jb      @f
  704.         mov     [es:0x9000], al
  705.         mov     dword [es:0x9018], 0x800000
  706.        @@:
  707.         mov     [es:0x9008],bx
  708.         mov     [es:0x900A],cx
  709.         mov     [es:0x900C],dx
  710.         test    bh, bh
  711.         jz      nov
  712.  
  713. ; USE DEFAULTS OR PROBE
  714.  
  715. ; bx - mode : cx - x size : dx - y size
  716.         cmp     [preboot_gprobe-0x10000], 1
  717.         jz      noprobe
  718.  
  719.         mov     bx,0x100
  720.      newprobe:
  721.         inc     bx
  722.         cmp     bx,0x17f
  723.         mov     si,prnotfnd-0x10000
  724.         jz      sayerr
  725.  
  726.      probemore:
  727.         push    cx
  728.         mov     ax,0x4f01
  729.         mov     cx,bx
  730.         and     cx,0xfff
  731.         mov     di,0xa000
  732.         int     0x10
  733.         pop     cx
  734.  
  735.         test    byte [es:di], 80h       ; lfb?
  736.         jz      newprobe
  737.         cmp     [es:di+0x12], cx        ; x size?
  738.         jnz     newprobe
  739.         cmp     [es:di+0x14], dx        ; y size?
  740.         jnz     newprobe
  741.         cmp     byte [es:di+0x19], 32 ;24
  742.         jb      newprobe
  743.  
  744. ;       add     bx,0100000000000000b
  745.         or      bh, 40h
  746.         mov     [es:0x9008],bx
  747.  
  748.      noprobe:
  749.  
  750.  
  751. ; FIND VESA 2.0 LFB & BPP
  752.  
  753.         mov     ax,0x4f01
  754.         mov     cx,bx
  755.         and     cx,0xfff
  756.         mov     di,0xa000
  757.         int     0x10
  758.         ; LFB
  759.         mov     eax,[es:di+0x28]
  760.         mov     [es:0x9018],eax
  761.         ; ---- vbe voodoo
  762.         BytesPerScanLine equ 0x10
  763.         mov ax, [es:di+BytesPerScanLine]
  764.         mov [es:0x9001],ax
  765.         ; BPP
  766.         mov     al,byte [es:di+0x19]
  767.         mov     [es:0x9000],al
  768.        nov:
  769.         cmp     al,24
  770.         mov     si,bt24-0x10000
  771.         jz      bppl
  772.         cmp     al,32
  773.         mov     si,bt32-0x10000
  774.         jz     bppl
  775.         mov     si,btns-0x10000
  776.         jmp     sayerr
  777.        bppl:
  778.         call    print
  779.  
  780.  
  781. ; FIND VESA 1.2 PM BANK SWITCH ADDRESS
  782.  
  783.         push    es
  784.         mov     ax,0x4f0A
  785.         xor     bx, bx
  786.         int     0x10
  787.         xor     eax,eax
  788.         mov     ax,es
  789.         shl     eax,4
  790.         movzx   ebx,di
  791.         add     eax,ebx
  792.         mov     bx,[es:di]
  793.         add     eax,ebx
  794.         pop     es
  795.         mov     [es:0x9014],eax
  796.  
  797.  
  798. ; GRAPHICS ACCELERATION
  799.  
  800.         mov     al, [preboot_mtrr-0x10000]
  801.         mov     [es:0x901C],al
  802.  
  803. ; VRR_M USE
  804.  
  805.         mov     al,[preboot_vrrm-0x10000]
  806.         mov     [es:0x9030],al
  807.  
  808.  
  809. ; MEMORY MODEL
  810.  
  811. ;        movzx   eax,byte [es:preboot_memory-0x10000]
  812. ;        cmp     eax,0
  813. ;        jne     pre_mem
  814. ;;;;;;;;;;;;;;;;;;;;;;;;;
  815. ; mario79 - memory size ;
  816. ;;;;;;;;;;;;;;;;;;;;;;;;;
  817. ;           mov ax,0E801h
  818. ;;;           xor bx,bx    ; thanks to Alexei for bugfix [18.07.2004]
  819. ;           xor cx, cx
  820. ;           xor dx, dx
  821. ;           int 0x15
  822. ;           movzx ebx, dx ;bx
  823. ;           movzx eax, cx ;ax
  824. ;           shl   ebx,6   ; ïåðåâîä â êèëîáàéòû (x64)
  825. ;           add   eax,ebx
  826. ;           add eax, 1000h ;440h
  827. ;           cmp eax,40000h ; 256?
  828. ;           jge mem_256_z
  829. ;           cmp eax,20000h ; 128?
  830. ;           jge mem_128_z
  831. ;           cmp eax,10000h ; 64?
  832. ;           jge mem_64_z
  833. ;           cmp eax,8000h ; 32?
  834. ;           jge mem_32_z
  835. ;           jmp mem_16_z
  836. ;
  837. ;mem_256_z: mov     si,memokz256-0x10000
  838. ;           call    printplain
  839. ;           mov eax,5
  840. ;           jmp pre_mem
  841. ;mem_128_z: mov     si,memokz128-0x10000
  842. ;           call    printplain
  843. ;           mov eax,4
  844. ;           jmp pre_mem
  845. ;mem_64_z:  mov     si,memokz64-0x10000
  846. ;           call    printplain
  847. ;           mov eax,3
  848. ;           jmp pre_mem
  849. ;mem_32_z:  mov     si,memokz32-0x10000
  850. ;           call    printplain
  851. ;           mov eax,2
  852. ;           jmp pre_mem
  853. ;mem_16_z:  mov     si,memokz16-0x10000
  854. ;           call    printplain
  855. ;           mov eax,1
  856. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  857. ;      pre_mem:
  858. ;        push    word 0x0000
  859. ;        pop     es
  860. ;        mov     [es:0x9030],al
  861. ;        push    word 0x1000
  862. ;        pop     es
  863. ;        mov     si,linef-0x10000
  864. ;        call    printplain
  865.  
  866.  
  867.  
  868.  
  869. ; DIRECT WRITE TO LFB, PAGING DISABLED
  870.  
  871. ;        movzx   eax,byte [es:preboot_lfb-0x10000]
  872. ;        mov     eax,1                             ; paging disabled
  873. ;        cmp     eax,0
  874. ;        jne     pre_lfb
  875. ;        mov     si,gr_direct-0x10000
  876. ;        call    printplain
  877. ;        mov     ebx,'12'
  878. ;        call    getkey
  879. ;      pre_lfb:
  880. ;        push    word 0x0000
  881. ;        pop     es
  882. ;        mov     [es:0x901E],al
  883. ;        mov     ax,0x1000
  884. ;        mov     es,ax
  885. ;        mov     si,linef-0x10000
  886. ;        call    printplain
  887.         mov     [es:0x901E],byte 1
  888.  
  889.  
  890.  
  891. ; BOOT DEVICE
  892.  
  893.         mov     al, [preboot_device-0x10000]
  894.         dec     al
  895.         mov     [boot_dev-0x10000],al
  896.  
  897. ; READ DISKETTE TO MEMORY
  898.  
  899. ;        cmp     [boot_dev-0x10000],0
  900.         jne     no_sys_on_floppy
  901.         mov     si,diskload-0x10000
  902.         call    print
  903.         xor     ax, ax                  ; reset drive
  904.         xor     dx, dx
  905.         int     0x13
  906.         mov     cx,0x0001               ; startcyl,startsector
  907.         xor     dx, dx                  ; starthead,drive
  908.         push    word 80*2               ; read no of sect
  909.        reads:
  910.         pusha
  911.         xor     si,si
  912.        newread:
  913.         mov     bx,0xa000               ; es:bx -> data area
  914.         mov     ax,0x0200+18            ; read, no of sectors to read
  915.         int     0x13
  916.         test    ah, ah
  917.         jz      goodread
  918.         inc     si
  919.         cmp     si,10
  920.         jnz     newread
  921.         mov     si,badsect-0x10000
  922. sayerr_plain:
  923.         call    printplain
  924.         jmp     $
  925.        goodread:
  926.         ; move -> 1mb
  927.         mov     si,movedesc-0x10000
  928.         push    es
  929.         push    ds
  930.         pop     es
  931.         mov     cx,256*18
  932.         mov     ah,0x87
  933.         int     0x15
  934.         pop     es
  935.  
  936.         test    ah,ah                  ; was the move successfull ?
  937.         je      goodmove
  938.         mov     dx,0x3f2              ; floppy motor off
  939.         mov     al,0
  940.         out     dx,al
  941.         mov     si,memmovefailed-0x10000
  942.         jmp     sayerr_plain
  943.       goodmove:
  944.  
  945.         add     dword [movedesc-0x10000+0x18+2], 512*18
  946.         popa
  947.         inc     dh
  948.         cmp     dh,2
  949.         jnz     bb2
  950.         mov     dh,0
  951.         inc     ch
  952.         pusha                        ; print prosentage
  953.         mov     si,pros-0x10000
  954.         shr     ch, 2
  955.         mov     al, '5'
  956.         test    ch, 1
  957.         jnz     @f
  958.         mov     al, '0'
  959. @@:
  960.         mov     [si+1], al
  961.         shr     ch, 1
  962.         add     ch, '0'
  963.         mov     [si], ch
  964.         call    printplain
  965.         popa
  966.        bb2:
  967.         pop     ax
  968.         dec     ax
  969.         push    ax
  970.         jnz     reads
  971.        readdone:
  972.         pop     ax
  973.         mov     si,backspace2-0x10000
  974.         call    printplain
  975.         mov     si,okt-0x10000
  976.         call    printplain
  977.        no_sys_on_floppy:
  978.         xor     ax, ax          ; reset drive
  979.         xor     dx, dx
  980.         int     0x13
  981.        mov dx,0x3f2 ; floppy motor off
  982.        mov al,0
  983.        out dx,al
  984.  
  985.         push    es
  986. ; PAGE TABLE
  987.  
  988.         push    dword [es:0x9018]
  989.  
  990.         map_mem equ 64                ; amount of memory to map
  991.  
  992.         push    0x6000
  993.         pop     es                    ; es:di = 6000:0
  994.         xor     di,di
  995.         mov     cx,256*map_mem         ; Map (mapmem) M
  996. ;        mov     eax,7
  997. ;       pt2:
  998. ;        cmp     cx,256*(map_mem-8)     ; 8 M map to LFB
  999. ;        jnz     pt3
  1000. ;        pop     eax
  1001. ;        add     eax,7
  1002. ;       pt3:
  1003. ;        cmp     cx,256*(map_mem-12)    ; 12 M back to linear = physical
  1004. ;        jnz     pt4
  1005. ;        mov     eax,12*0x100000 + 7
  1006. ;       pt4:
  1007. ;        stosd
  1008. ;        add     eax,4096
  1009. ;        loop    pt2
  1010. ; initialize as identity mapping
  1011.         xor     eax, eax
  1012.         call    pagetable_set
  1013. ; 8M..12M map to LFB
  1014.         pop     eax
  1015. ;       mov     cx, 256*4
  1016.         mov     ch, 4
  1017.         mov     di, 2000h
  1018.         call    pagetable_set
  1019.  
  1020.         push    0x7100
  1021.         pop     es
  1022.         xor     di,di
  1023.         mov     eax,8*0x100000
  1024.         mov     cx,256*4
  1025.         call    pagetable_set
  1026.        
  1027. ; 4 KB PAGE DIRECTORY
  1028.  
  1029.         push    0x7F00
  1030.         pop     es                ; es:di = 7F00:0
  1031.         xor     di, di
  1032.         mov     cx, 64 / 4
  1033.         mov     eax, 0x60007            ; for 0 M
  1034.         call    pagetable_set
  1035.         mov     dword [es:0x800],0x71007   ;map region 0x80000000-0x803FFFFF to 0x800000-0xCFFFFF
  1036.         xor     si,si
  1037.         mov     di,second_base_address shr 20
  1038.         mov     cx,64/2
  1039.         rep     movs word [es:di], [es:si]
  1040.        
  1041.         mov     eax, 0x7F000 +8+16      ; Page directory and enable caches
  1042.         mov     cr3, eax
  1043.  
  1044. ; SET GRAPHICS
  1045.  
  1046.         pop     es
  1047.         mov     ax,[es:0x9008]          ; vga & 320x200
  1048.         mov     bx, ax
  1049.         cmp     ax,0x13
  1050.         je      setgr
  1051.         cmp     ax,0x12
  1052.         je      setgr
  1053.         mov     ax,0x4f02            ; Vesa
  1054.        setgr:
  1055.         int     0x10
  1056.         test    ah,ah
  1057.         mov     si, fatalsel-0x10000
  1058.         jnz     sayerr
  1059. ; set mode 0x12 graphics registers:
  1060.         cmp     bx,0x12
  1061.         jne     gmok2
  1062.  
  1063.         mov     al,0x05
  1064.         mov     dx,0x03ce
  1065.         push    dx
  1066.         out     dx,al      ; select GDC mode register
  1067.         mov     al,0x02
  1068.         inc     dx
  1069.         out     dx,al      ; set write mode 2
  1070.  
  1071.         mov     al,0x02
  1072.         mov     dx,0x03c4
  1073.         out     dx,al      ; select VGA sequencer map mask register
  1074.         mov     al,0x0f
  1075.         inc     dx
  1076.         out     dx,al      ; set mask for all planes 0-3
  1077.  
  1078.         mov     al,0x08
  1079.         pop     dx
  1080.         out     dx,al      ; select GDC bit mask register
  1081.                            ; for writes to 0x03cf
  1082.  
  1083.        gmok2:
  1084.         push    ds
  1085.         pop     es
  1086.