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 UUID_LEN␉ sizeof(uuid_t)␊ |
92 | #define UUID_STR_LEN sizeof(uuid_string_t)␊ |
93 | ␊ |
94 | ␊ |
95 | #define PLATFORM_NAME_LEN 64␊ |
96 | #define ROOT_PATH_LEN 256␊ |
97 | ␊ |
98 | #define DEFAULT_SCREEN_WIDTH 1024␊ |
99 | #define DEFAULT_SCREEN_HEIGHT 768␊ |
100 | ␊ |
101 | /*␊ |
102 | * Max size fo config data array, in bytes.␊ |
103 | */␊ |
104 | #define IO_CONFIG_DATA_SIZE␉␉40960 // was 4096 // was 163840␊ |
105 | ␊ |
106 | struct tm {␊ |
107 | ␉int␉tm_sec;␉␉/* seconds after the minute [0-60] */␊ |
108 | ␉int␉tm_min;␉␉/* minutes after the hour [0-59] */␊ |
109 | ␉int␉tm_hour;␉/* hours since midnight [0-23] */␊ |
110 | ␉int␉tm_mday;␉/* day of the month [1-31] */␊ |
111 | ␉int␉tm_mon;␉␉/* months since January [0-11] */␊ |
112 | ␉int␉tm_year;␉/* years since 1900 */␊ |
113 | ␉int␉tm_wday;␉/* days since Sunday [0-6] */␊ |
114 | ␉int␉tm_yday;␉/* days since January 1 [0-365] */␊ |
115 | ␉int␉tm_isdst;␉/* Daylight Savings Time flag */␊ |
116 | ␉long␉tm_gmtoff;␉/* offset from CUT in seconds */␊ |
117 | ␉char␉*tm_zone;␉/* timezone abbreviation */␊ |
118 | };␊ |
119 | ␊ |
120 | /** System time structure */␊ |
121 | struct timeval {␊ |
122 | ␉time_t tv_sec; /**< Seconds */␊ |
123 | ␉suseconds_t tv_usec; /**< Microseconds */␊ |
124 | };␊ |
125 | ␊ |
126 | typedef struct tm_t␊ |
127 | {␊ |
128 | int tm_sec ; /* seconds after minute [0-61] (61 allows for 2 leap-seconds)*/␊ |
129 | int tm_min ; /* minutes after hour [0-59] */␊ |
130 | int tm_hour ; /* hours after midnight [0-23] */␊ |
131 | int tm_mday ; /* day of the month [1-31] */␊ |
132 | int tm_mon ; /* month of year [0-11] */␊ |
133 | int tm_year ; /* current year-1900 */␊ |
134 | ␊ |
135 | }tm_t;␊ |
136 | ␊ |
137 | typedef unsigned long entry_t;␊ |
138 | ␊ |
139 | typedef struct {␊ |
140 | unsigned int sectors:8;␊ |
141 | unsigned int heads:8;␊ |
142 | unsigned int cylinders:16;␊ |
143 | } compact_diskinfo_t;␊ |
144 | ␊ |
145 | struct driveParameters {␊ |
146 | int cylinders;␊ |
147 | int sectors;␊ |
148 | int heads;␊ |
149 | int totalDrives;␊ |
150 | };␊ |
151 | ␊ |
152 | struct Tag {␊ |
153 | ␉long type;␊ |
154 | ␉char *string;␊ |
155 | ␉long␉ offset;␊ |
156 | ␉struct Tag *tag;␊ |
157 | ␉struct Tag *tagNext;␊ |
158 | };␊ |
159 | typedef struct Tag Tag, *TagPtr;␊ |
160 | ␊ |
161 | typedef struct {␊ |
162 | ␉char␉plist[IO_CONFIG_DATA_SIZE];␉// buffer for plist␊ |
163 | ␉TagPtr␉dictionary;␉␉// buffer for xml dictionary␊ |
164 | ␉bool canOverride; // flag to mark a dictionary can be overriden␊ |
165 | } config_file_t;␊ |
166 | ␊ |
167 | /*␊ |
168 | * BIOS drive information.␊ |
169 | */␊ |
170 | struct boot_drive_info {␊ |
171 | struct drive_params {␊ |
172 | ␉unsigned short buf_size;␊ |
173 | ␉unsigned short info_flags;␊ |
174 | ␉unsigned long phys_cyls;␊ |
175 | ␉unsigned long phys_heads;␊ |
176 | ␉unsigned long phys_spt;␊ |
177 | ␉unsigned long long phys_sectors;␊ |
178 | ␉unsigned short phys_nbps;␊ |
179 | ␉unsigned short dpte_offset;␊ |
180 | ␉unsigned short dpte_segment;␊ |
181 | ␉unsigned short key;␊ |
182 | ␉unsigned char path_len;␊ |
183 | ␉unsigned char reserved1;␊ |
184 | ␉unsigned short reserved2;␊ |
185 | ␉unsigned char bus_type[4];␊ |
186 | ␉unsigned char interface_type[8];␊ |
187 | ␉unsigned char interface_path[8];␊ |
188 | ␉unsigned char dev_path[8];␊ |
189 | ␉unsigned char reserved3;␊ |
190 | ␉unsigned char checksum;␊ |
191 | } params __attribute__((packed));␊ |
192 | struct drive_dpte {␊ |
193 | ␉unsigned short io_port_base;␊ |
194 | ␉unsigned short control_port_base;␊ |
195 | ␉unsigned char head_flags;␊ |
196 | ␉unsigned char vendor_info;␊ |
197 | ␉unsigned char irq : 4;␊ |
198 | ␉unsigned char irq_unused : 4;␊ |
199 | ␉unsigned char block_count;␊ |
200 | ␉unsigned char dma_channel : 4;␊ |
201 | ␉unsigned char dma_type : 4;␊ |
202 | ␉unsigned char pio_type : 4;␊ |
203 | ␉unsigned char pio_unused : 4;␊ |
204 | ␉unsigned short option_flags;␊ |
205 | ␉unsigned short reserved;␊ |
206 | ␉unsigned char revision;␊ |
207 | ␉unsigned char checksum;␊ |
208 | } dpte __attribute__((packed));␊ |
209 | } __attribute__((packed));␊ |
210 | typedef struct boot_drive_info boot_drive_info_t;␊ |
211 | ␊ |
212 | struct driveInfo {␊ |
213 | boot_drive_info_t di;␊ |
214 | int uses_ebios;␊ |
215 | int no_emulation;␊ |
216 | int biosdev;␊ |
217 | int valid;␊ |
218 | };␊ |
219 | ␊ |
220 | typedef struct FinderInfo {␊ |
221 | unsigned char data[16];␊ |
222 | } FinderInfo;␊ |
223 | ␊ |
224 | struct BootVolume;␊ |
225 | typedef struct BootVolume * BVRef;␊ |
226 | typedef struct BootVolume * CICell;␊ |
227 | ␊ |
228 | typedef long (*FSInit)(CICell ih);␊ |
229 | typedef long (*FSLoadFile)(CICell ih, char * filePath);␊ |
230 | typedef long (*FSReadFile)(CICell ih, char *filePath, void *base, uint64_t offset, uint64_t length);␊ |
231 | typedef long (*FSGetFileBlock)(CICell ih, char *filePath, unsigned long long *firstBlock);␊ |
232 | typedef long (*FSGetDirEntry)(CICell ih, char * dirPath, long long * dirIndex,␊ |
233 | char ** name, long * flags, long * time,␊ |
234 | FinderInfo * finderInfo, long * infoValid);␊ |
235 | typedef long (*FSGetUUID)(CICell ih, char *uuidStr, long strMaxLen);␊ |
236 | typedef void (*BVGetDescription)(CICell ih, char * str, long strMaxLen);␊ |
237 | // Can be just pointed to free or a special free function␊ |
238 | typedef void (*BVFree)(CICell ih);␊ |
239 | ␊ |
240 | struct iob {␊ |
241 | unsigned int i_flgs; /* see F_* below */␊ |
242 | unsigned int i_offset; /* seek byte offset in file */␊ |
243 | int i_filesize; /* size of file */␊ |
244 | char * i_buf; /* file load address */␊ |
245 | };␊ |
246 | ␊ |
247 | #define BPS 512 /* sector size of the device */␊ |
248 | #define F_READ 0x1 /* file opened for reading */␊ |
249 | #define F_WRITE 0x2 /* file opened for writing */␊ |
250 | #define F_ALLOC 0x4 /* buffer allocated */␊ |
251 | #define F_FILE 0x8 /* file instead of device */␊ |
252 | #define F_NBSF 0x10 /* no bad sector forwarding */␊ |
253 | #define F_SSI 0x40 /* set skip sector inhibit */␊ |
254 | #define F_MEM 0x80 /* memory instead of file or device */␊ |
255 | ␊ |
256 | struct dirstuff {␊ |
257 | char * dir_path; /* directory path */␊ |
258 | long long dir_index; /* directory entry index */␊ |
259 | BVRef dir_bvr; /* volume reference */␊ |
260 | };␊ |
261 | ␊ |
262 | #define BVSTRLEN 32␊ |
263 | ␊ |
264 | struct BootVolume {␊ |
265 | BVRef next; /* list linkage pointer */␊ |
266 | int biosdev; /* BIOS device number */␊ |
267 | int type; /* device type (floppy, hd, network) */␊ |
268 | unsigned int flags; /* attribute flags */␊ |
269 | BVGetDescription description; /* BVGetDescription function */␊ |
270 | int part_no; /* partition number (1 based) */␊ |
271 | unsigned int part_boff; /* partition block offset */␊ |
272 | unsigned int part_type; /* partition type */␊ |
273 | unsigned int fs_boff; /* 1st block # of next read */␊ |
274 | unsigned int fs_byteoff; /* Byte offset for read within block */␊ |
275 | FSLoadFile fs_loadfile; /* FSLoadFile function */␊ |
276 | FSReadFile fs_readfile; /* FSReadFile function */␊ |
277 | FSGetDirEntry fs_getdirentry; /* FSGetDirEntry function */␊ |
278 | FSGetFileBlock fs_getfileblock; /* FSGetFileBlock function */␊ |
279 | FSGetUUID fs_getuuid; /* FSGetUUID function */␊ |
280 | unsigned int bps; /* bytes per sector for this device */␊ |
281 | char name[BVSTRLEN]; /* (name of partition) */␊ |
282 | char type_name[BVSTRLEN]; /* (type of partition, eg. Apple_HFS) */␊ |
283 | BVFree bv_free; /* BVFree function */␊ |
284 | uint32_t modTime;␊ |
285 | char␉␉␉ label[BVSTRLEN]; /* partition volume label */␊ |
286 | char␉␉␉ altlabel[BVSTRLEN]; /* partition volume label */␊ |
287 | bool filtered; /* newFilteredBVChain() will set to TRUE */␊ |
288 | bool visible; /* will shown in the device list */␊ |
289 | char␉␉␉ OSVersion[8];␊ |
290 | ␉char␉␉␉ OSInstall[30];␊ |
291 | bool␉␉␉ kernelfound; /* mach_kernel found in default location, currently only /mach_kernel is supported */␊ |
292 | 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 */␊ |
293 | };␊ |
294 | ␊ |
295 | enum {␊ |
296 | kBVFlagPrimary = 0x01,␊ |
297 | kBVFlagNativeBoot = 0x02,␊ |
298 | kBVFlagForeignBoot = 0x04,␊ |
299 | kBVFlagBootable = 0x08,␊ |
300 | kBVFlagEFISystem = 0x10,␊ |
301 | #ifdef BOOT_HELPER_SUPPORT␊ |
302 | kBVFlagBooter = 0x20,␊ |
303 | #endif␊ |
304 | kBVFlagSystemVolume = 0x40␊ |
305 | };␊ |
306 | ␊ |
307 | enum {␊ |
308 | kBIOSDevTypeFloppy = 0x00,␊ |
309 | kBIOSDevTypeHardDrive = 0x80,␊ |
310 | kBIOSDevTypeNetwork = 0xE0,␊ |
311 | kBIOSDevUnitMask = 0x0F,␊ |
312 | kBIOSDevTypeMask = 0xF0,␊ |
313 | kBIOSDevMask = 0xFF␊ |
314 | };␊ |
315 | ␊ |
316 | enum {␊ |
317 | ␉␊ |
318 | ␉kPartitionTypeHFS␉ = 0xAF,␊ |
319 | ␉kPartitionTypeHPFS = 0x07,␊ |
320 | ␉kPartitionTypeFAT16 = 0x06,␊ |
321 | ␉kPartitionTypeFAT32 = 0x0c,␊ |
322 | ␉kPartitionTypeEXT3 = 0x83,␊ |
323 | ␉kPartitionTypeFreeBSD = 0xa5,␊ |
324 | ␉kPartitionTypeOpenBSD = 0xa6,␊ |
325 | ␉kPartitionTypeBEFS␉ = 0xEB␊ |
326 | };␊ |
327 | ␊ |
328 | //#define BIOS_DEV_TYPE(d) ((d) & kBIOSDevTypeMask)␊ |
329 | #define BIOS_DEV_UNIT(bvr) ((bvr)->biosdev - (bvr)->type)␊ |
330 | ␊ |
331 | #ifndef max␊ |
332 | #define max(a,b) ((a) > (b) ? (a) : (b))␊ |
333 | #endif␊ |
334 | ␊ |
335 | #ifndef min␊ |
336 | #define min(a,b) ((a) < (b) ? (a) : (b))␊ |
337 | #endif␊ |
338 | ␊ |
339 | #define␉round2(x, m)␉(((x) + (m / 2)) & ~(m - 1))␊ |
340 | #define roundup2(x, m) (((x) + m - 1) & ~(m - 1))␊ |
341 | ␊ |
342 | #define MAKEKERNDEV(t, u, p) MAKEBOOTDEV(t, 0, 0, u, p)␊ |
343 | ␊ |
344 | enum {␊ |
345 | kNetworkDeviceType = kBIOSDevTypeNetwork,␊ |
346 | kBlockDeviceType = kBIOSDevTypeHardDrive␊ |
347 | };␊ |
348 | ␊ |
349 | enum {␊ |
350 | kCursorTypeHidden = 0x0100,␊ |
351 | kCursorTypeUnderline = 0x0607␊ |
352 | };␊ |
353 | ␊ |
354 | #endif /* !__LIBSAIO_SAIO_TYPES_H */␊ |
355 | |