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