Subversion Repositories Kolibri OS

Rev

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