You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bios_disks.c 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #include "realmode.h"
  2. #include "console.h"
  3. #include "disk.h"
  4. #include "bios_disks.h"
  5. #warning "This file is obsolete"
  6. #if 0
  7. #define CF ( 1 << 0 )
  8. #define BIOS_DISK_NONE 0
  9. /*
  10. * Reset the disk system using INT 13,0. Forces both hard disks and
  11. * floppy disks to seek back to track 0.
  12. *
  13. */
  14. static void bios_disk_init ( void ) {
  15. REAL_EXEC ( rm_bios_disk_init,
  16. "sti\n\t"
  17. "xorw %%ax,%%ax\n\t"
  18. "movb $0x80,%%dl\n\t"
  19. "int $0x13\n\t"
  20. "cli\n\t",
  21. 0,
  22. OUT_CONSTRAINTS (),
  23. IN_CONSTRAINTS (),
  24. CLOBBER ( "eax", "ebx", "ecx", "edx",
  25. "ebp", "esi", "edi" ) );
  26. }
  27. /*
  28. * Read a single sector from a disk using INT 13,2.
  29. *
  30. * Returns the BIOS status code (%ah) - 0 indicates success.
  31. * Automatically retries up to three times to allow time for floppy
  32. * disks to spin up, calling bios_disk_init() after each failure.
  33. *
  34. */
  35. static unsigned int bios_disk_read ( struct bios_disk_device *bios_disk,
  36. unsigned int cylinder,
  37. unsigned int head,
  38. unsigned int sector,
  39. struct bios_disk_sector *buf ) {
  40. uint16_t basemem_buf, ax, flags;
  41. unsigned int status, discard_c, discard_d;
  42. int retry = 3;
  43. basemem_buf = BASEMEM_PARAMETER_INIT ( *buf );
  44. do {
  45. REAL_EXEC ( rm_bios_disk_read,
  46. "sti\n\t"
  47. "movw $0x0201, %%ax\n\t" /* Read a single sector */
  48. "int $0x13\n\t"
  49. "pushfw\n\t"
  50. "popw %%bx\n\t"
  51. "cli\n\t",
  52. 4,
  53. OUT_CONSTRAINTS ( "=a" ( ax ), "=b" ( flags ),
  54. "=c" ( discard_c ),
  55. "=d" ( discard_d ) ),
  56. IN_CONSTRAINTS ( "c" ( ( (cylinder & 0xff) << 8 ) |
  57. ( (cylinder >> 8) & 0x3 ) |
  58. sector ),
  59. "d" ( ( head << 8 ) |
  60. bios_disk->drive ),
  61. "b" ( basemem_buf ) ),
  62. CLOBBER ( "ebp", "esi", "edi" ) );
  63. status = ( flags & CF ) ? ( ax >> 8 ) : 0;
  64. } while ( ( status != 0 ) && ( bios_disk_init(), retry-- ) );
  65. BASEMEM_PARAMETER_DONE ( *buf );
  66. return status;
  67. }
  68. /*
  69. * Increment a bus_loc structure to the next possible BIOS disk
  70. * location. Leave the structure zeroed and return 0 if there are no
  71. * more valid locations.
  72. *
  73. */
  74. static int bios_disk_next_location ( struct bus_loc *bus_loc ) {
  75. struct bios_disk_loc *bios_disk_loc
  76. = ( struct bios_disk_loc * ) bus_loc;
  77. /*
  78. * Ensure that there is sufficient space in the shared bus
  79. * structures for a struct bios_disk_loc and a struct
  80. * bios_disk_dev, as mandated by bus.h.
  81. *
  82. */
  83. BUS_LOC_CHECK ( struct bios_disk_loc );
  84. BUS_DEV_CHECK ( struct bios_disk_device );
  85. return ( ++bios_disk_loc->drive );
  86. }
  87. /*
  88. * Fill in parameters for a BIOS disk device based on drive number
  89. *
  90. */
  91. static int bios_disk_fill_device ( struct bus_dev *bus_dev,
  92. struct bus_loc *bus_loc ) {
  93. struct bios_disk_loc *bios_disk_loc
  94. = ( struct bios_disk_loc * ) bus_loc;
  95. struct bios_disk_device *bios_disk
  96. = ( struct bios_disk_device * ) bus_dev;
  97. uint16_t flags;
  98. /* Store drive in struct bios_disk_device */
  99. bios_disk->drive = bios_disk_loc->drive;
  100. REAL_EXEC ( rm_bios_disk_exists,
  101. "sti\n\t"
  102. "movb $0x15, %%ah\n\t"
  103. "int $0x13\n\t"
  104. "pushfw\n\t"
  105. "popw %%dx\n\t"
  106. "movb %%ah, %%al\n\t"
  107. "cli\n\t",
  108. 2,
  109. OUT_CONSTRAINTS ( "=a" ( bios_disk->type ),
  110. "=d" ( flags ) ),
  111. IN_CONSTRAINTS ( "d" ( bios_disk->drive ) ),
  112. CLOBBER ( "ebx", "ecx", "esi", "edi", "ebp" ) );
  113. if ( ( flags & CF ) || ( bios_disk->type == BIOS_DISK_NONE ) )
  114. return 0;
  115. DBG ( "BIOS disk found valid drive %hhx\n", bios_disk->drive );
  116. return 1;
  117. }
  118. /*
  119. * Test whether or not a driver is capable of driving the device.
  120. *
  121. */
  122. static int bios_disk_check_driver ( struct bus_dev *bus_dev,
  123. struct device_driver *device_driver ) {
  124. struct bios_disk_device *bios_disk
  125. = ( struct bios_disk_device * ) bus_dev;
  126. struct bios_disk_driver *driver
  127. = ( struct bios_disk_driver * ) device_driver->bus_driver_info;
  128. /* Compare against driver's valid ID range */
  129. if ( ( bios_disk->drive >= driver->min_drive ) &&
  130. ( bios_disk->drive <= driver->max_drive ) ) {
  131. driver->fill_drive_name ( bios_disk->name, bios_disk->drive );
  132. DBG ( "BIOS disk found drive %hhx (\"%s\") "
  133. "matching driver %s\n",
  134. bios_disk->drive, bios_disk->name,
  135. driver->name );
  136. return 1;
  137. }
  138. return 0;
  139. }
  140. /*
  141. * Describe a BIOS disk device
  142. *
  143. */
  144. static char * bios_disk_describe_device ( struct bus_dev *bus_dev ) {
  145. struct bios_disk_device *bios_disk
  146. = ( struct bios_disk_device * ) bus_dev;
  147. static char bios_disk_description[] = "BIOS disk 00";
  148. sprintf ( bios_disk_description + 10, "%hhx", bios_disk->drive );
  149. return bios_disk_description;
  150. }
  151. /*
  152. * Name a BIOS disk device
  153. *
  154. */
  155. static const char * bios_disk_name_device ( struct bus_dev *bus_dev ) {
  156. struct bios_disk_device *bios_disk
  157. = ( struct bios_disk_device * ) bus_dev;
  158. return bios_disk->name;
  159. }
  160. /*
  161. * BIOS disk bus operations table
  162. *
  163. */
  164. struct bus_driver bios_disk_driver __bus_driver = {
  165. .name = "BIOS DISK",
  166. .next_location = bios_disk_next_location,
  167. .fill_device = bios_disk_fill_device,
  168. .check_driver = bios_disk_check_driver,
  169. .describe_device = bios_disk_describe_device,
  170. .name_device = bios_disk_name_device,
  171. };
  172. /*
  173. * Fill in a disk structure
  174. *
  175. */
  176. void bios_disk_fill_disk ( struct disk *disk __unused,
  177. struct bios_disk_device *bios_disk __unused ) {
  178. }
  179. #endif