11 #include <gpxe/list.h>
16 * @defgroup int13ops INT 13 operation codes
20 /** Reset disk system */
21 #define INT13_RESET 0x00
22 /** Get status of last operation */
23 #define INT13_GET_LAST_STATUS 0x01
25 #define INT13_READ_SECTORS 0x02
27 #define INT13_WRITE_SECTORS 0x03
28 /** Get drive parameters */
29 #define INT13_GET_PARAMETERS 0x08
31 #define INT13_GET_DISK_TYPE 0x15
32 /** Extensions installation check */
33 #define INT13_EXTENSION_CHECK 0x41
35 #define INT13_EXTENDED_READ 0x42
37 #define INT13_EXTENDED_WRITE 0x43
38 /** Get extended drive parameters */
39 #define INT13_GET_EXTENDED_PARAMETERS 0x48
40 /** Get CD-ROM status / terminate emulation */
41 #define INT13_CDROM_STATUS_TERMINATE 0x4b
46 * @defgroup int13status INT 13 status codes
50 /** Operation completed successfully */
51 #define INT13_STATUS_SUCCESS 0x00
52 /** Invalid function or parameter */
53 #define INT13_STATUS_INVALID 0x01
55 #define INT13_STATUS_READ_ERROR 0x04
57 #define INT13_STATUS_WRITE_ERROR 0xcc
61 /** Block size for non-extended INT 13 calls */
62 #define INT13_BLKSIZE 512
64 /** An INT 13 emulated drive */
66 /** List of all registered drives */
67 struct list_head list;
69 /** Underlying block device */
70 struct block_device *blockdev;
72 /** BIOS drive number (0x80-0xff) */
74 /** Number of cylinders
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
82 unsigned int cylinders;
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.
91 /** Number of sectors per track
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.
97 unsigned int sectors_per_track;
99 /** Status of last operation */
103 /** An INT 13 disk address packet */
104 struct int13_disk_address {
105 /** Size of the packet, in bytes */
107 /** Reserved, must be zero */
112 struct segoff buffer;
113 /** Starting block number */
115 /** Data buffer (EDD-3.0 only) */
116 uint64_t buffer_phys;
117 } __attribute__ (( packed ));
119 /** INT 13 disk parameters */
120 struct int13_disk_parameters {
121 /** Size of this structure */
125 /** Number of cylinders */
127 /** Number of heads */
129 /** Number of sectors per track */
130 uint32_t sectors_per_track;
131 /** Total number of sectors on drive */
133 /** Bytes per sector */
134 uint16_t sector_size;
136 } __attribute__ (( packed ));
139 * @defgroup int13types INT 13 disk types
144 #define INT13_DISK_TYPE_NONE 0x00
145 /** Floppy without change-line support */
146 #define INT13_DISK_TYPE_FDD 0x01
147 /** Floppy with change-line support */
148 #define INT13_DISK_TYPE_FDD_CL 0x02
150 #define INT13_DISK_TYPE_HDD 0x03
155 * @defgroup int13flags INT 13 disk parameter flags
159 /** DMA boundary errors handled transparently */
160 #define INT13_FL_DMA_TRANSPARENT 0x01
161 /** CHS information is valid */
162 #define INT13_FL_CHS_VALID 0x02
163 /** Removable drive */
164 #define INT13_FL_REMOVABLE 0x04
165 /** Write with verify supported */
166 #define INT13_FL_VERIFIABLE 0x08
167 /** Has change-line supported (valid only for removable drives) */
168 #define INT13_FL_CHANGE_LINE 0x10
169 /** Drive can be locked (valid only for removable drives) */
170 #define INT13_FL_LOCKABLE 0x20
171 /** CHS is max possible, not current media (valid only for removable drives) */
172 #define INT13_FL_CHS_MAX 0x40
177 * @defgroup int13exts INT 13 extension flags
181 /** Extended disk access functions supported */
182 #define INT13_EXTENSION_LINEAR 0x01
183 /** Removable drive functions supported */
184 #define INT13_EXTENSION_REMOVABLE 0x02
185 /** EDD functions supported */
186 #define INT13_EXTENSION_EDD 0x04
191 * @defgroup int13vers INT 13 extension versions
195 /** INT13 extensions version 1.x */
196 #define INT13_EXTENSION_VER_1_X 0x01
197 /** INT13 extensions version 2.0 (EDD-1.0) */
198 #define INT13_EXTENSION_VER_2_0 0x20
199 /** INT13 extensions version 2.1 (EDD-1.1) */
200 #define INT13_EXTENSION_VER_2_1 0x21
201 /** INT13 extensions version 3.0 (EDD-3.0) */
202 #define INT13_EXTENSION_VER_3_0 0x30
206 /** Bootable CD-ROM specification packet */
207 struct int13_cdrom_specification {
208 /** Size of packet in bytes */
210 /** Boot media type */
214 /** CD-ROM controller number */
216 /** LBA of disk image to emulate */
218 /** Device specification */
220 /** Segment of 3K buffer for caching CD-ROM reads */
221 uint16_t cache_segment;
222 /** Load segment for initial boot image */
223 uint16_t load_segment;
224 /** Number of 512-byte sectors to load */
225 uint16_t load_sectors;
226 /** Low 8 bits of cylinder number */
228 /** Sector number, plus high 2 bits of cylinder number */
232 } __attribute__ (( packed ));
234 /** A C/H/S address within a partition table entry */
235 struct partition_chs {
238 /** Sector number, plus high 2 bits of cylinder number */
240 /** Low 8 bits of cylinder number */
242 } __attribute__ (( packed ));
244 #define PART_HEAD(chs) ( (chs).head )
245 #define PART_SECTOR(chs) ( (chs).cyl_sector & 0x3f )
246 #define PART_CYLINDER(chs) ( (chs).cyl | ( ( (chs).cyl_sector & 0xc0 ) << 2 ) )
248 /** A partition table entry within the MBR */
249 struct partition_table_entry {
252 /** C/H/S start address */
253 struct partition_chs chs_start;
254 /** System indicator (partition type) */
256 /** C/H/S end address */
257 struct partition_chs chs_end;
258 /** Linear start address */
262 } __attribute__ (( packed ));
264 /** A Master Boot Record */
265 struct master_boot_record {
267 /** Partition table */
268 struct partition_table_entry partitions[4];
269 /** 0x55aa MBR signature */
271 } __attribute__ (( packed ));
273 extern void register_int13_drive ( struct int13_drive *drive );
274 extern void unregister_int13_drive ( struct int13_drive *drive );
275 extern int int13_boot ( unsigned int drive );