edd.S 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * BIOS Enhanced Disk Drive support
  3. * Copyright (C) 2002, 2003, 2004 Dell, Inc.
  4. * by Matt Domsch <Matt_Domsch@dell.com> October 2002
  5. * conformant to T13 Committee www.t13.org
  6. * projects 1572D, 1484D, 1386D, 1226DT
  7. * disk signature read by Matt Domsch <Matt_Domsch@dell.com>
  8. * and Andrew Wilks <Andrew_Wilks@dell.com> September 2003, June 2004
  9. * legacy CHS retrieval by Patrick J. LoPresti <patl@users.sourceforge.net>
  10. * March 2004
  11. * Command line option parsing, Matt Domsch, November 2004
  12. */
  13. #include <linux/edd.h>
  14. #include <asm/setup.h>
  15. #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
  16. movb $0, (EDD_MBR_SIG_NR_BUF)
  17. movb $0, (EDDNR)
  18. # Check the command line for two options:
  19. # edd=of disables EDD completely (edd=off)
  20. # edd=sk skips the MBR test (edd=skipmbr)
  21. pushl %esi
  22. cmpl $0, %cs:cmd_line_ptr
  23. jz done_cl
  24. movl %cs:(cmd_line_ptr), %esi
  25. # ds:esi has the pointer to the command line now
  26. movl $(COMMAND_LINE_SIZE-7), %ecx
  27. # loop through kernel command line one byte at a time
  28. cl_loop:
  29. cmpl $EDD_CL_EQUALS, (%si)
  30. jz found_edd_equals
  31. incl %esi
  32. loop cl_loop
  33. jmp done_cl
  34. found_edd_equals:
  35. # only looking at first two characters after equals
  36. addl $4, %esi
  37. cmpw $EDD_CL_OFF, (%si) # edd=of
  38. jz do_edd_off
  39. cmpw $EDD_CL_SKIP, (%si) # edd=sk
  40. jz do_edd_skipmbr
  41. jmp done_cl
  42. do_edd_skipmbr:
  43. popl %esi
  44. jmp edd_start
  45. do_edd_off:
  46. popl %esi
  47. jmp edd_done
  48. done_cl:
  49. popl %esi
  50. # Read the first sector of each BIOS disk device and store the 4-byte signature
  51. edd_mbr_sig_start:
  52. movb $0x80, %dl # from device 80
  53. movw $EDD_MBR_SIG_BUF, %bx # store buffer ptr in bx
  54. edd_mbr_sig_read:
  55. movl $0xFFFFFFFF, %eax
  56. movl %eax, (%bx) # assume failure
  57. pushw %bx
  58. movb $READ_SECTORS, %ah
  59. movb $1, %al # read 1 sector
  60. movb $0, %dh # at head 0
  61. movw $1, %cx # cylinder 0, sector 0
  62. pushw %es
  63. pushw %ds
  64. popw %es
  65. movw $EDDBUF, %bx # disk's data goes into EDDBUF
  66. pushw %dx # work around buggy BIOSes
  67. stc # work around buggy BIOSes
  68. int $0x13
  69. sti # work around buggy BIOSes
  70. popw %dx
  71. popw %es
  72. popw %bx
  73. jc edd_mbr_sig_done # on failure, we're done.
  74. movl (EDDBUF+EDD_MBR_SIG_OFFSET), %eax # read sig out of the MBR
  75. movl %eax, (%bx) # store success
  76. incb (EDD_MBR_SIG_NR_BUF) # note that we stored something
  77. incb %dl # increment to next device
  78. addw $4, %bx # increment sig buffer ptr
  79. cmpb $EDD_MBR_SIG_MAX, (EDD_MBR_SIG_NR_BUF) # Out of space?
  80. jb edd_mbr_sig_read # keep looping
  81. edd_mbr_sig_done:
  82. # Do the BIOS Enhanced Disk Drive calls
  83. # This consists of two calls:
  84. # int 13h ah=41h "Check Extensions Present"
  85. # int 13h ah=48h "Get Device Parameters"
  86. # int 13h ah=08h "Legacy Get Device Parameters"
  87. #
  88. # A buffer of size EDDMAXNR*(EDDEXTSIZE+EDDPARMSIZE) is reserved for our use
  89. # in the boot_params at EDDBUF. The first four bytes of which are
  90. # used to store the device number, interface support map and version
  91. # results from fn41. The next four bytes are used to store the legacy
  92. # cylinders, heads, and sectors from fn08. The following 74 bytes are used to
  93. # store the results from fn48. Starting from device 80h, fn41, then fn48
  94. # are called and their results stored in EDDBUF+n*(EDDEXTSIZE+EDDPARMIZE).
  95. # Then the pointer is incremented to store the data for the next call.
  96. # This repeats until either a device doesn't exist, or until EDDMAXNR
  97. # devices have been stored.
  98. # The one tricky part is that ds:si always points EDDEXTSIZE bytes into
  99. # the structure, and the fn41 and fn08 results are stored at offsets
  100. # from there. This removes the need to increment the pointer for
  101. # every store, and leaves it ready for the fn48 call.
  102. # A second one-byte buffer, EDDNR, in the boot_params stores
  103. # the number of BIOS devices which exist, up to EDDMAXNR.
  104. # In setup.c, copy_edd() stores both boot_params buffers away
  105. # for later use, as they would get overwritten otherwise.
  106. # This code is sensitive to the size of the structs in edd.h
  107. edd_start:
  108. # %ds points to the bootsector
  109. # result buffer for fn48
  110. movw $EDDBUF+EDDEXTSIZE, %si # in ds:si, fn41 results
  111. # kept just before that
  112. movb $0x80, %dl # BIOS device 0x80
  113. edd_check_ext:
  114. movb $CHECKEXTENSIONSPRESENT, %ah # Function 41
  115. movw $EDDMAGIC1, %bx # magic
  116. int $0x13 # make the call
  117. jc edd_done # no more BIOS devices
  118. cmpw $EDDMAGIC2, %bx # is magic right?
  119. jne edd_next # nope, next...
  120. movb %dl, %ds:-8(%si) # store device number
  121. movb %ah, %ds:-7(%si) # store version
  122. movw %cx, %ds:-6(%si) # store extensions
  123. incb (EDDNR) # note that we stored something
  124. edd_get_device_params:
  125. movw $EDDPARMSIZE, %ds:(%si) # put size
  126. movw $0x0, %ds:2(%si) # work around buggy BIOSes
  127. movb $GETDEVICEPARAMETERS, %ah # Function 48
  128. int $0x13 # make the call
  129. # Don't check for fail return
  130. # it doesn't matter.
  131. edd_get_legacy_chs:
  132. xorw %ax, %ax
  133. movw %ax, %ds:-4(%si)
  134. movw %ax, %ds:-2(%si)
  135. # Ralf Brown's Interrupt List says to set ES:DI to
  136. # 0000h:0000h "to guard against BIOS bugs"
  137. pushw %es
  138. movw %ax, %es
  139. movw %ax, %di
  140. pushw %dx # legacy call clobbers %dl
  141. movb $LEGACYGETDEVICEPARAMETERS, %ah # Function 08
  142. int $0x13 # make the call
  143. jc edd_legacy_done # failed
  144. movb %cl, %al # Low 6 bits are max
  145. andb $0x3F, %al # sector number
  146. movb %al, %ds:-1(%si) # Record max sect
  147. movb %dh, %ds:-2(%si) # Record max head number
  148. movb %ch, %al # Low 8 bits of max cyl
  149. shr $6, %cl
  150. movb %cl, %ah # High 2 bits of max cyl
  151. movw %ax, %ds:-4(%si)
  152. edd_legacy_done:
  153. popw %dx
  154. popw %es
  155. movw %si, %ax # increment si
  156. addw $EDDPARMSIZE+EDDEXTSIZE, %ax
  157. movw %ax, %si
  158. edd_next:
  159. incb %dl # increment to next device
  160. cmpb $EDDMAXNR, (EDDNR) # Out of space?
  161. jb edd_check_ext # keep looping
  162. edd_done:
  163. #endif