您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

int13.h 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  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 <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. /** An INT 13 disk address packet */
  64. struct int13_disk_address {
  65. /** Size of the packet, in bytes */
  66. uint8_t bufsize;
  67. /** Reserved */
  68. uint8_t reserved_a;
  69. /** Block count */
  70. uint8_t count;
  71. /** Reserved */
  72. uint8_t reserved_b;
  73. /** Data buffer */
  74. struct segoff buffer;
  75. /** Starting block number */
  76. uint64_t lba;
  77. /** Data buffer (EDD 3.0+ only) */
  78. uint64_t buffer_phys;
  79. /** Block count (EDD 4.0+ only) */
  80. uint32_t long_count;
  81. /** Reserved */
  82. uint32_t reserved_c;
  83. } __attribute__ (( packed ));
  84. /** INT 13 disk parameters */
  85. struct int13_disk_parameters {
  86. /** Size of this structure */
  87. uint16_t bufsize;
  88. /** Flags */
  89. uint16_t flags;
  90. /** Number of cylinders */
  91. uint32_t cylinders;
  92. /** Number of heads */
  93. uint32_t heads;
  94. /** Number of sectors per track */
  95. uint32_t sectors_per_track;
  96. /** Total number of sectors on drive */
  97. uint64_t sectors;
  98. /** Bytes per sector */
  99. uint16_t sector_size;
  100. /** Device parameter table extension */
  101. struct segoff dpte;
  102. /** Device path information */
  103. struct edd_device_path_information dpi;
  104. } __attribute__ (( packed ));
  105. /**
  106. * @defgroup int13types INT 13 disk types
  107. * @{
  108. */
  109. /** No such drive */
  110. #define INT13_DISK_TYPE_NONE 0x00
  111. /** Floppy without change-line support */
  112. #define INT13_DISK_TYPE_FDD 0x01
  113. /** Floppy with change-line support */
  114. #define INT13_DISK_TYPE_FDD_CL 0x02
  115. /** Hard disk */
  116. #define INT13_DISK_TYPE_HDD 0x03
  117. /** @} */
  118. /**
  119. * @defgroup int13flags INT 13 disk parameter flags
  120. * @{
  121. */
  122. /** DMA boundary errors handled transparently */
  123. #define INT13_FL_DMA_TRANSPARENT 0x01
  124. /** CHS information is valid */
  125. #define INT13_FL_CHS_VALID 0x02
  126. /** Removable drive */
  127. #define INT13_FL_REMOVABLE 0x04
  128. /** Write with verify supported */
  129. #define INT13_FL_VERIFIABLE 0x08
  130. /** Has change-line supported (valid only for removable drives) */
  131. #define INT13_FL_CHANGE_LINE 0x10
  132. /** Drive can be locked (valid only for removable drives) */
  133. #define INT13_FL_LOCKABLE 0x20
  134. /** CHS is max possible, not current media (valid only for removable drives) */
  135. #define INT13_FL_CHS_MAX 0x40
  136. /** @} */
  137. /**
  138. * @defgroup int13exts INT 13 extension flags
  139. * @{
  140. */
  141. /** Extended disk access functions supported */
  142. #define INT13_EXTENSION_LINEAR 0x01
  143. /** Removable drive functions supported */
  144. #define INT13_EXTENSION_REMOVABLE 0x02
  145. /** EDD functions supported */
  146. #define INT13_EXTENSION_EDD 0x04
  147. /** 64-bit extensions are present */
  148. #define INT13_EXTENSION_64BIT 0x08
  149. /** @} */
  150. /**
  151. * @defgroup int13vers INT 13 extension versions
  152. * @{
  153. */
  154. /** INT13 extensions version 1.x */
  155. #define INT13_EXTENSION_VER_1_X 0x01
  156. /** INT13 extensions version 2.0 (EDD-1.0) */
  157. #define INT13_EXTENSION_VER_2_0 0x20
  158. /** INT13 extensions version 2.1 (EDD-1.1) */
  159. #define INT13_EXTENSION_VER_2_1 0x21
  160. /** INT13 extensions version 3.0 (EDD-3.0) */
  161. #define INT13_EXTENSION_VER_3_0 0x30
  162. /** @} */
  163. /** Maximum number of sectors for which CHS geometry is allowed to be valid
  164. *
  165. * This number is taken from the EDD specification.
  166. */
  167. #define INT13_MAX_CHS_SECTORS 15482880
  168. /** Bootable CD-ROM specification packet */
  169. struct int13_cdrom_specification {
  170. /** Size of packet in bytes */
  171. uint8_t size;
  172. /** Boot media type */
  173. uint8_t media_type;
  174. /** Drive number */
  175. uint8_t drive;
  176. /** CD-ROM controller number */
  177. uint8_t controller;
  178. /** LBA of disk image to emulate */
  179. uint32_t lba;
  180. /** Device specification */
  181. uint16_t device;
  182. /** Segment of 3K buffer for caching CD-ROM reads */
  183. uint16_t cache_segment;
  184. /** Load segment for initial boot image */
  185. uint16_t load_segment;
  186. /** Number of 512-byte sectors to load */
  187. uint16_t load_sectors;
  188. /** Low 8 bits of cylinder number */
  189. uint8_t cyl;
  190. /** Sector number, plus high 2 bits of cylinder number */
  191. uint8_t cyl_sector;
  192. /** Head number */
  193. uint8_t head;
  194. } __attribute__ (( packed ));
  195. /** Bootable CD-ROM boot catalog command packet */
  196. struct int13_cdrom_boot_catalog_command {
  197. /** Size of packet in bytes */
  198. uint8_t size;
  199. /** Number of sectors of boot catalog to read */
  200. uint8_t count;
  201. /** Buffer for boot catalog */
  202. uint32_t buffer;
  203. /** First sector in boot catalog to transfer */
  204. uint16_t start;
  205. } __attribute__ (( packed ));
  206. /** A C/H/S address within a partition table entry */
  207. struct partition_chs {
  208. /** Head number */
  209. uint8_t head;
  210. /** Sector number, plus high 2 bits of cylinder number */
  211. uint8_t cyl_sector;
  212. /** Low 8 bits of cylinder number */
  213. uint8_t cyl;
  214. } __attribute__ (( packed ));
  215. #define PART_HEAD(chs) ( (chs).head )
  216. #define PART_SECTOR(chs) ( (chs).cyl_sector & 0x3f )
  217. #define PART_CYLINDER(chs) ( (chs).cyl | ( ( (chs).cyl_sector & 0xc0 ) << 2 ) )
  218. /** A partition table entry within the MBR */
  219. struct partition_table_entry {
  220. /** Bootable flag */
  221. uint8_t bootable;
  222. /** C/H/S start address */
  223. struct partition_chs chs_start;
  224. /** System indicator (partition type) */
  225. uint8_t type;
  226. /** C/H/S end address */
  227. struct partition_chs chs_end;
  228. /** Linear start address */
  229. uint32_t start;
  230. /** Linear length */
  231. uint32_t length;
  232. } __attribute__ (( packed ));
  233. /** A Master Boot Record */
  234. struct master_boot_record {
  235. /** Code area */
  236. uint8_t code[440];
  237. /** Disk signature */
  238. uint32_t signature;
  239. /** Padding */
  240. uint8_t pad[2];
  241. /** Partition table */
  242. struct partition_table_entry partitions[4];
  243. /** 0x55aa MBR signature */
  244. uint16_t magic;
  245. } __attribute__ (( packed ));
  246. /** MBR magic signature */
  247. #define INT13_MBR_MAGIC 0xaa55
  248. /** ISO9660 block size */
  249. #define ISO9660_BLKSIZE 2048
  250. /** An ISO9660 Primary Volume Descriptor (fixed portion) */
  251. struct iso9660_primary_descriptor_fixed {
  252. /** Descriptor type */
  253. uint8_t type;
  254. /** Identifier ("CD001") */
  255. uint8_t id[5];
  256. } __attribute__ (( packed ));
  257. /** An ISO9660 Primary Volume Descriptor */
  258. struct iso9660_primary_descriptor {
  259. /** Fixed portion */
  260. struct iso9660_primary_descriptor_fixed fixed;
  261. } __attribute__ (( packed ));
  262. /** ISO9660 Primary Volume Descriptor type */
  263. #define ISO9660_TYPE_PRIMARY 0x01
  264. /** ISO9660 identifier */
  265. #define ISO9660_ID "CD001"
  266. /** ISO9660 Primary Volume Descriptor block address */
  267. #define ISO9660_PRIMARY_LBA 16
  268. /** An El Torito Boot Record Volume Descriptor (fixed portion) */
  269. struct eltorito_descriptor_fixed {
  270. /** Descriptor type */
  271. uint8_t type;
  272. /** Identifier ("CD001") */
  273. uint8_t id[5];
  274. /** Version, must be 1 */
  275. uint8_t version;
  276. /** Boot system indicator; must be "EL TORITO SPECIFICATION" */
  277. uint8_t system_id[32];
  278. } __attribute__ (( packed ));
  279. /** An El Torito Boot Record Volume Descriptor */
  280. struct eltorito_descriptor {
  281. /** Fixed portion */
  282. struct eltorito_descriptor_fixed fixed;
  283. /** Unused */
  284. uint8_t unused[32];
  285. /** Boot catalog sector */
  286. uint32_t sector;
  287. } __attribute__ (( packed ));
  288. /** ISO9660 Boot Volume Descriptor type */
  289. #define ISO9660_TYPE_BOOT 0x00
  290. /** El Torito Boot Record Volume Descriptor block address */
  291. #define ELTORITO_LBA 17
  292. /** An El Torito Boot Catalog Validation Entry */
  293. struct eltorito_validation_entry {
  294. /** Header ID; must be 1 */
  295. uint8_t header_id;
  296. /** Platform ID
  297. *
  298. * 0 = 80x86
  299. * 1 = PowerPC
  300. * 2 = Mac
  301. */
  302. uint8_t platform_id;
  303. /** Reserved */
  304. uint16_t reserved;
  305. /** ID string */
  306. uint8_t id_string[24];
  307. /** Checksum word */
  308. uint16_t checksum;
  309. /** Signature; must be 0xaa55 */
  310. uint16_t signature;
  311. } __attribute__ (( packed ));
  312. /** El Torito platform IDs */
  313. enum eltorito_platform_id {
  314. ELTORITO_PLATFORM_X86 = 0x00,
  315. ELTORITO_PLATFORM_POWERPC = 0x01,
  316. ELTORITO_PLATFORM_MAC = 0x02,
  317. };
  318. /** A bootable entry in the El Torito Boot Catalog */
  319. struct eltorito_boot_entry {
  320. /** Boot indicator
  321. *
  322. * Must be @c ELTORITO_BOOTABLE for a bootable ISO image
  323. */
  324. uint8_t indicator;
  325. /** Media type
  326. *
  327. */
  328. uint8_t media_type;
  329. /** Load segment */
  330. uint16_t load_segment;
  331. /** System type */
  332. uint8_t filesystem;
  333. /** Unused */
  334. uint8_t reserved_a;
  335. /** Sector count */
  336. uint16_t length;
  337. /** Starting sector */
  338. uint32_t start;
  339. /** Unused */
  340. uint8_t reserved_b[20];
  341. } __attribute__ (( packed ));
  342. /** Boot indicator for a bootable ISO image */
  343. #define ELTORITO_BOOTABLE 0x88
  344. /** El Torito media types */
  345. enum eltorito_media_type {
  346. /** No emulation */
  347. ELTORITO_NO_EMULATION = 0,
  348. };
  349. #endif /* INT13_H */