Subversion Repositories Kolibri OS

Rev

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

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