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 8.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. #ifndef INT13_H
  2. #define INT13_H
  3. /** @file
  4. *
  5. * INT 13 emulation
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. #include <stdint.h>
  10. #include <ipxe/list.h>
  11. #include <ipxe/edd.h>
  12. #include <realmode.h>
  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. /** Verify sectors */
  36. #define INT13_EXTENDED_VERIFY 0x44
  37. /** Extended seek */
  38. #define INT13_EXTENDED_SEEK 0x47
  39. /** Get extended drive parameters */
  40. #define INT13_GET_EXTENDED_PARAMETERS 0x48
  41. /** Get CD-ROM status / terminate emulation */
  42. #define INT13_CDROM_STATUS_TERMINATE 0x4b
  43. /** Read CD-ROM boot catalog */
  44. #define INT13_CDROM_READ_BOOT_CATALOG 0x4d
  45. /** @} */
  46. /**
  47. * @defgroup int13status INT 13 status codes
  48. * @{
  49. */
  50. /** Operation completed successfully */
  51. #define INT13_STATUS_SUCCESS 0x00
  52. /** Invalid function or parameter */
  53. #define INT13_STATUS_INVALID 0x01
  54. /** Read error */
  55. #define INT13_STATUS_READ_ERROR 0x04
  56. /** Reset failed */
  57. #define INT13_STATUS_RESET_FAILED 0x05
  58. /** Write error */
  59. #define INT13_STATUS_WRITE_ERROR 0xcc
  60. /** @} */
  61. /** Block size for non-extended INT 13 calls */
  62. #define INT13_BLKSIZE 512
  63. /** @defgroup int13fddtype INT 13 floppy disk drive types
  64. * @{
  65. */
  66. /** 360K */
  67. #define INT13_FDD_TYPE_360K 0x01
  68. /** 1.2M */
  69. #define INT13_FDD_TYPE_1M2 0x02
  70. /** 720K */
  71. #define INT13_FDD_TYPE_720K 0x03
  72. /** 1.44M */
  73. #define INT13_FDD_TYPE_1M44 0x04
  74. /** An INT 13 disk address packet */
  75. struct int13_disk_address {
  76. /** Size of the packet, in bytes */
  77. uint8_t bufsize;
  78. /** Reserved */
  79. uint8_t reserved_a;
  80. /** Block count */
  81. uint8_t count;
  82. /** Reserved */
  83. uint8_t reserved_b;
  84. /** Data buffer */
  85. struct segoff buffer;
  86. /** Starting block number */
  87. uint64_t lba;
  88. /** Data buffer (EDD 3.0+ only) */
  89. uint64_t buffer_phys;
  90. /** Block count (EDD 4.0+ only) */
  91. uint32_t long_count;
  92. /** Reserved */
  93. uint32_t reserved_c;
  94. } __attribute__ (( packed ));
  95. /** INT 13 disk parameters */
  96. struct int13_disk_parameters {
  97. /** Size of this structure */
  98. uint16_t bufsize;
  99. /** Flags */
  100. uint16_t flags;
  101. /** Number of cylinders */
  102. uint32_t cylinders;
  103. /** Number of heads */
  104. uint32_t heads;
  105. /** Number of sectors per track */
  106. uint32_t sectors_per_track;
  107. /** Total number of sectors on drive */
  108. uint64_t sectors;
  109. /** Bytes per sector */
  110. uint16_t sector_size;
  111. /** Device parameter table extension */
  112. struct segoff dpte;
  113. /** Device path information */
  114. struct edd_device_path_information dpi;
  115. } __attribute__ (( packed ));
  116. /**
  117. * @defgroup int13types INT 13 disk types
  118. * @{
  119. */
  120. /** No such drive */
  121. #define INT13_DISK_TYPE_NONE 0x00
  122. /** Floppy without change-line support */
  123. #define INT13_DISK_TYPE_FDD 0x01
  124. /** Floppy with change-line support */
  125. #define INT13_DISK_TYPE_FDD_CL 0x02
  126. /** Hard disk */
  127. #define INT13_DISK_TYPE_HDD 0x03
  128. /** @} */
  129. /**
  130. * @defgroup int13flags INT 13 disk parameter flags
  131. * @{
  132. */
  133. /** DMA boundary errors handled transparently */
  134. #define INT13_FL_DMA_TRANSPARENT 0x01
  135. /** CHS information is valid */
  136. #define INT13_FL_CHS_VALID 0x02
  137. /** Removable drive */
  138. #define INT13_FL_REMOVABLE 0x04
  139. /** Write with verify supported */
  140. #define INT13_FL_VERIFIABLE 0x08
  141. /** Has change-line supported (valid only for removable drives) */
  142. #define INT13_FL_CHANGE_LINE 0x10
  143. /** Drive can be locked (valid only for removable drives) */
  144. #define INT13_FL_LOCKABLE 0x20
  145. /** CHS is max possible, not current media (valid only for removable drives) */
  146. #define INT13_FL_CHS_MAX 0x40
  147. /** @} */
  148. /**
  149. * @defgroup int13exts INT 13 extension flags
  150. * @{
  151. */
  152. /** Extended disk access functions supported */
  153. #define INT13_EXTENSION_LINEAR 0x01
  154. /** Removable drive functions supported */
  155. #define INT13_EXTENSION_REMOVABLE 0x02
  156. /** EDD functions supported */
  157. #define INT13_EXTENSION_EDD 0x04
  158. /** 64-bit extensions are present */
  159. #define INT13_EXTENSION_64BIT 0x08
  160. /** @} */
  161. /**
  162. * @defgroup int13vers INT 13 extension versions
  163. * @{
  164. */
  165. /** INT13 extensions version 1.x */
  166. #define INT13_EXTENSION_VER_1_X 0x01
  167. /** INT13 extensions version 2.0 (EDD-1.0) */
  168. #define INT13_EXTENSION_VER_2_0 0x20
  169. /** INT13 extensions version 2.1 (EDD-1.1) */
  170. #define INT13_EXTENSION_VER_2_1 0x21
  171. /** INT13 extensions version 3.0 (EDD-3.0) */
  172. #define INT13_EXTENSION_VER_3_0 0x30
  173. /** @} */
  174. /** Maximum number of sectors for which CHS geometry is allowed to be valid
  175. *
  176. * This number is taken from the EDD specification.
  177. */
  178. #define INT13_MAX_CHS_SECTORS 15482880
  179. /** Bootable CD-ROM specification packet */
  180. struct int13_cdrom_specification {
  181. /** Size of packet in bytes */
  182. uint8_t size;
  183. /** Boot media type */
  184. uint8_t media_type;
  185. /** Drive number */
  186. uint8_t drive;
  187. /** CD-ROM controller number */
  188. uint8_t controller;
  189. /** LBA of disk image to emulate */
  190. uint32_t lba;
  191. /** Device specification */
  192. uint16_t device;
  193. /** Segment of 3K buffer for caching CD-ROM reads */
  194. uint16_t cache_segment;
  195. /** Load segment for initial boot image */
  196. uint16_t load_segment;
  197. /** Number of 512-byte sectors to load */
  198. uint16_t load_sectors;
  199. /** Low 8 bits of cylinder number */
  200. uint8_t cyl;
  201. /** Sector number, plus high 2 bits of cylinder number */
  202. uint8_t cyl_sector;
  203. /** Head number */
  204. uint8_t head;
  205. } __attribute__ (( packed ));
  206. /** Bootable CD-ROM boot catalog command packet */
  207. struct int13_cdrom_boot_catalog_command {
  208. /** Size of packet in bytes */
  209. uint8_t size;
  210. /** Number of sectors of boot catalog to read */
  211. uint8_t count;
  212. /** Buffer for boot catalog */
  213. uint32_t buffer;
  214. /** First sector in boot catalog to transfer */
  215. uint16_t start;
  216. } __attribute__ (( packed ));
  217. /** A C/H/S address within a partition table entry */
  218. struct partition_chs {
  219. /** Head number */
  220. uint8_t head;
  221. /** Sector number, plus high 2 bits of cylinder number */
  222. uint8_t cyl_sector;
  223. /** Low 8 bits of cylinder number */
  224. uint8_t cyl;
  225. } __attribute__ (( packed ));
  226. #define PART_HEAD(chs) ( (chs).head )
  227. #define PART_SECTOR(chs) ( (chs).cyl_sector & 0x3f )
  228. #define PART_CYLINDER(chs) ( (chs).cyl | ( ( (chs).cyl_sector & 0xc0 ) << 2 ) )
  229. /** A partition table entry within the MBR */
  230. struct partition_table_entry {
  231. /** Bootable flag */
  232. uint8_t bootable;
  233. /** C/H/S start address */
  234. struct partition_chs chs_start;
  235. /** System indicator (partition type) */
  236. uint8_t type;
  237. /** C/H/S end address */
  238. struct partition_chs chs_end;
  239. /** Linear start address */
  240. uint32_t start;
  241. /** Linear length */
  242. uint32_t length;
  243. } __attribute__ (( packed ));
  244. /** A Master Boot Record */
  245. struct master_boot_record {
  246. /** Code area */
  247. uint8_t code[440];
  248. /** Disk signature */
  249. uint32_t signature;
  250. /** Padding */
  251. uint8_t pad[2];
  252. /** Partition table */
  253. struct partition_table_entry partitions[4];
  254. /** 0x55aa MBR signature */
  255. uint16_t magic;
  256. } __attribute__ (( packed ));
  257. /** MBR magic signature */
  258. #define INT13_MBR_MAGIC 0xaa55
  259. /** A floppy disk geometry */
  260. struct int13_fdd_geometry {
  261. /** Number of tracks */
  262. uint8_t tracks;
  263. /** Number of heads and sectors per track */
  264. uint8_t heads_spt;
  265. };
  266. /** Define a floppy disk geometry */
  267. #define INT13_FDD_GEOMETRY( cylinders, heads, sectors ) \
  268. { \
  269. .tracks = (cylinders), \
  270. .heads_spt = ( ( (heads) << 6 ) | (sectors) ), \
  271. }
  272. /** Get floppy disk number of cylinders */
  273. #define INT13_FDD_CYLINDERS( geometry ) ( (geometry)->tracks )
  274. /** Get floppy disk number of heads */
  275. #define INT13_FDD_HEADS( geometry ) ( (geometry)->heads_spt >> 6 )
  276. /** Get floppy disk number of sectors per track */
  277. #define INT13_FDD_SECTORS( geometry ) ( (geometry)->heads_spt & 0x3f )
  278. /** A floppy drive parameter table */
  279. struct int13_fdd_parameters {
  280. uint8_t step_rate__head_unload;
  281. uint8_t head_load__ndma;
  282. uint8_t motor_off_delay;
  283. uint8_t bytes_per_sector;
  284. uint8_t sectors_per_track;
  285. uint8_t gap_length;
  286. uint8_t data_length;
  287. uint8_t format_gap_length;
  288. uint8_t format_filler;
  289. uint8_t head_settle_time;
  290. uint8_t motor_start_time;
  291. } __attribute__ (( packed ));
  292. #endif /* INT13_H */