1 | /*␊ |
2 | * Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.␊ |
3 | *␊ |
4 | * @APPLE_LICENSE_HEADER_START@␊ |
5 | * ␊ |
6 | * Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights␊ |
7 | * Reserved. This file contains Original Code and/or Modifications of␊ |
8 | * Original Code as defined in and that are subject to the Apple Public␊ |
9 | * Source License Version 2.0 (the "License"). You may not use this file␊ |
10 | * except in compliance with the License. Please obtain a copy of the␊ |
11 | * License at http://www.apple.com/publicsource and read it before using␊ |
12 | * this file.␊ |
13 | * ␊ |
14 | * The Original Code and all software distributed under the License are␊ |
15 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER␊ |
16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,␊ |
17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,␊ |
18 | * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the␊ |
19 | * License for the specific language governing rights and limitations␊ |
20 | * under the License.␊ |
21 | * ␊ |
22 | * @APPLE_LICENSE_HEADER_END@␊ |
23 | */␊ |
24 | /* Useful types. */␊ |
25 | ␊ |
26 | #ifndef __LIBSAIO_SAIO_TYPES_H␊ |
27 | #define __LIBSAIO_SAIO_TYPES_H␊ |
28 | ␊ |
29 | #include <sys/reboot.h>␊ |
30 | #include <sys/types.h>␊ |
31 | #include "bios.h"␊ |
32 | #ifdef NBP_SUPPORT␊ |
33 | #include "nbp_cmd.h"␊ |
34 | #else␊ |
35 | #include <IOKit/IOTypes.h>␊ |
36 | #endif␊ |
37 | #include "bootXnu.h"␊ |
38 | #include "uuidP.h"␊ |
39 | ␊ |
40 | #if DEBUG␊ |
41 | #define DEBUG_DISK(x) printf x␊ |
42 | #else␊ |
43 | #define DEBUG_DISK(x)␊ |
44 | #endif␊ |
45 | ␊ |
46 | /*␊ |
47 | * Keys used in system Boot.plist␊ |
48 | */␊ |
49 | #define kGraphicsModeKey␉"Graphics Mode"␊ |
50 | #define kTextModeKey␉␉"Text Mode"␊ |
51 | #define kQuietBootKey␉␉"Quiet Boot"␊ |
52 | #define kKernelFlagsKey␉␉"Kernel Flags"␊ |
53 | #define kMKextCacheKey␉␉"MKext Cache"␊ |
54 | #define kKernelNameKey␉␉"Kernel"␊ |
55 | #define kKernelCacheKey "Kernel Cache"␊ |
56 | #define kUseKernelCache "UseKernelCache" ␊ |
57 | #define kBootDeviceKey␉␉"Boot Device"␊ |
58 | #define kTimeoutKey␉␉␉"Timeout"␊ |
59 | #define kRootDeviceKey␉␉"rd"␊ |
60 | #define kBootUUIDKey␉␉"boot-uuid"␊ |
61 | #define kHelperRootUUIDKey␉"Root UUID"␊ |
62 | #define kPlatformKey␉␉"platform"␊ |
63 | #define kCDROMPromptKey␉␉"CD-ROM Prompt"␊ |
64 | #define kCDROMOptionKey␉␉"CD-ROM Option Key"␊ |
65 | #define kRescanPromptKey␉"Rescan Prompt"␊ |
66 | #define kRescanKey␉␉ "Rescan"␊ |
67 | #define kScanSingleDriveKey␉"Scan Single Drive"␊ |
68 | #define kInsantMenuKey␉␉"Instant Menu"␊ |
69 | #define kDefaultKernel␉␉"mach_kernel"␊ |
70 | #define kWaitForKeypressKey␉"Wait"␊ |
71 | ␊ |
72 | /* AsereBLN: added the other keys */␊ |
73 | ␊ |
74 | #define kProductVersion␉␉"ProductVersion"␉/* boot.c */␊ |
75 | #define karch␉␉␉␉"arch"␉␉␉␉/* boot.c */␊ |
76 | #define kDeviceProperties␉"device-properties"␉/* device_inject.c */␊ |
77 | #define kHidePartition␉␉"Hide Partition"␉/* disk.c */␊ |
78 | #define kRenamePartition␉"Rename Partition"␉/* disk.c */␊ |
79 | #define kSMBIOSKey␉␉␉"SMBIOS"␉␉␉/* fake_efi.c */␊ |
80 | #define kSystemID␉␉␉"SystemId"␉␉␉/* fake_efi.c */␊ |
81 | #define kRandomSystemID␉␉"RandomSystemId"␉/* fake_efi.c */␊ |
82 | #define kSystemType␉␉␉"SystemType"␉␉/* fake_efi.c */␊ |
83 | #define kPCIRootUID␉␉␉"PCIRootUID"␉␉/* pci_root.c */␊ |
84 | #define kDefaultPartition␉"Default Partition"␉/* sys.c */␊ |
85 | ␊ |
86 | ␊ |
87 | #define kAcpiMethod␉␉␉"Acpi2Method"␉␉// 2 (= method 2) for some machines that may hang on acpi 2 (aka acpi 64 bit) detection (replace the old kUnsafeACPI "UnsafeACPI") ␉␊ |
88 | #define kRebootOnPanic␉␉"RebootOnPanic"␊ |
89 | #define kEnableHiDPI␉␉"EnableHiDPI"␉␉// enable High resolution display (aka Retina)␊ |
90 | ␊ |
91 | #define VGA_TEXT_MODE 0␊ |
92 | ␊ |
93 | ␊ |
94 | #define UUID_LEN␉ sizeof(uuid_t)␊ |
95 | #define UUID_STR_LEN sizeof(uuid_string_t)␊ |
96 | ␊ |
97 | ␊ |
98 | #define PLATFORM_NAME_LEN 64␊ |
99 | #define ROOT_PATH_LEN 256␊ |
100 | ␊ |
101 | #define DEFAULT_SCREEN_WIDTH 1024␊ |
102 | #define DEFAULT_SCREEN_HEIGHT 768␊ |
103 | ␊ |
104 | /*␊ |
105 | * Max size fo config data array, in bytes.␊ |
106 | */␊ |
107 | #define IO_CONFIG_DATA_SIZE␉␉40960 // was 4096 // was 163840␊ |
108 | ␊ |
109 | struct tm {␊ |
110 | ␉int␉tm_sec;␉␉/* seconds after the minute [0-60] */␊ |
111 | ␉int␉tm_min;␉␉/* minutes after the hour [0-59] */␊ |
112 | ␉int␉tm_hour;␉/* hours since midnight [0-23] */␊ |
113 | ␉int␉tm_mday;␉/* day of the month [1-31] */␊ |
114 | ␉int␉tm_mon;␉␉/* months since January [0-11] */␊ |
115 | ␉int␉tm_year;␉/* years since 1900 */␊ |
116 | ␉int␉tm_wday;␉/* days since Sunday [0-6] */␊ |
117 | ␉int␉tm_yday;␉/* days since January 1 [0-365] */␊ |
118 | ␉int␉tm_isdst;␉/* Daylight Savings Time flag */␊ |
119 | ␉long␉tm_gmtoff;␉/* offset from CUT in seconds */␊ |
120 | ␉char␉*tm_zone;␉/* timezone abbreviation */␊ |
121 | };␊ |
122 | ␊ |
123 | /** System time structure */␊ |
124 | struct timeval {␊ |
125 | ␉time_t tv_sec; /**< Seconds */␊ |
126 | ␉suseconds_t tv_usec; /**< Microseconds */␊ |
127 | };␊ |
128 | ␊ |
129 | typedef struct tm_t␊ |
130 | {␊ |
131 | int tm_sec ; /* seconds after minute [0-61] (61 allows for 2 leap-seconds)*/␊ |
132 | int tm_min ; /* minutes after hour [0-59] */␊ |
133 | int tm_hour ; /* hours after midnight [0-23] */␊ |
134 | int tm_mday ; /* day of the month [1-31] */␊ |
135 | int tm_mon ; /* month of year [0-11] */␊ |
136 | int tm_year ; /* current year-1900 */␊ |
137 | ␊ |
138 | }tm_t;␊ |
139 | ␊ |
140 | typedef unsigned long entry_t;␊ |
141 | ␊ |
142 | typedef struct {␊ |
143 | unsigned int sectors:8;␊ |
144 | unsigned int heads:8;␊ |
145 | unsigned int cylinders:16;␊ |
146 | } compact_diskinfo_t;␊ |
147 | ␊ |
148 | struct driveParameters {␊ |
149 | int cylinders;␊ |
150 | int sectors;␊ |
151 | int heads;␊ |
152 | int totalDrives;␊ |
153 | };␊ |
154 | ␊ |
155 | struct Tag {␊ |
156 | ␉long type;␊ |
157 | ␉char *string;␊ |
158 | ␉long␉ offset;␊ |
159 | ␉struct Tag *tag;␊ |
160 | ␉struct Tag *tagNext;␊ |
161 | };␊ |
162 | typedef struct Tag Tag, *TagPtr;␊ |
163 | ␊ |
164 | typedef struct {␊ |
165 | ␉char␉plist[IO_CONFIG_DATA_SIZE];␉// buffer for plist␊ |
166 | ␉TagPtr␉dictionary;␉␉// buffer for xml dictionary␊ |
167 | ␉bool canOverride; // flag to mark a dictionary can be overriden␊ |
168 | } config_file_t;␊ |
169 | ␊ |
170 | /*␊ |
171 | * BIOS drive information.␊ |
172 | */␊ |
173 | struct boot_drive_info {␊ |
174 | struct drive_params {␊ |
175 | ␉␉unsigned short buf_size;␊ |
176 | ␉␉unsigned short info_flags;␊ |
177 | ␉␉unsigned long phys_cyls;␊ |
178 | ␉␉unsigned long phys_heads;␊ |
179 | ␉␉unsigned long phys_spt;␊ |
180 | ␉␉unsigned long long phys_sectors;␊ |
181 | ␉␉unsigned short phys_nbps;␊ |
182 | ␉␉unsigned short dpte_offset;␊ |
183 | ␉␉unsigned short dpte_segment;␊ |
184 | ␉␉unsigned short key;␊ |
185 | ␉␉unsigned char path_len;␊ |
186 | ␉␉unsigned char reserved1;␊ |
187 | ␉␉unsigned short reserved2;␊ |
188 | ␉␉unsigned char bus_type[4];␊ |
189 | ␉␉unsigned char interface_type[8];␊ |
190 | ␉␉unsigned char interface_path[8];␊ |
191 | ␉␉unsigned char dev_path[8];␊ |
192 | ␉␉unsigned char reserved3;␊ |
193 | ␉␉unsigned char checksum;␊ |
194 | } params __attribute__((packed));␊ |
195 | struct drive_dpte {␊ |
196 | ␉␉unsigned short io_port_base;␊ |
197 | ␉␉unsigned short control_port_base;␊ |
198 | ␉␉unsigned char head_flags;␊ |
199 | ␉␉unsigned char vendor_info;␊ |
200 | ␉␉unsigned char irq : 4;␊ |
201 | ␉␉unsigned char irq_unused : 4;␊ |
202 | ␉␉unsigned char block_count;␊ |
203 | ␉␉unsigned char dma_channel : 4;␊ |
204 | ␉␉unsigned char dma_type : 4;␊ |
205 | ␉␉unsigned char pio_type : 4;␊ |
206 | ␉␉unsigned char pio_unused : 4;␊ |
207 | ␉␉unsigned short option_flags;␊ |
208 | ␉␉unsigned short reserved;␊ |
209 | ␉␉unsigned char revision;␊ |
210 | ␉␉unsigned char checksum;␊ |
211 | } dpte __attribute__((packed));␊ |
212 | } __attribute__((packed));␊ |
213 | typedef struct boot_drive_info boot_drive_info_t;␊ |
214 | ␊ |
215 | struct driveInfo {␊ |
216 | boot_drive_info_t di;␊ |
217 | int uses_ebios;␊ |
218 | int no_emulation;␊ |
219 | int biosdev;␊ |
220 | int valid;␊ |
221 | };␊ |
222 | ␊ |
223 | typedef struct FinderInfo {␊ |
224 | unsigned char data[16];␊ |
225 | } FinderInfo;␊ |
226 | ␊ |
227 | struct BootVolume;␊ |
228 | typedef struct BootVolume * BVRef;␊ |
229 | typedef struct BootVolume * CICell;␊ |
230 | ␊ |
231 | typedef long (*FSInit)(CICell ih);␊ |
232 | typedef long (*FSLoadFile)(CICell ih, char * filePath);␊ |
233 | typedef long (*FSReadFile)(CICell ih, char *filePath, void *base, uint64_t offset, uint64_t length);␊ |
234 | typedef long (*FSGetFileBlock)(CICell ih, char *filePath, unsigned long long *firstBlock);␊ |
235 | typedef long (*FSGetDirEntry)(CICell ih, char * dirPath, long long * dirIndex,␊ |
236 | char ** name, long * flags, long * time,␊ |
237 | FinderInfo * finderInfo, long * infoValid);␊ |
238 | typedef long (*FSGetUUID)(CICell ih, char *uuidStr, long strMaxLen);␊ |
239 | typedef void (*BVGetDescription)(CICell ih, char * str, long strMaxLen);␊ |
240 | // Can be just pointed to free or a special free function␊ |
241 | typedef void (*BVFree)(CICell ih);␊ |
242 | ␊ |
243 | struct iob {␊ |
244 | unsigned int i_flgs; /* see F_* below */␊ |
245 | unsigned int i_offset; /* seek byte offset in file */␊ |
246 | int i_filesize; /* size of file */␊ |
247 | char * i_buf; /* file load address */␊ |
248 | };␊ |
249 | ␊ |
250 | #define BPS 512 /* sector size of the device */␊ |
251 | #define F_READ 0x1 /* file opened for reading */␊ |
252 | #define F_WRITE 0x2 /* file opened for writing */␊ |
253 | #define F_ALLOC 0x4 /* buffer allocated */␊ |
254 | #define F_FILE 0x8 /* file instead of device */␊ |
255 | #define F_NBSF 0x10 /* no bad sector forwarding */␊ |
256 | #define F_SSI 0x40 /* set skip sector inhibit */␊ |
257 | #define F_MEM 0x80 /* memory instead of file or device */␊ |
258 | ␊ |
259 | struct dirstuff {␊ |
260 | char * dir_path; /* directory path */␊ |
261 | long long dir_index; /* directory entry index */␊ |
262 | BVRef dir_bvr; /* volume reference */␊ |
263 | };␊ |
264 | ␊ |
265 | #define BVSTRLEN 32␊ |
266 | ␊ |
267 | struct BootVolume {␊ |
268 | BVRef next; /* list linkage pointer */␊ |
269 | int biosdev; /* BIOS device number */␊ |
270 | int type; /* device type (floppy, hd, network) */␊ |
271 | unsigned int flags; /* attribute flags */␊ |
272 | BVGetDescription description; /* BVGetDescription function */␊ |
273 | int part_no; /* partition number (1 based) */␊ |
274 | unsigned int part_boff; /* partition block offset */␊ |
275 | unsigned int part_type; /* partition type */␊ |
276 | unsigned int fs_boff; /* 1st block # of next read */␊ |
277 | unsigned int fs_byteoff; /* Byte offset for read within block */␊ |
278 | FSLoadFile fs_loadfile; /* FSLoadFile function */␊ |
279 | FSReadFile fs_readfile; /* FSReadFile function */␊ |
280 | FSGetDirEntry fs_getdirentry; /* FSGetDirEntry function */␊ |
281 | FSGetFileBlock fs_getfileblock; /* FSGetFileBlock function */␊ |
282 | FSGetUUID fs_getuuid; /* FSGetUUID function */␊ |
283 | unsigned int bps; /* bytes per sector for this device */␊ |
284 | char name[BVSTRLEN]; /* (name of partition) */␊ |
285 | char type_name[BVSTRLEN]; /* (type of partition, eg. Apple_HFS) */␊ |
286 | BVFree bv_free; /* BVFree function */␊ |
287 | uint32_t modTime;␊ |
288 | char␉␉␉ label[BVSTRLEN]; /* partition volume label */␊ |
289 | char␉␉␉ altlabel[BVSTRLEN]; /* partition volume label */␊ |
290 | bool filtered; /* newFilteredBVChain() will set to TRUE */␊ |
291 | bool visible; /* will shown in the device list */␊ |
292 | char␉␉␉ OSVersion[8];␊ |
293 | ␉char␉␉␉ OSInstall[30];␊ |
294 | bool␉␉␉ kernelfound; /* mach_kernel found in default location, currently only /mach_kernel is supported */␊ |
295 | bool OSisServer; /* 1 = OS X server , 0 = OS X client, not to be confused with Platform->CPU.isServer which means it tries to emulate an xserve in the smbios */␊ |
296 | };␊ |
297 | ␊ |
298 | enum {␊ |
299 | ␉kBVFlagPrimary = 0x01,␊ |
300 | ␉kBVFlagNativeBoot = 0x02,␊ |
301 | ␉kBVFlagForeignBoot = 0x04,␊ |
302 | ␉kBVFlagBootable = 0x08,␊ |
303 | ␉kBVFlagEFISystem = 0x10,␊ |
304 | #ifdef BOOT_HELPER_SUPPORT␊ |
305 | ␉kBVFlagBooter = 0x20,␊ |
306 | #endif␊ |
307 | ␉kBVFlagSystemVolume = 0x40␊ |
308 | };␊ |
309 | ␊ |
310 | enum {␊ |
311 | kBIOSDevTypeFloppy = 0x00,␊ |
312 | kBIOSDevTypeHardDrive = 0x80,␊ |
313 | kBIOSDevTypeNetwork = 0xE0,␊ |
314 | kBIOSDevUnitMask = 0x0F,␊ |
315 | kBIOSDevTypeMask = 0xF0,␊ |
316 | kBIOSDevMask = 0xFF␊ |
317 | };␊ |
318 | ␊ |
319 | enum {␊ |
320 | ␉␊ |
321 | ␉kPartitionTypeHFS␉ = 0xAF,␊ |
322 | ␉kPartitionTypeHPFS = 0x07,␊ |
323 | ␉kPartitionTypeFAT16 = 0x06,␊ |
324 | ␉kPartitionTypeFAT32 = 0x0c,␊ |
325 | ␉kPartitionTypeEXT3 = 0x83,␊ |
326 | ␉kPartitionTypeFreeBSD = 0xa5,␊ |
327 | ␉kPartitionTypeOpenBSD = 0xa6,␊ |
328 | ␉kPartitionTypeBEFS␉ = 0xEB␊ |
329 | };␊ |
330 | ␊ |
331 | //#define BIOS_DEV_TYPE(d) ((d) & kBIOSDevTypeMask)␊ |
332 | #define BIOS_DEV_UNIT(bvr) ((bvr)->biosdev - (bvr)->type)␊ |
333 | ␊ |
334 | #ifndef max␊ |
335 | #define max(a,b) ((a) > (b) ? (a) : (b))␊ |
336 | #endif␊ |
337 | ␊ |
338 | #ifndef min␊ |
339 | #define min(a,b) ((a) < (b) ? (a) : (b))␊ |
340 | #endif␊ |
341 | ␊ |
342 | #if 0␊ |
343 | #ifndef MAX␊ |
344 | #define MAX(a,b) ((a) > (b) ? (a) : (b))␊ |
345 | #endif␊ |
346 | ␊ |
347 | #ifndef MIN␊ |
348 | #define MIN(a,b) ((a) < (b) ? (a) : (b))␊ |
349 | #endif␊ |
350 | #endif␊ |
351 | ␊ |
352 | #define␉round2(x, m)␉(((x) + (m / 2)) & ~(m - 1))␊ |
353 | #define roundup2(x, m) (((x) + m - 1) & ~(m - 1))␊ |
354 | ␊ |
355 | #define MAKEKERNDEV(t, u, p) MAKEBOOTDEV(t, 0, 0, u, p)␊ |
356 | ␊ |
357 | enum {␊ |
358 | kNetworkDeviceType = kBIOSDevTypeNetwork,␊ |
359 | kBlockDeviceType = kBIOSDevTypeHardDrive␊ |
360 | };␊ |
361 | ␊ |
362 | enum {␊ |
363 | kCursorTypeHidden = 0x0100,␊ |
364 | kCursorTypeUnderline = 0x0607␊ |
365 | };␊ |
366 | ␊ |
367 | #endif /* !__LIBSAIO_SAIO_TYPES_H */␊ |
368 | |