Subversion Repositories Kolibri OS

Rev

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