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