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

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