Subversion Repositories Kolibri OS

Rev

Rev 2047 | Rev 3169 | 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: 3163 $
  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.  
  123. cpugood:
  124.  
  125.         push    0
  126.         popf
  127.         sti
  128.  
  129. ; set up esp
  130.         movzx   esp, sp
  131.  
  132.         push    0
  133.         pop     es
  134.         and     word [es:0x9031], 0
  135. ; \begin{Mario79}
  136. ; find HDD IDE DMA PCI device
  137. ; check for PCI BIOS
  138.         mov     ax, 0xB101
  139.         int     0x1A
  140.         jc      .nopci
  141.         cmp     edx, 'PCI '
  142.         jnz     .nopci
  143. ; find PCI class code
  144. ; class 1 = mass storage
  145. ; subclass 1 = IDE controller
  146. ; a) class 1, subclass 1, programming interface 0x80
  147.         mov     ax, 0xB103
  148.         mov     ecx, 1*10000h + 1*100h + 0x80
  149.         xor     si, si  ; device index = 0
  150.         int     0x1A
  151.         jnc     .found
  152. ; b) class 1, subclass 1, programming interface 0x8A
  153.         mov     ax, 0xB103
  154.         mov     ecx, 1*10000h + 1*100h + 0x8A
  155.         xor     si, si  ; device index = 0
  156.         int     0x1A
  157.         jnc     .found
  158. ; c) class 1, subclass 1, programming interface 0x85
  159.         mov     ax, 0xB103
  160.         mov     ecx, 1*10000h + 1*100h + 0x85
  161.         xor     si, si
  162.         int     0x1A
  163.         jc      .nopci
  164. .found:
  165. ; get memory base
  166.         mov     ax, 0xB10A
  167.         mov     di, 0x20        ; memory base is config register at 0x20
  168.         int     0x1A
  169.         jc      .nopci
  170.         and     cx, 0xFFF0      ; clear address decode type
  171.         mov     [es:0x9031], cx
  172. .nopci:
  173. ; \end{Mario79}
  174.  
  175. ; --------------- APM ---------------------
  176.         and     word [es:0x9044], 0     ; ver = 0.0 (APM not found)
  177.  if 0
  178.         mov     ax, 0x5300
  179.         xor     bx, bx
  180.         int     0x15
  181.         jc      apm_end                 ; APM not found
  182.         test    cx, 2
  183.         jz      apm_end                 ; APM 32-bit protected-mode interface not supported
  184.         mov     [es:0x9044], ax         ; Save APM Version
  185.         mov     [es:0x9046], cx         ; Save APM flags
  186.  
  187.         mov     ax, 0x5304              ; Disconnect interface
  188.         xor     bx, bx
  189.         int     0x15
  190.         mov     ax, 0x5303              ; Connect 32 bit mode interface
  191.         xor     bx, bx
  192.         int     0x15
  193.  
  194.         mov     [es:0x9040], ebx
  195.         mov     [es:0x9050], ax
  196.         mov     [es:0x9052], cx
  197.         mov     [es:0x9054], dx
  198.  
  199. apm_end:
  200. end if
  201.  
  202. ;CHECK current of code
  203.         cmp     [cfgmanager.loader_block], -1
  204.         jz      noloaderblock
  205.         les     bx, [cfgmanager.loader_block]
  206.         cmp     byte [es:bx], 1
  207.         jnz     sayerr
  208.         push    0
  209.         pop     es
  210.  
  211. noloaderblock:
  212. ; DISPLAY VESA INFORMATION
  213. ;         call    print_vesa_info
  214. ;         call    calc_vmodes_table
  215. ;         call    check_first_parm  ;check and enable cursor_pos
  216.  
  217. ; \begin{diamond}[30.11.2005]
  218. cfgmanager:
  219. ; settings:
  220. ; a) preboot_graph = graphical mode
  221. ;    preboot_gprobe = probe this mode?
  222. ; b) preboot_dma  = use DMA access?
  223. ; c) preboot_vrrm = use VRR?
  224. ; d) preboot_device = from what boot?
  225.  
  226. ; determine default settings
  227. ;        mov     [.bSettingsChanged], 0
  228.  
  229. ;.preboot_gr_end:
  230.         mov     di, preboot_device
  231. ; if image in memory is present and [preboot_device] is uninitialized,
  232. ; set it to use this preloaded image
  233.         cmp     byte [di], 0
  234.         jnz     .preboot_device_inited
  235.         cmp     [.loader_block], -1
  236.         jz      @f
  237.         les     bx, [.loader_block]
  238.         test    byte [es:bx+1], 1
  239.         jz      @f
  240.         mov     byte [di], 3
  241.         jmp     .preboot_device_inited
  242. @@:
  243. ; otherwise, set [preboot_device] to 1 (default value - boot from floppy)
  244.         mov     byte [di], 1
  245. .preboot_device_inited:
  246. ; following 4 lines set variables to 1 if its current value is 0
  247.         cmp     byte [di+preboot_dma-preboot_device], 1
  248.         adc     byte [di+preboot_dma-preboot_device], 0
  249.         cmp     byte [di+preboot_biosdisk-preboot_device], 1
  250.         adc     byte [di+preboot_biosdisk-preboot_device], 0
  251.  
  252. ;        pop     ax              ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ??
  253.         jmp     .continue
  254.  
  255. .loader_block dd -1
  256. .continue:
  257.         sti
  258.         jmp      .load
  259.  
  260. .loadc:
  261.         pop     eax
  262. .cont:
  263.         push    cs
  264.         pop     ds
  265. .load:
  266.  
  267. ; ASK GRAPHICS MODE
  268.  
  269. ;       call    set_vmode
  270.  
  271. ; GRAPHICS ACCELERATION
  272. ; force yes
  273.         mov     [es:0x901C], byte 1
  274.  
  275. ; DMA ACCESS TO HD
  276.  
  277.         mov     al, [preboot_dma]
  278.         mov     [es:0x901F], al
  279.  
  280. ; VRR_M USE
  281.  
  282.         mov     al,[preboot_vrrm]
  283.         mov     [es:0x9030], al
  284.         mov     [es:0x901E], byte 1
  285.  
  286. ; BOOT DEVICE
  287.  
  288.         mov     al, [preboot_device]
  289.         dec     al
  290.         mov     [boot_dev], al
  291.  
  292.  
  293. ; SET GRAPHICS
  294.  
  295.         xor     ax, ax
  296.         mov     es, ax
  297.  
  298. ;        mov     bx, [es:0x9008]         ; vga & 320x200
  299.         mov     ax, 0xA000              ; AtomBIOS Fn00
  300.         mov     cx, 0x550A              ; 1024x768, 32bpp, ARGB8888
  301. setgr:
  302.         int     0x10
  303.         test    ah, ah
  304.         jnz     $
  305.         mov     ax, 0xA006              ; AtomBIOS Fn06
  306.         int     0x10
  307.         mov     [es:0x9018], ebx        ; LFB
  308.  
  309. gmok2:
  310.         push    ds
  311.         pop     es
  312.