Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / arch / i386 / include / int13.h
1 #ifndef INT13_H
2 #define INT13_H
3
4 /** @file
5  *
6  * INT 13 emulation
7  *
8  */
9
10 FILE_LICENCE ( GPL2_OR_LATER );
11
12 #include <stdint.h>
13 #include <ipxe/list.h>
14 #include <ipxe/edd.h>
15 #include <realmode.h>
16
17 /**
18  * @defgroup int13ops INT 13 operation codes
19  * @{
20  */
21
22 /** Reset disk system */
23 #define INT13_RESET                     0x00
24 /** Get status of last operation */
25 #define INT13_GET_LAST_STATUS           0x01
26 /** Read sectors */
27 #define INT13_READ_SECTORS              0x02
28 /** Write sectors */
29 #define INT13_WRITE_SECTORS             0x03
30 /** Get drive parameters */
31 #define INT13_GET_PARAMETERS            0x08
32 /** Get disk type */
33 #define INT13_GET_DISK_TYPE             0x15
34 /** Extensions installation check */
35 #define INT13_EXTENSION_CHECK           0x41
36 /** Extended read */
37 #define INT13_EXTENDED_READ             0x42
38 /** Extended write */
39 #define INT13_EXTENDED_WRITE            0x43
40 /** Verify sectors */
41 #define INT13_EXTENDED_VERIFY           0x44
42 /** Extended seek */
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
50
51 /** @} */
52
53 /**
54  * @defgroup int13status INT 13 status codes
55  * @{
56  */
57
58 /** Operation completed successfully */
59 #define INT13_STATUS_SUCCESS            0x00
60 /** Invalid function or parameter */
61 #define INT13_STATUS_INVALID            0x01
62 /** Read error */
63 #define INT13_STATUS_READ_ERROR         0x04
64 /** Reset failed */
65 #define INT13_STATUS_RESET_FAILED       0x05
66 /** Write error */
67 #define INT13_STATUS_WRITE_ERROR        0xcc
68
69 /** @} */
70
71 /** Block size for non-extended INT 13 calls */
72 #define INT13_BLKSIZE 512
73
74 /** @defgroup int13fddtype INT 13 floppy disk drive types
75  * @{
76  */
77
78 /** 360K */
79 #define INT13_FDD_TYPE_360K             0x01
80 /** 1.2M */
81 #define INT13_FDD_TYPE_1M2              0x02
82 /** 720K */
83 #define INT13_FDD_TYPE_720K             0x03
84 /** 1.44M */
85 #define INT13_FDD_TYPE_1M44             0x04
86
87 /** An INT 13 disk address packet */
88 struct int13_disk_address {
89         /** Size of the packet, in bytes */
90         uint8_t bufsize;
91         /** Reserved */
92         uint8_t reserved_a;
93         /** Block count */
94         uint8_t count;
95         /** Reserved */
96         uint8_t reserved_b;
97         /** Data buffer */
98         struct segoff buffer;
99         /** Starting block number */
100         uint64_t lba;
101         /** Data buffer (EDD 3.0+ only) */
102         uint64_t buffer_phys;
103         /** Block count (EDD 4.0+ only) */
104         uint32_t long_count;
105         /** Reserved */
106         uint32_t reserved_c;
107 } __attribute__ (( packed ));
108
109 /** INT 13 disk parameters */
110 struct int13_disk_parameters {
111         /** Size of this structure */
112         uint16_t bufsize;
113         /** Flags */
114         uint16_t flags;
115         /** Number of cylinders */
116         uint32_t cylinders;
117         /** Number of heads */
118         uint32_t heads;
119         /** Number of sectors per track */
120         uint32_t sectors_per_track;
121         /** Total number of sectors on drive */
122         uint64_t sectors;
123         /** Bytes per sector */
124         uint16_t sector_size;
125         /** Device parameter table extension */
126         struct segoff dpte;
127         /** Device path information */
128         struct edd_device_path_information dpi;
129 } __attribute__ (( packed ));
130
131 /**
132  * @defgroup int13types INT 13 disk types
133  * @{
134  */
135
136 /** No such drive */
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
142 /** Hard disk */
143 #define INT13_DISK_TYPE_HDD     0x03
144
145 /** @} */
146
147 /**
148  * @defgroup int13flags INT 13 disk parameter flags
149  * @{
150  */
151
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
166
167 /** @} */
168
169 /**
170  * @defgroup int13exts INT 13 extension flags
171  * @{
172  */
173
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
182
183 /** @} */
184
185 /**
186  * @defgroup int13vers INT 13 extension versions
187  * @{
188  */
189
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
198
199 /** @} */ 
200
201 /** Maximum number of sectors for which CHS geometry is allowed to be valid
202  *
203  * This number is taken from the EDD specification.
204  */
205 #define INT13_MAX_CHS_SECTORS           15482880
206
207 /** Bootable CD-ROM specification packet */
208 struct int13_cdrom_specification {
209         /** Size of packet in bytes */
210         uint8_t size;
211         /** Boot media type */
212         uint8_t media_type;
213         /** Drive number */
214         uint8_t drive;
215         /** CD-ROM controller number */
216         uint8_t controller;
217         /** LBA of disk image to emulate */
218         uint32_t lba;
219         /** Device specification */
220         uint16_t device;
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 */
228         uint8_t cyl;
229         /** Sector number, plus high 2 bits of cylinder number */
230         uint8_t cyl_sector;
231         /** Head number */
232         uint8_t head;
233 } __attribute__ (( packed ));
234
235 /** Bootable CD-ROM boot catalog command packet */
236 struct int13_cdrom_boot_catalog_command {
237         /** Size of packet in bytes */
238         uint8_t size;
239         /** Number of sectors of boot catalog to read */
240         uint8_t count;
241         /** Buffer for boot catalog */
242         uint32_t buffer;
243         /** First sector in boot catalog to transfer */
244         uint16_t start;
245 } __attribute__ (( packed ));
246
247 /** A C/H/S address within a partition table entry */
248 struct partition_chs {
249         /** Head number */
250         uint8_t head;
251         /** Sector number, plus high 2 bits of cylinder number */
252         uint8_t cyl_sector;
253         /** Low 8 bits of cylinder number */
254         uint8_t cyl;
255 } __attribute__ (( packed ));
256
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 ) )
260
261 /** A partition table entry within the MBR */
262 struct partition_table_entry {
263         /** Bootable flag */
264         uint8_t bootable;
265         /** C/H/S start address */
266         struct partition_chs chs_start;
267         /** System indicator (partition type) */
268         uint8_t type;
269         /** C/H/S end address */
270         struct partition_chs chs_end;
271         /** Linear start address */
272         uint32_t start;
273         /** Linear length */
274         uint32_t length;
275 } __attribute__ (( packed ));
276
277 /** A Master Boot Record */
278 struct master_boot_record {
279         /** Code area */
280         uint8_t code[440];
281         /** Disk signature */
282         uint32_t signature;
283         /** Padding */
284         uint8_t pad[2];
285         /** Partition table */
286         struct partition_table_entry partitions[4];
287         /** 0x55aa MBR signature */
288         uint16_t magic;
289 } __attribute__ (( packed ));
290
291 /** MBR magic signature */
292 #define INT13_MBR_MAGIC 0xaa55
293
294 /** A floppy disk geometry */
295 struct int13_fdd_geometry {
296         /** Number of tracks */
297         uint8_t tracks;
298         /** Number of heads and sectors per track */
299         uint8_t heads_spt;
300 };
301
302 /** Define a floppy disk geometry */
303 #define INT13_FDD_GEOMETRY( cylinders, heads, sectors )                 \
304         {                                                               \
305                 .tracks = (cylinders),                                  \
306                 .heads_spt = ( ( (heads) << 6 ) | (sectors) ),          \
307         }
308
309 /** Get floppy disk number of cylinders */
310 #define INT13_FDD_CYLINDERS( geometry ) ( (geometry)->tracks )
311
312 /** Get floppy disk number of heads */
313 #define INT13_FDD_HEADS( geometry ) ( (geometry)->heads_spt >> 6 )
314
315 /** Get floppy disk number of sectors per track */
316 #define INT13_FDD_SECTORS( geometry ) ( (geometry)->heads_spt & 0x3f )
317
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;
325         uint8_t gap_length;
326         uint8_t data_length;
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 ));
332
333 #endif /* INT13_H */