Subversion Repositories Kolibri OS

Rev

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

  1. ;-----------------------------------------------------------------------------
  2. ; find the IDE controller in the device list
  3. ;-----------------------------------------------------------------------------
  4.         mov     ecx, IDE_controller_1
  5.         mov     esi, pcidev_list
  6. ;--------------------------------------
  7. align 4
  8. .loop:
  9.         mov     esi, [esi+PCIDEV.fd]
  10.         cmp     esi, pcidev_list
  11.         jz      find_IDE_controller_done
  12.  
  13.         mov     eax, [esi+PCIDEV.class]
  14.         shr     eax, 4
  15.         cmp     eax, 0x01018
  16.         jnz     .loop
  17. ;--------------------------------------
  18. .found:
  19.         mov     eax, [esi+PCIDEV.class]
  20.         DEBUGF  1, 'K : IDE controller programming interface %x\n', eax
  21.         mov     [ecx+IDE_DATA.ProgrammingInterface], eax
  22.  
  23.         mov     ah, [esi+PCIDEV.bus]
  24.         mov     al, 2
  25.         mov     bh, [esi+PCIDEV.devfn]
  26. ;--------------------------------------
  27.         mov     bl, 0x10
  28.         push    eax
  29.         call    pci_read_reg
  30.         and     eax, 0xFFFC
  31.         cmp     ax, 0
  32.         je      @f
  33.  
  34.         cmp     ax, 1
  35.         jne     .show_BAR0
  36. ;--------------------------------------
  37. @@:
  38.         mov     ax, 0x1F0
  39. ;--------------------------------------
  40. .show_BAR0:
  41.         DEBUGF  1, 'K : BAR0 IDE base addr %x\n', ax
  42.         mov     [StandardATABases], ax
  43.         mov     [ecx+IDE_DATA.BAR0_val], ax
  44.         pop     eax
  45. ;--------------------------------------
  46.         mov     bl, 0x14
  47.         push    eax
  48.         call    pci_read_reg
  49.         and     eax, 0xFFFC
  50.         cmp     ax, 0
  51.         je      @f
  52.  
  53.         cmp     ax, 1
  54.         jne     .show_BAR1
  55. ;--------------------------------------
  56. @@:
  57.         mov     ax, 0x3F4
  58. ;--------------------------------------
  59. .show_BAR1:
  60.         DEBUGF  1, 'K : BAR1 IDE base addr %x\n', ax
  61.         mov     [ecx+IDE_DATA.BAR1_val], ax
  62.         pop     eax
  63. ;--------------------------------------
  64.         mov     bl, 0x18
  65.         push    eax
  66.         call    pci_read_reg
  67.         and     eax, 0xFFFC
  68.         cmp     ax, 0
  69.         je      @f
  70.  
  71.         cmp     ax, 1
  72.         jne     .show_BAR2
  73. ;--------------------------------------
  74. @@:
  75.         mov     ax, 0x170
  76. ;--------------------------------------
  77. .show_BAR2:
  78.         DEBUGF  1, 'K : BAR2 IDE base addr %x\n', ax
  79.         mov     [StandardATABases+2], ax
  80.         mov     [ecx+IDE_DATA.BAR2_val], ax
  81.         pop     eax
  82. ;--------------------------------------
  83.         mov     bl, 0x1C
  84.         push    eax
  85.         call    pci_read_reg
  86.         and     eax, 0xFFFC
  87.         cmp     ax, 0
  88.         je      @f
  89.  
  90.         cmp     ax, 1
  91.         jne     .show_BAR3
  92. ;--------------------------------------
  93. @@:
  94.         mov     ax, 0x374
  95. ;--------------------------------------
  96. .show_BAR3:
  97.         DEBUGF  1, 'K : BAR3 IDE base addr %x\n', ax
  98.         mov     [ecx+IDE_DATA.BAR3_val], ax
  99.         pop     eax
  100. ;--------------------------------------
  101.         mov     bl, 0x20
  102.         push    eax
  103.         call    pci_read_reg
  104.         and     eax, 0xFFFC
  105.         DEBUGF  1, 'K : BAR4 IDE controller register base addr %x\n', ax
  106.         mov     [ecx+IDE_DATA.RegsBaseAddres], ax
  107.         pop     eax
  108. ;--------------------------------------
  109.         mov     bl, 0x3C
  110.         push    eax
  111.         call    pci_read_reg
  112.         and     eax, 0xFF
  113.         DEBUGF  1, 'K : IDE Interrupt %x\n', al
  114.         mov     [ecx+IDE_DATA.Interrupt], ax
  115.         pop     eax
  116.  
  117.         add     ecx, sizeof.IDE_DATA
  118. ;--------------------------------------
  119.         jmp     .loop
  120. ;-----------------------------------------------------------------------------
  121. uglobal
  122. align 4
  123. ;--------------------------------------
  124. IDE_controller_pointer dd ?
  125. ;--------------------------------------
  126. IDE_controller_1 IDE_DATA
  127. IDE_controller_2 IDE_DATA
  128. IDE_controller_3 IDE_DATA
  129. ;--------------------------------------
  130. cache_ide0  IDE_CACHE
  131. cache_ide1  IDE_CACHE
  132. cache_ide2  IDE_CACHE
  133. cache_ide3  IDE_CACHE
  134. cache_ide4  IDE_CACHE
  135. cache_ide5  IDE_CACHE
  136. cache_ide6  IDE_CACHE
  137. cache_ide7  IDE_CACHE
  138. cache_ide8  IDE_CACHE
  139. cache_ide9  IDE_CACHE
  140. cache_ide10 IDE_CACHE
  141. cache_ide11 IDE_CACHE
  142. ;--------------------------------------
  143. IDE_device_1 rd 2
  144. IDE_device_2 rd 2
  145. IDE_device_3 rd 2
  146. ;--------------------------------------
  147. endg
  148. ;-----------------------------------------------------------------------------
  149. ; START of initialisation IDE ATA code
  150. ;-----------------------------------------------------------------------------
  151. Init_IDE_ATA_controller:
  152.         cmp     [ecx+IDE_DATA.ProgrammingInterface], 0
  153.         jne     @f
  154.  
  155.         ret
  156. ;--------------------------------------
  157. @@:
  158.         mov     esi, boot_disabling_ide
  159.         call    boot_log
  160. ;--------------------------------------
  161. ; Disable IDE interrupts, because the search
  162. ; for IDE partitions is in the PIO mode.
  163. ;--------------------------------------
  164. .disable_IDE_interrupt:
  165. ; Disable interrupts in IDE controller for PIO
  166.         mov     al, 2
  167.         mov     dx, [ecx+IDE_DATA.BAR1_val] ;0x3F4
  168.         add     dx, 2 ;0x3F6
  169.         out     dx, al
  170.         mov     dx, [ecx+IDE_DATA.BAR3_val] ;0x374
  171.         add     dx, 2 ;0x376
  172.         out     dx, al
  173. ;-----------------------------------------------------------------------------
  174. ; set current ata bases
  175. @@:
  176.         mov     ax, [ecx+IDE_DATA.BAR0_val]
  177.         mov     [StandardATABases], ax
  178.         mov     ax, [ecx+IDE_DATA.BAR2_val]
  179.         mov     [StandardATABases+2], ax
  180.  
  181.         mov     esi, boot_detecthdcd
  182.         call    boot_log
  183. ;--------------------------------------
  184. include 'dev_hdcd.inc'
  185. ;--------------------------------------
  186.         ret
  187. ;-----------------------------------------------------------------------------
  188. Init_IDE_ATA_controller_2:
  189.         cmp     [ecx+IDE_DATA.ProgrammingInterface], 0
  190.         jne     @f
  191.  
  192.         ret
  193. ;--------------------------------------
  194. @@:
  195.         mov     dx, [ecx+IDE_DATA.RegsBaseAddres]
  196. ; test whether it is our interrupt?
  197.         add     dx, 2
  198.         in      al, dx
  199.         test    al, 100b
  200.         jz      @f
  201. ; clear Bus Master IDE Status register
  202. ; clear Interrupt bit
  203.         out     dx, al
  204. ;--------------------------------------
  205. @@:
  206.         add     dx, 8
  207. ; test whether it is our interrupt?
  208.         in      al, dx
  209.         test    al, 100b
  210.         jz      @f
  211. ; clear Bus Master IDE Status register
  212. ; clear Interrupt bit
  213.         out     dx, al
  214. ;--------------------------------------
  215. @@:
  216. ; read status register and remove the interrupt request
  217.         mov     dx, [ecx+IDE_DATA.BAR0_val] ;0x1F0
  218.         add     dx, 0x7 ;0x1F7
  219.         in      al, dx
  220.         mov     dx, [ecx+IDE_DATA.BAR2_val] ;0x170
  221.         add     dx, 0x7 ;0x177
  222.         in      al, dx
  223. ;-----------------------------------------------------------------------------
  224. ;        push    eax edx
  225. ;        mov     dx, [ecx+IDE_DATA.RegsBaseAddres]
  226. ;        xor     eax, eax
  227. ;        add     dx, 2
  228. ;        in      al, dx
  229. ;        DEBUGF  1, "K : Primary Bus Master IDE Status Register %x\n", eax
  230.  
  231. ;        add     dx, 8
  232. ;        in      al, dx
  233. ;        DEBUGF  1, "K : Secondary Bus Master IDE Status Register %x\n", eax
  234. ;        pop     edx eax
  235.  
  236. ;        cmp     [ecx+IDE_DATA.RegsBaseAddres], 0
  237. ;        setnz   [ecx+IDE_DATA.dma_hdd]
  238. ;-----------------------------------------------------------------------------
  239. ; set interrupts for IDE Controller
  240. ;-----------------------------------------------------------------------------
  241.         mov     esi, boot_set_int_IDE
  242.         call    boot_log
  243. .set_interrupts_for_IDE_controllers:
  244.         mov     eax, [ecx+IDE_DATA.ProgrammingInterface]
  245.         cmp     ax, 0x0180
  246.         je      .pata_ide
  247.  
  248.         cmp     ax, 0x018a
  249.         jne     .sata_ide
  250. ;--------------------------------------
  251. .pata_ide:
  252.         cmp     [ecx+IDE_DATA.RegsBaseAddres], 0
  253.         je      .end_set_interrupts
  254.  
  255.         push    ecx
  256.         stdcall attach_int_handler, 14, IDE_irq_14_handler, 0
  257.         DEBUGF  1, "K : Set IDE IRQ14 return code %x\n", eax
  258.         stdcall attach_int_handler, 15, IDE_irq_15_handler, 0
  259.         DEBUGF  1, "K : Set IDE IRQ15 return code %x\n", eax
  260.         pop     ecx
  261.  
  262.         jmp     .enable_IDE_interrupt
  263. ;--------------------------------------
  264. .sata_ide:
  265.         cmp     ax, 0x0185
  266.         je      .sata_ide_1
  267.  
  268.         cmp     ax, 0x018f
  269.         jne     .end_set_interrupts
  270. ;--------------------------------------
  271. .sata_ide_1:
  272.         cmp     [ecx+IDE_DATA.RegsBaseAddres], 0
  273.         je      .end_set_interrupts
  274.  
  275.         mov     ax, [ecx+IDE_DATA.Interrupt]
  276.         movzx   eax, al
  277.         push    ecx
  278.         stdcall attach_int_handler, eax, IDE_common_irq_handler, 0
  279.         pop     ecx
  280.         DEBUGF  1, "K : Set IDE IRQ%d return code %x\n", [ecx+IDE_DATA.Interrupt]:1, eax
  281. ;--------------------------------------
  282. .enable_IDE_interrupt:
  283.         mov     esi, boot_enabling_ide
  284.         call    boot_log
  285. ; Enable interrupts in IDE controller for DMA
  286.         xor     ebx, ebx
  287.         cmp     ecx, IDE_controller_2
  288.         jne     @f
  289.  
  290.         add     ebx, 5
  291.         jmp     .check_DRIVE_DATA
  292. ;--------------------------------------
  293. @@:
  294.         cmp     ecx, IDE_controller_3
  295.         jne     .check_DRIVE_DATA
  296.  
  297.         add     ebx, 10
  298. ;--------------------------------------
  299. .check_DRIVE_DATA:
  300.         mov     al, 0
  301.         mov     ah, [ebx+DRIVE_DATA+1]
  302.         test    ah, 10100000b ; check for ATAPI devices
  303.         jz      @f
  304. ;--------------------------------------
  305. .ch1_pio_set_ATAPI:
  306.         DEBUGF  1, "K : IDE CH1 PIO, because ATAPI drive present\n"
  307.         jmp     .ch1_pio_set_for_all
  308. ;--------------------------------------
  309. .ch1_pio_set_no_devices:
  310.         DEBUGF  1, "K : IDE CH1 PIO because no devices\n"
  311.         jmp     .ch1_pio_set_for_all
  312. ;-------------------------------------
  313. .ch1_pio_set:
  314.         DEBUGF  1, "K : IDE CH1 PIO because device not support UDMA\n"
  315. ;-------------------------------------
  316. .ch1_pio_set_for_all:
  317.         mov     [ecx+IDE_DATA.dma_hdd_channel_1], al
  318.         jmp     .ch2_check
  319. ;--------------------------------------
  320. @@:
  321.         xor     ebx, ebx
  322.         call    calculate_IDE_device_values_storage
  323.  
  324.         test    ah, 1010000b
  325.         jz      .ch1_pio_set_no_devices
  326.  
  327.         test    ah, 1000000b
  328.         jz      @f
  329.  
  330.         cmp     [ebx+IDE_DEVICE.UDMA_possible_modes], al
  331.         je      .ch1_pio_set
  332.  
  333.         cmp     [ebx+IDE_DEVICE.UDMA_set_mode], al
  334.         je      .ch1_pio_set
  335. ;--------------------------------------
  336. @@:
  337.         test    ah, 10000b
  338.         jz      @f
  339.  
  340.         add     ebx, 2
  341.  
  342.         cmp     [ebx+IDE_DEVICE.UDMA_possible_modes], al
  343.         je      .ch1_pio_set
  344.  
  345.         cmp     [ebx+IDE_DEVICE.UDMA_set_mode], al
  346.         je      .ch1_pio_set
  347. ;--------------------------------------
  348. @@:
  349.         mov     dx, [ecx+IDE_DATA.BAR1_val] ;0x3F4
  350.         add     dx, 2 ;0x3F6
  351.         out     dx, al
  352.         DEBUGF  1, "K : IDE CH1 DMA enabled\n"
  353.         mov     [ecx+IDE_DATA.dma_hdd_channel_1], byte 1
  354. ;--------------------------------------
  355. .ch2_check:
  356.         test    ah, 1010b ; check for ATAPI devices
  357.         jz      @f
  358. ;--------------------------------------
  359. .ch2_pio_set_ATAPI:
  360.         DEBUGF  1, "K : IDE CH2 PIO, because ATAPI drive present\n"
  361.         jmp     .ch2_pio_set_for_all
  362. ;--------------------------------------
  363. .ch2_pio_set_no_devices:
  364.         DEBUGF  1, "K : IDE CH2 PIO because no devices\n"
  365.         jmp     .ch2_pio_set_for_all
  366. ;--------------------------------------
  367. .ch2_pio_set:
  368.         DEBUGF  1, "K : IDE CH2 PIO because device not support UDMA\n"
  369. ;--------------------------------------
  370. .ch2_pio_set_for_all:
  371.         mov     [ecx+IDE_DATA.dma_hdd_channel_2], al
  372.         jmp     .end_set_interrupts
  373. ;--------------------------------------
  374. @@:
  375.         mov     ebx, 4
  376.         call    calculate_IDE_device_values_storage
  377.  
  378.         test    ah, 101b
  379.         jz      .ch2_pio_set_no_devices
  380.  
  381.         test    ah, 100b
  382.         jz      @f
  383.  
  384.         cmp     [ebx+IDE_DEVICE.UDMA_possible_modes], al
  385.         je      .ch2_pio_set
  386.  
  387.         cmp     [ebx+IDE_DEVICE.UDMA_set_mode], al
  388.         je      .ch2_pio_set
  389. ;--------------------------------------
  390. @@:
  391.         test    ah, 1b
  392.         jz      @f
  393.  
  394.         add     ebx, 2
  395.  
  396.         cmp     [ebx+IDE_DEVICE.UDMA_possible_modes], al
  397.         je      .ch2_pio_set
  398.  
  399.         cmp     [ebx+IDE_DEVICE.UDMA_set_mode], al
  400.         je      .ch2_pio_set
  401. ;--------------------------------------
  402. @@:
  403.         mov     dx, [ecx+IDE_DATA.BAR3_val] ;0x374
  404.         add     dx, 2 ;0x376
  405.         out     dx, al
  406.         DEBUGF  1, "K : IDE CH2 DMA enabled\n"
  407.         mov     [ecx+IDE_DATA.dma_hdd_channel_2], byte 1
  408. ;--------------------------------------
  409. .end_set_interrupts:
  410.         ret
  411. ;-----------------------------------------------------------------------------
  412. ; END of initialisation IDE ATA code
  413. ;-----------------------------------------------------------------------------
  414. find_IDE_controller_done:
  415.         mov     ecx, IDE_controller_1
  416.         mov     [IDE_controller_pointer], ecx
  417.         call    Init_IDE_ATA_controller
  418.         mov     ecx, IDE_controller_2
  419.         mov     [IDE_controller_pointer], ecx
  420.         call    Init_IDE_ATA_controller
  421.         mov     ecx, IDE_controller_3
  422.         mov     [IDE_controller_pointer], ecx
  423.         call    Init_IDE_ATA_controller
  424. ;-----------------------------------------------------------------------------
  425.         mov     esi, boot_getcache
  426.         call    boot_log
  427. include 'getcache.inc'
  428. ;-----------------------------------------------------------------------------
  429.         mov     esi, boot_detectpart
  430.         call    boot_log
  431. include 'sear_par.inc'
  432. ;-----------------------------------------------------------------------------
  433.         mov     esi, boot_init_sys
  434.         call    boot_log
  435.         call    Parser_params
  436.  
  437. if ~ defined extended_primary_loader
  438. ; ramdisk image should be loaded by extended primary loader if it exists
  439. ; READ RAMDISK IMAGE FROM HD
  440. include '../boot/rdload.inc'
  441. end if
  442. ;-----------------------------------------------------------------------------
  443.         mov     ecx, IDE_controller_1
  444.         mov     [IDE_controller_pointer], ecx
  445.         call    Init_IDE_ATA_controller_2
  446.         mov     ecx, IDE_controller_2
  447.         mov     [IDE_controller_pointer], ecx
  448.         call    Init_IDE_ATA_controller_2
  449.         mov     ecx, IDE_controller_3
  450.         mov     [IDE_controller_pointer], ecx
  451.         call    Init_IDE_ATA_controller_2
  452. ;-----------------------------------------------------------------------------
  453.