Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2013. All rights reserved. ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  7.  
  8. $Revision: 3742 $
  9.  
  10. search_partitions:
  11. ; 1. Fill missing parameters in HD_DATA structures.
  12.         mov     eax, [hd_address_table]
  13.         mov     [hd0_data.hdbase], eax   ;0x1f0
  14.         mov     [hd1_data.hdbase], eax
  15.         mov     eax, [hd_address_table+16]
  16.         mov     [hd2_data.hdbase], eax
  17.         mov     [hd3_data.hdbase], eax
  18. ; 2. Notify the system about /hd* disks.
  19. ; For every existing disk, call ide_disk_add with correct parameters.
  20. ; Generate name "hdN" on the stack; this is 4 bytes including terminating zero.
  21. ; 2a. /hd0: exists if mask 0x40 in [DRIVE_DATA+1] is set,
  22. ;     data: hd0_data,
  23. ;     number of partitions: [DRIVE_DATA+2]
  24.         test    [DRIVE_DATA+1], byte 0x40
  25.         jz      @f
  26.         push    'hd0'
  27.         mov     eax, esp        ; name
  28.         mov     edx, hd0_data
  29.         call    ide_disk_add
  30.         mov     [DRIVE_DATA+2], al
  31.         pop     ecx             ; restore the stack
  32. @@:
  33. ; 2b. /hd1: exists if mask 0x10 in [DRIVE_DATA+1] is set,
  34. ;     data: hd1_data,
  35. ;     number of partitions: [DRIVE_DATA+3]
  36.         test    [DRIVE_DATA+1], byte 0x10
  37.         jz      @f
  38.         push    'hd1'
  39.         mov     eax, esp
  40.         mov     edx, hd1_data
  41.         call    ide_disk_add
  42.         mov     [DRIVE_DATA+3], al
  43.         pop     ecx
  44. @@:
  45. ; 2c. /hd2: exists if mask 4 in [DRIVE_DATA+1] is set,
  46. ;     data: hd2_data,
  47. ;     number of partitions: [DRIVE_DATA+4]
  48.         test    [DRIVE_DATA+1], byte 4
  49.         jz      @f
  50.         push    'hd2'
  51.         mov     eax, esp
  52.         mov     edx, hd2_data
  53.         call    ide_disk_add
  54.         mov     [DRIVE_DATA+4], al
  55.         pop     ecx
  56. @@:
  57. ; 2d. /hd3: exists if mask 1 in [DRIVE_DATA+1] is set,
  58. ;     data: hd3_data,
  59. ;     number of partitions: [DRIVE_DATA+5]
  60.         test    [DRIVE_DATA+1], byte 1
  61.         jz      @f
  62.         push    'hd3'
  63.         mov     eax, esp
  64.         mov     edx, hd3_data
  65.         call    ide_disk_add
  66.         mov     [DRIVE_DATA+5], al
  67.         pop     ecx
  68. @@:
  69. ; 3. Notify the system about /bd* disks.
  70. ; 3a. Check whether there are BIOS disks. If no, skip step 3.
  71.         xor     esi, esi
  72.         cmp     esi, [NumBiosDisks]
  73.         jz      .nobd
  74. ; Loop over all disks.
  75.         push    0
  76.         push    'bd'
  77. .bdloop:
  78. ; 3b. Get the drive number for using in /bd* name.
  79.         movzx   eax, byte [BiosDisksData+esi*4]
  80.         sub     al, 80h
  81. ; 3c. Convert eax to decimal and store starting with [esp+3].
  82. ; First 2 bytes in [esp] are "bd".
  83.         lea     edi, [esp+2]
  84. ; store digits in the stack, ending with -'0'
  85.         push    -'0'
  86. @@:
  87.         xor     edx, edx
  88. iglobal
  89. align 4
  90. _10     dd      10
  91. endg
  92.         div     [_10]
  93.         push    edx
  94.         test    eax, eax
  95.         jnz     @b
  96. ; restore digits from the stack, this reverses the order;
  97. ; add '0', stop, when zero is reached
  98. @@:
  99.         pop     eax
  100.         add     al, '0'
  101.         stosb
  102.         jnz     @b
  103. ; 3e. Call the API with userdata = 80h + ecx.
  104.         mov     eax, esp
  105.         lea     edx, [esi+80h]
  106.         stdcall disk_add, bd_callbacks, eax, edx, 0
  107.         test    eax, eax
  108.         jz      @f
  109.         stdcall disk_media_changed, eax, 1
  110. @@:
  111. ; 3f. Continue the loop.
  112.         inc     esi
  113.         cmp     esi, [NumBiosDisks]
  114.         jnz     .bdloop
  115.         pop     ecx ecx ; restore stack after name
  116. .nobd:
  117.         jmp     end_search_partitions
  118.  
  119. ; Helper procedure for search_partitions, adds one IDE disk.
  120. ; For compatibility, number of partitions for IDE disks is kept in a separate variable,
  121. ; so the procedure returns number of partitions.
  122. ; eax -> name, edx -> disk data
  123. proc ide_disk_add
  124.         stdcall disk_add, ide_callbacks, eax, edx, 0
  125.         test    eax, eax
  126.         jz      @f
  127.         push    eax
  128.         stdcall disk_media_changed, eax, 1
  129.         pop     eax
  130.         mov     eax, [eax+DISK.NumPartitions]
  131.         cmp     eax, 255
  132.         jbe     @f
  133.         mov     eax, 255
  134. @@:
  135.         ret
  136. endp
  137.  
  138.  end_search_partitions:
  139.  
  140.