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 <sys/param.h>␊ |
32 | #include "bios.h"␊ |
33 | #include "nbp_cmd.h"␊ |
34 | #include "bootargs.h"␊ |
35 | ␊ |
36 | #if DEBUG␊ |
37 | ␉#define DEBUG_DISK(x) printf x␊ |
38 | #else␊ |
39 | ␉#define DEBUG_DISK(x)␊ |
40 | #endif␊ |
41 | ␊ |
42 | typedef unsigned long entry_t;␊ |
43 | ␊ |
44 | typedef struct␊ |
45 | {␊ |
46 | ␉unsigned int sectors:8;␊ |
47 | ␉unsigned int heads:8;␊ |
48 | ␉unsigned int cylinders:16;␊ |
49 | } compact_diskinfo_t;␊ |
50 | ␊ |
51 | ␊ |
52 | struct driveParameters␊ |
53 | {␊ |
54 | ␉int cylinders;␊ |
55 | ␉int sectors;␊ |
56 | ␉int heads;␊ |
57 | ␉int totalDrives;␊ |
58 | };␊ |
59 | ␊ |
60 | typedef struct Tag␊ |
61 | {␊ |
62 | ␉long␉␉type;␊ |
63 | ␉char␉␉*string;␊ |
64 | ␉uint8_t␉␉*data;␊ |
65 | ␉long␉␉dataLen;␊ |
66 | ␉long␉␉offset;␊ |
67 | ␉struct Tag *tag;␊ |
68 | ␉struct Tag *tagNext;␊ |
69 | } Tag, *TagPtr;␊ |
70 | ␊ |
71 | /*␊ |
72 | * Max size fo config data array, in bytes.␊ |
73 | */␊ |
74 | #define IO_CONFIG_DATA_SIZE␉␉40960 // was 4096 // was 163840␊ |
75 | ␊ |
76 | typedef struct␊ |
77 | {␊ |
78 | ␉char␉plist[IO_CONFIG_DATA_SIZE];␉// buffer for plist␊ |
79 | ␉TagPtr␉dictionary;␉␉␉// buffer for xml dictionary␊ |
80 | ␉bool␉canOverride;␉␉␉// flag to mark a dictionary can be overriden␊ |
81 | } config_file_t;␊ |
82 | ␊ |
83 | /*␊ |
84 | * BIOS drive information.␊ |
85 | */␊ |
86 | typedef struct boot_drive_info␊ |
87 | {␊ |
88 | ␉struct drive_params␊ |
89 | ␉{␊ |
90 | ␉␉unsigned short buf_size;␊ |
91 | ␉␉unsigned short info_flags;␊ |
92 | ␉␉unsigned long phys_cyls;␊ |
93 | ␉␉unsigned long phys_heads;␊ |
94 | ␉␉unsigned long phys_spt;␊ |
95 | ␉␉unsigned long long phys_sectors;␊ |
96 | ␉␉unsigned short phys_nbps;␊ |
97 | ␉␉unsigned short dpte_offset;␊ |
98 | ␉␉unsigned short dpte_segment;␊ |
99 | ␉␉unsigned short key;␊ |
100 | ␉␉unsigned char path_len;␊ |
101 | ␉␉unsigned char reserved1;␊ |
102 | ␉␉unsigned short reserved2;␊ |
103 | ␉␉unsigned char bus_type[4];␊ |
104 | ␉␉unsigned char interface_type[8];␊ |
105 | ␉␉unsigned char interface_path[8];␊ |
106 | ␉␉unsigned char dev_path[16];␊ |
107 | ␉␉unsigned char reserved3;␊ |
108 | ␉␉unsigned char checksum;␊ |
109 | ␉} params __attribute__((packed));␊ |
110 | ␊ |
111 | ␉struct drive_dpte␊ |
112 | ␉{␊ |
113 | ␉␉unsigned short io_port_base;␊ |
114 | ␉␉unsigned short control_port_base;␊ |
115 | ␉␉unsigned char head_flags;␊ |
116 | ␉␉unsigned char vendor_info;␊ |
117 | ␉␉unsigned char irq : 4;␊ |
118 | ␉␉unsigned char irq_unused : 4;␊ |
119 | ␉␉unsigned char block_count;␊ |
120 | ␉␉unsigned char dma_channel : 4;␊ |
121 | ␉␉unsigned char dma_type : 4;␊ |
122 | ␉␉unsigned char pio_type : 4;␊ |
123 | ␉␉unsigned char pio_unused : 4;␊ |
124 | ␉␉unsigned short option_flags;␊ |
125 | ␉␉unsigned short reserved;␊ |
126 | ␉␉unsigned char revision;␊ |
127 | ␉␉unsigned char checksum;␊ |
128 | } dpte __attribute__((packed));␊ |
129 | } __attribute__((packed)) boot_drive_info_t;␊ |
130 | ␊ |
131 | ␊ |
132 | struct driveInfo␊ |
133 | {␊ |
134 | ␉boot_drive_info_t di;␊ |
135 | ␊ |
136 | ␉int uses_ebios;␊ |
137 | ␉int no_emulation;␊ |
138 | ␉int biosdev;␊ |
139 | ␉int valid;␊ |
140 | };␊ |
141 | ␊ |
142 | ␊ |
143 | typedef struct FinderInfo␊ |
144 | {␊ |
145 | ␉unsigned char data[16];␊ |
146 | } FinderInfo;␊ |
147 | ␊ |
148 | ␊ |
149 | struct␉␉BootVolume;␊ |
150 | typedef struct␉BootVolume *BVRef;␊ |
151 | typedef struct␉BootVolume *CICell;␊ |
152 | ␊ |
153 | typedef long (*FSInit)(CICell ih);␊ |
154 | typedef long (*FSLoadFile)(CICell ih, char *filePath);␊ |
155 | typedef long (*FSReadFile)(CICell ih, char *filePath, void *base, uint64_t offset, uint64_t length);␊ |
156 | typedef long (*FSGetFileBlock)(CICell ih, char *filePath, unsigned long long *firstBlock);␊ |
157 | typedef long (*FSGetDirEntry)(CICell ih, char * dirPath, long long *dirIndex,␊ |
158 | ␉␉␉␉␉␉␉ char **name, long * flags, u_int32_t *time,␊ |
159 | ␉␉␉␉␉␉␉ FinderInfo *finderInfo, long *infoValid);␊ |
160 | typedef long (*FSGetUUID)(CICell ih, char *uuidStr);␊ |
161 | typedef void (*BVGetDescription)(CICell ih, char * str, long strMaxLen);␊ |
162 | // Can be just pointed to free or a special free function␊ |
163 | typedef void (*BVFree)(CICell ih);␊ |
164 | ␊ |
165 | struct iob {␊ |
166 | ␉char * i_buf; /* file load address */␊ |
167 | ␉unsigned int i_flgs; /* see F_* below */␊ |
168 | ␉unsigned int i_offset; /* seek byte offset in file */␊ |
169 | ␉int i_filesize; /* size of file */␊ |
170 | };␊ |
171 | ␊ |
172 | #define BPS␉ 512␉␉␉␉/* sector size of the device */␊ |
173 | #define F_READ␉ 0x1␉␉␉␉/* file opened for reading */␊ |
174 | #define F_WRITE␉ 0x2␉␉␉␉/* file opened for writing */␊ |
175 | #define F_ALLOC␉ 0x4␉␉␉␉/* buffer allocated */␊ |
176 | #define F_FILE␉ 0x8␉␉␉␉/* file instead of device */␊ |
177 | #define F_NBSF␉ 0x10␉␉␉␉/* no bad sector forwarding */␊ |
178 | #define F_SSI␉ 0x40␉␉␉␉/* set skip sector inhibit */␊ |
179 | #define F_MEM␉ 0x80␉␉␉␉/* memory instead of file or device */␊ |
180 | ␊ |
181 | struct dirstuff {␊ |
182 | ␉char *␉␉ dir_path;␉␉/* directory path */␊ |
183 | ␉long long␉ dir_index;␉␉/* directory entry index */␊ |
184 | ␉BVRef␉␉ dir_bvr;␉␉/* volume reference */␊ |
185 | };␊ |
186 | ␊ |
187 | #define BVSTRLEN 36 // changed from 32 to 36 due to gpt partition name length␊ |
188 | #define OSVERSTRLEN 9␊ |
189 | ␊ |
190 | struct BootVolume {␊ |
191 | ␉BVRef␉␉␉next;␉␉␉/* list linkage pointer */␊ |
192 | ␉int␉␉␉biosdev;␉␉/* BIOS device number */␊ |
193 | ␉int␉␉␉type;␉␉␉/* device type (floppy, hd, network) */␊ |
194 | ␉unsigned int␉␉flags;␉␉␉/* attribute flags */␊ |
195 | ␉BVGetDescription␉description;␉␉/* BVGetDescription function */␊ |
196 | ␉int␉␉␉part_no;␉␉/* partition number (1 based) */␊ |
197 | ␉unsigned int␉␉part_boff;␉␉/* partition block offset */␊ |
198 | ␉unsigned int␉␉part_type;␉␉/* partition type */␊ |
199 | ␉unsigned int␉␉fs_boff;␉␉/* 1st block # of next read */␊ |
200 | ␉unsigned int␉␉fs_byteoff;␉␉/* Byte offset for read within block */␊ |
201 | ␉FSLoadFile␉␉fs_loadfile;␉␉/* FSLoadFile function */␊ |
202 | ␉FSReadFile␉␉fs_readfile;␉␉/* FSReadFile function */␊ |
203 | ␉FSGetDirEntry␉␉fs_getdirentry;␉␉/* FSGetDirEntry function */␊ |
204 | ␉FSGetFileBlock␉␉fs_getfileblock;␉/* FSGetFileBlock function */␊ |
205 | ␉FSGetUUID␉␉fs_getuuid;␉␉/* FSGetUUID function */␊ |
206 | ␉unsigned int␉␉bps;␉␉␉/* bytes per sector for this device */␊ |
207 | ␉char␉␉␉name[BVSTRLEN];␉␉/* (name of partition) */␊ |
208 | ␉char␉␉␉type_name[BVSTRLEN];␉/* (type of partition, eg. Apple_HFS) */␊ |
209 | ␉BVFree␉␉␉bv_free;␉␉/* BVFree function */␊ |
210 | ␉uint32_t␉␉modTime;␊ |
211 | ␉char␉␉␉label[BVSTRLEN];␉/* partition volume label */␊ |
212 | ␉char␉␉␉altlabel[BVSTRLEN];␉/* alternate partition volume label */␊ |
213 | ␉bool␉␉␉filtered;␉␉/* newFilteredBVChain() will set to TRUE */␊ |
214 | ␉bool␉␉␉visible;␉␉/* will shown in the device list */␊ |
215 | ␉char␉␉␉OSVersion[OSVERSTRLEN]; /* Null terminated string from '/System/Library/CoreServices/SystemVersion.plist/ProductVersion' e.g. "10.10.10" - hope will not reach e.g. 111.222.333 soon:) If so, OSVERSTRLEN 9 change to 12 */␊ |
216 | ␉char␉␉␉OSFullVer[OSVERSTRLEN]; /* Null terminated string from '/System/Library/CoreServices/SystemVersion.plist/ProductVersion' */␊ |
217 | ␉char␉␉␉OSBuildVer[OSVERSTRLEN];/* Null terminated string from '/System/Library/CoreServices/SystemVersion.plist/ProductBuildVersion' */␊ |
218 | ␉bool␉␉␉OSisServer;␉␉/* 1 = OS X server , 0 = OS X client */␊ |
219 | ␉bool␉␉␉OSisInstaller;␉␉/* 1 = OS X Installer */␊ |
220 | ␉bool␉␉␉OSisMacOSXUpgrade;␉/* 1 = OS X Installer Upgrade */␊ |
221 | ␉bool␉␉␉OSisOSXUpgrade;␉␉/* 1 = OS X Installer Upgrade */␊ |
222 | ␉bool␉␉␉OSisRecovery;␉␉/* 1 = Recovery HD partition */␊ |
223 | ␉char␉␉␉comAppleBoot[150];␉/* additional arguments */␊ |
224 | };␊ |
225 | ␊ |
226 | enum␊ |
227 | {␊ |
228 | ␉kBVFlagZero␉␉␉= 0x00,␊ |
229 | ␉kBVFlagPrimary␉␉␉= 0x01,␊ |
230 | ␉kBVFlagNativeBoot␉␉= 0x02,␊ |
231 | ␉kBVFlagForeignBoot␉␉= 0x04,␊ |
232 | ␉kBVFlagBootable␉␉␉= 0x08,␊ |
233 | ␉kBVFlagEFISystem␉␉= 0x10,␊ |
234 | ␉kBVFlagBooter␉␉␉= 0x20,␊ |
235 | ␉kBVFlagSystemVolume␉␉= 0x40,␊ |
236 | ␉kBVFlagInstallVolume␉␉= 0x80␊ |
237 | };␊ |
238 | ␊ |
239 | enum␊ |
240 | {␊ |
241 | ␉kBIOSDevTypeFloppy␉␉= 0x00,␊ |
242 | ␉kBIOSDevTypeHardDrive␉␉= 0x80,␊ |
243 | ␉kBIOSDevTypeNetwork␉␉= 0xE0,␊ |
244 | ␉kBIOSDevUnitMask␉␉= 0x0F,␊ |
245 | ␉kBIOSDevTypeMask␉␉= 0xF0,␊ |
246 | ␉kBIOSDevMask␉␉␉= 0xFF␊ |
247 | };␊ |
248 | ␊ |
249 | enum␊ |
250 | {␊ |
251 | ␉//KPartitionTypeFAT12␉␉= 0x01, // FAT12␊ |
252 | ␉kPartitionTypeHPFS␉␉= 0x07, // Mac OS X␊ |
253 | ␉kPartitionTypeFAT16␉␉= 0x06, // FAT16␊ |
254 | ␉kPartitionTypeFAT32␉␉= 0x0C, // FAT32␊ |
255 | ␉kPartitionTypeEXT3␉␉= 0x83, // Linux␊ |
256 | ␉kPartitionTypeOSXBoot␉␉= 0xAB, // Mac OS X Boot partition␊ |
257 | ␉kPartitionTypeFreeBSD␉␉= 0xA5, // FreeBSD␊ |
258 | ␉kPartitionTypeOpenBSD␉␉= 0xA6, // OpenBSD␊ |
259 | ␉//kPartitionTypeNeXTSTEP␉= 0xA7 // NeXTSTEP␊ |
260 | ␉//kPartitionTypeNetBSD␉␉= 0xA9 // NetBSD␊ |
261 | ␉kPartitionTypeHFS␉␉= 0xAF, // Mac OS X␊ |
262 | ␉//kPartitionTypeSolaris␉␉= 0xBE,␉ // Solaris␊ |
263 | ␉kPartitionTypeBEFS␉␉= 0xEB, // BeOS BFS␊ |
264 | ␉//kPartitionTypeBeOS␉␉= 0xEB, // BeOS BFS␊ |
265 | ␉//kPartitionTypeSkyOS␉␉= 0xEC, // SkyOS␊ |
266 | };␊ |
267 | ␊ |
268 | //#define BIOS_DEV_TYPE(d)␉((d) & kBIOSDevTypeMask)␊ |
269 | #define BIOS_DEV_UNIT(bvr)␉((bvr)->biosdev - (bvr)->type)␊ |
270 | ␊ |
271 | // KernBootStruct device types.␊ |
272 | ␊ |
273 | enum␊ |
274 | {␊ |
275 | ␉DEV_SD = 0,␊ |
276 | ␉DEV_HD = 1,␊ |
277 | ␉DEV_FD = 2,␊ |
278 | ␉DEV_EN = 3␊ |
279 | };␊ |
280 | ␊ |
281 | /*␊ |
282 | * min/max Macros.␊ |
283 | * counting and rounding Macros.␊ |
284 | *␊ |
285 | * Azi: defined on <sys/param.h>,␊ |
286 | *␉␉i386/include/IOKit/IOLib.h (min/max), and others...␊ |
287 | *␊ |
288 | #ifndef MIN␊ |
289 | #define MIN(a,b) ( ((a) < (b)) ? (a) : (b) )␊ |
290 | #endif␊ |
291 | #ifndef MAX␊ |
292 | #define MAX(a,b) ( ((a) > (b)) ? (a) : (b) )␊ |
293 | #endif␊ |
294 | ␊ |
295 | #define round2(x, m)␉(((x) + (m / 2)) & ~(m - 1))␊ |
296 | #define roundup2(x, m)␉(((x) + m - 1) & ~(m - 1))*/␊ |
297 | ␊ |
298 | enum {␊ |
299 | ␉kNetworkDeviceType = kBIOSDevTypeNetwork,␊ |
300 | ␉kBlockDeviceType = kBIOSDevTypeHardDrive␊ |
301 | }; //gBootFileType_t;␊ |
302 | ␊ |
303 | enum␊ |
304 | {␊ |
305 | ␉kCursorTypeHidden = 0x0100,␊ |
306 | ␉kCursorTypeUnderline = 0x0607␊ |
307 | };␊ |
308 | ␊ |
309 | #endif /* !__LIBSAIO_SAIO_TYPES_H */␊ |
310 | |