10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
13 #include <ipxe/list.h>
18 * @defgroup int13ops INT 13 operation codes
22 /** Reset disk system */
23 #define INT13_RESET 0x00
24 /** Get status of last operation */
25 #define INT13_GET_LAST_STATUS 0x01
27 #define INT13_READ_SECTORS 0x02
29 #define INT13_WRITE_SECTORS 0x03
30 /** Get drive parameters */
31 #define INT13_GET_PARAMETERS 0x08
33 #define INT13_GET_DISK_TYPE 0x15
34 /** Extensions installation check */
35 #define INT13_EXTENSION_CHECK 0x41
37 #define INT13_EXTENDED_READ 0x42
39 #define INT13_EXTENDED_WRITE 0x43
41 #define INT13_EXTENDED_VERIFY 0x44
43 #define INT13_EXTENDED_SEEK 0x47
44 /** Get extended drive parameters */
45 #define INT13_GET_EXTENDED_PARAMETERS 0x48
46 /** Get CD-ROM status / terminate emulation */
47 #define INT13_CDROM_STATUS_TERMINATE 0x4b
48 /** Read CD-ROM boot catalog */
49 #define INT13_CDROM_READ_BOOT_CATALOG 0x4d
54 * @defgroup int13status INT 13 status codes
58 /** Operation completed successfully */
59 #define INT13_STATUS_SUCCESS 0x00
60 /** Invalid function or parameter */
61 #define INT13_STATUS_INVALID 0x01
63 #define INT13_STATUS_READ_ERROR 0x04
65 #define INT13_STATUS_RESET_FAILED 0x05
67 #define INT13_STATUS_WRITE_ERROR 0xcc
71 /** Block size for non-extended INT 13 calls */
72 #define INT13_BLKSIZE 512
74 /** @defgroup int13fddtype INT 13 floppy disk drive types
79 #define INT13_FDD_TYPE_360K 0x01
81 #define INT13_FDD_TYPE_1M2 0x02
83 #define INT13_FDD_TYPE_720K 0x03
85 #define INT13_FDD_TYPE_1M44 0x04
87 /** An INT 13 disk address packet */
88 struct int13_disk_address {
89 /** Size of the packet, in bytes */
99 /** Starting block number */
101 /** Data buffer (EDD 3.0+ only) */
102 uint64_t buffer_phys;
103 /** Block count (EDD 4.0+ only) */
107 } __attribute__ (( packed ));
109 /** INT 13 disk parameters */
110 struct int13_disk_parameters {
111 /** Size of this structure */
115 /** Number of cylinders */
117 /** Number of heads */
119 /** Number of sectors per track */
120 uint32_t sectors_per_track;
121 /** Total number of sectors on drive */
123 /** Bytes per sector */
124 uint16_t sector_size;
125 /** Device parameter table extension */
127 /** Device path information */
128 struct edd_device_path_information dpi;
129 } __attribute__ (( packed ));
132 * @defgroup int13types INT 13 disk types
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
143 #define INT13_DISK_TYPE_HDD 0x03
148 * @defgroup int13flags INT 13 disk parameter flags
152 /** DMA boundary errors handled transparently */
153 #define INT13_FL_DMA_TRANSPARENT 0x01
154 /** CHS information is valid */
155 #define INT13_FL_CHS_VALID 0x02
156 /** Removable drive */
157 #define INT13_FL_REMOVABLE 0x04
158 /** Write with verify supported */
159 #define INT13_FL_VERIFIABLE 0x08
160 /** Has change-line supported (valid only for removable drives) */
161 #define INT13_FL_CHANGE_LINE 0x10
162 /** Drive can be locked (valid only for removable drives) */
163 #define INT13_FL_LOCKABLE 0x20
164 /** CHS is max possible, not current media (valid only for removable drives) */
165 #define INT13_FL_CHS_MAX 0x40
170 * @defgroup int13exts INT 13 extension flags
174 /** Extended disk access functions supported */
175 #define INT13_EXTENSION_LINEAR 0x01
176 /** Removable drive functions supported */
177 #define INT13_EXTENSION_REMOVABLE 0x02
178 /** EDD functions supported */
179 #define INT13_EXTENSION_EDD 0x04
180 /** 64-bit extensions are present */
181 #define INT13_EXTENSION_64BIT 0x08
186 * @defgroup int13vers INT 13 extension versions
190 /** INT13 extensions version 1.x */
191 #define INT13_EXTENSION_VER_1_X 0x01
192 /** INT13 extensions version 2.0 (EDD-1.0) */
193 #define INT13_EXTENSION_VER_2_0 0x20
194 /** INT13 extensions version 2.1 (EDD-1.1) */
195 #define INT13_EXTENSION_VER_2_1 0x21
196 /** INT13 extensions version 3.0 (EDD-3.0) */
197 #define INT13_EXTENSION_VER_3_0 0x30
201 /** Maximum number of sectors for which CHS geometry is allowed to be valid
203 * This number is taken from the EDD specification.
205 #define INT13_MAX_CHS_SECTORS 15482880
207 /** Bootable CD-ROM specification packet */
208 struct int13_cdrom_specification {
209 /** Size of packet in bytes */
211 /** Boot media type */
215 /** CD-ROM controller number */
217 /** LBA of disk image to emulate */
219 /** Device specification */
221 /** Segment of 3K buffer for caching CD-ROM reads */
222 uint16_t cache_segment;
223 /** Load segment for initial boot image */
224 uint16_t load_segment;
225 /** Number of 512-byte sectors to load */
226 uint16_t load_sectors;
227 /** Low 8 bits of cylinder number */
229 /** Sector number, plus high 2 bits of cylinder number */
233 } __attribute__ (( packed ));
235 /** Bootable CD-ROM boot catalog command packet */
236 struct int13_cdrom_boot_catalog_command {
237 /** Size of packet in bytes */
239 /** Number of sectors of boot catalog to read */
241 /** Buffer for boot catalog */
243 /** First sector in boot catalog to transfer */
245 } __attribute__ (( packed ));
247 /** A C/H/S address within a partition table entry */
248 struct partition_chs {
251 /** Sector number, plus high 2 bits of cylinder number */
253 /** Low 8 bits of cylinder number */
255 } __attribute__ (( packed ));
257 #define PART_HEAD(chs) ( (chs).head )
258 #define PART_SECTOR(chs) ( (chs).cyl_sector & 0x3f )
259 #define PART_CYLINDER(chs) ( (chs).cyl | ( ( (chs).cyl_sector & 0xc0 ) << 2 ) )
261 /** A partition table entry within the MBR */
262 struct partition_table_entry {
265 /** C/H/S start address */
266 struct partition_chs chs_start;
267 /** System indicator (partition type) */
269 /** C/H/S end address */
270 struct partition_chs chs_end;
271 /** Linear start address */
275 } __attribute__ (( packed ));
277 /** A Master Boot Record */
278 struct master_boot_record {
281 /** Disk signature */
285 /** Partition table */
286 struct partition_table_entry partitions[4];
287 /** 0x55aa MBR signature */
289 } __attribute__ (( packed ));
291 /** MBR magic signature */
292 #define INT13_MBR_MAGIC 0xaa55
294 /** A floppy disk geometry */
295 struct int13_fdd_geometry {
296 /** Number of tracks */
298 /** Number of heads and sectors per track */
302 /** Define a floppy disk geometry */
303 #define INT13_FDD_GEOMETRY( cylinders, heads, sectors ) \
305 .tracks = (cylinders), \
306 .heads_spt = ( ( (heads) << 6 ) | (sectors) ), \
309 /** Get floppy disk number of cylinders */
310 #define INT13_FDD_CYLINDERS( geometry ) ( (geometry)->tracks )
312 /** Get floppy disk number of heads */
313 #define INT13_FDD_HEADS( geometry ) ( (geometry)->heads_spt >> 6 )
315 /** Get floppy disk number of sectors per track */
316 #define INT13_FDD_SECTORS( geometry ) ( (geometry)->heads_spt & 0x3f )
318 /** A floppy drive parameter table */
319 struct int13_fdd_parameters {
320 uint8_t step_rate__head_unload;
321 uint8_t head_load__ndma;
322 uint8_t motor_off_delay;
323 uint8_t bytes_per_sector;
324 uint8_t sectors_per_track;
327 uint8_t format_gap_length;
328 uint8_t format_filler;
329 uint8_t head_settle_time;
330 uint8_t motor_start_time;
331 } __attribute__ (( packed ));