Chameleon

Chameleon Commit Details

Date:2015-01-17 20:06:45 (9 years 3 months ago)
Author:ErmaC
Commit:2538
Parents: 2537
Message:Typo (Credits to Bungo)
Changes:
M/trunk/i386/libsaio/gma.c
M/trunk/i386/boot2/boot.c
M/trunk/i386/libsaio/bootstruct.c
M/trunk/i386/libsaio/ntfs_private.h
M/trunk/i386/boot2/boot.h
M/trunk/i386/libsaio/pci.c
M/trunk/i386/boot2/modules.c
M/trunk/i386/libsaio/stringTable.c
M/trunk/i386/libsaio/convert.c
M/trunk/i386/libsaio/acpi.h
M/trunk/i386/libsaio/acpi_patcher.c
M/trunk/i386/libsaio/state_generator.c
M/trunk/i386/boot2/gui.c
M/trunk/i386/libsaio/disk.c
M/trunk/i386/libsaio/device_inject.c
M/trunk/i386/libsaio/state_generator.h
M/trunk/i386/libsaio/smbios.c
M/trunk/i386/boot2/options.c
M/trunk/i386/libsaio/asm.s
M/trunk/i386/libsaio/smbios.h
M/trunk/i386/libsaio/console.c
M/trunk/i386/boot2/graphics.c
M/trunk/i386/libsaio/fdisk.h
M/trunk/i386/libsaio/vbe.c
M/trunk/i386/libsaio/sys.c
M/trunk/i386/libsaio/device_tree.c
M/trunk/i386/libsaio/pci_root.c
M/trunk/i386/libsaio/hfs.c
M/trunk/i386/boot2/drivers.c
M/trunk/i386/libsaio/saio_types.h
M/trunk/i386/libsaio/spd.c
M/trunk/i386/libsaio/cpu.c
M/trunk/i386/libsaio/smbios_getters.c
M/trunk/i386/libsaio/fake_efi.c
M/trunk/i386/libsaio/cpu.h
M/trunk/i386/libsaio/smbios_decode.c
M/trunk/i386/include/IOKit/storage/IOFDiskPartitionScheme.h

File differences

