|
|
1.1 root 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:
49: /** @} */
50:
51: /**
52: * @defgroup int13status INT 13 status codes
53: * @{
54: */
55:
56: /** Operation completed successfully */
57: #define INT13_STATUS_SUCCESS 0x00
58: /** Invalid function or parameter */
59: #define INT13_STATUS_INVALID 0x01
60: /** Read error */
61: #define INT13_STATUS_READ_ERROR 0x04
62: /** Reset failed */
63: #define INT13_STATUS_RESET_FAILED 0x05
64: /** Write error */
65: #define INT13_STATUS_WRITE_ERROR 0xcc
66:
67: /** @} */
68:
69: /** Block size for non-extended INT 13 calls */
70: #define INT13_BLKSIZE 512
71:
72: /** An INT 13 disk address packet */
73: struct int13_disk_address {
74: /** Size of the packet, in bytes */
75: uint8_t bufsize;
76: /** Reserved */
77: uint8_t reserved_a;
78: /** Block count */
79: uint8_t count;
80: /** Reserved */
81: uint8_t reserved_b;
82: /** Data buffer */
83: struct segoff buffer;
84: /** Starting block number */
85: uint64_t lba;
86: /** Data buffer (EDD 3.0+ only) */
87: uint64_t buffer_phys;
88: /** Block count (EDD 4.0+ only) */
89: uint32_t long_count;
90: /** Reserved */
91: uint32_t reserved_c;
92: } __attribute__ (( packed ));
93:
94: /** INT 13 disk parameters */
95: struct int13_disk_parameters {
96: /** Size of this structure */
97: uint16_t bufsize;
98: /** Flags */
99: uint16_t flags;
100: /** Number of cylinders */
101: uint32_t cylinders;
102: /** Number of heads */
103: uint32_t heads;
104: /** Number of sectors per track */
105: uint32_t sectors_per_track;
106: /** Total number of sectors on drive */
107: uint64_t sectors;
108: /** Bytes per sector */
109: uint16_t sector_size;
110: /** Device parameter table extension */
111: struct segoff dpte;
112: /** Device path information */
113: struct edd_device_path_information dpi;
114: } __attribute__ (( packed ));
115:
116: /**
117: * @defgroup int13types INT 13 disk types
118: * @{
119: */
120:
121: /** No such drive */
122: #define INT13_DISK_TYPE_NONE 0x00
123: /** Floppy without change-line support */
124: #define INT13_DISK_TYPE_FDD 0x01
125: /** Floppy with change-line support */
126: #define INT13_DISK_TYPE_FDD_CL 0x02
127: /** Hard disk */
128: #define INT13_DISK_TYPE_HDD 0x03
129:
130: /** @} */
131:
132: /**
133: * @defgroup int13flags INT 13 disk parameter flags
134: * @{
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:
154: /**
155: * @defgroup int13exts INT 13 extension flags
156: * @{
157: */
158:
159: /** Extended disk access functions supported */
160: #define INT13_EXTENSION_LINEAR 0x01
161: /** Removable drive functions supported */
162: #define INT13_EXTENSION_REMOVABLE 0x02
163: /** EDD functions supported */
164: #define INT13_EXTENSION_EDD 0x04
165: /** 64-bit extensions are present */
166: #define INT13_EXTENSION_64BIT 0x08
167:
168: /** @} */
169:
170: /**
171: * @defgroup int13vers INT 13 extension versions
172: * @{
173: */
174:
175: /** INT13 extensions version 1.x */
176: #define INT13_EXTENSION_VER_1_X 0x01
177: /** INT13 extensions version 2.0 (EDD-1.0) */
178: #define INT13_EXTENSION_VER_2_0 0x20
179: /** INT13 extensions version 2.1 (EDD-1.1) */
180: #define INT13_EXTENSION_VER_2_1 0x21
181: /** INT13 extensions version 3.0 (EDD-3.0) */
182: #define INT13_EXTENSION_VER_3_0 0x30
183:
184: /** @} */
185:
186: /** Maximum number of sectors for which CHS geometry is allowed to be valid
187: *
188: * This number is taken from the EDD specification.
189: */
190: #define INT13_MAX_CHS_SECTORS 15482880
191:
192: /** Bootable CD-ROM specification packet */
193: struct int13_cdrom_specification {
194: /** Size of packet in bytes */
195: uint8_t size;
196: /** Boot media type */
197: uint8_t media_type;
198: /** Drive number */
199: uint8_t drive;
200: /** CD-ROM controller number */
201: uint8_t controller;
202: /** LBA of disk image to emulate */
203: uint32_t lba;
204: /** Device specification */
205: uint16_t device;
206: /** Segment of 3K buffer for caching CD-ROM reads */
207: uint16_t cache_segment;
208: /** Load segment for initial boot image */
209: uint16_t load_segment;
210: /** Number of 512-byte sectors to load */
211: uint16_t load_sectors;
212: /** Low 8 bits of cylinder number */
213: uint8_t cyl;
214: /** Sector number, plus high 2 bits of cylinder number */
215: uint8_t cyl_sector;
216: /** Head number */
217: uint8_t head;
218: } __attribute__ (( packed ));
219:
220: /** A C/H/S address within a partition table entry */
221: struct partition_chs {
222: /** Head number */
223: uint8_t head;
224: /** Sector number, plus high 2 bits of cylinder number */
225: uint8_t cyl_sector;
226: /** Low 8 bits of cylinder number */
227: uint8_t cyl;
228: } __attribute__ (( packed ));
229:
230: #define PART_HEAD(chs) ( (chs).head )
231: #define PART_SECTOR(chs) ( (chs).cyl_sector & 0x3f )
232: #define PART_CYLINDER(chs) ( (chs).cyl | ( ( (chs).cyl_sector & 0xc0 ) << 2 ) )
233:
234: /** A partition table entry within the MBR */
235: struct partition_table_entry {
236: /** Bootable flag */
237: uint8_t bootable;
238: /** C/H/S start address */
239: struct partition_chs chs_start;
240: /** System indicator (partition type) */
241: uint8_t type;
242: /** C/H/S end address */
243: struct partition_chs chs_end;
244: /** Linear start address */
245: uint32_t start;
246: /** Linear length */
247: uint32_t length;
248: } __attribute__ (( packed ));
249:
250: /** A Master Boot Record */
251: struct master_boot_record {
252: /** Code area */
253: uint8_t code[440];
254: /** Disk signature */
255: uint32_t signature;
256: /** Padding */
257: uint8_t pad[2];
258: /** Partition table */
259: struct partition_table_entry partitions[4];
260: /** 0x55aa MBR signature */
261: uint16_t magic;
262: } __attribute__ (( packed ));
263:
264: /** Use natural BIOS drive number */
265: #define INT13_USE_NATURAL_DRIVE 0xff
266:
267: #endif /* INT13_H */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.