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 "bootLion.h"␊ |
38 | ␊ |
39 | #if DEBUG␊ |
40 | #define DEBUG_DISK(x) printf x␊ |
41 | #else␊ |
42 | #define DEBUG_DISK(x)␊ |
43 | #endif␊ |
44 | ␊ |
45 | /*␊ |
46 | * Max size fo config data array, in bytes.␊ |
47 | */␊ |
48 | #define IO_CONFIG_DATA_SIZE␉␉40960 // was 4096 // was 163840␊ |
49 | ␊ |
50 | #define rand_tab_len 100␊ |
51 | ␊ |
52 | struct ran_obj {␊ |
53 | ␉int tab[rand_tab_len];␊ |
54 | ␉int rmin;␉␊ |
55 | ␉int n;␊ |
56 | };␊ |
57 | ␊ |
58 | typedef unsigned long entry_t;␊ |
59 | ␊ |
60 | typedef struct {␊ |
61 | unsigned int sectors:8;␊ |
62 | unsigned int heads:8;␊ |
63 | unsigned int cylinders:16;␊ |
64 | } compact_diskinfo_t;␊ |
65 | ␊ |
66 | struct driveParameters {␊ |
67 | int cylinders;␊ |
68 | int sectors;␊ |
69 | int heads;␊ |
70 | int totalDrives;␊ |
71 | };␊ |
72 | ␊ |
73 | struct Tag {␊ |
74 | ␉long type;␊ |
75 | ␉char *string;␊ |
76 | ␉long␉ offset;␊ |
77 | ␉struct Tag *tag;␊ |
78 | ␉struct Tag *tagNext;␊ |
79 | };␊ |
80 | typedef struct Tag Tag, *TagPtr;␊ |
81 | ␊ |
82 | typedef struct {␊ |
83 | ␉char␉plist[IO_CONFIG_DATA_SIZE];␉// buffer for plist␊ |
84 | ␉TagPtr␉dictionary;␉␉// buffer for xml dictionary␊ |
85 | ␉bool canOverride; // flag to mark a dictionary can be overriden␊ |
86 | } config_file_t;␊ |
87 | ␊ |
88 | /*␊ |
89 | * BIOS drive information.␊ |
90 | */␊ |
91 | struct boot_drive_info {␊ |
92 | struct drive_params {␊ |
93 | ␉unsigned short buf_size;␊ |
94 | ␉unsigned short info_flags;␊ |
95 | ␉unsigned long phys_cyls;␊ |
96 | ␉unsigned long phys_heads;␊ |
97 | ␉unsigned long phys_spt;␊ |
98 | ␉unsigned long long phys_sectors;␊ |
99 | ␉unsigned short phys_nbps;␊ |
100 | ␉unsigned short dpte_offset;␊ |
101 | ␉unsigned short dpte_segment;␊ |
102 | ␉unsigned short key;␊ |
103 | ␉unsigned char path_len;␊ |
104 | ␉unsigned char reserved1;␊ |
105 | ␉unsigned short reserved2;␊ |
106 | ␉unsigned char bus_type[4];␊ |
107 | ␉unsigned char interface_type[8];␊ |
108 | ␉unsigned char interface_path[8];␊ |
109 | ␉unsigned char dev_path[8];␊ |
110 | ␉unsigned char reserved3;␊ |
111 | ␉unsigned char checksum;␊ |
112 | } params __attribute__((packed));␊ |
113 | struct drive_dpte {␊ |
114 | ␉unsigned short io_port_base;␊ |
115 | ␉unsigned short control_port_base;␊ |
116 | ␉unsigned char head_flags;␊ |
117 | ␉unsigned char vendor_info;␊ |
118 | ␉unsigned char irq : 4;␊ |
119 | ␉unsigned char irq_unused : 4;␊ |
120 | ␉unsigned char block_count;␊ |
121 | ␉unsigned char dma_channel : 4;␊ |
122 | ␉unsigned char dma_type : 4;␊ |
123 | ␉unsigned char pio_type : 4;␊ |
124 | ␉unsigned char pio_unused : 4;␊ |
125 | ␉unsigned short option_flags;␊ |
126 | ␉unsigned short reserved;␊ |
127 | ␉unsigned char revision;␊ |
128 | ␉unsigned char checksum;␊ |
129 | } dpte __attribute__((packed));␊ |
130 | } __attribute__((packed));␊ |
131 | typedef struct boot_drive_info boot_drive_info_t;␊ |
132 | ␊ |
133 | struct driveInfo {␊ |
134 | boot_drive_info_t di;␊ |
135 | int uses_ebios;␊ |
136 | int no_emulation;␊ |
137 | int biosdev;␊ |
138 | int valid;␊ |
139 | };␊ |
140 | ␊ |
141 | typedef struct FinderInfo {␊ |
142 | unsigned char data[16];␊ |
143 | } FinderInfo;␊ |
144 | ␊ |
145 | struct BootVolume;␊ |
146 | typedef struct BootVolume * BVRef;␊ |
147 | typedef struct BootVolume * CICell;␊ |
148 | ␊ |
149 | typedef long (*FSInit)(CICell ih);␊ |
150 | typedef long (*FSLoadFile)(CICell ih, char * filePath);␊ |
151 | typedef long (*FSReadFile)(CICell ih, char *filePath, void *base, uint64_t offset, uint64_t length);␊ |
152 | typedef long (*FSGetFileBlock)(CICell ih, char *filePath, unsigned long long *firstBlock);␊ |
153 | typedef long (*FSGetDirEntry)(CICell ih, char * dirPath, long long * dirIndex,␊ |
154 | char ** name, long * flags, long * time,␊ |
155 | FinderInfo * finderInfo, long * infoValid);␊ |
156 | typedef long (*FSGetUUID)(CICell ih, char *uuidStr);␊ |
157 | typedef void (*BVGetDescription)(CICell ih, char * str, long strMaxLen);␊ |
158 | // Can be just pointed to free or a special free function␊ |
159 | typedef void (*BVFree)(CICell ih);␊ |
160 | ␊ |
161 | struct iob {␊ |
162 | unsigned int i_flgs; /* see F_* below */␊ |
163 | unsigned int i_offset; /* seek byte offset in file */␊ |
164 | int i_filesize; /* size of file */␊ |
165 | char * i_buf; /* file load address */␊ |
166 | };␊ |
167 | ␊ |
168 | #define BPS 512 /* sector size of the device */␊ |
169 | #define F_READ 0x1 /* file opened for reading */␊ |
170 | #define F_WRITE 0x2 /* file opened for writing */␊ |
171 | #define F_ALLOC 0x4 /* buffer allocated */␊ |
172 | #define F_FILE 0x8 /* file instead of device */␊ |
173 | #define F_NBSF 0x10 /* no bad sector forwarding */␊ |
174 | #define F_SSI 0x40 /* set skip sector inhibit */␊ |
175 | #define F_MEM 0x80 /* memory instead of file or device */␊ |
176 | ␊ |
177 | struct dirstuff {␊ |
178 | char * dir_path; /* directory path */␊ |
179 | long long dir_index; /* directory entry index */␊ |
180 | BVRef dir_bvr; /* volume reference */␊ |
181 | };␊ |
182 | ␊ |
183 | #define BVSTRLEN 32␊ |
184 | ␊ |
185 | struct BootVolume {␊ |
186 | BVRef next; /* list linkage pointer */␊ |
187 | int biosdev; /* BIOS device number */␊ |
188 | int type; /* device type (floppy, hd, network) */␊ |
189 | unsigned int flags; /* attribute flags */␊ |
190 | BVGetDescription description; /* BVGetDescription function */␊ |
191 | int part_no; /* partition number (1 based) */␊ |
192 | unsigned int part_boff; /* partition block offset */␊ |
193 | unsigned int part_type; /* partition type */␊ |
194 | unsigned int fs_boff; /* 1st block # of next read */␊ |
195 | unsigned int fs_byteoff; /* Byte offset for read within block */␊ |
196 | FSLoadFile fs_loadfile; /* FSLoadFile function */␊ |
197 | FSReadFile fs_readfile; /* FSReadFile function */␊ |
198 | FSGetDirEntry fs_getdirentry; /* FSGetDirEntry function */␊ |
199 | FSGetFileBlock fs_getfileblock; /* FSGetFileBlock function */␊ |
200 | FSGetUUID fs_getuuid; /* FSGetUUID function */␊ |
201 | unsigned int bps; /* bytes per sector for this device */␊ |
202 | char name[BVSTRLEN]; /* (name of partition) */␊ |
203 | char type_name[BVSTRLEN]; /* (type of partition, eg. Apple_HFS) */␊ |
204 | BVFree bv_free; /* BVFree function */␊ |
205 | uint32_t modTime;␊ |
206 | char␉␉␉ label[BVSTRLEN]; /* partition volume label */␊ |
207 | char␉␉␉ altlabel[BVSTRLEN]; /* partition volume label */␊ |
208 | bool filtered; /* newFilteredBVChain() will set to TRUE */␊ |
209 | bool visible; /* will shown in the device list */␊ |
210 | char␉␉␉ OSVersion[8];␊ |
211 | 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 */␊ |
212 | };␊ |
213 | ␊ |
214 | enum {␊ |
215 | kBVFlagPrimary = 0x01,␊ |
216 | kBVFlagNativeBoot = 0x02,␊ |
217 | kBVFlagForeignBoot = 0x04,␊ |
218 | kBVFlagBootable = 0x08,␊ |
219 | kBVFlagEFISystem = 0x10,␊ |
220 | #ifdef BOOT_HELPER_SUPPORT␊ |
221 | kBVFlagBooter = 0x20,␊ |
222 | #endif␊ |
223 | kBVFlagSystemVolume = 0x40␊ |
224 | };␊ |
225 | ␊ |
226 | enum {␊ |
227 | kBIOSDevTypeFloppy = 0x00,␊ |
228 | kBIOSDevTypeHardDrive = 0x80,␊ |
229 | kBIOSDevTypeNetwork = 0xE0,␊ |
230 | kBIOSDevUnitMask = 0x0F,␊ |
231 | kBIOSDevTypeMask = 0xF0,␊ |
232 | kBIOSDevMask = 0xFF␊ |
233 | };␊ |
234 | ␊ |
235 | enum {␊ |
236 | ␉␊ |
237 | ␉kPartitionTypeHFS␉ = 0xAF,␊ |
238 | ␉kPartitionTypeHPFS = 0x07,␊ |
239 | ␉kPartitionTypeFAT16 = 0x06,␊ |
240 | ␉kPartitionTypeFAT32 = 0x0c,␊ |
241 | ␉kPartitionTypeEXT3 = 0x83,␊ |
242 | ␉kPartitionTypeFreeBSD = 0xa5,␊ |
243 | ␉kPartitionTypeOpenBSD = 0xa6,␊ |
244 | ␉kPartitionTypeBEFS␉ = 0xEB␊ |
245 | };␊ |
246 | ␊ |
247 | //#define BIOS_DEV_TYPE(d) ((d) & kBIOSDevTypeMask)␊ |
248 | #define BIOS_DEV_UNIT(bvr) ((bvr)->biosdev - (bvr)->type)␊ |
249 | ␊ |
250 | #ifndef max␊ |
251 | #define max(a,b) ((a) > (b) ? (a) : (b))␊ |
252 | #endif␊ |
253 | ␊ |
254 | #ifndef min␊ |
255 | #define min(a,b) ((a) < (b) ? (a) : (b))␊ |
256 | #endif␊ |
257 | ␊ |
258 | #define␉round2(x, m)␉(((x) + (m / 2)) & ~(m - 1))␊ |
259 | #define roundup2(x, m) (((x) + m - 1) & ~(m - 1))␊ |
260 | ␊ |
261 | #define MAKEKERNDEV(t, u, p) MAKEBOOTDEV(t, 0, 0, u, p)␊ |
262 | ␊ |
263 | enum {␊ |
264 | kNetworkDeviceType = kBIOSDevTypeNetwork,␊ |
265 | kBlockDeviceType = kBIOSDevTypeHardDrive␊ |
266 | };␊ |
267 | ␊ |
268 | enum {␊ |
269 | kCursorTypeHidden = 0x0100,␊ |
270 | kCursorTypeUnderline = 0x0607␊ |
271 | };␊ |
272 | ␊ |
273 | #endif /* !__LIBSAIO_SAIO_TYPES_H */␊ |
274 | |