trunk/i386/libsaio/asm.s
521521
522522
523523
524
524
popl%edx
ret
// computeRand() end function - - - - - - - - - - - - - - - - - - - - - - - -
trunk/i386/libsaio/console.c
9999
100100
101101
102
102
103
103104
104105
105106
106
107
108
107109
108110
109111
......
117119
118120
119121
120
122
123
121124
122125
123126
......
300303
301304
302305
303
306
304307
305
308
306309
307310
va_list ap;
struct putc_info pi;
if (!msgbuf) {
if (!msgbuf)
{
return;
}
if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE))) {
if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
{
return;
}
void setupBooterLog(void)
{
if (!msgbuf) {
if (!msgbuf)
{
return;
}
}
/** Print a "Press a key to continue..." message and wait for a key press. */
void pause()
void pause()
{
printf("Press a key to continue...\n");
printf("Press a key to continue...\n");
getchar(); // replace getchar() by pause() were useful.
}
trunk/i386/libsaio/bootstruct.c
9797
9898
9999
100
100101
101102
102103
if (node == 0) {
stop("Couldn't create root node");
}
getPlatformName(platformName);
nameLen = strlen(platformName) + 1;
DT__AddProperty(node, "compatible", nameLen, platformName);
trunk/i386/libsaio/ntfs_private.h
9494
9595
9696
97
9798
9899
99100
......
105106
106107
107108
108
109
110
109
110
111
112
111113
112
113
114
115
114
115
116
117
116118
117119
120
118121
119122
120123
......
266269
267270
268271
269
272
270273
271274
272275
......
275278
276279
277280
278
281
279282
280
283
281284
282285
283286
};
#define NTFS_AF_INRUN0x00000001
struct attrhdr {
u_int32_t a_type;
u_int32_t reclen;
u_int8_t reserved2;
u_int16_t a_index;
};
#define NTFS_A_STD0x10
#define NTFS_A_ATTRLIST0x20
#define NTFS_A_NAME0x30
#define NTFS_A_STD0x10
#define NTFS_A_ATTRLIST0x20
#define NTFS_A_NAME0x30
#define NTFS_A_VOLUMENAME0x60
#define NTFS_A_DATA0x80
#defineNTFS_A_INDXROOT0x90
#defineNTFS_A_INDX0xA0
#define NTFS_A_INDXBITMAP 0xB0
#define NTFS_A_DATA0x80
#defineNTFS_A_INDXROOT0x90
#defineNTFS_A_INDX0xA0
#define NTFS_A_INDXBITMAP0xB0
#define NTFS_MAXATTRNAME255
struct attr {
struct attrhdr a_hdr;
union {
u_int8_t bf_spc;/* sectors per cluster */
u_int8_t reserved2[7];/* unused (zeroed) */
u_int8_t bf_media;/* media desc. (0xF8) */
u_int8_t reserved3[2];
u_int8_t reserved3[2];/* always 0 */
u_int16_t bf_spt;/* sectors per track */
u_int16_t bf_heads;/* number of heads */
u_int8_t reserver4[12];
cn_t bf_mftmirrcn;/* $MFTMirr cn */
u_int8_t bf_mftrecsz;/* MFT record size (clust) */
/* 0xF6 inducates 1/4 */
u_int8_t reserved5[3];
u_int8_t reserved5[3];
u_int8_t bf_ibsz;/* index buffer size */
u_int8_t reserved6[3];
u_int8_t reserved6[3];
u_int64_t bf_volsn;/* volume ser. num. */
};
trunk/i386/libsaio/vbe.c
6969
7070
7171
72
72
7373
7474
7575
......
8181
8282
8383
84
84
8585
8686
8787
......
268268
269269
270270
271
272
273
274
275
276
277
278
279
271
272
273
274
275
276
277
278
279
280
280281
281282
282283
283284
284285
285286
286
287
288
289
290
291
292
293
294
287
288
289
290
291
292
293
294
295
295296
296297
297298
298299
299300
300301
301
302
303
304
305
306
307
308
309
302
303
304
305
306
307
308
309
310
310311
311312
312313
313314
314315
315316
316
317
318
319
320
317
318
319
320
321
321322
322323
323324
324325
325326
326327
327
328
329
330
331
332
333
334
328
329
330
331
332
333
334
335
335336
#endif /* UNUSED */
//==============================================================================
int getVBEInfo( void * infoBlock )
int getVBEInfo( void *infoBlock )
{
bb.intno = 0x10;
bb.eax.rr = funcGetControllerInfo;
//==============================================================================
int getVBEModeInfo( int mode, void * minfo_p )
int getVBEModeInfo( int mode, void *minfo_p )
{
bb.intno = 0x10;
bb.eax.rr = funcGetModeInfo;
int setVBEMode(unsigned short mode, const VBECRTCInfoBlock * timing)
{
bb.intno = 0x10;
bb.eax.rr = funcSetMode;
bb.ebx.rr = mode;
if (timing) {
bb.es = SEG(timing);
bb.edi.rr = OFF(timing);
}
bios(&bb);
return(bb.eax.r.h);
bb.intno = 0x10;
bb.eax.rr = funcSetMode;
bb.ebx.rr = mode;
if (timing)
{
bb.es = SEG(timing);
bb.edi.rr = OFF(timing);
}
bios(&bb);
return(bb.eax.r.h);
}
//==============================================================================
int setVBEPalette(void *palette)
{
bb.intno = 0x10;
bb.eax.rr = funcGetSetPaletteData;
bb.ebx.r.l = subfuncSet;
bb.ecx.rr = 256;
bb.edx.rr = 0;
bb.es = SEG(palette);
bb.edi.rr = OFF(palette);
bios(&bb);
return(bb.eax.r.h);
bb.intno = 0x10;
bb.eax.rr = funcGetSetPaletteData;
bb.ebx.r.l = subfuncSet;
bb.ecx.rr = 256;
bb.edx.rr = 0;
bb.es = SEG(palette);
bb.edi.rr = OFF(palette);
bios(&bb);
return(bb.eax.r.h);
}
//==============================================================================
int getVBEPalette(void *palette)
{
bb.intno = 0x10;
bb.eax.rr = funcGetSetPaletteData;
bb.ebx.r.l = subfuncGet;
bb.ecx.rr = 256;
bb.edx.rr = 0;
bb.es = SEG(palette);
bb.edi.rr = OFF(palette);
bios(&bb);
return(bb.eax.r.h);
bb.intno = 0x10;
bb.eax.rr = funcGetSetPaletteData;
bb.ebx.r.l = subfuncGet;
bb.ecx.rr = 256;
bb.edx.rr = 0;
bb.es = SEG(palette);
bb.edi.rr = OFF(palette);
bios(&bb);
return(bb.eax.r.h);
}
//==============================================================================
int getVBECurrentMode(unsigned short *mode)
{
bb.intno = 0x10;
bb.eax.rr = funcGetCurrentMode;
bios(&bb);
*mode = bb.ebx.rr;
return(bb.eax.r.h);
bb.intno = 0x10;
bb.eax.rr = funcGetCurrentMode;
bios(&bb);
*mode = bb.ebx.rr;
return(bb.eax.r.h);
}
//==============================================================================
int getVBEPixelClock(unsigned short mode, unsigned long * pixelClock)
{
bb.intno = 0x10;
bb.eax.rr = funcGetSetPixelClock;
bb.ebx.r.l = 0;
bb.ecx.rx = *pixelClock;
bb.edx.rr = mode;
bios(&bb);
*pixelClock = bb.ecx.rx;
return(bb.eax.r.h);
bb.intno = 0x10;
bb.eax.rr = funcGetSetPixelClock;
bb.ebx.r.l = 0;
bb.ecx.rx = *pixelClock;
bb.edx.rr = mode;
bios(&bb);
*pixelClock = bb.ecx.rx;
return(bb.eax.r.h);
}
trunk/i386/libsaio/device_tree.c
8787
8888
8989
90
90
9191
9292
9393
9494
9595
96
96
9797
9898
9999
......
159159
160160
161161
162
162
163163
164164
165165
......
183183
184184
185185
186
187
186
187
188188
189189
190190
......
239239
240240
241241
242
242
243243
244244
245245
......
430430
431431
432432
433
433
434434
435435
436436
437
437
438438
439439
440440
......
447447
448448
449449
450
451
452
453
454
455
456
457
458
459
460
461
462
450
463451
452
464453
465454
466
467455
468
469
470
456
471457
472
473
474
458
459
460
475461
476
477
462
463
464
465
466
478467
468
469
470
471
472
473
474
475
476
477
479478
480479
481480
{
Property *prop;
DPRINTF("DT__AddProperty([Node '%s'], '%s', %d, 0x%x)\n", DT__GetName(node), name, length, value);
DPRINTF("DT__AddProperty([Node '%s'], '%s', %d, 0x%X)\n", DT__GetName(node), name, length, value);
if (freeProperties == NULL) {
void *buf = malloc(kAllocSize);
int i;
DPRINTF("Allocating more free properties\n");
DPRINTF("DT__AddProperty: Allocating more free properties\n");
if (buf == 0) {
return 0;
int i;
DPRINTF("Allocating more free nodes\n");
DPRINTF("DT__AddChild: Allocating more free nodes\n");
bzero(buf, kAllocSize);
node = (Node *)buf;
node = freeNodes;
freeNodes = node->next;
DPRINTF("Got free node 0x%x\n", node);
DPRINTF("prop = 0x%x, children = 0x%x, next = 0x%x\n", node->properties, node->children, node->next);
DPRINTF("DT__AddChild: Got free node 0x%x\n", node);
DPRINTF("DT__AddChild: prop = 0x%x, children = 0x%x, next = 0x%x\n", node->properties, node->children, node->next);
if (parent == NULL)
{
DTInfo.totalPropertySize = 0;
rootNode = DT__AddChild(NULL, "/");
DPRINTF("DT__Initialize done\n");
DPRINTF("DT__Initialize: done\n");
}
//==============================================================================
// Start at root
node = rootNode;
DPRINTF("root = 0x%x\n", rootNode);
DPRINTF("DT__FindNode: root = 0x%x\n", rootNode);
while (node)
{
// Skip leading slash
// Skip leading slash(es)
while (*path == '/')
{
path++;
*bp = '\0';
if (nameBuf[0] == '\0')
{
// last path entry
break;
}
DPRINTF("Node '%s'\n", nameBuf);
for (child = node->children; child != 0; child = child->next)
{
DPRINTF("Child 0x%x\n", child);
if (strcmp(DT__GetName(child), nameBuf) == 0)
if (nameBuf[0] == '\0')
{
// last path entry
break;
}
}
if (child == 0 && createIfMissing)
{
DPRINTF("Creating node\n");
DPRINTF("DT__FindNode: Node '%s'\n", nameBuf);
char *str = malloc(strlen(nameBuf) + 1);
// XXX this will leak
strcpy(str, nameBuf);
for (child = node->children; child != 0; child = child->next)
{
DPRINTF("DT__FindNode: Child 0x%x\n", child);
child = DT__AddChild(node, str);
}
if (strcmp(DT__GetName(child), nameBuf) == 0)
{
break;
}
}
if (child == 0 && createIfMissing)
{
char *str = malloc(strlen(nameBuf) + 1);
// XXX this will leak
strcpy(str, nameBuf);
child = DT__AddChild(node, str);
DPRINTF("DT__FindNode: Creating node: %s\n", str);
}
node = child;
}
trunk/i386/libsaio/hfs.c
290290
291291
292292
293
293
294294
295295
296296
......
453453
454454
455455
456
456
457457
458458
459459
......
505505
506506
507507
508
508
509509
510510
511511
......
568568
569569
570570
571
571
572572
573573
574574
return HFSReadFile(ih, filePath, (void *)gFSLoadAddress, 0, 0);
}
long HFSReadFile(CICell ih, char * filePath, void *base, u_int64_t offset, u_int64_t length)
long HFSReadFile(CICell ih, char *filePath, void *base, u_int64_t offset, u_int64_t length)
{
char entry[512];
char devStr[12];
nodeSize = SWAP_BE16(gBTHeaders[kBTreeCatalog]->nodeSize);
firstLeafNode = SWAP_BE32(gBTHeaders[kBTreeCatalog]->firstLeafNode);
dirIndex = (long long) firstLeafNode * nodeSize;
dirIndex = (long long)firstLeafNode * nodeSize;
GetCatalogEntry(&dirIndex, &name, &flags, &time, 0, 0);
if ((result == -1) || ((flags & kFileTypeMask) != kFileTypeFlat))
{
printf("HFS: Resolve path %s failed\n", filePath);
printf("HFS: Resolve path '%s' failed\n", filePath);
return -1;
}
if (offset > fileLength)
{
printf("Offset is too large.\n");
printf("ReadFile(HFS%c): Offset is too large.\n", gIsHFSPlus ? "+" : "");
return -1;
}
trunk/i386/libsaio/acpi_patcher.c
4242
4343
4444
45
45
4646
4747
4848
......
6565
6666
6767
68
68
6969
7070
7171
72
72
7373
74
74
7575
7676
7777
......
9797
9898
9999
100
100
101101
102102
103103
......
127127
128128
129129
130
130
131131
132
132
133133
134134
135135
136136
137137
138
138
139139
140140
141
141
142142
143143
144
145
144
145
146146
147147
148148
149149
150
150
151151
152152
153
153
154154
155155
156156
157157
158158
159159
160
161
160
162161
162
163163
164
164
165165
166166
167167
168
168
169169
170170
171171
172172
173173
174
174
175175
176176
177177
......
186186
187187
188188
189
189
190190
191191
192192
......
202202
203203
204204
205
205
206206
207207
208208
......
212212
213213
214214
215
215
216216
217217
218218
219219
220
220
221221
222222
223223
......
253253
254254
255255
256
256
257257
258258
259259
260260
261261
262262
263
263
264264
265265
266266
......
412412
413413
414414
415
415
416416
417417
418418
......
449449
450450
451451
452
452
453453
454454
455455
......
463463
464464
465465
466
466
467467
468468
469469
......
472472
473473
474474
475
475
476476
477477
478
478
479479
480480
481
482
481
482
483483
484484
485485
486486
487487
488488
489
490
491
492
493
494
489
490
491
492
493
494
495495
496496
497497
......
536536
537537
538538
539
539
540540
541541
542542
......
561561
562562
563563
564
565
566
567
568
564
565
566
567
568
569
569570
570571
571572
......
612613
613614
614615
615
616
616617
617618
618
619
620
621
619
620
621
622
622623
623
624
624625
625626
626627
627628
628
629
629630
630631
631632
......
639640
640641
641642
642
643
643644
644645
645646
......
692693
693694
694695
695
696
697
698
696
697
698
699
700
699701
700702
701703
}
/* Gets the ACPI 1.0 RSDP address */
static struct acpi_2_rsdp* getAddressOfAcpiTable()
static struct acpi_2_rsdp *getAddressOfAcpiTable()
{
/* TODO: Before searching the BIOS space we are supposed to search the first 1K of the EBDA */
}
/* Gets the ACPI 2.0 RSDP address */
static struct acpi_2_rsdp* getAddressOfAcpi20Table()
static struct acpi_2_rsdp *getAddressOfAcpi20Table()
{
/* TODO: Before searching the BIOS space we are supposed to search the first 1K of the EBDA */
void *acpi_addr = (void*)ACPI_RANGE_START;
void *acpi_addr = (void *)ACPI_RANGE_START;
for(; acpi_addr <= (void*)ACPI_RANGE_END; acpi_addr += 16)
for(; acpi_addr <= (void *)ACPI_RANGE_END; acpi_addr += 16)
{
if(*(uint64_t *)acpi_addr == ACPI_SIGNATURE_UINT64_LE)
{
/* The folowing ACPI Table search algo. should be reused anywhere needed:*/
/* WARNING: outDirspec string will be overwritten by subsequent calls! */
int search_and_get_acpi_fd(const char * filename, const char ** outDirspec)
int search_and_get_acpi_fd(const char *filename, const char **outDirspec)
{
int fd = 0;
static char dirSpec[512];
return fd;
}
void *loadACPITable (const char * filename)
void *loadACPITable (const char *filename)
{
const char * dirspec=NULL;
const char *dirspec = NULL;
int fd = search_and_get_acpi_fd(filename, &dirspec);
if (fd >= 0)
{
void *tableAddr = (void*)AllocateKernelMemory(file_size (fd));
void *tableAddr = (void*)AllocateKernelMemory(file_size(fd));
if (tableAddr)
{
if (read (fd, tableAddr, file_size (fd))!=file_size (fd))
if (read(fd, tableAddr, file_size(fd)) != file_size(fd))
{
DBG("Couldn't read table %s\n",dirspec);
free (tableAddr);
close (fd);
free(tableAddr);
close(fd);
return NULL;
}
DBG("Table %s read and stored at: %x\n", dirspec, tableAddr);
close (fd);
close(fd);
return tableAddr;
}
close (fd);
close(fd);
DBG("Couldn't allocate memory for table \n", dirspec);
}
//printf("Couldn't find table %s\n", filename);
return NULL;
}
uint8_tacpi_cpu_count = 0;
char* acpi_cpu_name[32];
uint8_t acpi_cpu_count = 0;
uint32_t acpi_cpu_p_blk = 0;
char *acpi_cpu_name[32];
void get_acpi_cpu_names(unsigned char* dsdt, uint32_t length)
void get_acpi_cpu_names(unsigned char *dsdt, uint32_t length)
{
uint32_t i;
DBG("Start finding cpu names. length %d\n", length);
DBG("ACPIpatcher: start finding cpu names. Length %d\n", length);
for (i=0; i<length-7; i++)
{
if (dsdt[i] == 0x5B && dsdt[i+1] == 0x83) // ProcessorOP
{
DBG("DSDT: %x%x\n", dsdt[i], dsdt[i+1]);
DBG("ACPIpatcher: DSDT[%X%X]\n", dsdt[i], dsdt[i+1]);
uint32_t offset = i + 3 + (dsdt[i+2] >> 6);
if (!aml_isvalidchar(c))
{
add_name = false;
DBG("Invalid character found in ProcessorOP 0x%x!\n", c);
DBG("ACPIpatcher: invalid character found in ProcessorOP '0x%X'!\n", c);
break;
}
}
acpi_cpu_p_blk = dsdt[i] | (dsdt[i+1] << 8);
}
DBG("Found ACPI CPU: %c%c%c%c\n", acpi_cpu_name[acpi_cpu_count][0], acpi_cpu_name[acpi_cpu_count][1], acpi_cpu_name[acpi_cpu_count][2], acpi_cpu_name[acpi_cpu_count][3]);
DBG("ACPIpatcher: found ACPI CPU [%c%c%c%c]\n", acpi_cpu_name[acpi_cpu_count][0], acpi_cpu_name[acpi_cpu_count][1], acpi_cpu_name[acpi_cpu_count][2], acpi_cpu_name[acpi_cpu_count][3]);
if (++acpi_cpu_count == 32)
{
}
}
DBG("End finding cpu names: cpu names found: %d\n", acpi_cpu_count);
DBG("ACPIpatcher: finished finding cpu names. Found: %d.\n", acpi_cpu_count);
}
struct acpi_2_fadt *patch_fadt(struct acpi_2_fadt *fadt, struct acpi_2_dsdt *new_dsdt)
{
extern void setupSystemType();
extern void setupSystemType();
struct acpi_2_fadt *fadt_mod = NULL;
bool fadt_rev2_needed = false;
// Allocate new fadt table
if (fadt->Length < 0x84 && fadt_rev2_needed)
{
fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(0x84);
fadt_mod = (struct acpi_2_fadt *)AllocateKernelMemory(0x84);
memcpy(fadt_mod, fadt, fadt->Length);
fadt_mod->Length = 0x84;
fadt_mod->Revision = 0x02; // FADT rev 2 (ACPI 1.0B MS extensions)
}
else
{
fadt_mod=(struct acpi_2_fadt *)AllocateKernelMemory(fadt->Length);
fadt_mod = (struct acpi_2_fadt *)AllocateKernelMemory(fadt->Length);
memcpy(fadt_mod, fadt, fadt->Length);
}
// Determine system type / PM_Model
int ssdt_count=0;
// SSDT Options
bool drop_ssdt=false, generate_pstates=false, generate_cstates=false;
bool drop_ssdt = false, generate_pstates = false, generate_cstates = false;
getBoolForKey(kDropSSDT, &drop_ssdt, &bootInfo->chameleonConfig);
getBoolForKey(kGeneratePStates, &generate_pstates, &bootInfo->chameleonConfig);
int rsdplength;
// Find original rsdp
rsdp=(struct acpi_2_rsdp *)(version ? getAddressOfAcpi20Table() : getAddressOfAcpiTable());
rsdp = (struct acpi_2_rsdp *)(version ? getAddressOfAcpi20Table() : getAddressOfAcpiTable());
if (!rsdp)
{
DBG("No ACPI version %d found. Ignoring\n", version+1);
}
continue;
}
rsdplength=version ? rsdp->Length : 20;
rsdplength = version ? rsdp->Length : 20;
DBG("RSDP version %d found @%x. Length=%d\n",version+1,rsdp,rsdplength);
* For more info see ACPI Specification pages 110 and following
*/
rsdp_mod=(struct acpi_2_rsdp *) AllocateKernelMemory(rsdplength);
rsdp_mod = (struct acpi_2_rsdp *) AllocateKernelMemory(rsdplength);
memcpy(rsdp_mod, rsdp, rsdplength);
rsdt=(struct acpi_2_rsdt *)(rsdp->RsdtAddress);
rsdt = (struct acpi_2_rsdt *)rsdp->RsdtAddress;
DBG("RSDT @%x, Length %d\n",rsdt, rsdt ? rsdt->Length : 0);
if (rsdt && (uint32_t)rsdt !=0xffffffff && rsdt->Length<0x10000)
if (rsdt && (uint32_t)rsdt !=0xffffffff && rsdt->Length < 0x10000)
{
uint32_t *rsdt_entries;
int rsdt_entries_num;
int dropoffset=0, i;
// mozo: using malloc cos I didn't found how to free already allocated kernel memory
rsdt_mod=(struct acpi_2_rsdt *)malloc(rsdt->Length);
memcpy (rsdt_mod, rsdt, rsdt->Length);
rsdp_mod->RsdtAddress=(uint32_t)rsdt_mod;
rsdt_entries_num=(rsdt_mod->Length-sizeof(struct acpi_2_rsdt))/4;
rsdt_entries=(uint32_t *)(rsdt_mod+1);
for (i=0;i<rsdt_entries_num;i++)
rsdt_mod = (struct acpi_2_rsdt *)malloc(rsdt->Length);
memcpy(rsdt_mod, rsdt, rsdt->Length);
rsdp_mod->RsdtAddress = (uint32_t)rsdt_mod;
rsdt_entries_num = (rsdt_mod->Length - sizeof(struct acpi_2_rsdt)) / 4;
rsdt_entries = (uint32_t *)(rsdt_mod + 1);
for (i = 0;i < rsdt_entries_num;i++)
{
char *table=(char *)(rsdt_entries[i]);
if (!table)
}
fadt_mod = patch_fadt(fadt, new_dsdt);
rsdt_entries[i-dropoffset]=(uint32_t)fadt_mod;
rsdt_entries[i-dropoffset] = (uint32_t)fadt_mod;
// Generate _CST SSDT
if (generate_cstates && (new_ssdt[ssdt_count] = generate_cst_ssdt(fadt_mod)))
// Allocate rsdt in Kernel memory area
rsdt_mod->Length += 4*ssdt_count - 4*dropoffset;
struct acpi_2_rsdt *rsdt_copy = (struct acpi_2_rsdt *)AllocateKernelMemory(rsdt_mod->Length);
memcpy (rsdt_copy, rsdt_mod, rsdt_mod->Length);
free(rsdt_mod); rsdt_mod = rsdt_copy;
rsdp_mod->RsdtAddress=(uint32_t)rsdt_mod;
rsdt_entries_num=(rsdt_mod->Length-sizeof(struct acpi_2_rsdt))/4;
rsdt_entries=(uint32_t *)(rsdt_mod+1);
memcpy(rsdt_copy, rsdt_mod, rsdt_mod->Length);
free(rsdt_mod);
rsdt_mod = rsdt_copy;
rsdp_mod->RsdtAddress = (uint32_t)rsdt_mod;
rsdt_entries_num = (rsdt_mod->Length-sizeof(struct acpi_2_rsdt)) / 4;
rsdt_entries = (uint32_t *)(rsdt_mod + 1);
// Mozodojo: Insert additional SSDTs into RSDT
if(ssdt_count > 0)
int dropoffset=0;
// mozo: using malloc cos I didn't found how to free already allocated kernel memory
xsdt_mod=(struct acpi_2_xsdt*)malloc(xsdt->Length);
xsdt_mod=(struct acpi_2_xsdt*)malloc(xsdt->Length);
memcpy(xsdt_mod, xsdt, xsdt->Length);
rsdp_mod->XsdtAddress=(uint32_t)xsdt_mod;
xsdt_entries_num=(xsdt_mod->Length-sizeof(struct acpi_2_xsdt))/8;
xsdt_entries=(uint64_t *)(xsdt_mod+1);
for (i=0;i<xsdt_entries_num;i++)
rsdp_mod->XsdtAddress = (uint32_t)xsdt_mod;
xsdt_entries_num = (xsdt_mod->Length - sizeof(struct acpi_2_xsdt)) / 8;
xsdt_entries = (uint64_t *)(xsdt_mod + 1);
for (i = 0;i < xsdt_entries_num;i++)
{
char *table=(char *)((uint32_t)(xsdt_entries[i]));
char *table = (char *)((uint32_t)(xsdt_entries[i]));
if (!table)
{
continue;
}
xsdt_entries[i-dropoffset]=xsdt_entries[i];
xsdt_entries[i - dropoffset] = xsdt_entries[i];
if (drop_ssdt && tableSign(table, "SSDT"))
{
if (new_dsdt)
{
xsdt_entries[i-dropoffset]=(uint32_t)new_dsdt;
xsdt_entries[i-dropoffset] = (uint32_t)new_dsdt;
DBG("custom table added\n");
}
xsdt_mod->Length += 8*ssdt_count - 8*dropoffset;
struct acpi_2_xsdt *xsdt_copy = (struct acpi_2_xsdt *)AllocateKernelMemory(xsdt_mod->Length);
memcpy(xsdt_copy, xsdt_mod, xsdt_mod->Length);
free(xsdt_mod); xsdt_mod = xsdt_copy;
rsdp_mod->XsdtAddress=(uint32_t)xsdt_mod;
xsdt_entries_num=(xsdt_mod->Length-sizeof(struct acpi_2_xsdt))/8;
xsdt_entries=(uint64_t *)(xsdt_mod+1);
free(xsdt_mod);
xsdt_mod = xsdt_copy;
rsdp_mod->XsdtAddress = (uint32_t)xsdt_mod;
xsdt_entries_num = (xsdt_mod->Length - sizeof(struct acpi_2_xsdt)) / 8;
xsdt_entries = (uint64_t *)(xsdt_mod + 1);
// Mozodojo: Insert additional SSDTs into XSDT
if(ssdt_count > 0)
trunk/i386/libsaio/spd.c
128128
129129
130130
131
131
132
132133
133134
134135
......
239240
240241
241242
242
243
244
245
243246
244247
245248
static void init_spd(char * spd, uint32_t base, int slot)
{
int i;
for (i=0; i< SPD_INDEXES_SIZE; i++) {
for (i = 0; i < SPD_INDEXES_SIZE; i++)
{
READ_SPD(spd, base, slot, spd_indexes[i]);
}
}
if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR3) {
start = 128;
} else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR) {
}
else if (spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR2 || spd[SPD_MEMORY_TYPE]==SPD_MEMORY_TYPE_SDRAM_DDR)
{
start = 73;
}
trunk/i386/libsaio/gma.c
396396
397397
398398
399
399
400400
401401
402402
......
716716
717717
718718
719
719
720720
721721
722722
struct DevPropDevice *device = devprop_add_device(string, devicepath);
if (!device) {
printf("Failed initializing dev-prop string dev-entry.\n");
printf("[setup_gma_devprop] Failed initializing dev-prop string dev-entry!\n");
pause();
return false;
}
stringdata = malloc(sizeof(uint8_t) * string->length);
if (!stringdata)
{
printf("No stringdata.\n");
printf("[setup_gma_devprop] No stringdata!\n");
pause();
return false;
}
trunk/i386/libsaio/pci_root.c
9797
9898
9999
100
100
101
101102
102103
103104
104105
105
106
107
106108
107109
108110
fsize = file_size(fd);
if (!(new_dsdt = malloc(fsize))) {
if (!(new_dsdt = malloc(fsize)))
{
verbose("[ERROR] alloc DSDT memory failed\n");
close (fd);
goto out;
}
if (read (fd, new_dsdt, fsize) != fsize) {
if (read (fd, new_dsdt, fsize) != fsize)
{
verbose("[ERROR] read %s failed\n", dsdt_filename);
free(new_dsdt);
close (fd);
trunk/i386/libsaio/device_inject.c
6464
6565
6666
67
6768
6869
6970
7071
7172
7273
73
74
7475
7576
7677
binStr = convertHexStr2Binary(val, &cnt2);
if (cnt2 > 0) {
DT__AddProperty(node, DEVICE_PROPERTIES_PROP, cnt2, binStr);
DBG("Adding device-properties string to DT");
}
}
}
DevPropString *devprop_create_string(void)
{
string = (struct DevPropString*)malloc(sizeof(struct DevPropString));
string = (struct DevPropString *)malloc(sizeof(struct DevPropString));
if(string == NULL) {
return NULL;
trunk/i386/libsaio/fdisk.h
4141
4242
4343
44
44
45
4546
4647
4748
4849
4950
50
51
52
51
52
53
54
55
5356
54
55
56
57
58
59
57
58
59
60
61
62
63
64
65
66
67
6068
6169
6270
#define DISK_SIGNATURE0xAA55/* signature of the boot record */
#define FDISK_NPART4 /* number of entries in fdisk table */
#define FDISK_ACTIVE0x80/* indicator of active partition */
#define FDISK_NEXTNAME0xA7/* indicator of NeXT partition */
#define FDISK_DOS120x01/* 12-bit fat < 10MB dos partition */
#define FDISK_DOS16S0x04/* 16-bit fat < 32MB dos partition */
#define FDISK_DOSEXT0x05/* extended DOS partition */
#define FDISK_DOS16B0x06/* 16-bit fat >= 32MB dos partition */
#define FDISK_NTFS0x07/* NTFS partition */
#define FDISK_SMALLFAT320x0b/* FAT32 partition */
#define FDISK_FAT320x0c/* FAT32 partition */
#define FDISK_DOS16SLBA0x0e /* 16-bit FAT, LBA-mapped */
#define FDISK_SMALLFAT320x0B/* DOS FAT32 partition */
#define FDISK_FAT320x0C/* Win FAT32 partition */
#define FDISK_DOS16SLBA0x0E /* Win 16-bit FAT, LBA-mapped */
#define FDISK_WIN_LDM0x42/* NTFS partition */
#define FDISK_LINUX_SWAP0x82 /* Linux swap */
#define FDISK_LINUX0x83 /* Linux native */
#define FDISK_OPENBSD0xa6 /* OpenBSD FFS partition */
#define FDISK_FREEBSD0xa5 /* FreeBSD UFS2 partition */
#define FDISK_BEFS0xeb /* Haiku BeFS partition */
#define FDISK_UFS0xa8/* Apple UFS partition */
#define FDISK_HFS0xaf/* Apple HFS partition */
#define FDISK_BOOTER0xab/* Apple booter partition */
#define FDISK_LINUX_LVM0x8E /* Linux LVM */
#define FDISK_FREEBSD0xA5 /* FreeBSD UFS2 partition */
#define FDISK_OPENBSD0xA6 /* OpenBSD FFS partition */
#define FDISK_NEXTNAME0xA7/* Indicator of NeXT partition */
#define FDISK_UFS0xA8/* Apple UFS partition */
#define FDISK_NETBSD0xA9 /* NetBSD disk label */
#define FDISK_BOOTER0xAB/* Apple booter partition */
#define FDISK_ENCRYPTED0xAE/* Apple encrypted */
#define FDISK_HFS0xAF/* Apple HFS partition */
#define FDISK_BEFS0xEB /* Haiku BeFS partition */
#define FDISK_LINUX_RAID0xFD /* Linux RAID */
#define FDISK_PSEUDO_EXFAT0x107/* Shared with FDISK_NTFS */
/*
trunk/i386/libsaio/sys.c
8585
8686
8787
88
88
8989
9090
9191
......
385385
386386
387387
388
388
389389
390
390
391391
392392
393
393
394394
395395
396396
......
498498
499499
500500
501
501
502502
503503
504
504
505505
506506
507507
......
822822
823823
824824
825
825
826826
827
828
829
827
828
829
830830
831831
832832
833833
834
834
835835
836836
837837
......
948948
949949
950950
951
951
952952
953953
954954
......
963963
964964
965965
966
966
967967
968968
969969
......
990990
991991
992992
993
993
994994
995995
996996
......
10051005
10061006
10071007
1008
1008
10091009
10101010
10111011
10121012
10131013
10141014
1015
1015
10161016
10171017
1018
1018
10191019
10201020
10211021
10221022
10231023
10241024
1025
1026
1027
1025
1026
1027
10281028
10291029
10301030
......
10371037
10381038
10391039
1040
1040
10411041
10421042
10431043
1044
1044
10451045
10461046
10471047
......
11021102
11031103
11041104
1105
1105
11061106
11071107
11081108
......
11301130
11311131
11321132
1133
1134
1133
1134
11351135
11361136
11371137
struct devsw
{
const char * name;
const char *name;
// size increased from char to short to handle non-BIOS internal devices
unsigned short biosdev;
int type;
// GetFileInfo - LOW-LEVEL FILESYSTEM FUNCTION.
// Get attributes for the specified file.
static char* gMakeDirSpec;
static char *gMakeDirSpec;
long GetFileInfo(const char * dirSpec, const char * name, long * flags, u_int32_t * time)
long GetFileInfo(const char *dirSpec, const char *name, long *flags, u_int32_t *time)
{
long long index = 0;
const char * entryName;
const char *entryName;
if (gMakeDirSpec == 0)
{
//==========================================================================
// openmem()
int openmem(char * buf, int len)
int openmem(char *buf, int len)
{
int fdesc;
struct iob * io;
struct iob *io;
fdesc = GetFreeFd();
io = &iob[fdesc];
//==========================================================================
struct dirstuff * opendir(const char * path)
struct dirstuff *opendir(const char *path)
{
struct dirstuff * dirp = 0;
const char * dirPath;
BVRef bvr;
struct dirstuff *dirp = 0;
const char *dirPath;
BVRef bvr;
if ((bvr = getBootVolumeRef(path, &dirPath)) == NULL)
goto error;
dirp = (struct dirstuff *) malloc(sizeof(struct dirstuff));
dirp = (struct dirstuff *)malloc(sizeof(struct dirstuff));
if (dirp == NULL)
goto error;
//==========================================================================
BVRef selectBootVolume( BVRef chain )
BVRef selectBootVolume(BVRef chain)
{
bool filteredChain = false;
bool foundPrimary = false;
{
for ( bvr = chain; bvr; bvr = bvr->next )
{
if ( bvr->part_no == multiboot_partition && bvr->biosdev == gBIOSDev )
if ( (bvr->part_no == multiboot_partition) && (bvr->biosdev == gBIOSDev) )
{
return bvr;
}
}
/*
* Scannig the volume chain backwards and trying to find
* Scannig the volume chain backwards and trying to find
* a HFS+ volume with valid boot record signature.
* If not found any active partition then we will
* select this volume as the boot volume.
}
}
if ( bvr->flags & kBVFlagPrimary && bvr->biosdev == gBIOSDev )
if ( (bvr->flags & kBVFlagPrimary) && (bvr->biosdev == gBIOSDev) )
{
foundPrimary = true;
}
// zhell -- Undo a regression that was introduced from r491 to 492.
// if gBIOSBootVolume is set already, no change is required
if ( bvr->flags & (kBVFlagBootable|kBVFlagSystemVolume)
if ( (bvr->flags & (kBVFlagBootable | kBVFlagSystemVolume))
&& gBIOSBootVolume
&& (!filteredChain || (filteredChain && bvr->visible))
&& bvr->biosdev == gBIOSDev )
&& (bvr->biosdev == gBIOSDev) )
{
bvr2 = bvr;
}
// zhell -- if gBIOSBootVolume is NOT set, we use the "if" statement
// from r491,
if ( bvr->flags & kBVFlagBootable
&& ! gBIOSBootVolume
&& bvr->biosdev == gBIOSDev )
if ( (bvr->flags & kBVFlagBootable)
&& !gBIOSBootVolume
&& (bvr->biosdev == gBIOSDev) )
{
bvr2 = bvr;
}
{
for ( bvr = chain; bvr; bvr = bvr->next )
{
if ( bvr->flags & kBVFlagNativeBoot && bvr->biosdev == gBIOSDev )
if ( (bvr->flags & kBVFlagNativeBoot) && (bvr->biosdev == gBIOSDev) )
{
bvr1 = bvr;
}
if ( bvr->flags & kBVFlagPrimary && bvr->biosdev == gBIOSDev )
if ( (bvr->flags & kBVFlagPrimary) && (bvr->biosdev == gBIOSDev) )
{
bvr2 = bvr;
}
is changed to the selected volume unless the volume selector is
that of a ramdisk.
*/
BVRef getBootVolumeRef( const char * path, const char ** outPath )
BVRef getBootVolumeRef(const char *path, const char **outPath)
{
const char*cp;
BVRef bvr= gRootVolume;
}
else if ((cp - path) == 2) // found "xx("
{
const struct devsw * dp;
const char * xp = path;
const struct devsw *dp;
const char *xp = path;
int i;
int unit = -1;
trunk/i386/libsaio/acpi.h
2222
2323
2424
25
2526
2627
2728
2829
2930
31
3032
3133
3234
......
141143
142144
143145
146
144147
145148
146149
// TODO Migrate
struct acpi_2_rsdp
{
// 1.0
charSignature[8];
uint8_tChecksum;
charOEMID[6];
uint8_tRevision;
uint32_tRsdtAddress;
// 2.0
uint32_tLength;
uint64_tXsdtAddress;
uint8_tExtendedChecksum;
/* Begin Asere */
//Reset Fix
uint32_t Flags;
// Reset Register
uint8_t Reset_SpaceID;
uint8_t Reset_BitWidth;
uint8_t Reset_BitOffset;
trunk/i386/libsaio/cpu.c
8080
8181
8282
83
84
83
84
8585
8686
8787
lastValue = timerValue;
} while (timerValue > 5);
printf("timerValue %d\n",timerValue);
printf("intermediate 0x%016llx\n",intermediate);
printf("saveTime 0x%016llx\n",saveTime);
printf("intermediate 0x%016llX\n",intermediate);
printf("saveTime 0x%016llX\n",saveTime);
intermediate -= saveTime;// raw count for about 1/20 second
intermediate *= scale[timerValue];// rescale measured time spent
trunk/i386/libsaio/disk.c
8989
9090
9191
92
9293
9394
9495
......
100101
101102
102103
104
105
106
107
108
109
110
111
103112
113
114
115
116
117
118
119
120
121
122
104123
105124
106125
......
110129
111130
112131
113
114
115
116
117
118
119
120
121
132
133
122134
123
124
125
126135
127136
128137
......
130139
131140
132141
142
133143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
134185
135186
136187
......
182233
183234
184235
185
186236
187
188
189
190
191
192
193
194237
195238
196239
197
240
198241
199242
200243
......
207250
208251
209252
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224253
225254
226255
......
247276
248277
249278
250
251
252279
253280
254281
......
366393
367394
368395
369
370396
371397
372398
......
388414
389415
390416
391
417
392418
393419
394420
......
414440
415441
416442
417
443
418444
419445
420446
......
437463
438464
439465
440
441
466
442467
443468
444469
445470
446471
447472
448
449
473
474
450475
451476
452477
......
529554
530555
531556
532
533
534
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
535658
536659
537660
......
540663
541664
542665
543
666
544667
545668
546669
......
573696
574697
575698
576
699
577700
578701
579702
......
613736
614737
615738
616
739
617740
618
741
619742
743
744
620745
621746
622747
......
632757
633758
634759
635
760
636761
637762
638763
......
668793
669794
670795
671
796
672797
673798
674799
......
686811
687812
688813
689
814
815
690816
691817
692818
819
693820
694821
695822
......
721848
722849
723850
724
725
726
851
852
853
854
855
856
727857
728858
729859
730860
731861
732862
733
863
864
865
734866
735
867
736868
737869
738870
739871
740
741
742
743
744
745
746
747
748
749
750
872
873
874
875
876
877
878
879
880
881
882
751883
752884
753885
......
796928
797929
798930
799
931
932
800933
801934
802935
936
803937
804938
805939
......
812946
813947
814948
815
949
816950
817
818
819
820
951
952
953
954
821955
822
956
823957
824
825
826
958
959
960
827961
828962
829963
......
841975
842976
843977
844
978
979
845980
846981
847
982
848983
849984
850985
......
857992
858993
859994
860
861
995
862996
863997
864998
......
8791013
8801014
8811015
882
1016
8831017
8841018
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
9011035
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
9201056
9211057
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
9381074
9391075
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
9611097
962
963
964
965
966
967
968
969
970
971
972
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
9731110
974
975
976
977
978
979
980
981
982
983
984
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
9851123
986
987
988
989
990
991
992
993
994
995
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
9961135
997
998
999
1000
1001
1002
1003
1004
1005
1006
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
10071147
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
10181159
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
10301171
1031
1032
1033
1034
1035
1036
1037
1172
1173
1174
1175
1176
1177
1178
10381179
10391180
1040
1041
1181
1182
10421183
10431184
10441185
......
10561197
10571198
10581199
1200
10591201
10601202
10611203
10621204
1063
10641205
10651206
10661207
......
10881229
10891230
10901231
1091
1232
10921233
10931234
1094
1235
10951236
10961237
10971238
......
11011242
11021243
11031244
1104
1245
11051246
11061247
11071248
11081249
11091250
11101251
1111
1112
1113
1114
1115
1252
1253
1254
1255
1256
11161257
11171258
11181259
11191260
11201261
1262
11211263
11221264
11231265
......
11251267
11261268
11271269
1270
11281271
11291272
11301273
......
11651308
11661309
11671310
1168
1311
11691312
11701313
11711314
......
11741317
11751318
11761319
1177
1320
11781321
11791322
11801323
......
12101353
12111354
12121355
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1356
12341357
1235
1358
12361359
12371360
1238
1239
1240
1241
1361
12421362
1243
1363
12441364
12451365
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1366
13081367
13091368
13101369
......
13261385
13271386
13281387
1329
1388
1389
13301390
13311391
13321392
......
13741434
13751435
13761436
1377
1437
13781438
13791439
13801440
......
13841444
13851445
13861446
1387
1447
13881448
13891449
13901450
......
14051465
14061466
14071467
1408
1409
1410
1411
1412
1413
1468
1469
1470
1471
1472
1473
14141474
14151475
14161476
......
14581518
14591519
14601520
1461
1521
1522
14621523
14631524
14641525
14651526
1466
1527
14671528
14681529
14691530
......
14761537
14771538
14781539
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
14961557
14971558
1498
1499
1559
1560
1561
15001562
15011563
15021564
......
16061668
16071669
16081670
1609
1671
1672
16101673
16111674
16121675
1613
1676
1677
16141678
16151679
16161680
16171681
16181682
1619
1683
1684
1685
16201686
16211687
16221688
......
16861752
16871753
16881754
1689
16901755
16911756
16921757
......
17571822
17581823
17591824
1760
1825
17611826
17621827
17631828
......
17961861
17971862
17981863
1799
1864
18001865
18011866
18021867
......
18971962
18981963
18991964
1965
19001966
19011967
19021968
......
19061972
19071973
19081974
1975
19091976
19101977
19111978
19121979
1980
19131981
19141982
19151983
......
20822150
20832151
20842152
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
21072153
21082154
21092155
......
22642310
22652311
22662312
2267
2313
22682314
22692315
22702316
......
22792325
22802326
22812327
2282
2328
22832329
22842330
2285
2331
22862332
22872333
22882334
22892335
22902336
2291
2337
22922338
22932339
22942340
......
23282374
23292375
23302376
2331
2377
23322378
2333
2334
2379
2380
23352381
2336
2382
23372383
2338
2384
23392385
2340
2386
23412387
23422388
23432389
23442390
23452391
2346
2392
23472393
23482394
2349
2350
2395
2396
23512397
23522398
23532399
......
24702516
24712517
24722518
2473
2519
24742520
24752521
24762522
......
24832529
24842530
24852531
2486
2532
24872533
24882534
24892535
#define UFS_FRONT_PORCH 0
#define kAPMSector 2 /* Sector number of Apple partition map */
#define kAPMCDSector 8 /* Translated sector of Apple partition map on a CD */
#define ECC_CORRECTED_ERR 0x11
/*
* IORound and IOTrunc convenience functions, in the spirit
#define IOTrunc(value,multiple) \
(((value) / (multiple)) * (multiple));
//==========================================================================
// Maps (E)BIOS return codes to message strings.
struct NamedValue {
unsigned char value;
const char *name;
};
/*
* Map a disk drive to bootable volumes contained within.
*/
struct DiskBVMap {
int biosdev;// BIOS device number (unique)
BVRef bvr;// chain of boot volumes on the disk
int bvrcnt;// number of boot volumes
struct DiskBVMap *next;// linkage to next mapping
};
/*
* trackbuf points to the start of the track cache. Biosread()
* will store the sectors read from disk to this memory area.
*
static char * const trackbuf = (char *) ptov(BIOS_ADDR);
static char * biosbuf;
/*
* Map a disk drive to bootable volumes contained within.
*/
struct DiskBVMap {
int biosdev; // BIOS device number (unique)
BVRef bvr; // chain of boot volumes on the disk
int bvrcnt; // number of boot volumes
struct DiskBVMap * next; // linkage to next mapping
};
static struct DiskBVMap *gDiskBVMap = NULL;
static struct disk_blk0 *gBootSector = NULL;
static struct DiskBVMap * gDiskBVMap = NULL;
static struct disk_blk0 * gBootSector = NULL;
// Function pointers to be filled in if ramdisks are available:
int (*p_ramdiskReadBytes)( int biosdev, unsigned int blkno,
unsigned int byteoff,
int (*p_get_ramdisk_info)(int biosdev, struct driveInfo *dip) = NULL;
static bool getOSVersion(BVRef bvr, char *str);
static bool cache_valid = false;
static const struct NamedValue bios_errors[] =
{
{ 0x10, "Media error" },
{ 0x11, "Corrected ECC error" },
{ 0x20, "Controller or device error" },
{ 0x40, "Seek failed" },
{ 0x80, "Device timeout" },
{ 0xAA, "Drive not ready" },
{ 0x00, NULL }
};
static const struct NamedValue fdiskTypes[] =
{
{ FDISK_DOS12,"DOS_FAT_12" },
{ FDISK_DOS16S,"DOS_FAT_16_S" },
{ FDISK_DOS16B,"DOS_FAT_16" },
{ FDISK_NTFS,"Windows NTFS" },
{ FDISK_DOS16SLBA,"Windows FAT16" },
{ FDISK_FAT32,"Windows FAT32" },
{ FDISK_SMALLFAT32,"Windows FAT32" },
{ FDISK_LINUX,"Linux" },
{ FDISK_FREEBSD,"FreeBSD" },
{ FDISK_OPENBSD,"OpenBSD" },
{ FDISK_NEXTNAME, "Apple_Rhapsody_UFS" }, // 0xA7
{ FDISK_UFS,"Apple UFS" },
{ FDISK_NETBSD, "NetBSD" }, // 0xA9
{ FDISK_BOOTER,"Apple_Boot" }, // 0xAB
{ FDISK_ENCRYPTED, "Apple_Encrypted" }, // 0xAE
{ FDISK_HFS,"Apple HFS" }, // 0xAF
{ 0xCD,"CD-ROM" },
{ FDISK_BEFS, "Haiku" }, // 0xEB
{ FDISK_LINUX_RAID, "Linux_RAID" }, // 0xFD
{ 0x00,NULL } /* must be last */
};
//==============================================================================
extern void spinActivityIndicator(int sectors);
//==========================================================================
}
//==========================================================================
// Maps (E)BIOS return codes to message strings.
struct NamedValue {
unsigned char value;
const char * name;
};
//==========================================================================
static const char * getNameForValue( const struct NamedValue * nameTable,
unsigned char value )
{
const struct NamedValue * np;
const struct NamedValue *np;
for ( np = nameTable; np->value; np++)
{
return NULL;
}
#define ECC_CORRECTED_ERR 0x11
static const struct NamedValue bios_errors[] =
{
{ 0x10, "Media error" },
{ 0x11, "Corrected ECC error" },
{ 0x20, "Controller or device error" },
{ 0x40, "Seek failed" },
{ 0x80, "Device timeout" },
{ 0xAA, "Drive not ready" },
{ 0x00, 0 }
};
//==============================================================================
static const char * bios_error(int errnum)
// Return:
// 0 on success, or an error code from INT13/F2 or INT13/F42 BIOS call.
static bool cache_valid = false;
static int Biosread( int biosdev, unsigned long long secno )
{
static int xbiosdev, xcyl, xhead;
return rc;
}
//==============================================================================
int testBiosread(int biosdev, unsigned long long secno)
int error;
int copy_len;
DEBUG_DISK(("%s: dev %x block %x [%d] -> 0x%x...", __FUNCTION__, biosdev, blkno, byteCount, (unsigned)cbuf));
DEBUG_DISK(("%s: dev %X block %X [%d] -> 0x%X...", __FUNCTION__, biosdev, blkno, byteCount, (unsigned)cbuf));
for (; byteCount; cbuf += copy_len, blkno++)
{
//==============================================================================
static int isExtendedFDiskPartition( const struct fdisk_part * part )
static int isExtendedFDiskPartition( const struct fdisk_part *part )
{
static unsigned char extParts[] =
{
//==============================================================================
static int getNextFDiskPartition( int biosdev, int * partno,
const struct fdisk_part ** outPart )
static int getNextFDiskPartition( int biosdev, int *partno, const struct fdisk_part **outPart )
{
static int sBiosdev = -1;
static int sNextPartNo;
static unsigned int sFirstBase;
static unsigned int sExtBase;
static unsigned int sExtDepth;
static struct fdisk_part * sExtPart;
struct fdisk_part * part;
static struct fdisk_part *sExtPart;
struct fdisk_part *part;
if ( sBiosdev != biosdev || *partno < 0 )
{
//==============================================================================
static BVRef newFDiskBVRef( int biosdev, int partno, unsigned int blkoff,
const struct fdisk_part * part,
FSInit initFunc, FSLoadFile loadFunc,
/*
* Trying to figure out the filsystem type of a given partition.
* X = fdisk partition type
* 0 = Unknown/Unused
* -1 = error
*/
static int probeFileSystem(int biosdev, unsigned int blkoff)
{
// detected filesystem type;
int result = -1;
int fatbits = 0;
// Allocating buffer for 4 sectors.
const void *probeBuffer = malloc(PROBEFS_SIZE);
if (probeBuffer == NULL)
{
goto exit;
}
// Reading first 4 sectors of current partition
int error = readBytes(biosdev, blkoff, 0, PROBEFS_SIZE, (void *)probeBuffer);
if (error)
{
goto exit;
}
if (HFSProbe(probeBuffer))
{
result = FDISK_HFS;
}
else if (EX2Probe(probeBuffer))
{
result = FDISK_LINUX;
}
else if (FreeBSDProbe(probeBuffer))
{
result = FDISK_FREEBSD;
}
else if (OpenBSDProbe(probeBuffer))
{
result = FDISK_OPENBSD;
}
else if (BeFSProbe(probeBuffer))
{
result = FDISK_BEFS;
}
else if (NTFSProbe(probeBuffer))
{
result = FDISK_NTFS;
}
else if (EXFATProbe(probeBuffer))
{
result = FDISK_PSEUDO_EXFAT;
}
else if ((fatbits = MSDOSProbe(probeBuffer)))
{
switch (fatbits)
{
case 12:
result = FDISK_DOS12;
break;
case 16:
result = FDISK_DOS16B;
break;
case 32:
default:
result = FDISK_FAT32;
break;
}
}
else
{
// Couldn't detect filesystem type
result = 0;
}
exit:
if (probeBuffer)
{
free((void *)probeBuffer);
}
return result;
}
//==============================================================================
static BVRef newFDiskBVRef( int biosdev,
int partno,
unsigned int blkoff,
const struct fdisk_part *part,
FSInit initFunc,
FSLoadFile loadFunc,
FSReadFile readFunc,
FSGetDirEntry getdirFunc,
FSGetFileBlock getBlockFunc,
BVFree bvFreeFunc,
int probe, int type, unsigned int bvrFlags )
{
BVRef bvr = (BVRef) malloc( sizeof(*bvr) );
BVRef bvr = (BVRef)malloc(sizeof(*bvr));
if ( bvr )
{
bzero(bvr, sizeof(*bvr));
{
// filesystem probe failed.
DEBUG_DISK(("%s: failed probe on dev %x part %d\n", __FUNCTION__, biosdev, partno));
DEBUG_DISK(("%s: failed probe on dev %X part %d\n", __FUNCTION__, biosdev, partno));
(*bvr->bv_free)(bvr);
bvr = NULL;
}
}
if (bvr) bvr->flags |= bvrFlags;
if ( bvr )
{
return bvr;
bvr->flags |= bvrFlags;
}
return bvr;
}
//==============================================================================
BVFree bvFreeFunc,
int probe, int type, unsigned int bvrFlags )
{
BVRef bvr = (BVRef) malloc( sizeof(*bvr) );
BVRef bvr = (BVRef)malloc(sizeof(*bvr));
if ( bvr )
{
bzero(bvr, sizeof(*bvr));
{
// filesystem probe failed.
DEBUG_DISK(("%s: failed probe on dev %x part %d\n", __FUNCTION__, biosdev, partno));
DEBUG_DISK(("%s: failed probe on dev %X part %d\n", __FUNCTION__, biosdev, partno));
(*bvr->bv_free)(bvr);
bvr = NULL;
bvr = NULL;
}
}
if (bvr)
if ( bvr )
{
bvr->flags |= bvrFlags;
}
return bvr;
}
// same as Apple ZFS
//EFI_GUID const GPT_ZFS_GUID= { 0x6A898CC3, 0x1DD2, 0x11B2, { 0x99, 0xA6, 0x08, 0x00, 0x20, 0x73, 0x66, 0x31 } }; // 0xBF01 "Solaris /usr & Apple ZFS
BVRef newGPTBVRef( int biosdev, int partno, unsigned int blkoff,
const gpt_ent * part,
FSInit initFunc, FSLoadFile loadFunc,
BVRef newGPTBVRef( int biosdev,
int partno,
unsigned int blkoff,
const gpt_ent *part,
FSInit initFunc,
FSLoadFile loadFunc,
FSReadFile readFunc,
FSGetDirEntry getdirFunc,
FSGetFileBlock getBlockFunc,
FSGetUUID getUUIDFunc,
BVGetDescription getDescriptionFunc,
BVFree bvFreeFunc,
int probe, int type, unsigned int bvrFlags )
int probe,
int type,
unsigned int bvrFlags )
{
BVRef bvr = (BVRef) malloc( sizeof(*bvr) );
BVRef bvr = (BVRef)malloc(sizeof(*bvr));
if ( bvr )
{
bzero(bvr, sizeof(*bvr));
bvr->biosdev = biosdev;
bvr->part_no = partno;
bvr->part_boff = blkoff;
bvr->fs_loadfile = loadFunc;
bvr->fs_readfile = readFunc;
bvr->fs_getdirentry = getdirFunc;
bvr->fs_getfileblock= getBlockFunc;
bvr->fs_getuuid = getUUIDFunc;
bvr->description = getDescriptionFunc;
bvr->type = type;
bvr->bv_free = bvFreeFunc;
bvr->biosdev = biosdev;
bvr->part_no = partno;
bvr->part_boff = blkoff;
bvr->fs_loadfile = loadFunc;
bvr->fs_readfile = readFunc;
bvr->fs_getdirentry = getdirFunc;
bvr->fs_getfileblock = getBlockFunc;
bvr->fs_getuuid = getUUIDFunc;
bvr->description = getDescriptionFunc;
bvr->type = type;
bvr->bv_free = bvFreeFunc;
// FIXME: UCS-2 -> UTF-8 the name
strlcpy(bvr->name, "----", DPISTRLEN);
if ( (efi_guid_compare(&GPT_BOOT_GUID, (EFI_GUID const*)part->ent_type) == 0) || (efi_guid_compare(&GPT_HFS_GUID, (EFI_GUID const*)part->ent_type) == 0) )
bvr = NULL;
}
}
if (bvr)
if ( bvr )
{
bvr->flags |= bvrFlags;
}
return bvr;
}
* one extended partition they will be numbered 1, 2, 5.
*/
static BVRef diskScanFDiskBootVolumes( int biosdev, int * countPtr )
static BVRef diskScanFDiskBootVolumes( int biosdev, int *countPtr )
{
const struct fdisk_part * part;
struct DiskBVMap * map;
int partno = -1;
BVRef bvr;
const struct fdisk_part*part;
struct DiskBVMap*map;
intpartno = -1;
BVRefbvr;
#if UFS_SUPPORT
BVRef booterUFS = NULL;
BVRefbooterUFS = NULL;
#endif
int spc;
struct driveInfo di;
boot_drive_info_t *dp;
intspc;
struct driveInfodi;
boot_drive_info_t*dp;
/* Initialize disk info */
spc = 1;
}
do {
do
{
// Create a new mapping.
map = (struct DiskBVMap *) malloc( sizeof(*map) );
map = (struct DiskBVMap *)malloc(sizeof(*map));
if ( map )
{
map->biosdev = biosdev;
while ( getNextFDiskPartition( biosdev, &partno, &part ) )
{
DEBUG_DISK(("%s: part %d [%x]\n", __FUNCTION__,
partno, part->systid));
DEBUG_DISK(("%s: part %d [%X]\n", __FUNCTION__, partno, part->systid));
bvr = 0;
switch ( part->systid )
UFSFree,
0,
kBIOSDevTypeHardDrive, 0);
break;
break;
#endif
case FDISK_HFS:
bvr = newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
HFSInitPartition,
HFSLoadFile,
HFSReadFile,
HFSGetDirEntry,
HFSGetFileBlock,
HFSGetUUID,
HFSGetDescription,
HFSFree,
0,
kBIOSDevTypeHardDrive, 0);
break;
case FDISK_HFS:
bvr = newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
HFSInitPartition,
HFSLoadFile,
HFSReadFile,
HFSGetDirEntry,
HFSGetFileBlock,
HFSGetUUID,
HFSGetDescription,
HFSFree,
0,
kBIOSDevTypeHardDrive, 0);
break;
// turbo - we want the booter type scanned also
case FDISK_BOOTER:
if (part->bootid & FDISK_ACTIVE)
gBIOSBootVolume = newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
HFSInitPartition,
HFSLoadFile,
HFSReadFile,
HFSGetDirEntry,
HFSGetFileBlock,
HFSGetUUID,
HFSGetDescription,
HFSFree,
0,
kBIOSDevTypeHardDrive, 0);
break;
// turbo - we want the booter type scanned also
case FDISK_BOOTER:
if (part->bootid & FDISK_ACTIVE)
{
gBIOSBootVolume = newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
HFSInitPartition,
HFSLoadFile,
HFSReadFile,
HFSGetDirEntry,
HFSGetFileBlock,
HFSGetUUID,
HFSGetDescription,
HFSFree,
0,
kBIOSDevTypeHardDrive, 0);
}
break;
#if UFS_SUPPORT
case FDISK_BOOTER:
booterUFS = newFDiskBVRef(
biosdev, partno,
((part->relsect + spc - 1) / spc) * spc,
part,
UFSInitPartition,
UFSLoadFile,
UFSReadFile,
UFSGetDirEntry,
UFSGetFileBlock,
UFSGetUUID,
UFSGetDescription,
UFSFree,
0,
kBIOSDevTypeHardDrive, 0);
break;
case FDISK_BOOTER:
booterUFS = newFDiskBVRef(
biosdev, partno,
((part->relsect + spc - 1) / spc) * spc,
part,
UFSInitPartition,
UFSLoadFile,
UFSReadFile,
UFSGetDirEntry,
UFSGetFileBlock,
UFSGetUUID,
UFSGetDescription,
UFSFree,
0,
kBIOSDevTypeHardDrive, 0);
break;
#endif
case FDISK_FAT32:
case FDISK_DOS12:
case FDISK_DOS16S:
case FDISK_DOS16B:
case FDISK_SMALLFAT32:
case FDISK_DOS16SLBA:
bvr = newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
MSDOSInitPartition,
MSDOSLoadFile,
MSDOSReadFile,
MSDOSGetDirEntry,
MSDOSGetFileBlock,
MSDOSGetUUID,
MSDOSGetDescription,
MSDOSFree,
0,
kBIOSDevTypeHardDrive, 0);
break;
case FDISK_FAT32:
case FDISK_DOS12:
case FDISK_DOS16S:
case FDISK_DOS16B:
case FDISK_SMALLFAT32:
case FDISK_DOS16SLBA:
bvr = newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
MSDOSInitPartition,
MSDOSLoadFile,
MSDOSReadFile,
MSDOSGetDirEntry,
MSDOSGetFileBlock,
MSDOSGetUUID,
MSDOSGetDescription,
MSDOSFree,
0,
kBIOSDevTypeHardDrive, 0);
break;
case FDISK_NTFS:
bvr = newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
0, 0, 0, 0, 0,
NTFSGetUUID,
NTFSGetDescription,
(BVFree)free,
0, kBIOSDevTypeHardDrive, 0);
break;
case FDISK_NTFS:
bvr = newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
0, 0, 0, 0, 0,
NTFSGetUUID,
NTFSGetDescription,
(BVFree)free,
0,
kBIOSDevTypeHardDrive, 0);
break;
case FDISK_LINUX:
bvr = newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
0, 0, 0, 0, 0,
EX2GetUUID,
EX2GetDescription,
(BVFree)free,
0, kBIOSDevTypeHardDrive, 0);
break;
case FDISK_LINUX:
bvr = newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
0, 0, 0, 0, 0,
EX2GetUUID,
EX2GetDescription,
(BVFree)free,
0,
kBIOSDevTypeHardDrive, 0);
break;
case FDISK_BEFS:
bvr = newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
0, 0, 0, 0, 0, 0,
BeFSGetDescription,
(BVFree)free,
0, kBIOSDevTypeHardDrive, 0);
break;
case FDISK_BEFS:
bvr = newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
0, 0, 0, 0, 0, 0,
BeFSGetDescription,
(BVFree)free,
0,
kBIOSDevTypeHardDrive, 0);
break;
case FDISK_FREEBSD:
bvr = newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
0, 0, 0, 0, 0, 0,
FreeBSDGetDescription,
(BVFree)free,
0, kBIOSDevTypeHardDrive, 0);
break;
case FDISK_FREEBSD:
bvr = newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
0, 0, 0, 0, 0, 0,
FreeBSDGetDescription,
(BVFree)free,
0,
kBIOSDevTypeHardDrive, 0);
break;
case FDISK_OPENBSD:
bvr = newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
0, 0, 0, 0, 0, 0,
OpenBSDGetDescription,
(BVFree)free,
0, kBIOSDevTypeHardDrive, 0);
break;
case FDISK_OPENBSD:
bvr = newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
0, 0, 0, 0, 0, 0,
OpenBSDGetDescription,
(BVFree)free,
0,
kBIOSDevTypeHardDrive, 0);
break;
default:
bvr = newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
0, 0, 0, 0, 0, 0, 0,
(BVFree)free,
0,
kBIOSDevTypeHardDrive, 0);
break;
}
default:
bvr = newFDiskBVRef(
biosdev, partno,
part->relsect,
part,
0, 0, 0, 0, 0, 0, 0,
(BVFree)free,
0,
kBIOSDevTypeHardDrive, 0);
break;
}
if ( bvr )
{
bvr->next = map->bvr;
map->bvr = bvr;
map->bvrcnt++;
}
}
if ( bvr )
{
bvr->next = map->bvr;
map->bvr = bvr;
map->bvrcnt++;
}
}
#if UFS_SUPPORT
// Booting from a CD with an UFS filesystem embedded
// in a booter partition.
// Booting from a CD with an UFS filesystem embedded
// in a booter partition.
if ( booterUFS )
{
}
} while (0);
#if UNUSED
/*
* If no FDisk partition, then we will check for
* an Apple partition map elsewhere.
*/
#if UNUSED
if (map && map->bvrcnt == 0)
{
static struct fdisk_part cdpart;
#endif
// Actually this should always be true given the above code
// (unless malloc failed above)
if(map && map == gDiskBVMap)
if(map && (map == gDiskBVMap))
{
// Don't leave a null map in the chain
if(map->bvrcnt == 0 && map->bvr == NULL)
if((map->bvrcnt == 0) && (map->bvr == NULL))
{
gDiskBVMap = map->next;
free(map);
if (countPtr) *countPtr = map ? map->bvrcnt : 0;
return map ? map->bvr : NULL;
return map ? map->bvr : NULL;
}
//==============================================================================
static BVRef diskScanAPMBootVolumes( int biosdev, int * countPtr )
{
struct DiskBVMap * map;
struct Block0 *block0_p;
unsigned int blksize;
unsigned int factor;
void *buffer = malloc(BPS);
struct DiskBVMap*map;
struct Block0*block0_p;
unsigned intblksize;
unsigned intfactor;
void*buffer = malloc(BPS);
if (!buffer)
{
return NULL;
}
bzero(buffer,BPS);
/* Check for alternate block size */
{
return NULL;
}
block0_p = buffer;
if (OSSwapBigToHostInt16(block0_p->sbSig) == BLOCK0_SIGNATURE)
{
map->next = gDiskBVMap;
gDiskBVMap = map;
for (i=0; i<npart; i++)
for (i = 0; i < npart; i++)
{
error = readBytes( biosdev, (kAPMSector + i) * factor, 0, blksize, buffer );
break;
}
if (i==0)
if (i == 0)
{
npart = OSSwapBigToHostInt32(dpme_p->dpme_map_entries);
}
}
} while (0);
free(buffer);
if (countPtr) *countPtr = map ? map->bvrcnt : 0;
return map ? map->bvr : NULL;
}
//==============================================================================
/*
* Trying to figure out the filsystem type of a given partition.
*/
static int probeFileSystem(int biosdev, unsigned int blkoff)
{
// detected filesystem type;
int result = -1;
int fatbits;
// Allocating buffer for 4 sectors.
const void * probeBuffer = malloc(PROBEFS_SIZE);
if (probeBuffer == NULL)
if (buffer)
{
goto exit;
free(buffer);
}
// Reading first 4 sectors of current partition
int error = readBytes(biosdev, blkoff, 0, PROBEFS_SIZE, (void *)probeBuffer);
if (error)
if (countPtr)
{
goto exit;
*countPtr = map ? map->bvrcnt : 0;
}
if (HFSProbe(probeBuffer))
{
result = FDISK_HFS;
}
else if (EX2Probe(probeBuffer))
{
result = FDISK_LINUX;
}
else if (FreeBSDProbe(probeBuffer))
{
result = FDISK_FREEBSD;
}
else if (OpenBSDProbe(probeBuffer))
{
result = FDISK_OPENBSD;
}
else if (BeFSProbe(probeBuffer))
{
result = FDISK_BEFS;
}
else if (EXFATProbe(probeBuffer))
{
result = FDISK_PSEUDO_EXFAT;
}
else if (NTFSProbe(probeBuffer))
{
result = FDISK_NTFS;
}
else if ( (fatbits = MSDOSProbe(probeBuffer)) )
{
switch (fatbits)
{
case 32:
default:
result = FDISK_FAT32;
break;
case 16:
result = FDISK_DOS16B;
break;
case 12:
result = FDISK_DOS12;
break;
}
}
else
{
// Couldn't detect filesystem type
result = 0;
}
exit:
if (probeBuffer)
{
free((void *)probeBuffer);
}
return result;
return map ? map->bvr : NULL;
}
//==============================================================================
void *buffer = malloc(BPS);
int error;
if ( (error = readBytes( biosdev, /*secno*/0, 0, BPS, buffer )) != 0)
if ((error = readBytes( biosdev, /*secno*/0, 0, BPS, buffer )) != 0)
{
verbose("Failed to read boot sector from BIOS device %02xh. Error=%d\n", biosdev, error);
goto scanErr;
// Determine whether the partition header signature is present.
if ( memcmp(headerMap->hdr_sig, GPT_HDR_SIG, strlen(GPT_HDR_SIG)) )
if (memcmp(headerMap->hdr_sig, GPT_HDR_SIG, strlen(GPT_HDR_SIG)))
{
goto scanErr;
}
UInt32 headerCheck = OSSwapLittleToHostInt32(headerMap->hdr_crc_self);
UInt32 headerSize = OSSwapLittleToHostInt32(headerMap->hdr_size);
if ( headerSize < offsetof(gpt_hdr, padding) )
if (headerSize < offsetof(gpt_hdr, padding))
{
goto scanErr;
}
// Determine whether the partition entry size is valid.
UInt64 gptBlock = 0;
UInt32 gptCheck = 0;
UInt32 gptCount = 0;
UInt32 gptID = 0;
gpt_ent * gptMap = 0;
UInt32 gptSize = 0;
UInt64gptBlock= 0;
UInt32gptCheck= 0;
UInt32gptCount= 0;
UInt32gptID= 0;
gpt_ent*gptMap= 0;
UInt32gptSize= 0;
gptBlock = OSSwapLittleToHostInt64(headerMap->hdr_lba_table);
gptCheck = OSSwapLittleToHostInt32(headerMap->hdr_crc_table);
// fdisk like partition type id.
int fsType = 0;
for(gptID = 1; gptID <= gptCount; ++gptID) {
for(gptID = 1; gptID <= gptCount; ++gptID)
{
BVRef bvr = NULL;
unsigned int bvrFlags = 0;
// size on disk can be larger than sizeof(gpt_ent)
gptMap = (gpt_ent *) ( buffer + ( (gptID - 1) * gptSize) );
gptMap = (gpt_ent *)(buffer + ((gptID - 1) * gptSize));
// NOTE: EFI_GUID's are in LE and we know we're on an x86.
// The IOGUIDPartitionScheme.cpp code uses byte-based UUIDs, we don't.
// Getting fdisk like partition type.
fsType = probeFileSystem(biosdev, gptMap->ent_lba_start);
if ( (efi_guid_compare(&GPT_BOOT_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) || (efi_guid_compare(&GPT_HFS_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) ) {
bvrFlags = (efi_guid_compare(&GPT_BOOT_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) ? kBVFlagBooter : 0;
bvr = newGPTBVRef(biosdev,
gptID,
gptMap->ent_lba_start,
gptMap,
HFSInitPartition,
HFSLoadFile,
HFSReadFile,
HFSGetDirEntry,
HFSGetFileBlock,
HFSGetUUID,
HFSGetDescription,
HFSFree,
0,
kBIOSDevTypeHardDrive, bvrFlags);
}
if ( (efi_guid_compare(&GPT_BOOT_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) || (efi_guid_compare(&GPT_HFS_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) ) {
bvrFlags = (efi_guid_compare(&GPT_BOOT_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) ? kBVFlagBooter : 0;
bvr = newGPTBVRef(biosdev,
gptID,
gptMap->ent_lba_start,
gptMap,
HFSInitPartition,
HFSLoadFile,
HFSReadFile,
HFSGetDirEntry,
HFSGetFileBlock,
HFSGetUUID,
HFSGetDescription,
HFSFree,
0,
kBIOSDevTypeHardDrive, bvrFlags);
}
// zef - foreign OS support
if ( (efi_guid_compare(&GPT_BASICDATA_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) ||
(efi_guid_compare(&GPT_BASICDATA2_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) ) {
if ((efi_guid_compare(&GPT_BASICDATA_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) ||
(efi_guid_compare(&GPT_BASICDATA2_GUID, (EFI_GUID const*)gptMap->ent_type) == 0) )
{
switch (fsType)
{
case FDISK_NTFS:
}
scanErr:
if (buffer) {
if (buffer)
{
free(buffer);
}
if(map) {
if(map)
{
if(countPtr) *countPtr = map->bvrcnt;
{
return map->bvr;
}
} else {
}
else
{
if(countPtr) *countPtr = 0;
{
return NULL;
{
const char *val;
int len;
if (getValueForKey(kProductVersion, &val, &len, &systemVersion))
{
// getValueForKey uses const char for val
{
ret = -1;
error = 0;
//
// Check for alternate volume label on boot helper partitions.
//
if (bvr->flags & kBVFlagNativeBoot)
{
if (getOSVersion(bvr,bvr->OSVersion) == true)
if (getOSVersion(bvr, bvr->OSVersion) == true)
{
bvr->flags |= kBVFlagSystemVolume;
}
{
bvr = diskScanAPMBootVolumes(biosdev, &count);
}
if (bvr)
{
scanFSLevelBVRSettings(bvr);
{
bvr = map->bvr;
}
if (countPtr)
{
*countPtr += count;
}
return bvr;
}
//==============================================================================
static const struct NamedValue fdiskTypes[] =
{
{ FDISK_NTFS,"Windows NTFS" },
{ FDISK_DOS12,"Windows FAT12" },
{ FDISK_DOS16B,"Windows FAT16" },
{ FDISK_DOS16S,"Windows FAT16" },
{ FDISK_DOS16SLBA,"Windows FAT16" },
{ FDISK_SMALLFAT32,"Windows FAT32" },
{ FDISK_FAT32,"Windows FAT32" },
{ FDISK_FREEBSD,"FreeBSD" },
{ FDISK_OPENBSD,"OpenBSD" },
{ FDISK_LINUX,"Linux" },
{ FDISK_UFS,"Apple UFS" },
{ FDISK_HFS,"Apple HFS" },
{ FDISK_BOOTER,"Apple Boot/UFS" },
{ FDISK_BEFS,"Haiku" },
{ 0xCD,"CD-ROM" },
{ 0x00,0 } /* must be last */
};
//==============================================================================
bool matchVolumeToString( BVRef bvr, const char* match, long matchLen)
{
char testStr[128];
if (name == NULL)
{
sprintf(p, "TYPE %02x", type);
sprintf(p, "TYPE %02X", type);
}
else
{
//==============================================================================
int readBootSector(int biosdev, unsigned int secno, void * buffer)
int readBootSector(int biosdev, unsigned int secno, void *buffer)
{
int error;
struct disk_blk0 * bootSector = (struct disk_blk0 *) buffer;
struct disk_blk0 * bootSector = (struct disk_blk0 *)buffer;
if (bootSector == NULL)
{
if (gBootSector == NULL)
{
gBootSector = (struct disk_blk0 *) malloc(sizeof(*gBootSector));
gBootSector = (struct disk_blk0 *)malloc(sizeof(*gBootSector));
if (gBootSector == NULL)
{
//==============================================================================
int testFAT32EFIBootSector( int biosdev, unsigned int secno, void * buffer )
int testFAT32EFIBootSector(int biosdev, unsigned int secno, void *buffer)
{
struct disk_boot1f32_blk * bootSector = (struct disk_boot1f32_blk *) buffer;
int error;
struct disk_boot1f32_blk *bootSector = (struct disk_boot1f32_blk *)buffer;
int error;
if ( bootSector == NULL )
if (bootSector == NULL)
{
if ( gBootSector == NULL )
if (gBootSector == NULL)
{
gBootSector = (struct disk_blk0 *) malloc(sizeof(*gBootSector));
gBootSector = (struct disk_blk0 *)malloc(sizeof(*gBootSector));
if ( gBootSector == NULL )
{
return -1;
}
}
bootSector = (struct disk_boot1f32_blk *) gBootSector;
bootSector = (struct disk_boot1f32_blk *)gBootSector;
}
error = readBytes( biosdev, secno, 0, BPS, bootSector );
if ( error || bootSector->signature != DISK_SIGNATURE || strncmp((const char *)bootSector->magic, BOOT1F32_MAGIC, BOOT1F32_MAGICLEN) )
error = readBytes(biosdev, secno, 0, BPS, bootSector);
if (error || bootSector->signature != DISK_SIGNATURE || strncmp((const char *)bootSector->magic, BOOT1F32_MAGIC, BOOT1F32_MAGICLEN) )
{
return -1;
}
int diskIsCDROM(BVRef bvr)
{
struct driveInfo di;
struct driveInfo di;
if (getDriveInfo(bvr->biosdev, &di) == 0 && di.no_emulation)
{
int biosDevIsCDROM(int biosdev)
{
struct driveInfo di;
struct driveInfo di;
if (getDriveInfo(biosdev, &di) == 0 && di.no_emulation)
{
trunk/i386/libsaio/cpu.h
1111
1212
1313
14
14
1515
1616
1717
extern void scan_cpu(PlatformInfo_t *);
#define bit(n)(1ULL << (n))
#define bitmask(h,l)((bit(h)|(bit(h)-1)) & ~(bit(l)-1))
#define bitmask(h,l)((bit(h) | (bit(h)-1)) & ~(bit(l)-1))
#define bitfield(x,h,l)(((x) & bitmask(h,l)) >> l)
#define CPU_STRING_UNKNOWN"Unknown CPU Type"
trunk/i386/libsaio/smbios.c
828828
829829
830830
831
831
832832
833833
834834
......
11031103
11041104
11051105
1106
1106
11071107
11081108
11091109
......
12451245
12461246
12471247
1248
1248
12491249
1250
1250
12511251
12521252
1253
1253
12541254
12551255
12561256
......
12661266
12671267
12681268
1269
1269
1270
12701271
12711272
12721273
......
13501351
13511352
13521353
1354
1355
1356
13531357
13541358
1355
1356
13571359
13581360
13591361
strSize = strlen(string);
// remove any spaces found at the end but only in MemoryDevice
// remove any spaces found at the end but only in MemoryDevice avoiding errors
if (structHeader->type == kSMBTypeMemoryDevice) {
while ((strSize != 0) && (string[strSize - 1] == ' ')) {
strSize--;
if (handle < structPtr->orig->handle) {
handle = structPtr->orig->handle;
}
// Bungo: fix unsuported tables lengths from original smbios: extend smaller or truncate bigger - we use SMBIOS rev. 2.4 like Apple uses
// Bungo: fix unsuported tables lengths from original smbios: extend shorter or truncate longer - we use SMBIOS rev. 2.4 like Apple uses
switch (structPtr->orig->type) {
case kSMBTypeBIOSInformation:
structSize = sizeof(SMBBIOSInformation);
ptr = ((SMBSystemInformation *)structHeader)->uuid;
if (!sysId || !ret) { // no or bad custom UUID,...
if (!sysId || !ret) { // no or bad custom uuid,...
sysId = 0;
ret = Platform.UUID; // ...try bios dmi system uuid extraction
ret = Platform.UUID; // ...use original (factory) system uuid
}
for (i=0, isZero=1, isOnes=1; i<UUID_LEN; i++) // check if empty or setable, means: no uuid present
for (i = 0, isZero = 1, isOnes = 1; i < UUID_LEN; i++) // check if empty (zeroed) or setable (FFed), means: no uuid present
{
if (ret[i] != 0x00) {
isZero = 0;
ret = FixedUUID; // ...set a fixed value for system-id = 000102030405060708090A0B0C0D0E0F
}
memcpy(ptr, ret, UUID_LEN); // fix uuid in the table
memcpy(ptr, ret, UUID_LEN); // save uuid into the patched SMBIOS Table 1
return ptr;
} // Bungo: end fix
free(buffer);
free(structPtr);
DBG("SMBIOS orig was = %x\n", origeps);
DBG("SMBIOS new is = %x\n", neweps);
decodeSMBIOSTable(neweps);
DBG("SMBIOS orig was = %x\n", origeps);
DBG("SMBIOS new is = %x\n", neweps);
}
void *getSmbios(int which)
trunk/i386/libsaio/smbios_decode.c
2323
2424
2525
26
27
28
29
26
27
28
29
3030
31
31
3232
3333
3434
......
223223
224224
225225
226
227
226
228227
229228
230229
231230
232231
233232
234
233
234
235235
236236
237
237
238
238239
239240
240241
......
243244
244245
245246
246
247
247248
248249
249250
......
372373
373374
374375
375
376
376377
377378
378379
379380
380
381
382
381383
382
384
385
386
383387
384388
385389
......
388392
389393
390394
391
392
393
394
395
395
396
397
398
399
400
401
402
403
404
405
406
396407
397408
398409
......
533544
534545
535546
536
547
537548
538549
539550
extern char *getSMBStringForField(SMBStructHeader *structHeader, uint8_t field);
// Bungo:
#define NotSpecifiedStr "Not Specified" // no string
#define OutOfSpecStr "<OUT OF SPEC>" // value out of smbios spec. range
#define PrivateStr "** PRIVATE **" // masking private data
#define neverMask false
#define NotSpecifiedStr "Not Specified" // no string
#define OutOfSpecStr "<OUT OF SPEC>" // value out of smbios spec. range
#define PrivateStr "** PRIVATE **" // masking private data
#define neverMask false
static bool privateData = true;
static bool privateData = true;
static SMBByte minorVersion; // SMBIOS rev. minor
static SMBByte majorVersion; // SMBIOS rev. major
static SMBByte bcdRevisionLo; // DMI rev. minor
"FBD2"/* 19h FBD2 */
};
static const int kSMBMemoryDeviceTypeCount = sizeof(SMBMemoryDeviceTypes) /
sizeof(SMBMemoryDeviceTypes[0]);
static const int kSMBMemoryDeviceTypeCount = sizeof(SMBMemoryDeviceTypes) / sizeof(SMBMemoryDeviceTypes[0]);
// Bungo: fixes random string readout if null in smbios to "Not Specified" as dmidecode displays
char *SMBStringForField(SMBStructHeader *structHeader, uint8_t field, const bool mask)
{
char *str = NULL;
str = getSMBStringForField(structHeader, field);
if (!field) {
if (!field)
{
str = NotSpecifiedStr;
}
else if (mask) {
else if (mask)
{
str = PrivateStr;
}
void printHeader(SMBStructHeader *structHeader)
{
DBG("Handle: 0x%04x, DMI type %d, %d bytes\n", structHeader->handle, structHeader->type, structHeader->length);
DBG("Handle: 0x%04X, DMI type %d, %d bytes\n", structHeader->handle, structHeader->type, structHeader->length);
}
//-------------------------------------------------------------------------------------------------------------------------
//DBG("\tSignature: Type %u, Family %u, Model %u, Stepping %u\n", (eax >> 12) & 0x3, ((eax >> 20) & 0xFF) + ((eax >> 8) & 0x0F), ((eax >> 12) & 0xF0) + ((eax >> 4) & 0x0F), eax & 0xF);
// Flags:
DBG("\tVersion: %s\n", SMBStringForField(structHeader, ((SMBProcessorInformation *)structHeader)->processorVersion, neverMask));
//DBG("\tVoltage: 0.%xV\n", ((SMBProcessorInformation *)structHeader)->voltage);
//DBG("\tVoltage: 0.%dV\n", ((SMBProcessorInformation *)structHeader)->voltage);
DBG("\tExternal Clock: %d MHz\n", ((SMBProcessorInformation *)structHeader)->externalClock);
DBG("\tMax Speed: %d MHz\n", ((SMBProcessorInformation *)structHeader)->maximumClock);
DBG("\tCurrent Speed: %d MHz\n", ((SMBProcessorInformation *)structHeader)->currentClock);
// Status: Populated/Unpopulated
if ((((SMBProcessorInformation *)structHeader)->processorUpgrade < 1) || (((SMBProcessorInformation *)structHeader)->processorUpgrade > 0x2C)) {
if ((((SMBProcessorInformation *)structHeader)->processorUpgrade < 1) || (((SMBProcessorInformation *)structHeader)->processorUpgrade > 0x2C))
{
DBG("\tUpgrade: %s\n", OutOfSpecStr);
} else {
}
else
{
DBG("\tUpgrade: %s\n", SMBProcessorUpgrades[((SMBProcessorInformation *)structHeader)->processorUpgrade - 1]);
}
// L1 Cache Handle:
DBG("\tSerial Number: %s\n", SMBStringForField(structHeader, ((SMBProcessorInformation *)structHeader)->serialNumber, privateData));
DBG("\tAsset Tag: %s\n", SMBStringForField(structHeader, ((SMBProcessorInformation *)structHeader)->assetTag, neverMask));
DBG("\tPart Number: %s\n", SMBStringForField(structHeader, ((SMBProcessorInformation *)structHeader)->partNumber, neverMask));
if(((SMBProcessorInformation *)structHeader)->coreCount != 0) {
DBG("\tCore Count: %d\n", ((SMBProcessorInformation *)structHeader)->coreCount);}
if(((SMBProcessorInformation *)structHeader)->coreEnabled != 0) {
DBG("\tCore Enabled: %d\n", ((SMBProcessorInformation *)structHeader)->coreEnabled);}
if(((SMBProcessorInformation *)structHeader)->threadCount != 0) {
if(((SMBProcessorInformation *)structHeader)->coreCount != 0)
{
DBG("\tCore Count: %d\n", ((SMBProcessorInformation *)structHeader)->coreCount);
}
if(((SMBProcessorInformation *)structHeader)->coreEnabled != 0)
{
DBG("\tCore Enabled: %d\n", ((SMBProcessorInformation *)structHeader)->coreEnabled);
}
if(((SMBProcessorInformation *)structHeader)->threadCount != 0)
{
DBG("\tThread Count: %d\n", ((SMBProcessorInformation *)structHeader)->threadCount);
}
// Characteristics:
{
printHeader(structHeader);
DBG("Apple specific Processor Type\n");
DBG("\tCpu-type: 0x%x\n", ((SMBOemProcessorType *)structHeader)->ProcessorType);
DBG("\tCpu-type = 0x%04X\n", ((SMBOemProcessorType *)structHeader)->ProcessorType);
DBG("\n");
}
trunk/i386/libsaio/smbios.h
2323
2424
2525
26
2726
2827
2928
......
3332
3433
3534
36
3735
3836
3937
......
140138
141139
142140
143
141
144142
145143
146144
......
160158
161159
162160
163
161
164162
165163
166164
......
199197
200198
201199
202
200
203201
204202
205203
......
268266
269267
270268
271
269
272270
273271
274272
......
287285
288286
289287
290
288
289
291290
292291
293292
......
542541
543542
544543
545
544
546545
547546
548547
......
610609
611610
612611
613
612
614613
615614
616615
......
627626
628627
629628
630
629
631630
632631
633632
......
648647
649648
650649
651
650
652651
653652
654653
......
684683
685684
686685
687
686
688687
689688
690689
......
700699
701700
702701
703
702
704703
705704
706705
......
735734
736735
737736
738
737
739738
740739
741740
......
787786
788787
789788
790
789
791790
792791
793792
......
861860
862861
863862
864
865863
#ifndef __LIBSAIO_SMBIOS_H
#define __LIBSAIO_SMBIOS_H
/* Based on System Management BIOS Reference Specification v2.4 */
// http://dmtf.org/standards/smbios
typedef uint32_t SMBDWord;
typedef uint64_t SMBQWord;
typedef struct DMIEntryPoint
{
SMBByte anchor[5];
};
//----------------------------------------------------------------------------------------------------------
// Struct - BIOS Information (Type 0)
// Struct - BIOS Information (Type 0), Apple uses 24 bytes length
typedef struct SMBBIOSInformation
{
SMB_STRUCT_HEADER
} __attribute__((packed)) SMBBIOSInformation;
//----------------------------------------------------------------------------------------------------------
// Struct - System Information (Type 1)
// Struct - System Information (Type 1), Apple uses 27 bytes length
typedef struct SMBSystemInformation
{
// 2.0+ spec (8 bytes)
kSMBBaseBoardInterconnect = 0x0D// Interconnect board
} BASE_BOARD_TYPE;
// Struct - Base Board (or Module) Information (Type 2)
// Struct - Base Board (or Module) Information (Type 2), Apple uses 16 bytes length
typedef struct SMBBaseBoard
{
SMB_STRUCT_HEADER // Type 2
kSMBChassisSecurityStatusExternalInterfaceLockedEnabled = 0x05
} MISC_CHASSIS_SECURITY_STATE;
// Struct - System Enclosure (Type 3)
// Struct - System Enclosure (Type 3), Apple uses 21 bytes length
typedef struct SMBSystemEnclosure
{
SMB_STRUCT_HEADER // Type 3
SMBByte containedElementCount;// Number of Contained Element record that follow, in the range 0 to 255
//SMBByte containedElementRecord;// Byte leght of each Contained Element record that follow, in the range 0 to 255
//SMBByte containedElements;// Elements, possibly defined by other SMBIOS structures present in chassis
//SMBString skuNumber;// Number of null-terminated string describing the chassis or enclosure SKU number (2.7+)
// 2.7+
//SMBString skuNumber;// Number of null-terminated string describing the chassis or enclosure SKU number
} __attribute__((packed)) SMBSystemEnclosure;
//----------------------------------------------------------------------------------------------------------
kSMBprocessorUpgradeSocketFM2 = 0x2A
} PROCESSOR_UPGRADE;
// Struct - Processor Information (Type 4).
// Struct - Processor Information (Type 4), Apple uses 35 bytes length
typedef struct SMBProcessorInformation
{
// 2.0+ spec (26 bytes)
#define kSMBMemoryModuleSizeNotInstalled 0x7F
//----------------------------------------------------------------------------------------------------------
// Struct - Cache Information (Type 7)
// Struct - Cache Information (Type 7), Apple uses 19 bytes length
typedef struct SMBCacheInformation
{
SMB_STRUCT_HEADER // Type 7
} __attribute__((packed)) SMBCacheInformation;
//----------------------------------------------------------------------------------------------------------
// Struct - System Slots (Type 9)
// Struct - System Slots (Type 9), Apple uses 13 bytes length
typedef struct SMBSystemSlot
{
// 2.0+ spec (12 bytes)
} __attribute__((packed)) SMBSystemSlot;
//----------------------------------------------------------------------------------------------------------
// Struct - OEM Strings (Type 11)
// Struct - OEM Strings (Type 11), Apple uses 5 bytes length
typedef struct SMBOEMStrings
{
SMB_STRUCT_HEADER // Type 11
kSMBMemoryArrayErrorCorrectionTypeCRC = 0x07
} MEMORY_ERROR_CORRECTION;
// Struct - Physical Memory Array (Type 16)
// Struct - Physical Memory Array (Type 16), Apple uses 15 bytes length
typedef struct SMBPhysicalMemoryArray
{
// 2.1+ spec (15 bytes)
} __attribute__((packed)) SMBPhysicalMemoryArray;
//----------------------------------------------------------------------------------------------------------
// Struct - Memory Device (Type 17)
// Struct - Memory Device (Type 17), Apple uses 27 bytes length
typedef struct SMBMemoryDevice
{
// 2.1+ spec (21 bytes)
//----------------------------------------------------------------------------------------------------------
// Struct - Memory Array Mapped Address (Type 19)
// Struct - Memory Array Mapped Address (Type 19), Apple uses 15 bytes length
//typedef struct SMBMemoryArrayMappedAddress
//{
// 2.1+ spec
SMBDWord EndAddress;
} __attribute__((packed)) FW_REGION_INFO;
// Struct - Firmware Volume Description (Apple Specific - Type 128)
// Struct - Firmware Volume Description (Apple Specific - Type 128), Apple uses 88 bytes length
typedef struct SMBFirmwareVolume
{
SMB_STRUCT_HEADER// Type 128
extern void decodeSMBIOSTable(SMBEntryPoint *eps);
#endif /* !__LIBSAIO_SMBIOS_H */
trunk/i386/libsaio/pci.c
159159
160160
161161
162
162163
163164
164165
}
static char dev_path[256];
char *get_pci_dev_path(pci_dt_t *pci_dt)
{
pci_dt_t*current;
trunk/i386/libsaio/stringTable.c
332332
333333
334334
335
335
336336
337
338
339
337
338
339
340
340341
341342
342343
......
347348
348349
349350
350
351
351352
352353
353354
354355
355
356
356
357
358
359
357360
358
361
362
363
359364
360365
361366
......
363368
364369
365370
366
371
367372
368373
369374
370375
371376
372377
373
378
374379
375380
376381
......
508513
509514
510515
511
516
512517
513518
514519
......
547552
548553
549554
550
555
551556
552557
553558
......
617622
618623
619624
620
625
621626
622627
623628
}
/* Return NULL if no option has been successfully retrieved, or the string otherwise */
const char * getStringForKey(const char * key, config_file_t *config)
const char *getStringForKey(const char *key, config_file_t *config)
{
static const char* value =0;
int len=0;
if(!getValueForKey(key, &value, &len, config)) {
static const char *value = 0;
int len = 0;
if (!getValueForKey(key, &value, &len, config))
{
value = 0;
}
return value;
* The boolean value of the key is stored in 'val'.
*/
bool getBoolForKey( const char *key, bool *result_val, config_file_t *config )
bool getBoolForKey(const char *key, bool *result_val, config_file_t *config)
{
const char *key_val;
int size;
if (getValueForKey(key, &key_val, &size, config)) {
if ( (size >= 1) && (key_val[0] == 'Y' || key_val[0] == 'y') ) {
if (getValueForKey(key, &key_val, &size, config))
{
if ((size >= 1) && (key_val[0] == 'Y' || key_val[0] == 'y'))
{
*result_val = true;
} else {
}
else
{
*result_val = false;
}
return true;
return false;
}
bool getIntForKey( const char *key, int *value, config_file_t *config )
bool getIntForKey(const char *key, int *value, config_file_t *config)
{
const char *val;
int size, sum;
bool negative = false;
if (getValueForKey(key, &val, &size, config)) {
if ( size ) {
if (size) {
if (*val == '-') {
negative = true;
val++;
if (override) {
*val = overrideVal;
*size = overrideSize;
return true;
ret = true;
}
}
}
// (and does not modify dict pointer).
// Prints an error message if there is a parsing error.
//
int ParseXMLFile( char * buffer, TagPtr * dict )
int ParseXMLFile( char *buffer, TagPtr *dict )
{
long length, pos;
TagPtr tag;
"/Mac OS X Install Data/com.apple.Boot.plist",// OS X Installer (Lion 10.7)
"/OS X Install Data/com.apple.Boot.plist",// OS X Installer (10.8+)
"/.IABootFiles/com.apple.Boot.plist",// OS X Installer
"/Library/Preferences/SystemConfiguration/com.apple.Boot.plist",// com.boot.Apple.plist
"/Library/Preferences/SystemConfiguration/com.apple.Boot.plist",// com.apple.Boot.plist
"/com.apple.recovery.boot/com.apple.Boot.plist"// OS X Recovery
};
trunk/i386/libsaio/convert.c
2929
3030
3131
32
32
3333
3434
35
35
3636
3737
3838
39
39
4040
4141
4242
4343
4444
45
45
4646
4747
4848
char*p = (char *)source;
inti;
charbuf[3];
static EFI_CHAR8 uuid[UUID_LEN+1]="";
static EFI_CHAR8 uuid[UUID_LEN+1] = "";
buf[2] = '\0';
for (i=0; i<UUID_LEN; i++)
for (i = 0; i < UUID_LEN; i++)
{
if (p[0] == '\0' || p[1] == '\0' || !isxdigit(p[0]) || !isxdigit(p[1]))
{
verbose("[ERROR] UUID='%s' syntax error\n", source);
verbose("[ERROR] UUID='%s' syntax error.\n", source);
return 0;
}
buf[0] = *p++;
buf[1] = *p++;
uuid[i] = (unsigned char) strtoul(buf, NULL, 16);
if (*p == '-' && (i % 2) == 1 && i < UUID_LEN - 1)
if ((*p == '-') && ((i % 2) == 1) && (i < UUID_LEN - 1))
{
p++;
}
trunk/i386/libsaio/saio_types.h
145145
146146
147147
148
149
148
149
150150
151151
152152
......
206206
207207
208208
209
209
210210
211211
212212
structBootVolume;
typedef struct BootVolume * BVRef;
typedef struct BootVolume * CICell;
typedef structBootVolume *BVRef;
typedef structBootVolume *CICell;
typedef long (*FSInit)(CICell ih);
typedef long (*FSLoadFile)(CICell ih, char * filePath);
BVFreebv_free;/* BVFree function */
uint32_tmodTime;
charlabel[BVSTRLEN];/* partition volume label */
charaltlabel[BVSTRLEN];/* partition volume label */
charaltlabel[BVSTRLEN];/* alternate partition volume label */
boolfiltered;/* newFilteredBVChain() will set to TRUE */
boolvisible;/* will shown in the device list */
charOSVersion[8];
trunk/i386/libsaio/state_generator.c
6969
7070
7171
72
72
7373
7474
7575
......
355355
356356
357357
358
358
359359
360360
361361
......
370370
371371
372372
373
373
374374
375375
376376
0x00, 0x00, 0x00, 0x79, 0x00,
};
struct acpi_2_ssdt *generate_pss_ssdt(struct acpi_2_dsdt* dsdt)
struct acpi_2_ssdt *generate_pss_ssdt(struct acpi_2_dsdt *dsdt)
{
if (Platform.CPU.Vendor != 0x756E6547)
return NULL;
}
struct acpi_2_ssdt *generate_cst_ssdt(struct acpi_2_fadt* fadt)
struct acpi_2_ssdt *generate_cst_ssdt(struct acpi_2_fadt *fadt)
{
if (Platform.CPU.Vendor != 0x756E6547)
return NULL;
}
struct acpi_2_dsdt* dsdt = (void*)fadt->DSDT;
struct acpi_2_dsdt *dsdt = (void *)fadt->DSDT;
if (dsdt == NULL)
{
trunk/i386/libsaio/fake_efi.c
123123
124124
125125
126
126
127127
128128
129129
......
142142
143143
144144
145
145
146146
147147
148148
......
551551
552552
553553
554
555
554
555
556556
557557
558558
559559
560560
561561
562
562
563563
564564
565565
......
676676
677677
678678
679
679
680680
681681
682682
......
695695
696696
697697
698
698
699699
700700
701701
// We only do adds, not modifications and deletes like InstallConfigurationTable
if (i >= MAX_CONFIGURATION_TABLE_ENTRIES)
{
stop("Ran out of space for configuration tables. Increase the reserved size in the code.\n");
stop("Fake EFI [ERROR]: Ran out of space for configuration tables [%d]. Increase the reserved size in the code.\n", i);
}
if (pGuid == NULL)
Node *tableNode = DT__AddChild(gEfiConfigurationTableNode, mallocStringForGuid(pGuid));
// Use the pointer to the GUID we just stuffed into the system table
DT__AddProperty(tableNode, "guid", sizeof(EFI_GUID), (void*)pGuid);
DT__AddProperty(tableNode, "guid", sizeof(EFI_GUID), (void *)pGuid);
// The "table" property is the 32-bit (in our implementation) physical address of the table
DT__AddProperty(tableNode, "table", sizeof(void*) * 2, table);
*/
/*
* Must be called AFTER setup Acpi because we need to take care of correct
* facp content to reflect in ioregs
* Must be called AFTER setupAcpi because we need to take care of correct
* FACP content to reflect in ioregs
*/
void setupSystemType()
{
Node *node = DT__FindNode("/", false);
if (node == 0)
{
stop("Couldn't get root node");
stop("Couldn't get root '/' node");
}
// we need to write this property after facp parsing
// Export system-type only if it has been overrriden by the SystemType option
node = DT__FindNode("/", false);
if (node == 0)
{
stop("Couldn't get root node");
stop("Couldn't get root '/' node");
}
const char *boardid = getStringForKey("SMboardproduct", &bootInfo->smbiosConfig);
if (boardid)
chosenNode = DT__FindNode("/chosen", false);
if (chosenNode == 0)
{
stop("Couldn't get chosen node");
stop("setupChosenNode: Couldn't get '/chosen' node");
}
int length = strlen(gBootUUIDString);
trunk/i386/libsaio/smbios_getters.c
3131
3232
3333
34
3534
3635
3736
......
4948
5049
5150
51
5252
53
5453
5554
5655
5756
57
5858
5959
6060
......
7878
7979
8080
81
8281
8382
8483
......
138137
139138
140139
140
141
141142
142
143
143144
144
145
146
145147
146148
147149
148150
149
151
152
150153
151154
152155
......
181184
182185
183186
184
187
185188
186189
187190
......
381384
382385
383386
384
387
388
385389
386390
387391
switch (Platform.CPU.Family)
{
case 0x06:
{
switch (Platform.CPU.Model)
{
// set external clock to 0 for SANDY
break;
default:
value->word = (uint16_t)(Platform.CPU.FSBFrequency/1000000LL);
break;
}
}
break;
default:
value->word = (uint16_t)(Platform.CPU.FSBFrequency/1000000LL);
break;
}
}
else
switch (Platform.CPU.Family)
{
case 0x06:
{
switch (Platform.CPU.Model)
{
case CPUID_MODEL_PENTIUM_M:
value->word = qpibusspeed;
return true;
}
break;
default:
break; //Unsupported CPU type
break;
}
}
break;
default:
break;
}
}
return false;
return false; //Unsupported CPU type
}
uint16_t simpleGetSMBOemProcessorType(void)
{
case 0x0F:
case 0x06:
{
switch (Platform.CPU.Model)
{
case CPUID_MODEL_PENTIUM_M:
default:
break; // Unsupported CPU type
}
}
break;
default:
break;
}
trunk/i386/libsaio/state_generator.h
1515
1616
1717
18
19
20
18
19
20
2121
2222
#include "aml_generator.h"
#include "libsaio.h"
void get_acpi_cpu_names(uint8_t* dsdt, uint32_t length);
struct acpi_2_ssdt *generate_cst_ssdt(struct acpi_2_fadt* fadt);
struct acpi_2_ssdt *generate_pss_ssdt(struct acpi_2_dsdt* dsdt);
voidget_acpi_cpu_names(uint8_t *dsdt, uint32_t length);
structacpi_2_ssdt *generate_cst_ssdt(struct acpi_2_fadt *fadt);
structacpi_2_ssdt *generate_pss_ssdt(struct acpi_2_dsdt *dsdt);
#endif /* !__LIBSAIO_STATE_GENERATOR_H */
trunk/i386/include/IOKit/storage/IOFDiskPartitionScheme.h
5656
5757
5858
59
59
6060
6161
6262
UInt8 beghead; /* (beginning head) */
UInt8 begsect; /* (beginning sector; beginning cylinder, high 2 bits) */
UInt8 begcyl; /* (beginning cylinder, low 8 bits) */
UInt8 systid; /* (type) */
UInt8 systid; /* (OS type) */
UInt8 endhead; /* (ending head) */
UInt8 endsect; /* (ending sector; ending cylinder, high 2 bits) */
UInt8 endcyl; /* (ending cylinder, low 8 bits) */
trunk/i386/boot2/graphics.c
279279
280280
281281
282
282283
283284
284285
......
427428
428429
429430
430
431
432
433
431
432
433
434
434435
435
436
436
437
437438
438439
439440
440441
441442
442443
443
444
445
446
444
445
446
447
447448
448449
449450
......
484485
485486
486487
487
488
488489
489
490
490491
491492
492493
......
520521
521522
522523
523
524
524
525525
526526
527527
......
11201120
11211121
11221122
1123
1124
1123
1124
11251125
1126
1127
1126
1127
1128
11281129
1129
1130
1130
1131
11311132
1132
1133
11331134
1134
1135
1135
1136
11361137
11371138
11381139
11391140
1140
1141
11411142
11421143
11431144
1144
1145
11451146
11461147
11471148
......
11631164
11641165
11651166
1166
1167
11671168
11681169
11691170
......
11831184
11841185
11851186
1186
1187
11871188
11881189
11891190
......
11991200
12001201
12011202
1202
1203
12031204
12041205
12051206
......
12151216
12161217
12171218
1218
1219
12191220
12201221
12211222
12221223
12231224
12241225
1225
1226
12261227
12271228
12281229
......
12391240
12401241
12411242
1242
1243
12431244
1244
1245
12451246
12461247
12471248
12481249
12491250
1250
1251
12511252
12521253
12531254
// Get mode information.
bzero( &modeInfo, sizeof(modeInfo) );
err = getVBEModeInfo( *modePtr, &modeInfo );
if ( err != errSuccess )
{
unsigned char bitsPerPixel,
unsigned short refreshRate )
{
VBEModeInfoBlock minfo;
unsigned short mode;
unsigned short vesaVersion;
int err = errFuncNotSupported;
VBEModeInfoBlock minfo;
unsigned short mode;
unsigned short vesaVersion;
int err = errFuncNotSupported;
do {
mode = getVESAModeWithProperties( width, height, bitsPerPixel,
do {
mode = getVESAModeWithProperties( width, height, bitsPerPixel,
maColorModeBit |
maModeIsSupportedBit |
maGraphicsModeBit |
maLinearFrameBufferAvailBit,
0,
&minfo, &vesaVersion );
if ( mode == modeEndOfList )
{
break;
}
if ( mode == modeEndOfList )
{
break;
}
//
// FIXME : generateCRTCTiming() causes crash.
// Set the mode with default refresh rate.
err = setVBEMode( mode | kLinearFrameBufferBit, NULL );
err = setVBEMode(mode | kLinearFrameBufferBit, NULL);
if ( err != errSuccess )
if (err != errSuccess)
{
break;
}
bootArgs->Video.v_rowBytes = minfo.BytesPerScanline;
bootArgs->Video.v_baseAddr = VBEMakeUInt32(minfo.PhysBasePtr);
}
while ( 0 );
} while ( 0 );
return err;
}
unsigned long numbers[],
unsigned long maxArrayCount )
{
char * propStr;
unsigned long count = 0;
char *propStr;
unsigned long count = 0;
propStr = newStringForKey( (char *) propKey , &bootInfo->chameleonConfig );
if ( propStr )
propStr = newStringForKey((char *)propKey , &bootInfo->chameleonConfig);
if (propStr)
{
char * delimiter = propStr;
char * p = propStr;
char *delimiter = propStr;
char *p = propStr;
while ( count < maxArrayCount && *p != '\0' )
while ((count < maxArrayCount) && (*p != '\0'))
{
unsigned long val = strtoul( p, &delimiter, 10 );
if ( p != delimiter )
unsigned long val = strtoul(p, &delimiter, 10);
if (p != delimiter)
{
numbers[count++] = val;
p = delimiter;
}
while ( ( *p != '\0' ) && !isdigit(*p) )
while ((*p != '\0') && !isdigit(*p))
p++;
}
free( propStr );
free(propStr);
}
return count;
// Use the default resolution if we don't have an initialized GUI.
if (gui.screen.width == 0 || gui.screen.height == 0)
{
gui.screen.width = DEFAULT_SCREEN_WIDTH;
gui.screen.width = DEFAULT_SCREEN_WIDTH;
gui.screen.height = DEFAULT_SCREEN_HEIGHT;
}
if ( params[2] == 888 )
params[2] = 32;
return setVESAGraphicsMode( params[0], params[1], params[2], params[3] );
return setVESAGraphicsMode( params[0], params[1], params[2], params[3] );
}
//==========================================================================
if ( mode == GRAPHICS_MODE )
{
if ( (err=initGraphicsMode ()) == errSuccess )
if ( (err = initGraphicsMode()) == errSuccess )
{
if (gVerboseMode)
{
if ( (mode == VGA_TEXT_MODE) || (err != errSuccess) )
{
count = getNumberArrayFromProperty( kTextModeKey, params, 2 );
count = getNumberArrayFromProperty(kTextModeKey, params, 2);
if ( count < 2 )
{
params[0] = 80; // Default text mode is 80x25.
params[1] = 25;
}
setVESATextMode( params[0], params[1], 4 );
setVESATextMode(params[0], params[1], 4);
bootArgs->Video.v_display = VGA_TEXT_MODE;
}
unsigned short vesaVersion;
unsigned short mode = modeEndOfList;
getNumberArrayFromProperty( kGraphicsModeKey, params, 4);
getNumberArrayFromProperty(kGraphicsModeKey, params, 4);
mode = getVESAModeWithProperties( params[0], params[1], params[2],
mode = getVESAModeWithProperties(params[0], params[1], params[2],
maColorModeBit |
maModeIsSupportedBit |
maGraphicsModeBit |
maLinearFrameBufferAvailBit,
0,
&minfo, &vesaVersion );
&minfo, &vesaVersion);
params[0] = minfo.XResolution;
params[1] = minfo.YResolution;
trunk/i386/boot2/drivers.c
110110
111111
112112
113
114
115
116
117
118
113
114
115
116
117
118
119
120
119121
120122
121
123
122124
123125
124126
......
186188
187189
188190
189
191
190192
191193
192194
......
238240
239241
240242
241
243
242244
243245
244246
......
295297
296298
297299
298
300
299301
300302
301303
......
877879
878880
879881
880
881
882882
883883
884884
885
885
886886
887887
888888
......
899899
900900
901901
902
902
903903
904904
905905
......
912912
913913
914914
915
915
916
916917
917
918
919
920
918
921919
922920
923921
......
939937
940938
941939
942
940
943941
944942
945943
946
944
947945
948946
949947
......
955953
956954
957955
958
956
959957
960958
961959
962960
963
961
964962
965963
966964
......
969967
970968
971969
972
970
973971
974972
975973
......
991989
992990
993991
994
992
995993
996994
997995
static long InitDriverSupport(void);
ModulePtr gModuleHead, gModuleTail;
static TagPtr gPersonalityHead, gPersonalityTail;
static char * gExtensionsSpec;
static char * gDriverSpec;
static char * gFileSpec;
static char * gTempSpec;
static char * gFileName;
static TagPtrgPersonalityHead, gPersonalityTail;
static char*gExtensionsSpec;
static char*gDriverSpec;
static char*gFileSpec;
static char*gTempSpec;
static char*gFileName;
// Bungo
char *gDarwinBuildVerStr = "Darwin Kernel Version";
/*static*/ unsigned long
Adler32( unsigned char * buffer, long length )
Adler32( unsigned char *buffer, long length )
{
long cnt;
unsigned long result, lowHalf, highHalf;
{
if (NetLoadDrivers(dirSpec) != 0)
{
error("Could not load drivers from the network\n");
error("LoadDrivers: Could not load drivers from the network\n");
return -1;
}
}
if (gMKextName[0] != '\0')
{
verbose("LoadDrivers: Loading from [%s]\n", gMKextName);
verbose("LoadDrivers: Loading from '%s'\n", gMKextName);
if ( LoadDriverMKext(gMKextName) != 0 )
{
error("Could not load %s\n", gMKextName);
|| (((gBootMode & kBootModeSafe) == 0) && (time == (time2 + 1))))
{
snprintf(gDriverSpec, sizeof(altDirSpec) + 18, "%sExtensions.mkext", altDirSpec);
verbose("LoadDrivers: Loading from [%s]\n", gDriverSpec);
verbose("LoadDrivers: Loading from '%s'\n", gDriverSpec);
if (LoadDriverMKext(gDriverSpec) == 0)
{
static char gPlatformName[64];
#endif
char *gDarwinBuildVerStr = "Darwin Kernel Version"; // Bungo
long DecodeKernel(void *binary, entry_t *rentry, char **raddr, int *rsize)
{
long ret = 0;
compressed_kernel_header * kernel_header = (compressed_kernel_header *) binary;
compressed_kernel_header *kernel_header = (compressed_kernel_header *)binary;
u_int32_t uncompressed_size = 0, size = 0, adler32 = 0;
void *buffer = NULL;
unsigned long len = 0;
if (kernel_header->signature == OSSwapBigToHostConstInt32('comp'))
{
DBG("Decompressing Kernel: ");
DBG("Decompressing Kernel Cache");
if ((kernel_header->compress_type != OSSwapBigToHostConstInt32('lzss')) &&
(kernel_header->compress_type != OSSwapBigToHostConstInt32('lzvn')))
{
verbose ("Decompressing Kernel Using lzss\n");
}
else
if (kernel_header->compress_type == OSSwapBigToHostConstInt32('lzvn'))
{
if (kernel_header->compress_type == OSSwapBigToHostConstInt32('lzvn'))
{
verbose ("Decompressing Kernel Using lzvn\n");
}
verbose ("Decompressing Kernel Using lzvn\n");
}
#if NOTDEF
switch (kernel_header->compress_type)
{
case OSSwapBigToHostConstInt32('lzvn'):
size = lzvn_decode( binary, uncompressed_size, &kernel_header->data[0], OSSwapBigToHostInt32(kernel_header->compressed_size));
size = lzvn_decode(binary, uncompressed_size, &kernel_header->data[0], OSSwapBigToHostInt32(kernel_header->compressed_size));
break;
case OSSwapBigToHostConstInt32('lzss'):
size = decompress_lzss( (u_int8_t *)binary, uncompressed_size, &kernel_header->data[0], OSSwapBigToHostInt32(kernel_header->compressed_size));
size = decompress_lzss((u_int8_t *)binary, uncompressed_size, &kernel_header->data[0], OSSwapBigToHostInt32(kernel_header->compressed_size));
break;
default:
{
if ( kernel_header->compress_type == OSSwapBigToHostConstInt32('lzvn'))
{
error("ERROR: size mismatch from lzvn (found: %x, expected: %x).\n", size, uncompressed_size);
error("ERROR! Size mismatch from lzvn (found: %x, expected: %x).\n", size, uncompressed_size);
}
if ( kernel_header->compress_type == OSSwapBigToHostConstInt32('lzss'))
{
error("ERROR: size mismatch from lzss (found: %x, expected: %x).\n", size, uncompressed_size);
error("ERROR! size mismatch from lzss (found: %x, expected: %x).\n", size, uncompressed_size);
}
return -1;
adler32 = Adler32(binary, uncompressed_size);
if (OSSwapBigToHostInt32(kernel_header->adler32) != adler32)
{
error("ERROR: adler mismatch (found: %x, expected: %x).\n", adler32, OSSwapBigToHostInt32(kernel_header->adler32));
error("ERROR! Adler mismatch (found: %X, expected: %X).\n", adler32, OSSwapBigToHostInt32(kernel_header->adler32));
return -1;
}
gDarwinBuildVerStr = (char *)binary + size;
// Notify modules that the kernel has been decompressed, thinned and is about to be decoded
execute_hook("DecodeKernel", (void*)binary, NULL, NULL, NULL);
execute_hook("DecodeKernel", (void *)binary, NULL, NULL, NULL);
ret = DecodeMachO(binary, rentry, raddr, rsize);
if (ret < 0 && archCpuType == CPU_TYPE_X86_64)
trunk/i386/boot2/boot.c
9393
9494
9595
96
9796
9897
9998
......
127126
128127
129128
130
129
131130
132131
133132
......
135134
136135
137136
138
137
139138
140139
141140
142141
143
142
144143
145144
146145
......
151150
152151
153152
154
153
155154
156155
157156
......
161160
162161
163162
164
163
165164
166165
167166
......
180179
181180
182181
183
182
184183
185184
186185
......
198197
199198
200199
201
200
202201
203202
204203
......
224223
225224
226225
227
226
228227
229228
230229
......
259258
260259
261260
262
261
263262
264263
265264
......
271270
272271
273272
274
273
275274
276275
277276
......
279278
280279
281280
282
283
284
281
282
283
285284
286
285
287286
288
289
290
291
287
288
292289
293
294
290
295291
296
297
292
293
294
295
296
297
298298
299
299300
300
301
301302
302
303
303
304
304305
305306
306307
307
308
308309
309310
310311
......
367368
368369
369370
370
371
371372
372373
373374
......
376377
377378
378379
379
380
380381
381382
382383
383384
384
385
385386
386387
387388
......
478479
479480
480481
482
483
484
481485
482
483486
484487
485488
......
510513
511514
512515
513
514
515
516
516
517
518
519
517520
518521
519522
......
667670
668671
669672
670
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
671692
672
673
674
693
675694
676
677
695
696
697
678698
679
680
681
682
683
684
685
686699
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
700
701
702
703
704
705
702706
703
707
708
709
710
704711
705
712
713
714
715
716
717
718
719
720
706721
707722
708723
......
724739
725740
726741
727
728742
729
730743
731744
732745
733
734
735746
736
737747
738748
739749
......
764774
765775
766776
767
777
768778
769779
770780
......
782792
783793
784794
785
795
786796
787797
788798
extern char* msgbuf;
void showTextBuffer(char *buf, int size);
//==========================================================================
// Zero the BSS.
}
//==========================================================================
// execKernel - Load the kernel image (mach-o) and jump to its entry point.
// ExecKernel - Load the kernel image (mach-o) and jump to its entry point.
static int ExecKernel(void *binary)
{
entry_tkernelEntry;
bootArgs->kaddr = bootArgs->ksize = 0;
execute_hook("ExecKernel", (void*)binary, NULL, NULL, NULL);
execute_hook("ExecKernel", (void *)binary, NULL, NULL, NULL);
ret = DecodeKernel(binary,
&kernelEntry,
(char **) &bootArgs->kaddr,
(int *)&bootArgs->ksize );
(int *)&bootArgs->ksize);
if ( ret != 0 )
{
reserveKernBootStruct();
// Notify modules that the kernel has been decoded
execute_hook("DecodedKernel", (void*)binary, (void*)bootArgs->kaddr, (void*)bootArgs->ksize, NULL);
execute_hook("DecodedKernel", (void *)binary, (void *)bootArgs->kaddr, (void *)bootArgs->ksize, NULL);
setupFakeEfi();
LoadDrivers("/");
}
execute_hook("DriversLoaded", (void*)binary, NULL, NULL, NULL);
execute_hook("DriversLoaded", (void *)binary, NULL, NULL, NULL);
clearActivityIndicator();
{
if ( (ret = nbpUnloadBaseCode()) != nbpStatusSuccess )
{
printf("nbpUnloadBaseCode error %d\n", (int) ret);
printf("nbpUnloadBaseCode error %d\n", (int)ret);
sleep(2);
}
}
// verbose mode.
if (gVerboseMode)
{
setVideoMode( GRAPHICS_MODE, 0 );
setVideoMode(GRAPHICS_MODE, 0);
}
else
{
else
{
// Notify modules that the kernel is about to be started
execute_hook("Kernel Start", (void*)kernelEntry, (void*)bootArgs, NULL, NULL);
execute_hook("Kernel Start", (void *)kernelEntry, (void *)bootArgs, NULL, NULL);
// Masking out so that Lion doesn't doublefault
outb(0x21, 0xff);/* Maskout all interrupts Pic1 */
if (cacheFile[0] != 0)
{
strlcpy(kernelCacheFile, cacheFile, sizeof(kernelCacheFile));
verbose("Specified kernel cache file path = %s\n", cacheFile);
verbose("Specified kernel cache file path: %s\n", cacheFile);
}
else
{
snprintf(gCacheNameAdler + 64, sizeof(gCacheNameAdler) - 64, "%s,%s", gRootDevice, bootInfo->bootFile);
adler32 = Adler32((unsigned char *)gCacheNameAdler, sizeof(gCacheNameAdler));
snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%s.%08lX", kDefaultCachePathLeo, adler32);
verbose("Reseted kernel cache file path = %s\n", kernelCacheFile);
verbose("Reseted kernel cache file path: %s\n", kernelCacheFile);;
}
// Snow Leopard prelink kernel cache file
else if ( SNOW_LEOPARD )
snprintf(kernelCacheFile, sizeof(kernelCacheFile), "kernelcache_%s",
(archCpuType == CPU_TYPE_I386) ? "i386" : "x86_64");
intlnam = strlen(kernelCacheFile) + 9; //with adler32
char *name;
u_int32_t prev_time = 0;
intlnam = strlen(kernelCacheFile) + 9; //with adler32
char*name;
u_int32_t prev_time = 0;
structdirstuff* cacheDir = opendir(kDefaultCachePathSnow);
struct dirstuff* cacheDir = opendir(kDefaultCachePathSnow);
/* TODO: handle error? */
if (cacheDir)
{
while(readdir(cacheDir, (const char**)&name, &flags, &time) >= 0)
/* TODO: handle error? */
if (cacheDir)
{
if (((flags & kFileTypeMask) != kFileTypeDirectory) && time > prev_time
&& strstr(name, kernelCacheFile) && (name[lnam] != '.'))
while(readdir(cacheDir, (const char**)&name, &flags, &time) >= 0)
{
snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%s%s", kDefaultCachePathSnow, name);
prev_time = time;
if (((flags & kFileTypeMask) != kFileTypeDirectory) && time > prev_time
&& strstr(name, kernelCacheFile) && (name[lnam] != '.'))
{
snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%s%s", kDefaultCachePathSnow, name);
prev_time = time;
}
}
verbose("Kernel Cache file path (Mac OS X 10.6.X): %s\n", kernelCacheFile);
}
verbose("Snow Leopard kernel cache file path = %s\n", kernelCacheFile);
closedir(cacheDir);
}
closedir(cacheDir);
} else {
else
{
// Lion, Mountain Lion, Mavericks, and Yosemite prelink kernel cache file
// for 10.7 10.8 10.9 10.10
snprintf(kernelCacheFile, sizeof(kernelCacheFile), "%skernelcache", kDefaultCachePathSnow);
verbose("10.7, 10.8, 10.9 & 10.10 kernel cache file path = %s\n", kernelCacheFile);
verbose("Kernel Cache file path (Mac OS X 10.7 and newer): %s\n", kernelCacheFile);;
}
}
// Check if the kernel file is more recent than the cache file
if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeFlat) && (kerneltime > cachetime))
{
DBG("Kernel file (%s) is more recent than Kernel Cache (%s)! Ignoring Kernel Cache.\n", bootInfo->bootFile, kernelCacheFile);
DBG("Kernel file '%s' is more recent than Kernel Cache '%s'! Ignoring Kernel Cache.\n", bootInfo->bootFile, kernelCacheFile);
return -1;
}
// Check if the S/L/E directory time is more recent than the cache file
if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeDirectory) && (exttime > cachetime))
{
DBG("Folder: '/System/Library/Extensions' is more recent than Kernel Cache file (%s)! Ignoring Kernel Cache.\n", kernelCacheFile);
DBG("Folder '/System/Library/Extensions' is more recent than Kernel Cache file '%s'! Ignoring Kernel Cache.\n", kernelCacheFile);
return -1;
}
// Since the kernel cache file exists and is the most recent try to load it
DBG("Loading kernel cache: '%s'\n", kernelCachePath);
DBG("Loading Kernel Cache from: '%s'\n", kernelCachePath);
ret = LoadThinFatFile(kernelCachePath, binary);
return ret; // ret contain the length of the binary
gEnableCDROMRescan = true;
}
// Disable rescanPrompt option by default
rescanPrompt = false;
// Ask the user for Rescan option by setting "Rescan Prompt"=y in system config.
rescanPrompt = false;
if (getBoolForKey(kRescanPromptKey, &rescanPrompt , &bootInfo->chameleonConfig) && rescanPrompt && biosDevIsCDROM(gBIOSDev))
{
gEnableCDROMRescan = promptForRescanOption();
init_module_system();
#if DEBUG
printf(" Default: %d, ->biosdev: %d, ->part_no: %d ->flags: %d\n",
gBootVolume, gBootVolume->biosdev, gBootVolume->part_no, gBootVolume->flags);
printf(" bt(0,0): %d, ->biosdev: %d, ->part_no: %d ->flags: %d\n",
gBIOSBootVolume, gBIOSBootVolume->biosdev, gBIOSBootVolume->part_no, gBIOSBootVolume->flags);
printf("Default: %d, ->biosdev: %d, ->part_no: %d ->flags: 0x%08X\n",
gBootVolume, gBootVolume->biosdev, gBootVolume->part_no, gBootVolume->flags);
printf("bt(0,0): %d, ->biosdev: %d, ->part_no: %d ->flags: 0x%08X\n",
gBIOSBootVolume, gBIOSBootVolume->biosdev, gBIOSBootVolume->part_no, gBIOSBootVolume->flags);
getchar();
#endif
}
getBoolForKey(kUseKernelCache, &useKernelCache, &bootInfo->chameleonConfig);
if (useKernelCache) do {
if (useKernelCache)
{
do
{
// Determine the name of the Kernel Cache
if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig))
{
if (val[0] == '\\')
{
len--;
val++;
}
/* FIXME: check len vs sizeof(kernelCacheFile) */
strlcpy(kernelCacheFile, val, len + 1);
}
else
{
kernelCacheFile[0] = 0; // Use default kernel cache file
}
// Determine the name of the Kernel Cache
if (getValueForKey(kKernelCacheKey, &val, &len, &bootInfo->bootConfig)) {
if (val[0] == '\\')
if (gOverrideKernel && kernelCacheFile[0] == 0)
{
len--;
val++;
DBG("Using a non default kernel (%s) without specifying 'Kernel Cache' path, KernelCache will not be used\n", bootInfo->bootFile);
useKernelCache = false;
break;
}
/* FIXME: check len vs sizeof(kernelCacheFile) */
strlcpy(kernelCacheFile, val, len + 1);
}
else
{
kernelCacheFile[0] = 0; // Use default kernel cache file
}
if (gOverrideKernel && kernelCacheFile[0] == 0)
{
DBG("Using a non default kernel (%s) without specifying 'Kernel Cache' path, KernelCache will not be used\n", bootInfo->bootFile);
useKernelCache = false;
break;
}
if (gMKextName[0] != 0)
{
DBG("Using a specific MKext Cache (%s), KernelCache will not be used\n",
gMKextName);
useKernelCache = false;
break;
}
if (gBootFileType != kBlockDeviceType)
useKernelCache = false;
if (gMKextName[0] != 0)
{
DBG("Using a specific MKext Cache (%s), KernelCache will not be used\n", gMKextName);
useKernelCache = false;
break;
}
} while(0);
if (gBootFileType != kBlockDeviceType)
{
useKernelCache = false;
}
do {
} while(0);
}
else
{
verbose("Kernel Cache using disabled by user.");
}
do
{
if (useKernelCache)
{
ret = LoadKernelCache(kernelCacheFile, &binary);
{
if ( !YOSEMITE )
{
//printf(HEADER " (%s).\n", bootInfo->bootFile);
snprintf(bootFile, sizeof(bootFile), "/%s", bootInfo->bootFile); // append a leading /
//sleep(1);
}
else
{
//printf(HEADER " (%s).\n", bootInfo->bootFile);
snprintf(bootFile, sizeof(bootFile), kDefaultKernelPathForYos"%s", bootInfo->bootFile); // Yosemite
//sleep(1);
}
}
else
strlcpy(bootFilePath, bootFile, sizeof(bootFilePath));
}
DBG("Loading kernel: '%s'\n", bootFilePath);
DBG("Loading kernel from: '%s'\n", bootFilePath);
ret = LoadThinFatFile(bootFilePath, &binary);
if (ret <= 0 && archCpuType == CPU_TYPE_X86_64)
{
if (ret <= 0)
{
printf("Can't find %s\n", bootFile);
printf("Can't find boot file: '%s'\n", bootFile);
sleep(1);
if (gBootFileType == kNetworkDeviceType)
trunk/i386/boot2/boot.h
4343
4444
4545
46
47
46
47
4848
4949
50
51
50
51
5252
5353
54
55
54
55
5656
5757
5858
59
59
6060
6161
6262
......
8787
8888
8989
90
90
9191
9292
9393
......
184184
185185
186186
187
188187
189188
189
190190
191191
192192
......
199199
200200
201201
202
203
202
203
204204
205205
206206
......
231231
232232
233233
234
234
235235
236236
237237
......
257257
258258
259259
260
260
261261
262262
263263
......
266266
267267
268268
269
269
270270
271271
272272
273273
274274
275275
276
277276
278277
279278
280
281279
280
281
282282
283283
284284
......
289289
290290
291291
292
293292
294293
295294
......
313312
314313
315314
316
317
318
319
315
316
317
318
320319
321
322
323
324
325
320
321
322
323
324
326325
327326
328327
......
342341
343342
344343
345
344
346345
347
348
349346
*/
// kernel cache
#define kDefaultCachePathLeo "/System/Library/Caches/com.apple.kernelcaches/"
#define kDefaultCachePathSnow "/System/Library/Caches/com.apple.kext.caches/Startup/"
#define kDefaultCachePathLeo"/System/Library/Caches/com.apple.kernelcaches/"
#define kDefaultCachePathSnow"/System/Library/Caches/com.apple.kext.caches/Startup/"
// Lion installer
#define kLionInstallerDataFolder "/Mac OS X Install Data/"
#define kLionInstallerPlist kLionInstallerDataFolder "com.apple.Boot.plist"
#define kLionInstallerDataFolder"/Mac OS X Install Data/"
#define kLionInstallerPlistkLionInstallerDataFolder "com.apple.Boot.plist"
// Mountain Lion installer
#define kMLionInstallerDataFolder "/OS X Install Data/"
#define kMLionInstallerPlist kMLionInstallerDataFolder "com.apple.Boot.plist"
#define kMLionInstallerDataFolder"/OS X Install Data/"
#define kMLionInstallerPlistkMLionInstallerDataFolder "com.apple.Boot.plist"
//kernel path
#define kDefaultKernelPathPreYos"/"
#define kDefaultKernelPathForYos"/System/Library/Kernels/" //for Yosemite
#define kDefaultKernelPathForYos"/System/Library/Kernels/" //for Yosemite and newer
/*
* Keys used in system Boot.plist
#define kOSXKernel"kernel"// Yosemite
#define kGUIKey"GUI"
#define kBootBannerKey"Boot Banner"
#define kShowInfoKey"ShowInfo"/* gui.c */
#define kShowInfoKey"ShowInfo"// gui.c
#define kWaitForKeypressKey"Wait"
/* AsereBLN: added these keys */
#define kMemFullInfo"ForceFullMemInfo"/* smbios.c */
/* Bungo: added these keys */
// mask private data or no
#define kPrivateData"PrivateData"/* smbios_decode.c */
/*
* Flags to the booter or kernel
*/
/*
* Booter behavior control
*/
#define kBootTimeout -1
#define kCDBootTimeout 8
#define kBootTimeout-1
#define kCDBootTimeout8
/*
* A global set by boot() to record the device that the booter was loaded from.
extern void initialize_runtime();
extern void common_boot(int biosdev);
bool checkOSVersion(const char * version);
/*
* usb.c
*/
unsigned short y,
unsigned short width,
unsigned short height,
unsigned char * data
unsigned char *data
);
extern int
convertImage( unsigned short width,
unsigned char **newImageData );
extern char * decodeRLE( const void * rleData, int rleBlocks, int outBytes );
extern void drawBootGraphics(void);
extern void drawPreview(void *src, uint8_t * saveunder);
extern void drawPreview(void *src, uint8_t *saveunder);
extern int getVideoMode(void);
extern void loadImageScale (void *input, int iw, int ih, int ip, void *output, int ow, int oh, int op, int or);
/*
* drivers.c
*/
extern char *gDarwinBuildVerStr; // Bungo
extern long LoadExtraDrivers(char * dirSpec);
extern long LoadDrivers(char * dirSpec);
extern long DecodeKernel(void *binary, entry_t *rentry, char **raddr, int *rsize);
typedef long (*FileLoadDrivers_t)(char *dirSpec, long plugin);
// Bungo
extern char *gDarwinBuildVerStr;
/*!
Hookable function pointer called during the driver loading phase that
allows other code to cause additional drivers to be loaded.
* options.c
*/
extern char gBootUUIDString[];
extern int getBootOptions(bool firstRun);
extern int processBootOptions();
extern int selectAlternateBootDevice(int bootdevice);
/*
* lzvn.c
*/
extern size_t lzvn_decode(void * dst,
size_t dst_size,
const void * src,
size_t src_size);
extern size_t lzvn_decode(void*dst,
size_tdst_size,
const void*src,
size_tsrc_size);
/*
extern size_t lzvn_encode(void * dst,
size_t dst_size,
const void * src,
size_t src_size,
void * work);
extern size_t lzvn_encode(void*dst,
size_tdst_size,
const void*src,
size_tsrc_size,
void*work);
*/
struct compressed_kernel_header {
void HibernateBoot(char *boot_device);
/* bmdecompress.c */
void * DecompressData(void *srcbase, int *dw, int *dh, int *bytesPerPixel);
void *DecompressData(void *srcbase, int *dw, int *dh, int *bytesPerPixel);
bool checkOSVersion(const char * version);
#endif /* !__BOOT2_BOOT_H */
trunk/i386/boot2/modules.c
7676
7777
7878
79
79
8080
8181
8282
......
8888
8989
9090
91
91
92
9293
9394
9495
......
123124
124125
125126
126
127
127128
128129
129130
......
164165
165166
166167
167
168
168169
169170
170
171
171172
172173
173
174
174175
175176
176177
177178
178
179
179180
180181
181182
......
208209
209210
210211
212
211213
212214
213215
......
215217
216218
217219
218
220
221
219222
220223
221224
222225
223
224
225
226
227
226
227
228
229
230
228231
229232
230233
......
237240
238241
239242
240
243
244
241245
242246
243247
244248
245
249
246250
247251
248252
249
253
250254
251255
252256
253257
254
258
259
255260
256261
257262
......
311316
312317
313318
314
319
315320
316321
317322
......
320325
321326
322327
323
328
324329
325330
326331
327332
328
333
334
329335
330336
331337
......
335341
336342
337343
338
344
345
339346
340347
341348
......
365372
366373
367374
368
375
369376
370377
371378
......
431438
432439
433440
434
441
435442
436443
437444
......
564571
565572
566573
567
574
568575
569576
570577
......
925932
926933
927934
928
935
929936
930937
931938
......
944951
945952
946953
947
954
948955
949956
950957
......
962969
963970
964971
965
972
966973
967974
968975
......
987994
988995
989996
990
997
991998
992999
9931000
......
10721079
10731080
10741081
1075
1082
1083
10761084
10771085
10781086
......
10861094
10871095
10881096
1089
1097
1098
10901099
10911100
10921101
10931102
10941103
1095
1104
10961105
10971106
10981107
......
11081117
11091118
11101119
1111
1120
1121
11121122
1113
1123
11141124
11151125
11161126
11171127
1118
1128
11191129
11201130
11211131
1132
11221133
11231134
11241135
11251136
1126
1137
1138
11271139
11281140
11291141
......
11831195
11841196
11851197
1186
1198
11871199
11881200
11891201
......
12061218
12071219
12081220
1209
1221
12101222
12111223
12121224
12131225
12141226
1215
1227
12161228
12171229
12181230
// Module system was compiled in (Symbols.dylib addr known)
module_start = parse_mach(module_data, &load_module, &add_symbol, NULL);
if(module_start && module_start != (void*)0xFFFFFFFF)
if(module_start && (module_start != (void*)0xFFFFFFFF))
{
// Notify the system that it was laoded
module_loaded(SYMBOLS_MODULE, module_start, SYMBOLS_AUTHOR, SYMBOLS_DESCRIPTION, SYMBOLS_VERSION, SYMBOLS_COMPAT);
else
{
// The module does not have a valid start function
printf("Unable to start %s at 0x%x\n", SYMBOLS_MODULE, module_data); pause();
printf("Unable to start %s at 0x%x\n", SYMBOLS_MODULE, module_data);
pause();
}
}
module_start = parse_mach(module_data, &load_module, &add_symbol, NULL);
if(module_start && module_start != (void*)0xFFFFFFFF)
if(module_start && (module_start != (void*)0xFFFFFFFF))
{
// Notify the system that it was laoded
module_loaded(name, module_start, NULL, NULL, 0, 0 /*moduleName, NULL, moduleVersion, moduleCompat*/);
*/
void load_all_modules()
{
char* name;
char *name;
long flags;
u_int32_t time;
struct dirstuff* moduleDir = opendir("/Extra/modules/");
struct dirstuff *moduleDir = opendir("/Extra/modules/");
if(!moduleDir)
{
verbose("Warning: Unable to open modules folder at '/Extra/modules/'. Ignoring modules.\n");
verbose("[WARNING!] Unable to open modules folder at '/Extra/modules/'. Ignoring modules.\n");
return;
}
while (readdir(moduleDir, (const char**)&name, &flags, &time) >= 0) {
if(strcmp(&name[strlen(name) - sizeof("dylib")], ".dylib") == 0) {
char* tmp = malloc(strlen(name) + 1);
char *tmp = malloc(strlen(name) + 1);
strcpy(tmp, name);
if(!load_module(tmp))
// Check to see if the module has already been loaded
if(is_module_loaded(module))
{
DBG("Module '%s' already loaded.\n", module);
return 1;
}
fh = open(modString, 0);
if(fh < 0)
{
DBG("WARNING: Unable to locate module %s\n", modString); DBGPAUSE();
DBG("[WARNING!] Unable to locate module '%s'. Not loaded.\n", modString);
DBGPAUSE();
return 0;
}
unsigned int moduleSize = file_size(fh);
if(moduleSize == 0)
{
DBG("WARNING: The module %s has a file size of %d, the module will not be loaded.\n", modString, moduleSize);
return 0;
}
if(moduleSize == 0)
{
DBG("[WARNING!] The module '%s' has a file size=%d. Not loading.\n", modString, moduleSize);
return 0;
}
char* module_base = (char*) malloc(moduleSize);
if (moduleSize && read(fh, module_base, moduleSize) == moduleSize)
// Notify the system that it was laoded
module_loaded(module, module_start, NULL, NULL, 0, 0 /*moduleName, NULL, moduleVersion, moduleCompat*/);
(*module_start)();// Start the module
DBG("Module %s Loaded.\n", module); DBGPAUSE();
DBG("Module %s Loaded.\n", module);
DBGPAUSE();
}
#if CONFIG_MODULE_DEBUG
else // The module does not have a valid start function. This may be a library.
{
printf("WARNING: Unable to start %s\n", module);
printf("[WARNING!] Unable to start module '%s'.\n", module);
getchar();
}
#else
else msglog("WARNING: Unable to start %s\n", module);
else msglog("[WARNING!] Unable to start module '%s'.\n", module);
#endif
}
else
{
DBG("Unable to read in module %s\n.", module); DBGPAUSE();
DBG("[WARNING!] Unable to read in module '%s'.\n", module);
DBGPAUSE();
retVal = 0;
}
new_entry->compat = compat;
DBG("Module '%s' by '%s' Loaded.\n", name, author);
DBG("\tInitialization: 0x%X\n", start);
DBG("\tInitialization: 0x%08X\n", start);
DBG("\tDescription: %s\n", description);
DBG("\tVersion: %d\n", version); // todo: sperate to major.minor.bugfix
DBG("\tCompat: %d\n", compat); // todo: ^^^ major.minor.bugfix
int is_module_loaded(const char* name)
{
// todo sorted search
moduleList_t* entry = loadedModules;
moduleList_t *entry = loadedModules;
while(entry)
{
if(strcmp(entry->name, name) == 0)
{
DBG("Located module %s\n", name); DBGPAUSE();
DBG("Located module %s\n", name);
DBGPAUSE();
return 1;
}
else
}
DBG("Module %s not loaded\n", name); DBGPAUSE();
DBG("Module %s not loaded\n", name);
DBGPAUSE();
return 0;
}
}
#if CONFIG_MODULE_DEBUG
printf("Unable to locate symbol %s\n", name);
printf("[WARNING!] Unable to locate symbol %s.\n", name);
getchar();
#endif
}
else
{
verbose("Invalid mach magic 0x%X\n", ((struct mach_header*)binary)->magic);
verbose("[ERROR!] Invalid mach magic: 0x%08X.\n", ((struct mach_header*)binary)->magic);
return NULL;
}
break;
default:
DBG("Unhandled loadcommand 0x%X\n", loadCommand->cmd & 0x7FFFFFFF);
DBG("[WARNING!] Unhandled loadcommand: 0x%08X.\n", loadCommand->cmd & 0x7FFFFFFF);
break;
}
}
else
{
printf("Unable to bind symbol %s\n", symbolName);
printf("[ERROR!] Unable to bind symbol %s.\n", symbolName);
getchar();
}
}
else
{
printf("Unable to bind symbol %s\n", symbolName);
printf("[ERROR!] Unable to bind symbol %s.\n", symbolName);
getchar();
}
}
else
{
printf("Unable to bind symbol %s\n", symbolName);
printf("[ERROR!] Unable to bind symbol %s.\n", symbolName);
getchar();
}
segmentAddress += (immediate * sizeof(void*)) + sizeof(void*);
}
else
{
printf("Unable to bind symbol %s\n", symbolName);
printf("[ERROR!] Unable to bind symbol %s.\n", symbolName);
getchar();
}
break;
*/
int execute_hook(const char* name, void* arg1, void* arg2, void* arg3, void* arg4)
{
DBG("Attempting to execute hook '%s'\n", name); DBGPAUSE();
DBG("Attempting to execute hook '%s'...\n", name);
DBGPAUSE();
moduleHook_t* hook = hook_exists(name);
if(hook)
callbacks->callback(arg1, arg2, arg3, arg4);
callbacks = callbacks->next;
}
DBG("Hook '%s' executed.\n", name); DBGPAUSE();
DBG("Hook '%s' executed.\n", name);
DBGPAUSE();
return 1;
}
else
{
// Callback for this hook doesn't exist;
DBG("No callbacks for '%s' hook.\n", name);
DBG("No callbacks for hook '%s'.\n", name);
return 0;
}
}
*/
void register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*))
{
DBG("Adding callback for '%s' hook.\n", name); DBGPAUSE();
DBG("Adding callback for '%s' hook... ", name);
DBGPAUSE();
moduleHook_t* hook = hook_exists(name);
moduleHook_t *hook = hook_exists(name);
if(hook)
{
// append
callbackList_t* newCallback = malloc(sizeof(callbackList_t));
callbackList_t *newCallback = malloc(sizeof(callbackList_t));
newCallback->next = hook->callbacks;
hook->callbacks = newCallback;
newCallback->callback = callback;
DBG("Added.\n");
}
else
{
// create new hook
moduleHook_t* newHook = malloc(sizeof(moduleHook_t));
DBG("Hook not exists, creating a new hook.\n");
moduleHook_t *newHook = malloc(sizeof(moduleHook_t));
newHook->name = name;
newHook->callbacks = malloc(sizeof(callbackList_t));
newHook->callbacks->callback = callback;
void dyld_stub_binder()
{
printf("ERROR: dyld_stub_binder was called, should have been take care of by the linker.\n");
printf("[ERROR!] 'dyld_stub_binder' was called, should have been take care of by the linker.\n");
getchar();
}
void register_hook_callback(const char* name, void(*callback)(void*, void*, void*, void*))
{
printf("WARNING: register_hook_callback is not supported when compiled in.\n");
printf("[WARNING!] 'register_hook_callback' is not supported when compiled in.\n");
pause();
}
int replace_function(const char* symbol, void* newAddress)
{
printf("WARNING: replace_functions is not supported when compiled in.\n");
printf("[WARNING!] 'replace_functions' is not supported when compiled in.\n");
pause();
return 0;
}
trunk/i386/boot2/gui.c
889889
890890
891891
892
892
893893
894894
895895
......
911911
912912
913913
914
914
915
915916
916917
917
918
919
918920
919921
920922
int initGUI(void)
{
intval;
intval;
intlen;
chardirspec[256];
#endif
}
// parse display size parameters
if (getIntForKey("screen_width", &val, &bootInfo->themeConfig) && val > 0) {
if (getIntForKey("screen_width", &val, &bootInfo->themeConfig) && (val > 0))
{
screen_params[0] = val;
}
if (getIntForKey("screen_height", &val, &bootInfo->themeConfig) && val > 0) {
if (getIntForKey("screen_height", &val, &bootInfo->themeConfig) && (val > 0))
{
screen_params[1] = val;
}
trunk/i386/boot2/options.c
5050
5151
5252
53
5453
54
55
5556
5657
5758
5859
5960
6061
61
62
6263
6364
6465
......
185186
186187
187188
188
189
190
191
192
189
190
191
192
193
193194
194195
195196
......
260261
261262
262263
263
264
264265
265
266
267
268
269
270
266
267
268
269
270
271
271272
272
273
274
275
276
277
278
279
280
273
274
275
276
277
278
281279
282
283
284
285
286
287
288
289
290
291
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
292295
293296
294
295
296
297
297
298
299
300
298301
299
300
301
302
303
302
303
304
305
306
307
308
309
310
304311
305
312
306313
307314
308315
......
375382
376383
377384
378
385
379386
380
381
382
387
388
389
383390
384391
385392
......
905912
906913
907914
908
915
909916
910917
911918
......
11141121
11151122
11161123
1117
1124
11181125
11191126
11201127
11211128
11221129
11231130
1124
1131
1132
11251133
11261134
11271135
......
11791187
11801188
11811189
1182
1183
1190
11841191
11851192
11861193
......
11971204
11981205
11991206
1200
1201
1202
1203
1207
1208
1209
1210
1211
12041212
12051213
12061214
......
12171225
12181226
12191227
1220
1228
1229
12211230
12221231
12231232
......
12261235
12271236
12281237
1229
1238
1239
12301240
12311241
12321242
......
12591269
12601270
12611271
1262
12631272
1264
12651273
12661274
12671275
12681276
12691277
1270
12711278
12721279
12731280
......
12991306
13001307
13011308
1302
1303
1309
13041310
13051311
13061312
......
13781384
13791385
13801386
1381
1387
13821388
13831389
13841390
extern intgDeviceCount;
intselectIndex = 0;
MenuItem * menuItems = NULL;
MenuItem *menuItems = NULL;
enum {
kMenuTopRow = 5,
kMenuMaxItems = 10,
kScreenLastRow = 24
};
extern char* msgbuf;
extern char *msgbuf;
void showTextBuffer(char *buf_orig, int size);
//==========================================================================
char gBootArgs[BOOT_STRING_LEN];
static char * gBootArgsPtr = gBootArgs;
static char * gBootArgsEnd = gBootArgs + BOOT_STRING_LEN - 1;
static char booterCommand[BOOT_STRING_LEN];
static char booterParam[BOOT_STRING_LEN];
chargBootArgs[BOOT_STRING_LEN];
static char*gBootArgsPtr = gBootArgs;
static char*gBootArgsEnd = gBootArgs + BOOT_STRING_LEN - 1;
static charbooterCommand[BOOT_STRING_LEN];
static charbooterParam[BOOT_STRING_LEN];
static void clearBootArgs(void)
{
static void updateBootArgs( int key )
{
key = ASCII_KEY(key);
key = ASCII_KEY(key);
switch ( key )
{
case KEY_BKSP:
if ( gBootArgsPtr > gBootArgs )
{
*--gBootArgsPtr = '\0';
switch ( key )
{
case KEY_BKSP:
if ( gBootArgsPtr > gBootArgs )
{
*--gBootArgsPtr = '\0';
int x, y, t;
getCursorPositionAndType( &x, &y, &t );
if ( x == 0 && y )
{
x = 80; y--;
}
if (x) {
x--;
}
int x, y, t;
getCursorPositionAndType( &x, &y, &t );
if ( x == 0 && y )
{
x = 80; y--;
}
if( bootArgs->Video.v_display == VGA_TEXT_MODE )
{
setCursorPosition( x, y, 0 );
putca(' ', 0x07, 1);
}
else
{
updateGraphicBootPrompt();
}
}
if (x)
{
x--;
}
if( bootArgs->Video.v_display == VGA_TEXT_MODE )
{
setCursorPosition( x, y, 0 );
putca(' ', 0x07, 1);
}
else
{
updateGraphicBootPrompt();
}
}
break;
default:
if ( key >= ' ' && gBootArgsPtr < gBootArgsEnd)
{
*gBootArgsPtr++ = key;
default:
if ( key >= ' ' && gBootArgsPtr < gBootArgsEnd)
{
*gBootArgsPtr++ = key;
if( bootArgs->Video.v_display != VGA_TEXT_MODE )
updateGraphicBootPrompt();
else if ( key >= ' ' && key < 0x7f)
putchar(key);
}
if( bootArgs->Video.v_display != VGA_TEXT_MODE )
{
updateGraphicBootPrompt();
}
else if ( key >= ' ' && key < 0x7f)
{
putchar(key);
}
}
break;
break;
}
}
// Draw the visible items.
if( bootArgs->Video.v_display != VGA_TEXT_MODE )
{
drawDeviceList(gMenuStart, gMenuEnd, gMenuSelection);
else {
}
else
{
changeCursor( 0, row, kCursorTypeHidden, &cursorState );
for ( i = gMenuTop; i <= gMenuBottom; i++ )
// gDeviceCount is actually > 0, so menuItems[selectIndex] exists
menuBVR = (BVRef)(menuItems[selectIndex].param);
// what happen is bvChain is empty ?
// what happen if bvChain is empty ?
}
}
bool copyArgument(const char *argName, const char *val, int cnt, char **argP, int *cntRemainingP)
{
int argLen = argName ? strlen(argName) : 0;
int len = argLen + cnt + 1; // + 1 to account for space.
int len = argLen + cnt + 1; // +1 to account for space
if (argName)
{
len++; // +1 to account for '='
}
if (len > *cntRemainingP) {
if (len > *cntRemainingP)
{
error("Warning: boot arguments too long, truncating\n");
return false;
}
// Maximum config table value size
#define VALUE_SIZE 2048
int
processBootOptions()
int processBootOptions()
{
const char *cp = gBootArgs;
const char *val = 0;
skipblanks( &cp );
// Update the unit and partition number.
if ( gBootVolume ) {
if (!( gBootVolume->flags & kBVFlagNativeBoot )) {
readBootSector( gBootVolume->biosdev, gBootVolume->part_boff, (void *) 0x7c00 );
if (gBootVolume)
{
if (!(gBootVolume->flags & kBVFlagNativeBoot))
{
readBootSector(gBootVolume->biosdev, gBootVolume->part_boff, (void *)0x7c00);
//
// Setup edx, and signal intention to chain load the
// foreign booter.
}
// If no boot volume fail immediately because we're just going to fail
// trying to load the config file anyway.
else {
else
{
return -1;
}
// Load config table specified by the user, or use the default.
if (!getValueForBootKey(cp, "config", &val, &cnt)) {
if (!getValueForBootKey(cp, "config", &val, &cnt))
{
val = 0;
cnt = 0;
}
{
if( YOSEMITE ) // is 10.10
{
strlcpy( bootInfo->bootFile, kOSXKernel, sizeof(bootInfo->bootFile) );
//printf(HEADER "/System/Library/Kernels/%s\n", bootInfo->bootFile);
}
else
{ // OSX is not 10.10
strlcpy( bootInfo->bootFile, kDefaultKernel, sizeof(bootInfo->bootFile) );
//printf(HEADER "/%s\n", bootInfo->bootFile);
}
}
}
argP = bootArgs->CommandLine;
// Get config kernel flags, if not ignored.
if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) ||
!getValueForKey( kKernelFlagsKey, &val, &cnt, &bootInfo->bootConfig ))
if (getValueForBootKey(cp, kIgnoreBootFileFlag, &val, &cnt) || !getValueForKey(kKernelFlagsKey, &val, &cnt, &bootInfo->bootConfig))
{
val = "";
cnt = 0;
{
copyArgument( kRootDeviceKey, val, cnt, &argP, &cntRemaining);
}
strlcpy( gRootDevice, val, (cnt + 1));
strlcpy(gRootDevice, val, (cnt + 1));
}
/*

Archive Download the corresponding diff file

Revision: 2538