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.

int13.h 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. #ifndef INT13_H
  2. #define INT13_H
  3. /** @file
  4. *
  5. * INT 13 emulation
  6. *
  7. */
  8. #include <stdint.h>
  9. #include <gpxe/list.h>
  10. struct block_device;
  11. /**
  12. * @defgroup int13ops INT 13 operation codes
  13. * @{
  14. */
  15. /** Reset disk system */
  16. #define INT13_RESET 0x00
  17. /** Get status of last operation */
  18. #define INT13_GET_LAST_STATUS 0x01
  19. /** Read sectors */
  20. #define INT13_READ_SECTORS 0x02
  21. /** Write sectors */
  22. #define INT13_WRITE_SECTORS 0x03
  23. /** Get drive parameters */
  24. #define INT13_GET_PARAMETERS 0x08
  25. /** Get disk type */
  26. #define INT13_GET_DISK_TYPE 0x15
  27. /** Extensions installation check */
  28. #define INT13_EXTENSION_CHECK 0x41
  29. /** Extended read */
  30. #define INT13_EXTENDED_READ 0x42
  31. /** Extended write */
  32. #define INT13_EXTENDED_WRITE 0x43
  33. /** Get extended drive parameters */
  34. #define INT13_GET_EXTENDED_PARAMETERS 0x48
  35. /** Get CD-ROM status / terminate emulation */
  36. #define INT13_CDROM_STATUS_TERMINATE 0x4b
  37. /** @} */
  38. /**
  39. * @defgroup int13status INT 13 status codes
  40. * @{
  41. */
  42. /** Operation completed successfully */
  43. #define INT13_STATUS_SUCCESS 0x00
  44. /** Invalid function or parameter */
  45. #define INT13_STATUS_INVALID 0x01
  46. /** Read error */
  47. #define INT13_STATUS_READ_ERROR 0x04
  48. /** Write error */
  49. #define INT13_STATUS_WRITE_ERROR 0xcc
  50. /** @} */
  51. /** Block size for non-extended INT 13 calls */
  52. #define INT13_BLKSIZE 512
  53. /** An INT 13 emulated drive */
  54. struct int13_drive {
  55. /** List of all registered drives */
  56. struct list_head list;
  57. /** Underlying block device */
  58. struct block_device *blockdev;
  59. /** BIOS in-use drive number (0x80-0xff) */
  60. unsigned int drive;
  61. /** BIOS natural drive number (0x80-0xff)
  62. *
  63. * This is the drive number that would have been assigned by
  64. * 'naturally' appending the drive to the end of the BIOS
  65. * drive list.
  66. *
  67. * If the emulated drive replaces a preexisting drive, this is
  68. * the drive number that the preexisting drive gets remapped
  69. * to.
  70. */
  71. unsigned int natural_drive;
  72. /** Number of cylinders
  73. *
  74. * The cylinder number field in an INT 13 call is ten bits
  75. * wide, giving a maximum of 1024 cylinders. Conventionally,
  76. * when the 7.8GB limit of a CHS address is exceeded, it is
  77. * the number of cylinders that is increased beyond the
  78. * addressable limit.
  79. */
  80. unsigned int cylinders;
  81. /** Number of heads
  82. *
  83. * The head number field in an INT 13 call is eight bits wide,
  84. * giving a maximum of 256 heads. However, apparently all
  85. * versions of MS-DOS up to and including Win95 fail with 256
  86. * heads, so the maximum encountered in practice is 255.
  87. */
  88. unsigned int heads;
  89. /** Number of sectors per track
  90. *
  91. * The sector number field in an INT 13 call is six bits wide,
  92. * giving a maximum of 63 sectors, since sector numbering
  93. * (unlike head and cylinder numbering) starts at 1, not 0.
  94. */
  95. unsigned int sectors_per_track;
  96. /** Status of last operation */
  97. int last_status;
  98. };
  99. /** An INT 13 disk address packet */
  100. struct int13_disk_address {
  101. /** Size of the packet, in bytes */
  102. uint8_t bufsize;
  103. /** Reserved, must be zero */
  104. uint8_t reserved;
  105. /** Block count */
  106. uint16_t count;
  107. /** Data buffer */
  108. struct segoff buffer;
  109. /** Starting block number */
  110. uint64_t lba;
  111. /** Data buffer (EDD-3.0 only) */
  112. uint64_t buffer_phys;
  113. } __attribute__ (( packed ));
  114. /** INT 13 disk parameters */
  115. struct int13_disk_parameters {
  116. /** Size of this structure */
  117. uint16_t bufsize;
  118. /** Flags */
  119. uint16_t flags;
  120. /** Number of cylinders */
  121. uint32_t cylinders;
  122. /** Number of heads */
  123. uint32_t heads;
  124. /** Number of sectors per track */
  125. uint32_t sectors_per_track;
  126. /** Total number of sectors on drive */
  127. uint64_t sectors;
  128. /** Bytes per sector */
  129. uint16_t sector_size;
  130. } __attribute__ (( packed ));
  131. /**
  132. * @defgroup int13types INT 13 disk types
  133. * @{
  134. */
  135. /** No such drive */
  136. #define INT13_DISK_TYPE_NONE 0x00
  137. /** Floppy without change-line support */
  138. #define INT13_DISK_TYPE_FDD 0x01
  139. /** Floppy with change-line support */
  140. #define INT13_DISK_TYPE_FDD_CL 0x02
  141. /** Hard disk */
  142. #define INT13_DISK_TYPE_HDD 0x03
  143. /** @} */
  144. /**
  145. * @defgroup int13flags INT 13 disk parameter flags
  146. * @{
  147. */
  148. /** DMA boundary errors handled transparently */
  149. #define INT13_FL_DMA_TRANSPARENT 0x01
  150. /** CHS information is valid */
  151. #define INT13_FL_CHS_VALID 0x02
  152. /** Removable drive */
  153. #define INT13_FL_REMOVABLE 0x04
  154. /** Write with verify supported */
  155. #define INT13_FL_VERIFIABLE 0x08
  156. /** Has change-line supported (valid only for removable drives) */
  157. #define INT13_FL_CHANGE_LINE 0x10
  158. /** Drive can be locked (valid only for removable drives) */
  159. #define INT13_FL_LOCKABLE 0x20
  160. /** CHS is max possible, not current media (valid only for removable drives) */
  161. #define INT13_FL_CHS_MAX 0x40
  162. /** @} */
  163. /**
  164. * @defgroup int13exts INT 13 extension flags
  165. * @{
  166. */
  167. /** Extended disk access functions supported */
  168. #define INT13_EXTENSION_LINEAR 0x01
  169. /** Removable drive functions supported */
  170. #define INT13_EXTENSION_REMOVABLE 0x02
  171. /** EDD functions supported */
  172. #define INT13_EXTENSION_EDD 0x04
  173. /** @} */
  174. /**
  175. * @defgroup int13vers INT 13 extension versions
  176. * @{
  177. */
  178. /** INT13 extensions version 1.x */
  179. #define INT13_EXTENSION_VER_1_X 0x01
  180. /** INT13 extensions version 2.0 (EDD-1.0) */
  181. #define INT13_EXTENSION_VER_2_0 0x20
  182. /** INT13 extensions version 2.1 (EDD-1.1) */
  183. #define INT13_EXTENSION_VER_2_1 0x21
  184. /** INT13 extensions version 3.0 (EDD-3.0) */
  185. #define INT13_EXTENSION_VER_3_0 0x30
  186. /** @} */
  187. /** Bootable CD-ROM specification packet */
  188. struct int13_cdrom_specification {
  189. /** Size of packet in bytes */
  190. uint8_t size;
  191. /** Boot media type */
  192. uint8_t media_type;
  193. /** Drive number */
  194. uint8_t drive;
  195. /** CD-ROM controller number */
  196. uint8_t controller;
  197. /** LBA of disk image to emulate */
  198. uint32_t lba;
  199. /** Device specification */
  200. uint16_t device;
  201. /** Segment of 3K buffer for caching CD-ROM reads */
  202. uint16_t cache_segment;
  203. /** Load segment for initial boot image */
  204. uint16_t load_segment;
  205. /** Number of 512-byte sectors to load */
  206. uint16_t load_sectors;
  207. /** Low 8 bits of cylinder number */
  208. uint8_t cyl;
  209. /** Sector number, plus high 2 bits of cylinder number */
  210. uint8_t cyl_sector;
  211. /** Head number */
  212. uint8_t head;
  213. } __attribute__ (( packed ));
  214. /** A C/H/S address within a partition table entry */
  215. struct partition_chs {
  216. /** Head number */
  217. uint8_t head;
  218. /** Sector number, plus high 2 bits of cylinder number */
  219. uint8_t cyl_sector;
  220. /** Low 8 bits of cylinder number */
  221. uint8_t cyl;
  222. } __attribute__ (( packed ));
  223. #define PART_HEAD(chs) ( (chs).head )
  224. #define PART_SECTOR(chs) ( (chs).cyl_sector & 0x3f )
  225. #define PART_CYLINDER(chs) ( (chs).cyl | ( ( (chs).cyl_sector & 0xc0 ) << 2 ) )
  226. /** A partition table entry within the MBR */
  227. struct partition_table_entry {
  228. /** Bootable flag */
  229. uint8_t bootable;
  230. /** C/H/S start address */
  231. struct partition_chs chs_start;
  232. /** System indicator (partition type) */
  233. uint8_t type;
  234. /** C/H/S end address */
  235. struct partition_chs chs_end;
  236. /** Linear start address */
  237. uint32_t start;
  238. /** Linear length */
  239. uint32_t length;
  240. } __attribute__ (( packed ));
  241. /** A Master Boot Record */
  242. struct master_boot_record {
  243. uint8_t pad[446];
  244. /** Partition table */
  245. struct partition_table_entry partitions[4];
  246. /** 0x55aa MBR signature */
  247. uint16_t signature;
  248. } __attribute__ (( packed ));
  249. extern void register_int13_drive ( struct int13_drive *drive );
  250. extern void unregister_int13_drive ( struct int13_drive *drive );
  251. extern int int13_boot ( unsigned int drive );
  252. #endif /* INT13_H */