Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2010. All rights reserved. ;;
  4. ;; Copyright (C) MenuetOS 2000-2004 Ville Mikael Turjanmaa      ;;
  5. ;; Distributed under terms of the GNU General Public License    ;;
  6. ;;                                                              ;;
  7. ;;  BOOTCODE.INC                                                ;;
  8. ;;                                                              ;;
  9. ;;  KolibriOS 16-bit loader,                                    ;;
  10. ;;                        based on bootcode for MenuetOS        ;;
  11. ;;                                                              ;;
  12. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  13.  
  14. $Revision: 2014 $
  15.  
  16.  
  17. ;==========================================================================
  18. ;
  19. ;                           16 BIT FUNCTIONS
  20. ;
  21. ;==========================================================================
  22.  
  23.  
  24. boot_read_floppy:
  25.         push    si
  26.         xor     si, si
  27.         mov     ah, 2   ; read
  28. @@:
  29.         push    ax
  30.         int     0x13
  31.         pop     ax
  32.         jnc     @f
  33.         inc     si
  34.         cmp     si, 10
  35.         jnb     $
  36. @@:
  37.         pop     si
  38.         ret
  39.  
  40. sayerr_plain:
  41. sayerr:
  42.         jmp     $
  43.  
  44.  
  45. ; convert abs. sector number (AX) to BIOS T:H:S
  46. ; sector number = (abs.sector%BPB_SecPerTrk)+1
  47. ; pre.track number = (abs.sector/BPB_SecPerTrk)
  48. ; head number = pre.track number%BPB_NumHeads
  49. ; track number = pre.track number/BPB_NumHeads
  50. ; Return: cl - sector number
  51. ;         ch - track number
  52. ;         dl - drive number (0 = a:)
  53. ;         dh - head number
  54. conv_abs_to_THS:
  55.         push    bx
  56.         mov     bx,word [BPB_SecPerTrk]
  57.         xor     dx,dx
  58.         div     bx
  59.         inc     dx
  60.         mov     cl, dl                          ; cl = sector number
  61.         mov     bx,word [BPB_NumHeads]
  62.         xor     dx,dx
  63.         div     bx
  64.         ; !!!!!!! ax = track number, dx = head number
  65.         mov     ch,al                           ; ch=track number
  66.         xchg    dh,dl                           ; dh=head number
  67.         mov     dl,0                            ; dl=0 (drive 0 (a:))
  68.         pop     bx
  69.         retn
  70. ; needed variables
  71. BPB_SecPerTrk   dw      0                       ; sectors per track
  72. BPB_NumHeads    dw      0                       ; number of heads
  73. BPB_FATSz16     dw      0                       ; size of FAT
  74. BPB_RootEntCnt  dw      0                       ; count of root dir. entries
  75. BPB_BytsPerSec  dw      0                       ; bytes per sector
  76. BPB_RsvdSecCnt  dw      0                       ; number of reserved sectors
  77. BPB_TotSec16    dw      0                       ; count of the sectors on the volume
  78. BPB_SecPerClus  db      0                       ; number of sectors per cluster
  79. BPB_NumFATs     db      0                       ; number of FAT tables
  80. abs_sector_adj  dw      0                       ; adjustment to make abs. sector number
  81. end_of_FAT      dw      0                       ; end of FAT table
  82. FirstDataSector dw      0                       ; begin of data
  83.  
  84. ;=========================================================================
  85. ;
  86. ;                           16 BIT CODE
  87. ;
  88. ;=========================================================================
  89.  
  90. include 'bootvesa.inc'                 ;Include source for boot vesa
  91.  
  92. start_of_code:
  93.         cld
  94. ; \begin{diamond}[02.12.2005]
  95. ; if bootloader sets ax = 'KL', then ds:si points to loader block
  96.         cmp     ax, 'KL'
  97.         jnz     @f
  98.         mov     word [cs:cfgmanager.loader_block], si
  99.         mov     word [cs:cfgmanager.loader_block+2], ds
  100. @@:
  101. ; \end{diamond}[02.12.2005]
  102.  
  103. ; if bootloader sets cx = 'HA' and dx = 'RD', then bx contains identifier of source hard disk
  104. ; (see comment to bx_from_load)
  105.         cmp     cx, 'HA'
  106.         jnz     no_hd_load
  107.         cmp     dx,'RD'
  108.         jnz     no_hd_load
  109.         mov     word [cs:bx_from_load], bx              ; {SPraid}[13.03.2007]
  110. no_hd_load:
  111.  
  112. ; set up stack
  113.         mov     ax, 3000h
  114.         mov     ss, ax
  115.         mov     sp, 0EC00h
  116. ; set up segment registers
  117.         push    cs
  118.         pop     ds
  119.         push    cs
  120.         pop     es
  121.  
  122. if 0
  123. ; set videomode
  124.         mov     ax, 3
  125.         int     0x10
  126.  
  127. ; draw frames
  128.         push    0xb800
  129.         pop     es
  130.         xor     di, di
  131.         mov     ah, 1*16+15
  132. end if
  133.  
  134. cpugood:
  135.  
  136.         push    0
  137.         popf
  138.         sti
  139.  
  140. ; set up esp
  141.         movzx   esp, sp
  142.  
  143.         push    0
  144.         pop     es
  145.         and     word [es:0x9031], 0
  146. ; \begin{Mario79}
  147. ; find HDD IDE DMA PCI device
  148. ; check for PCI BIOS
  149.         mov     ax, 0xB101
  150.         int     0x1A
  151.         jc      .nopci
  152.         cmp     edx, 'PCI '
  153.         jnz     .nopci
  154. ; find PCI class code
  155. ; class 1 = mass storage
  156. ; subclass 1 = IDE controller
  157. ; a) class 1, subclass 1, programming interface 0x80
  158.         mov     ax, 0xB103
  159.         mov     ecx, 1*10000h + 1*100h + 0x80
  160.         xor     si, si  ; device index = 0
  161.         int     0x1A
  162.         jnc     .found
  163. ; b) class 1, subclass 1, programming interface 0x8A
  164.         mov     ax, 0xB103
  165.         mov     ecx, 1*10000h + 1*100h + 0x8A
  166.         xor     si, si  ; device index = 0
  167.         int     0x1A
  168.         jnc     .found
  169. ; c) class 1, subclass 1, programming interface 0x85
  170.         mov     ax, 0xB103
  171.         mov     ecx, 1*10000h + 1*100h + 0x85
  172.         xor     si, si
  173.         int     0x1A
  174.         jc      .nopci
  175. .found:
  176. ; get memory base
  177.         mov     ax, 0xB10A
  178.         mov     di, 0x20        ; memory base is config register at 0x20
  179.         int     0x1A
  180.         jc      .nopci
  181.         and     cx, 0xFFF0      ; clear address decode type
  182.         mov     [es:0x9031], cx
  183. .nopci:
  184. ; \end{Mario79}
  185.  
  186. ; --------------- APM ---------------------
  187.         and     word [es:0x9044], 0     ; ver = 0.0 (APM not found)
  188.         mov     ax, 0x5300
  189.         xor     bx, bx
  190.         int     0x15
  191.         jc      apm_end                 ; APM not found
  192.         test    cx, 2
  193.         jz      apm_end                 ; APM 32-bit protected-mode interface not supported
  194.         mov     [es:0x9044], ax         ; Save APM Version
  195.         mov     [es:0x9046], cx         ; Save APM flags
  196.  
  197.         mov     ax, 0x5304              ; Disconnect interface
  198.         xor     bx, bx
  199.         int     0x15
  200.         mov     ax, 0x5303              ; Connect 32 bit mode interface
  201.         xor     bx, bx
  202.         int     0x15
  203.  
  204.         mov     [es:0x9040], ebx
  205.         mov     [es:0x9050], ax
  206.         mov     [es:0x9052], cx
  207.         mov     [es:0x9054], dx
  208.  
  209. apm_end:
  210.  
  211. ;CHECK current of code
  212.         cmp     [cfgmanager.loader_block], -1
  213.         jz      noloaderblock
  214.         les     bx, [cfgmanager.loader_block]
  215.         cmp     byte [es:bx], 1
  216.         jnz     sayerr
  217.         push    0
  218.         pop     es
  219.  
  220. noloaderblock:
  221. ; DISPLAY VESA INFORMATION
  222.          call    print_vesa_info
  223.          call    calc_vmodes_table
  224.          call    check_first_parm  ;check and enable cursor_pos
  225.  
  226. ; \begin{diamond}[30.11.2005]
  227. cfgmanager:
  228. ; settings:
  229. ; a) preboot_graph = graphical mode
  230. ;    preboot_gprobe = probe this mode?
  231. ; b) preboot_dma  = use DMA access?
  232. ; c) preboot_vrrm = use VRR?
  233. ; d) preboot_device = from what boot?
  234.  
  235. ; determine default settings
  236. ;        mov     [.bSettingsChanged], 0
  237.  
  238. ;.preboot_gr_end:
  239.         mov     di, preboot_device
  240. ; if image in memory is present and [preboot_device] is uninitialized,
  241. ; set it to use this preloaded image
  242.         cmp     byte [di], 0
  243.         jnz     .preboot_device_inited
  244.         cmp     [.loader_block], -1
  245.         jz      @f
  246.         les     bx, [.loader_block]
  247.         test    byte [es:bx+1], 1
  248.         jz      @f
  249.         mov     byte [di], 3
  250.         jmp     .preboot_device_inited
  251. @@:
  252. ; otherwise, set [preboot_device] to 1 (default value - boot from floppy)
  253.         mov     byte [di], 1
  254. .preboot_device_inited:
  255. ; following 4 lines set variables to 1 if its current value is 0
  256.         cmp     byte [di+preboot_dma-preboot_device], 1
  257.         adc     byte [di+preboot_dma-preboot_device], 0
  258.         cmp     byte [di+preboot_biosdisk-preboot_device], 1
  259.         adc     byte [di+preboot_biosdisk-preboot_device], 0
  260.  
  261. ;        pop     ax              ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ??
  262.         jmp     .continue
  263.  
  264. .loader_block dd -1
  265. .continue:
  266.         sti
  267.         jmp      .load
  268.  
  269. .loadc:
  270.         pop     eax
  271. .cont:
  272.         push    cs
  273.         pop     ds
  274. .load:
  275.  
  276. ; ASK GRAPHICS MODE
  277.  
  278.         call    set_vmode
  279.  
  280. ; GRAPHICS ACCELERATION
  281. ; force yes
  282.         mov     [es:0x901C], byte 1
  283.  
  284. ; DMA ACCESS TO HD
  285.  
  286.         mov     al, [preboot_dma]
  287.         mov     [es:0x901F], al
  288.  
  289. ; VRR_M USE
  290.  
  291.         mov     al,[preboot_vrrm]
  292.         mov     [es:0x9030], al
  293.         mov     [es:0x901E], byte 1
  294.  
  295. ; BOOT DEVICE
  296.  
  297.         mov     al, [preboot_device]
  298.         dec     al
  299.         mov     [boot_dev], al
  300.  
  301. ; GET MEMORY MAP
  302. include 'detect/biosmem.inc'
  303.  
  304. ; READ DISKETTE TO MEMORY
  305.  
  306.  
  307.  
  308. ; SET GRAPHICS
  309.  
  310.         xor     ax, ax
  311.         mov     es, ax
  312.  
  313.         mov     bx, [es:0x9008]         ; vga & 320x200
  314.         mov     ax, 0x4f02              ; Vesa
  315. setgr:
  316.         int     0x10
  317.         test    ah, ah
  318.         jnz     $
  319. gmok2:
  320.         push    ds
  321.         pop     es
  322.