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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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 drive number (0x80-0xff) */
  60. unsigned int drive;
  61. /** Number of cylinders
  62. *
  63. * The cylinder number field in an INT 13 call is ten bits
  64. * wide, giving a maximum of 1024 cylinders. Conventionally,
  65. * when the 7.8GB limit of a CHS address is exceeded, it is
  66. * the number of cylinders that is increased beyond the
  67. * addressable limit.
  68. */
  69. unsigned int cylinders;
  70. /** Number of heads
  71. *
  72. * The head number field in an INT 13 call is eight bits wide,
  73. * giving a maximum of 256 heads. However, apparently all
  74. * versions of MS-DOS up to and including Win95 fail with 256
  75. * heads, so the maximum encountered in practice is 255.
  76. */
  77. unsigned int heads;
  78. /** Number of sectors per track
  79. *
  80. * The sector number field in an INT 13 call is six bits wide,
  81. * giving a maximum of 63 sectors, since sector numbering
  82. * (unlike head and cylinder numbering) starts at 1, not 0.
  83. */
  84. unsigned int sectors_per_track;
  85. /** Status of last operation */
  86. int last_status;
  87. };
  88. /** An INT 13 disk address packet */
  89. struct int13_disk_address {
  90. /** Size of the packet, in bytes */
  91. uint8_t bufsize;
  92. /** Reserved, must be zero */
  93. uint8_t reserved;
  94. /** Block count */
  95. uint16_t count;
  96. /** Data buffer */
  97. struct segoff buffer;
  98. /** Starting block number */
  99. uint64_t lba;
  100. /** Data buffer (EDD-3.0 only) */
  101. uint64_t buffer_phys;
  102. } __attribute__ (( packed ));
  103. /** INT 13 disk parameters */
  104. struct int13_disk_parameters {
  105. /** Size of this structure */
  106. uint16_t bufsize;
  107. /** Flags */
  108. uint16_t flags;
  109. /** Number of cylinders */
  110. uint32_t cylinders;
  111. /** Number of heads */
  112. uint32_t heads;
  113. /** Number of sectors per track */
  114. uint32_t sectors_per_track;
  115. /** Total number of sectors on drive */
  116. uint64_t sectors;
  117. /** Bytes per sector */
  118. uint16_t sector_size;
  119. } __attribute__ (( packed ));
  120. /**
  121. * @defgroup int13types INT 13 disk types
  122. * @{
  123. */
  124. /** No such drive */
  125. #define INT13_DISK_TYPE_NONE 0x00
  126. /** Floppy without change-line support */
  127. #define INT13_DISK_TYPE_FDD 0x01
  128. /** Floppy with change-line support */
  129. #define INT13_DISK_TYPE_FDD_CL 0x02
  130. /** Hard disk */
  131. #define INT13_DISK_TYPE_HDD 0x03
  132. /** @} */
  133. /**
  134. * @defgroup int13flags INT 13 disk parameter flags
  135. * @{
  136. */
  137. /** DMA boundary errors handled transparently */
  138. #define INT13_FL_DMA_TRANSPARENT 0x01
  139. /** CHS information is valid */
  140. #define INT13_FL_CHS_VALID 0x02
  141. /** Removable drive */
  142. #define INT13_FL_REMOVABLE 0x04
  143. /** Write with verify supported */
  144. #define INT13_FL_VERIFIABLE 0x08
  145. /** Has change-line supported (valid only for removable drives) */
  146. #define INT13_FL_CHANGE_LINE 0x10
  147. /** Drive can be locked (valid only for removable drives) */
  148. #define INT13_FL_LOCKABLE 0x20
  149. /** CHS is max possible, not current media (valid only for removable drives) */
  150. #define INT13_FL_CHS_MAX 0x40
  151. /** @} */
  152. /**
  153. * @defgroup int13exts INT 13 extension flags
  154. * @{
  155. */
  156. /** Extended disk access functions supported */
  157. #define INT13_EXTENSION_LINEAR 0x01
  158. /** Removable drive functions supported */
  159. #define INT13_EXTENSION_REMOVABLE 0x02
  160. /** EDD functions supported */
  161. #define INT13_EXTENSION_EDD 0x04
  162. /** @} */
  163. /**
  164. * @defgroup int13vers INT 13 extension versions
  165. * @{
  166. */
  167. /** INT13 extensions version 1.x */
  168. #define INT13_EXTENSION_VER_1_X 0x01
  169. /** INT13 extensions version 2.0 (EDD-1.0) */
  170. #define INT13_EXTENSION_VER_2_0 0x20
  171. /** INT13 extensions version 2.1 (EDD-1.1) */
  172. #define INT13_EXTENSION_VER_2_1 0x21
  173. /** INT13 extensions version 3.0 (EDD-3.0) */
  174. #define INT13_EXTENSION_VER_3_0 0x30
  175. /** @} */
  176. /** Bootable CD-ROM specification packet */
  177. struct int13_cdrom_specification {
  178. /** Size of packet in bytes */
  179. uint8_t size;
  180. /** Boot media type */
  181. uint8_t media_type;
  182. /** Drive number */
  183. uint8_t drive;
  184. /** CD-ROM controller number */
  185. uint8_t controller;
  186. /** LBA of disk image to emulate */
  187. uint32_t lba;
  188. /** Device specification */
  189. uint16_t device;
  190. /** Segment of 3K buffer for caching CD-ROM reads */
  191. uint16_t cache_segment;
  192. /** Load segment for initial boot image */
  193. uint16_t load_segment;
  194. /** Number of 512-byte sectors to load */
  195. uint16_t load_sectors;
  196. /** Low 8 bits of cylinder number */
  197. uint8_t cyl;
  198. /** Sector number, plus high 2 bits of cylinder number */
  199. uint8_t cyl_sector;
  200. /** Head number */
  201. uint8_t head;
  202. } __attribute__ (( packed ));
  203. /** A C/H/S address within a partition table entry */
  204. struct partition_chs {
  205. /** Head number */
  206. uint8_t head;
  207. /** Sector number, plus high 2 bits of cylinder number */
  208. uint8_t cyl_sector;
  209. /** Low 8 bits of cylinder number */
  210. uint8_t cyl;
  211. } __attribute__ (( packed ));
  212. #define PART_HEAD(chs) ( (chs).head )
  213. #define PART_SECTOR(chs) ( (chs).cyl_sector & 0x3f )
  214. #define PART_CYLINDER(chs) ( (chs).cyl | ( ( (chs).cyl_sector & 0xc0 ) << 2 ) )
  215. /** A partition table entry within the MBR */
  216. struct partition_table_entry {
  217. /** Bootable flag */
  218. uint8_t bootable;
  219. /** C/H/S start address */
  220. struct partition_chs chs_start;
  221. /** System indicator (partition type) */
  222. uint8_t type;
  223. /** C/H/S end address */
  224. struct partition_chs chs_end;
  225. /** Linear start address */
  226. uint32_t start;
  227. /** Linear length */
  228. uint32_t length;
  229. } __attribute__ (( packed ));
  230. /** A Master Boot Record */
  231. struct master_boot_record {
  232. uint8_t pad[446];
  233. /** Partition table */
  234. struct partition_table_entry partitions[4];
  235. /** 0x55aa MBR signature */
  236. uint16_t signature;
  237. } __attribute__ (( packed ));
  238. extern void register_int13_drive ( struct int13_drive *drive );
  239. extern void unregister_int13_drive ( struct int13_drive *drive );
  240. extern int int13_boot ( unsigned int drive );
  241. #endif /* INT13_H */