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

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