Chameleon

Chameleon Commit Details

Date:2015-07-13 00:27:42 (8 years 9 months ago)
Author:ErmaC
Commit:2734
Parents: 2733
Message:Typo indent and whitespace.
Changes:
M/trunk/i386/libsaio/bios.h
M/trunk/i386/boot2/graphics.c
M/trunk/i386/libsaio/hfs_CaseTables.h
M/trunk/i386/libsa/string.c
M/trunk/i386/libsaio/device_tree.c
M/trunk/i386/libsaio/load.c
M/trunk/i386/libsaio/biosfn.c
M/trunk/i386/libsaio/hfs.c
M/trunk/i386/libsaio/device_tree.h
M/trunk/i386/libsaio/saio_types.h
M/trunk/i386/libsaio/hfs_compare.c
M/trunk/i386/boot2/gui.c
M/trunk/i386/libsaio/libsaio.h
M/trunk/i386/libsaio/platform.h
M/trunk/i386/libsaio/fake_efi.c
M/trunk/i386/libsaio/disk.c
M/trunk/i386/libsaio/saio_internal.h
M/trunk/i386/libsa/prf.c
M/trunk/i386/libsa/strtol.c

File differences

trunk/i386/libsaio/hfs_CaseTables.h
245245
246246
247247
248
249
248
249
250250
251251
252252
......
261261
262262
263263
264
264
265265
266266
267267
......
271271
272272
273273
274
275274
276275
277276
278
279
280
281
277
278
279
280
281
282282
283283
284
285
286
287
284
285
286
287
288
288289
289290
290291
/* RelString case folding table */
unsigned short gCompareTable[] = {
unsigned short gCompareTable[] =
{
/* 0 */0x0000, 0x0100, 0x0200, 0x0300, 0x0400, 0x0500, 0x0600, 0x0700, 0x0800, 0x0900, 0x0A00, 0x0B00, 0x0C00, 0x0D00, 0x0E00, 0x0F00,
/* 1 */0x1000, 0x1100, 0x1200, 0x1300, 0x1400, 0x1500, 0x1600, 0x1700, 0x1800, 0x1900, 0x1A00, 0x1B00, 0x1C00, 0x1D00, 0x1E00, 0x1F00,
/* 2 */0x2000, 0x2100, 0x2200, 0x2300, 0x2400, 0x2500, 0x2600, 0x2700, 0x2800, 0x2900, 0x2A00, 0x2B00, 0x2C00, 0x2D00, 0x2E00, 0x2F00,
/* 7 */0x5000, 0x5100, 0x5200, 0x5300, 0x5400, 0x5500, 0x5600, 0x5700, 0x5800, 0x5900, 0x5A00, 0x7B00, 0x7C00, 0x7D00, 0x7E00, 0x7F00,
// range 0x80 to 0xd8 gets mapped...
/* 8 */0x4108, 0x410C, 0x4310, 0x4502, 0x4E0A, 0x4F08, 0x5508, 0x4182, 0x4104, 0x4186, 0x4108, 0x410A, 0x410C, 0x4310, 0x4502, 0x4584,
/* 9 */0x4586, 0x4588, 0x4982, 0x4984, 0x4986, 0x4988, 0x4E0A, 0x4F82, 0x4F84, 0x4F86, 0x4F08, 0x4F0A, 0x5582, 0x5584, 0x5586, 0x5508,
/* A */0xA000, 0xA100, 0xA200, 0xA300, 0xA400, 0xA500, 0xA600, 0x5382, 0xA800, 0xA900, 0xAA00, 0xAB00, 0xAC00, 0xAD00, 0x4114, 0x4F0E,
/* E */0xE000, 0xE100, 0xE200, 0xE300, 0xE400, 0xE500, 0xE600, 0xE700, 0xE800, 0xE900, 0xEA00, 0xEB00, 0xEC00, 0xED00, 0xEE00, 0xEF00,
/* F */0xF000, 0xF100, 0xF200, 0xF300, 0xF400, 0xF500, 0xF600, 0xF700, 0xF800, 0xF900, 0xFA00, 0xFB00, 0xFC00, 0xFD00, 0xFE00, 0xFF00,
};
#else /* ! UNCOMPRESSED */
enum {
kTypeLiteral = 0,
kTypeAscending = 1,
kTypeAscending256 = 2
enum
{
kTypeLiteral= 0,
kTypeAscending= 1,
kTypeAscending256= 2
};
struct compressed_block {
unsigned char type;
unsigned char count;
unsigned short data;
struct compressed_block
{
unsigned char type;
unsigned char count;
unsigned short data;
};
unsigned short *gLowerCaseTable;
trunk/i386/libsaio/device_tree.c
2727
2828
2929
30
30
31
3132
3233
3334
3435
3536
3637
37
38
39
3840
3941
4042
......
6668
6769
6870
69
71
72
7073
7174
7275
......
122125
123126
124127
125
128
129
126130
127
131
132
133
128134
129135
130136
......
196202
197203
198204
205
199206
200207
201208
......
281288
282289
283290
284
291
292
285293
286294
287295
......
326334
327335
328336
329
337
338
330339
331340
332341
......
421430
422431
423432
424
433
425434
426435
427436
......
547556
548557
549558
550
551
552
559
560
561
562
563
564
565
566
567
553568
554569
555
570
571
572
573
574
575
576
577
556578
557
558
579
559580
560
561
562
563
564581
565582
566583
#define kPropNameLength 32
typedef struct DeviceTreeNodeProperty {
typedef struct DeviceTreeNodeProperty
{
char name[kPropNameLength]; // NUL terminated property name
unsigned long length; // Length (bytes) of folloing prop value
// unsigned long value[1]; // Variable length value of property
// Padded to a multiple of a longword?
} DeviceTreeNodeProperty;
typedef struct OpaqueDTEntry {
typedef struct OpaqueDTEntry
{
unsigned long nProperties; // Number of props[] elements (0 => end)
unsigned long nChildren; // Number of children[] elements
// DeviceTreeNodeProperty props[];// array size == nProperties
#define RoundToLong(x)(((x) + 3) & ~3)
static struct _DTSizeInfo {
static struct _DTSizeInfo
{
uint32_tnumNodes;
uint32_tnumProperties;
uint32_ttotalPropertySize;
prop->value = value;
// Always add to end of list
if (node->properties == 0) {
if (node->properties == 0)
{
node->properties = prop;
} else {
}
else
{
node->last_prop->next = prop;
}
}
DTInfo.numNodes++;
DT__AddProperty(node, "name", strlen(name) + 1, (void *) name);
return node;
DeviceTreeNodeProperty *flatProp;
int count;
if (node == 0) {
if (node == 0)
{
return buffer;
}
DPRINTF("DT__FlattenDeviceTree(0x%x, 0x%x)\n", buffer_p, length);
#if DEBUG
if (buffer_p) {
if (buffer_p)
{
DT__PrintTree(rootNode);
}
#endif
int i;
DPRINTF("DT__FindNode('%s', %d)\n", path, createIfMissing);
// Start at root
node = rootNode;
void *prop;
int propSize;
if (level > 9) level = 9;
while (level--) *cp++ = ' ';
*cp = '\0';
if (level > 9)
{
level = 9;
}
while (level--)
{
*cp++ = ' ';
}
*cp = '\0';
printf("%s===Entry %p===\n", spaces, entry);
if (kSuccess != DTCreatePropertyIterator(entry, &propIter))
if (kSuccess != DTCreatePropertyIterator(entry, &propIter))
{
printf("Couldn't create property iterator\n");
return;
}
while( kSuccess == DTIterateProperties( propIter, &name))
{
if( kSuccess != DTGetProperty( entry, name, &prop, &propSize ))
{
printf("Couldn't create property iterator\n");
return;
continue;
}
while( kSuccess == DTIterateProperties( propIter, &name))
{
if( kSuccess != DTGetProperty( entry, name, &prop, &propSize ))
continue;
printf("%s Property %s = %s\n", spaces, name, prop);
}
DTDisposePropertyIterator(propIter);
trunk/i386/libsaio/hfs.c
105105
106106
107107
108
109
108
110109
110
111111
112112
113113
......
133133
134134
135135
136
137
138
139
136
137
140138
141
139
140
142141
143142
144143
......
170169
171170
172171
172
173173
174174
175175
176176
177
177178
178179
179180
180181
182
181183
182184
183185
184186
185187
188
186189
187190
188191
189192
190193
194
191195
192196
193197
......
469473
470474
471475
476
472477
473478
474479
......
509514
510515
511516
512
517
518
513519
514
520
521
522
515523
516524
517525
......
599607
600608
601609
602
610
603611
604612
605613
......
609617
610618
611619
620
612621
613622
614623
......
677686
678687
679688
689
680690
681691
682692
......
784794
785795
786796
797
787798
788799
789800
......
794805
795806
796807
808
797809
798810
799811
......
987999
9881000
9891001
990
1002
9911003
9921004
9931005
......
10481060
10491061
10501062
1063
10511064
10521065
10531066
10541067
10551068
1069
10561070
10571071
10581072
......
11621176
11631177
11641178
1165
11661179
11671180
11681181
......
12781291
12791292
12801293
1281
1294
12821295
12831296
12841297
......
13691382
13701383
13711384
1372
1385
13731386
13741387
13751388
13761389
1377
1378
1379
13801390
13811391
13821392
......
14151425
14161426
14171427
1418
1428
14191429
14201430
static long CompareHFSPlusExtentsKeys(void *key, void *testKey);
extern long FastRelString(u_int8_t *str1, u_int8_t *str2);
extern long BinaryUnicodeCompare(u_int16_t *uniStr1, u_int32_t len1,
u_int16_t *uniStr2, u_int32_t len2);
extern long BinaryUnicodeCompare(u_int16_t *uniStr1, u_int32_t len1, u_int16_t *uniStr2, u_int32_t len2);
//==============================================================================
static void SwapFinderInfo(FndrFileInfo *dst, FndrFileInfo *src)
bool HFSProbe (const void *buf)
{
const HFSMasterDirectoryBlock *mdb;
const HFSPlusVolumeHeader *header;
mdb = (const HFSMasterDirectoryBlock *)(((const char*)buf)+kMDBBaseOffset);
header = (const HFSPlusVolumeHeader *)(((const char*)buf)+kMDBBaseOffset);
const HFSMasterDirectoryBlock *mdb = (const HFSMasterDirectoryBlock *)(((const char*)buf)+kMDBBaseOffset);
const HFSPlusVolumeHeader *header = (const HFSPlusVolumeHeader *)(((const char*)buf)+kMDBBaseOffset);
if ( SWAP_BE16(mdb->drSigWord) == kHFSSigWord ) {
if ( SWAP_BE16(mdb->drSigWord) == kHFSSigWord )
{
return true;
}
{
gTempStr = (char *)malloc(4096);
}
if (!gLinkTemp)
{
gLinkTemp = (char *)malloc(64);
}
if (!gBTreeHeaderBuffer)
{
gBTreeHeaderBuffer = (char *)malloc(512);
}
if (!gHFSMdbVib)
{
gHFSMdbVib = (char *)malloc(kBlockSize);
gHFSMDB = (HFSMasterDirectoryBlock *)gHFSMdbVib;
}
if (!gHFSPlusHeader)
{
gHFSPlusHeader = (char *)malloc(kBlockSize);
gHFSPlus = (HFSPlusVolumeHeader *)gHFSPlusHeader;
}
if (!gTempStr || !gLinkTemp || !gBTreeHeaderBuffer || !gHFSMdbVib || !gHFSPlusHeader)
{
return -1;
long result, flags;
u_int32_t dirID;
void *extents;
HFSCatalogFile *hfsFile = (void *)entry;
HFSPlusCatalogFile *hfsPlusFile = (void *)entry;
return -1;
}
if (gIsHFSPlus) {
if (gIsHFSPlus)
{
extents = &hfsPlusFile->dataFork.extents;
} else {
}
else
{
extents = &hfsFile->dataExtents;
}
long valid = 0;
// Get information about the file.
switch ( SWAP_BE16(*(short *)entry) )
{
case kHFSFolderRecord :
case kHFSPlusFolderRecord :
*flags = kFileTypeDirectory | (SWAP_BE16(((HFSPlusCatalogFolder *)entry)->bsdInfo.fileMode) & kPermMask);
if (SWAP_BE32(((HFSPlusCatalogFolder *)entry)->bsdInfo.ownerID) != 0)
{
*flags |= kOwnerNotRoot;
// Copy the file name to gTempStr
cnt = 0;
while ((filePath[cnt] != '/') && (filePath[cnt] != '\0'))
{
cnt++;
gTempStr[((HFSCatalogKey *)testKey)->nodeName[0]] = '\0';
}
*name = gTempStr;
// Update dirIndex.
index = 0;
curNode = SWAP_BE32(node->fLink);
}
*dirIndex = (long long) curNode * nodeSize + index;
free(nodeBuf);
index = upperBound;
GetBTreeRecord(index, nodeBuf, nodeSize, &testKey, &recordData);
}
// Found the closest key... Recurse on it if this is an index node.
if (node->kind == kBTIndexNode)
{
if (dirIndex != 0)
{
index++;
if (index == SWAP_BE16(node->numRecords))
{
index = 0;
curNode = SWAP_BE32(node->fLink);
}
*dirIndex = (long long) curNode * nodeSize + index;
}
readOffset = ((blockNumber - countedBlocks) * gBlockSize) + (offset % gBlockSize);
// MacWen: fix overflow in multiplication by forcing 64bit multiplication
readSize = (long long)GetExtentSize(currentExtent, 0) * gBlockSize - readOffset;
if (readSize > (size - sizeRead))
{
result = 1;
}
else if (searchParentID < trialParentID)
else if (searchParentID < trialParentID)
{
result = -1;
}
{
HFSPlusExtentKey*searchKey, *trialKey;
longresult;
longresult = -1; // assume searchKey < trialKey
searchKey = key;
trialKey = testKey;
// assume searchKey < trialKey
result = -1;
if (searchKey->fileID == trialKey->fileID)
{
// FileNum's are equal; compare fork types
}
}
return result;
return result;
}
trunk/i386/libsaio/device_tree.h
3131
3232
3333
34
34
35
3536
3637
3738
......
4142
4243
4344
44
45
46
4547
4648
4749
4850
4951
5052
53
5154
52
53
55
5456
55
56
57
5758
58
59
59
6060
61
62
61
6362
64
65
63
6664
67
68
65
6966
70
71
67
7268
73
74
75
76
7769
70
7871
79
80
72
8173
82
83
84
85
8674
//==============================================================================
typedef struct _Property {
typedef struct _Property
{
const char *name;
uint32_tlength;
void *value;
//==============================================================================
typedef struct _Node {
typedef struct _Node
{
struct _Property *properties;
struct _Property *last_prop;
struct _Node *children;
struct _Node *next;
} Node;
extern Property *DT__AddProperty(Node *node, const char *name, uint32_t length, void *value);
extern Property *
DT__AddProperty(Node *node, const char *name, uint32_t length, void *value);
extern Node *DT__AddChild(Node *parent, const char *name);
extern Node *
DT__AddChild(Node *parent, const char *name);
Node *DT__FindNode(const char *path, bool createIfMissing);
Node *
DT__FindNode(const char *path, bool createIfMissing);
extern void DT__FreeProperty(Property *prop);
extern void
DT__FreeProperty(Property *prop);
extern void DT__FreeNode(Node *node);
extern void
DT__FreeNode(Node *node);
extern char *DT__GetName(Node *node);
extern char *
DT__GetName(Node *node);
extern Property *DT__GetProperty(Node *node, const char *name);
extern Property *
DT__GetProperty(Node *node, const char *name);
void DT__Initialize(void);
void
DT__Initialize(void);
// Free up memory used by in-memory representation of device tree.
extern void DT__Finalize(void);
extern void
DT__Finalize(void);
void DT__FlattenDeviceTree(void **result, uint32_t *length);
void
DT__FlattenDeviceTree(void **result, uint32_t *length);
#endif /* __DEVICE_TREE_H */
trunk/i386/libsaio/hfs_compare.c
1818
1919
2020
21
22
23
2421
25
22
2623
27
24
25
26
2827
2928
3029
......
3231
3332
3433
35
36
34
3735
38
39
40
41
36
4237
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
5976
6077
61
62
78
6379
64
65
80
81
82
6683
67
84
6885
69
86
7087
7188
7289
7390
74
7591
92
7693
7794
7895
7996
8097
8198
82
99
83100
84101
85102
......
94111
95112
96113
114
97115
116
98117
118
99119
120
100121
101122
102123
......
118139
119140
120141
142
121143
144
122145
123146
147
124148
149
125150
126151
127152
......
192217
193218
194219
195
196
220
197221
198222
199223
......
202226
203227
204228
205
229
230
206231
207232
208233
209234
210235
211
236
237
212238
239
213240
241
214242
243
215244
245
246
216247
217248
218249
219250
220251
221252
222
253
254
223255
256
224257
258
225259
260
226261
262
227263
228
229
264
265
266
267
230268
231269
232
270
271
233272
234
235
236
273
274
275
276
277
278
237279
238280
239281
282
240283
284
241285
286
242287
288
243289
244290
245291
......
247293
248294
249295
250
251
296
252297
253
254
255
298
299
300
256301
257
302
303
304
305
306
307
308
309
310
311
312
313
314
315
258316
259
260
261
262
263
264
265
266
267
317
318
319
320
268321
269
270
271
322
323
324
325
272326
273
274
275
276
277
327
328
329
330
331
278332
279
333
280334
281335
282336
......
287341
288342
289343
290
344
291345
292346
293347
......
307361
308362
309363
310
311
364
312365
313366
314367
315368
316369
317370
318
371
372
319373
374
320375
321
376
377
378
322379
380
323381
324
382
383
325384
385
326386
387
388
327389
328
390
391
392
393
329394
330395
331
396
397
398
332399
400
333401
334
335
402
336403
337
404
405
406
407
408
338409
410
339411
340
341
342
412
413
414
415
416
343417
344418
345419
......
364438
365439
366440
367
441
442
368443
444
369445
446
370447
371
372
448
449
450
373451
374
452
375453
376
377
378
379
454
455
456
457
458
459
460
461
380462
381463
382464
383
384
385
386
387
388
389
390
391
392
393
465
466
467
468
469
470
471
472
473
474
475
394476
395
396
397
477
478
479
480
481
398482
399
400
401
402
403
483
484
485
486
487
404488
405489
406
490
407491
492
408493
409
494
410495
496
497
411498
412
413
414
499
500
501
502
503
504
505
415506
416507
417
418
419
420
508
509
510
511
512
513
514
515
421516
* under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/
/*
* HFSCompare.c - Functions for working with and comparing HFS nams.
*
* Copyright (c) 1999-2000 Apple Computer, Inc.
* HFSCompare.c - Functions for working with and comparing HFS nams.
*
* DRI: Josh de Cesare
* Copyright (c) 1999-2000 Apple Computer, Inc.
*
* DRI: Josh de Cesare
*/
#include <sl.h>
#if ! UNCOMPRESSED
static unsigned short *
UncompressStructure(struct compressed_block *bp, int count, int size)
static unsigned short *UncompressStructure(struct compressed_block *bp, int count, int size)
{
unsigned short *out = malloc(size);
unsigned short *op = out;
unsigned short data;
int i, j;
int i, j;
for (i=0; i<count; i++, bp++) {
// If this happens (it shouldn't) please fix size and/or double check that count really is
// the number of elements in the array.
// This was a very hard bug to find, so please leave this code here.
if(out + size <= op + bp->count)
{
stop("HFS+ Unicode tables are malformed\n");
}
data = bp->data;
for (j=0; j<bp->count; j++) {
*op++ = data;
if (bp->type == kTypeAscending) data++;
else if (bp->type == kTypeAscending256) data += 256;
}
}
return out;
unsigned short *out = malloc(size);
if (out)
{
unsigned short *op = out;
unsigned short data;
for (i = 0; i < count; i++, bp++)
{
// If this happens (it shouldn't) please fix size and/or double check that count really is
// the number of elements in the array.
// This was a very hard bug to find, so please leave this code here.
if(out + size <= op + bp->count)
{
stop("HFS+ Unicode tables are malformed\n");
}
data = bp->data;
for (j = 0; j < bp->count; j++)
{
*op++ = data;
if (bp->type == kTypeAscending)
{
data++;
}
else if (bp->type == kTypeAscending256)
{
data += 256;
}
}
}
return out;
}
return NULL;
}
static void
InitCompareTables(void)
static void InitCompareTables(void)
{
if (gCompareTable == 0) {
gCompareTable = UncompressStructure(gCompareTableCompressed,
if (gCompareTable == 0)
{
gCompareTable = UncompressStructure(gCompareTableCompressed,
kCompareTableNBlocks, kCompareTableDataSize);
gLowerCaseTable = UncompressStructure(gLowerCaseTableCompressed,
gLowerCaseTable = UncompressStructure(gLowerCaseTableCompressed,
kLowerCaseTableNBlocks, kLowerCaseTableDataSize);
}
}
}
#endif /* ! UNCOMPRESSED */
//_______________________________________________________________________
//
//
//Routine:FastRelString
//
//Output:returns -1 if str1 < str2
//returns 1 if str1 > str2
//return 0 if equal
//
//_______________________________________________________________________
//
int32_tFastRelString(u_int8_t * str1, u_int8_t * str2)
{
length2 = *(str2++);
if (length == length2)
{
bestGuess = 0;
}
else if (length < length2)
{
bestGuess = -1;
}
else
{
bestGuess = 1;
bSortWord = gCompareTable[bChar];
if (aSortWord > bSortWord)
{
return 1;
}
if (aSortWord < bSortWord)
{
return -1;
}
}
/*
//return 1;
//
int32_t FastUnicodeCompare( u_int16_t * str1, register u_int32_t length1,
u_int16_t * str2, register u_int32_t length2, int byte_order )
int32_t FastUnicodeCompare( u_int16_t * str1, register u_int32_t length1, u_int16_t * str2, register u_int32_t length2, int byte_order )
{
register u_int16_t c1,c2;
register u_int16_t temp;
InitCompareTables();
#endif
while (1) {
while (1)
{
/* Set default values for c1, c2 in case there are no more valid chars */
c1 = 0;
c2 = 0;
/* Find next non-ignorable char from str1, or zero if no more */
while (length1 && c1 == 0) {
while (length1 && c1 == 0)
{
if (byte_order == OSBigEndian)
{
c1 = SWAP_BE16(*(str1++));
}
else
{
c1 = SWAP_LE16(*(str1++));
}
--length1;
if ((temp = gLowerCaseTable[c1>>8]) != 0)// is there a subtable for this upper byte?
c1 = gLowerCaseTable[temp + (c1 & 0x00FF)];// yes, so fold the char
}
/* Find next non-ignorable char from str2, or zero if no more */
while (length2 && c2 == 0) {
while (length2 && c2 == 0)
{
if (byte_order == OSBigEndian)
{
c2 = SWAP_BE16(*(str2++));
}
else
{
c2 = SWAP_LE16(*(str2++));
}
--length2;
if ((temp = gLowerCaseTable[c2>>8]) != 0)// is there a subtable for this upper byte?
c2 = gLowerCaseTable[temp + (c2 & 0x00FF)];// yes, so fold the char
if ((temp = gLowerCaseTable[c2>>8]) != 0)// Is there a subtable for this upper byte?
{
c2 = gLowerCaseTable[temp + (c2 & 0x00FF)];// Yes, so fold the char
}
}
if (c1 != c2)/* found a difference, so stop looping */
if (c1 != c2)/* Found a difference, so stop looping */
{
break;
if (c1 == 0)/* did we reach the end of both strings at the same time? */
return 0;/* yes, so strings are equal */
}
if (c1 == 0)/* Did we reach the end of both strings at the same time? */
{
return 0;/* Yes, so strings are equal */
}
}
if (c1 < c2)
{
return -1;
}
else
{
return 1;
}
}
// BinaryUnicodeCompare - Compare two Unicode strings; produce a relative ordering
// Compared using a 16-bit binary comparison (no case folding)
//
int32_t BinaryUnicodeCompare (u_int16_t * str1, u_int32_t length1,
u_int16_t * str2, u_int32_t length2)
int32_t BinaryUnicodeCompare(u_int16_t * str1, u_int32_t length1, u_int16_t * str2, u_int32_t length2)
{
register u_int16_t c1, c2;
int32_t bestGuess;
u_int32_t length;
register u_int16_t c1, c2;
int32_t bestGuess = 0;
u_int32_t length;
bestGuess = 0;
if (length1 < length2)
{
length = length1;
--bestGuess;
}
else if (length1 > length2)
{
length = length2;
++bestGuess;
}
else
{
length = length1;
}
if (length1 < length2) {
length = length1;
--bestGuess;
} else if (length1 > length2) {
length = length2;
++bestGuess;
} else {
length = length1;
}
while (length--)
{
c1 = *(str1++);
c2 = *(str2++);
while (length--) {
c1 = *(str1++);
c2 = *(str2++);
if (c1 > c2)
{
return (1);
}
if (c1 > c2)
return (1);
if (c1 < c2)
return (-1);
}
if (c1 < c2)
{
return (-1);
}
}
return (bestGuess);
return (bestGuess);
}
* requires a maximum of three 3 bytes per UCS-2 character. Only the
* shortest encoding required to represent the significant UCS-2 bits
* is legal.
*
*
* UTF-8 Multibyte Codes
*
* Bytes Bits UCS-2 Min UCS-2 Max UTF-8 Byte Sequence (binary)
* bufsize is the size of the output buffer in bytes
*/
void
utf_encodestr( const u_int16_t * ucsp, int ucslen,
u_int8_t * utf8p, u_int32_t bufsize, int byte_order )
utf_encodestr( const u_int16_t * ucsp, int ucslen, u_int8_t * utf8p, u_int32_t bufsize, int byte_order )
{
u_int8_t *bufend;
u_int16_t ucs_ch;
bufend = utf8p + bufsize;
while (ucslen-- > 0) {
while (ucslen-- > 0)
{
if (byte_order == OSBigEndian)
{
ucs_ch = SWAP_BE16(*ucsp++);
else
}
else
{
ucs_ch = SWAP_LE16(*ucsp++);
}
if (ucs_ch < 0x0080) {
if (ucs_ch < 0x0080)
{
if (utf8p >= bufend)
{
break;
}
if (ucs_ch == '\0')
continue;/* skip over embedded NULLs */
{
continue;/* Skip over embedded NULLs */
}
*utf8p++ = ucs_ch;
} else if (ucs_ch < 0x800) {
}
else if (ucs_ch < 0x800)
{
if ((utf8p + 1) >= bufend)
{
break;
*utf8p++ = (ucs_ch >> 6) | 0xc0;
*utf8p++ = (ucs_ch & 0x3f) | 0x80;
}
} else {
*utf8p++ = ((ucs_ch >> 6) | 0xc0);
*utf8p++ = ((ucs_ch & 0x3f) | 0x80);
}
else
{
if ((utf8p + 2) >= bufend)
{
break;
*utf8p++ = (ucs_ch >> 12) | 0xe0;
*utf8p++ = ((ucs_ch >> 6) & 0x3f) | 0x80;
*utf8p++ = ((ucs_ch) & 0x3f) | 0x80;
}
*utf8p++ = ((ucs_ch >> 12) | 0xe0);
*utf8p++ = (((ucs_ch >> 6) & 0x3f) | 0x80);
*utf8p++ = ((ucs_ch & 0x3f) | 0x80);
}
}
bufstart = ucsp;
bufend = (u_int16_t *)((u_int8_t *)ucsp + bufsize);
while ((byte = *utf8p++) != '\0') {
while ((byte = *utf8p++) != '\0')
{
if (ucsp >= bufend)
{
break;
}
/* check for ascii */
if (byte < 0x80) {
/* Check for ASCII */
if (byte < 0x80)
{
ucs_ch = byte;
if (byte_order == OSBigEndian)
*ucsp++ = SWAP_BE16(ucs_ch);
else
*ucsp++ = SWAP_LE16(ucs_ch);
{
*ucsp++ = SWAP_BE16(ucs_ch);
}
else
{
*ucsp++ = SWAP_LE16(ucs_ch);
}
continue;
}
switch (byte & 0xf0) {
/* 2 byte sequence*/
case 0xc0:
case 0xd0:
/* extract bits 6 - 10 from first byte */
ucs_ch = (byte & 0x1F) << 6;
break;
/* 3 byte sequence*/
case 0xe0:
/* extract bits 12 - 15 from first byte */
ucs_ch = (byte & 0x0F) << 6;
switch (byte & 0xf0)
{
/* 2 byte sequence */
case 0xc0:
case 0xd0:/* Extract bits 6 - 10 from first byte */
ucs_ch = ((byte & 0x1F) << 6);
break;
/* 3 byte sequence */
case 0xe0:
/* Extract bits 12 - 15 from first byte */
ucs_ch = ((byte & 0x0F) << 6);
/* extract bits 6 - 11 from second byte */
if (((byte = *utf8p++) & 0xc0) != 0x80)
goto stop;
/* Extract bits 6 - 11 from second byte */
if (((byte = *utf8p++) & 0xc0) != 0x80)
{
goto stop;
}
ucs_ch += (byte & 0x3F);
ucs_ch <<= 6;
break;
default:
goto stop;
ucs_ch += (byte & 0x3F);
ucs_ch <<= 6;
break;
default:
goto stop;
}
/* extract bits 0 - 5 from final byte */
/* Extract bits 0 - 5 from final byte */
if (((byte = *utf8p++) & 0xc0) != 0x80)
{
goto stop;
ucs_ch += (byte & 0x3F);
}
ucs_ch += (byte & 0x3F);
if (byte_order == OSBigEndian)
*ucsp++ = SWAP_BE16(ucs_ch);
else
*ucsp++ = SWAP_LE16(ucs_ch);
{
*ucsp++ = SWAP_BE16(ucs_ch);
}
else
{
*ucsp++ = SWAP_LE16(ucs_ch);
}
}
stop:
if (byte_order == OSBigEndian)
*ucslen = SWAP_BE16(ucsp - bufstart);
else
*ucslen = SWAP_LE16(ucsp - bufstart);
if (byte_order == OSBigEndian)
{
*ucslen = SWAP_BE16(ucsp - bufstart);
}
else
{
*ucslen = SWAP_LE16(ucsp - bufstart);
}
}
trunk/i386/libsaio/libsaio.h
2121
2222
2323
24
2524
2625
2726
*
* @APPLE_LICENSE_HEADER_END@
*/
/* libsaio.h */
#ifndef __LIBSAIO_LIBSAIO_H
#define __LIBSAIO_LIBSAIO_H
trunk/i386/libsaio/bios.h
3131
3232
3333
34
35
36
37
38
39
34
35
36
37
38
39
40
41
42
4043
4144
4245
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
5863
5964
60
61
62
63
64
65
66
67
68
69
70
71
72
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
7380
7481
7582
......
8289
8390
8491
85
92
93
8694
8795
8896
......
95103
96104
97105
98
99
100
101
102
106
107
108
109
110
111
103112
104113
105114
#include "bootargs.h"
typedef union {
unsigned int rx;
unsigned short rr;
struct {
unsigned char l;
unsigned char h;
typedef union
{
unsigned intrx;
unsigned shortrr;
struct
{
unsigned charl;
unsigned charh;
} r;
} machineRegister_t;
typedef struct {
unsigned short cf :1;
unsigned short :1;
unsigned short pf :1;
unsigned short :1;
unsigned short af :1;
unsigned short :1;
unsigned short zf :1;
unsigned short sf :1;
unsigned short tf :1;
unsigned short _if :1;
unsigned short df :1;
unsigned short of :1;
unsigned short iopl:2;
unsigned short nt :1;
typedef struct
{
unsigned short cf: 1;
unsigned short: 1;
unsigned short pf: 1;
unsigned short: 1;
unsigned short af: 1;
unsigned short: 1;
unsigned short zf: 1;
unsigned short sf: 1;
unsigned short tf: 1;
unsigned short _if: 1;
unsigned short df: 1;
unsigned short of: 1;
unsigned short iopl: 2;
unsigned short nt: 1;
} machineFlags_t;
typedef struct {
unsigned int intno;
machineRegister_t eax;
machineRegister_t ebx;
machineRegister_t ecx;
machineRegister_t edx;
machineRegister_t edi;
machineRegister_t esi;
machineRegister_t ebp;
unsigned short cs;
unsigned short ds;
unsigned short es;
machineFlags_t flags;
typedef struct
{
unsigned intintno;
machineRegister_teax;
machineRegister_tebx;
machineRegister_tecx;
machineRegister_tedx;
machineRegister_tedi;
machineRegister_tesi;
machineRegister_tebp;
unsigned shortcs;
unsigned shortds;
unsigned shortes;
machineFlags_tflags;
} biosBuf_t;
#define EBIOS_FIXED_DISK_ACCESS0x01
/*
* ACPI defined memory range types.
*/
enum {
enum
{
kMemoryRangeUsable = 1, // RAM usable by the OS.
kMemoryRangeReserved = 2, // Reserved. (Do not use)
kMemoryRangeACPI = 3, // ACPI tables. Can be reclaimed.
/*
* Memory range descriptor.
*/
typedef struct MemoryRange {
unsigned long long base; // 64-bit base address
unsigned long long length; // 64-bit length in bytes
unsigned long type; // type of memory range
unsigned long reserved;
typedef struct MemoryRange
{
unsigned long longbase;// 64-bit base address
unsigned long longlength;// 64-bit length in bytes
unsigned longtype;// type of memory range
unsigned longreserved;
} MemoryRange;
#endif /* !__LIBSAIO_BIOS_H */
trunk/i386/libsaio/load.c
3232
3333
3434
35
35
3636
37
37
3838
3939
4040
......
4444
4545
4646
47
47
4848
4949
5050
......
182182
183183
184184
185
185186
186
187187
188188
189189
......
193193
194194
195195
196
196197
197198
198199
......
257258
258259
259260
260
261
261262
262263
263264
......
288289
289290
290291
292
293
291294
292295
293296
#include <sl.h>
#if DEBUG
#define DBG(x...)printf(x)
#define DBG(x...)printf(x)
#else
#define DBG(x...)msglog(x)
#define DBG(x...)msglog(x)
#endif
static long DecodeSegment(long cmdBase, unsigned int*load_addr, unsigned int *load_size);
static unsigned long gBinaryAddress;
bool gHaveKernelCache;/* XXX aserebln: uninitialized? and only set to true, never to false */
cpu_type_t archCpuType=CPU_TYPE_I386;
cpu_type_t archCpuType = CPU_TYPE_I386;
//==============================================================================
switch (cmd)
{
case LC_SEGMENT:
case LC_SEGMENT_64:
case LC_SEGMENT:
ret = DecodeSegment(cmdBase, &load_addr, &load_size);
if (ret == 0 && load_size != 0 && load_addr >= KERNEL_ADDR)
}
break;
case LC_MAIN:/* Mountain Lion's replacement for LC_UNIXTHREAD */
case LC_UNIXTHREAD:
ret = DecodeUnixThread(cmdBase, &entry);
break;
struct segment_command_64 *segCmd;
segCmd = (struct segment_command_64 *)cmdBase;
vmaddr = (segCmd->vmaddr & 0x3fffffff);
vmsize = segCmd->vmsize;
vmsize = segCmd->vmsize;
fileaddr = (gBinaryAddress + segCmd->fileoff);
filesize = segCmd->filesize;
segname = segCmd->segname;
#endif
}
//===================================================
if (vmsize == 0 || filesize == 0)
{
*load_addr = ~0;
trunk/i386/libsaio/platform.h
417417
418418
419419
420
420
421
422
423
424
425
426
427
428
421429
422430
423431
......
430438
431439
432440
433
434
435
436
437
438
439
440441
441442
442443
} CPU;
struct RAM {
struct DMI
{
intMaxMemorySlots;// number of memory slots populated by SMBIOS
intCntMemorySlots;// number of memory slots counted
intMemoryModules;// number of memory modules installed
intDIMM[MAX_RAM_SLOTS];// Information and SPD mapping for each slot
} DMI;
struct RAM
{
uint64_tFrequency;// Ram Frequency
uint32_tDivider;// Memory divider
uint8_tCAS;// CAS 1/2/2.5/3/4/5/6/7
RamSlotInfo_tDIMM[MAX_RAM_SLOTS];// Information about each slot
} RAM;
struct DMI {
intMaxMemorySlots;// number of memory slots populated by SMBIOS
intCntMemorySlots;// number of memory slots counted
intMemoryModules;// number of memory modules installed
intDIMM[MAX_RAM_SLOTS];// Information and SPD mapping for each slot
} DMI;
uint8_tType;// system-type: 1=Desktop, 2=Portable, 3=Workstation... according ACPI2.0 (FACP: PM_Profile)
uint8_t*UUID;// system-id (SMBIOS Table 1: system uuid)
uint32_tHWSignature;// machine-signature (FACS: Hardware Signature)
trunk/i386/libsaio/disk.c
233233
234234
235235
236
237
236
238237
239238
240239
......
328327
329328
330329
331
330
332331
333332
334333
......
368367
369368
370369
371
370
372371
373372
373
374374
375375
376376
//==========================================================================
static const char *getNameForValue( const struct NamedValue *nameTable,
unsigned char value )
static const char *getNameForValue( const struct NamedValue *nameTable, unsigned char value )
{
const struct NamedValue *np;
{
if (rc == ECC_CORRECTED_ERR)
{
rc = 0; /* Ignore corrected ECC errors */
rc = 0; // Ignore corrected ECC errors
break;
}
{
if (rc == ECC_CORRECTED_ERR)
{
rc = 0; /* Ignore corrected ECC errors */
rc = 0; // Ignore corrected ECC errors
break;
}
error(" BIOS read error: %s\n", bios_error(rc), rc);
error(" Block %d, Cyl %d Head %d Sector %d\n", secno, cyl, head, sec);
sleep(1);
trunk/i386/libsaio/biosfn.c
242242
243243
244244
245
246
247
245
246
248247
249248
250249
......
252251
253252
254253
255
256
257
254
258255
259
256
257
260258
261259
262260
263261
264
262
263
265264
266265
267266
......
271270
272271
273272
274
273
274
275275
276276
277277
278278
279
280
281279
280
281
282
282283
283284
284285
......
294295
295296
296297
297
298
299
298300
299301
300302
......
336338
337339
338340
339
341
342
340343
341344
342345
......
396399
397400
398401
399
402
403
400404
401405
402406
......
409413
410414
411415
412
416
417
413418
414419
415420
416421
417
422
423
418424
419425
420426
......
422428
423429
424430
431
425432
426433
427434
......
432439
433440
434441
435
442
443
436444
437445
438446
......
443451
444452
445453
446
454
455
447456
448457
449458
......
457466
458467
459468
460
469
470
461471
462472
463
473
464474
465
475
476
466477
467478
468479
......
521532
522533
523534
524
525
526
527
528
535
536
537
538
539
529540
530541
531542
......
549560
550561
551562
552
563
564
553565
554566
555567
......
591603
592604
593605
594
595
596
597
598
606
607
608
599609
610
600611
601612
602613
......
683694
684695
685696
686
697
698
687699
688700
689701
690
691
702
703
704
692705
693706
694707
......
700713
701714
702715
703
716
717
704718
705719
706
720
721
722
707723
708724
709725
710726
711727
712
728
729
713730
714731
715732
......
729746
730747
731748
732
749
733750
734751
735752
......
745762
746763
747764
748
765
766
749767
750768
751769
......
759777
760778
761779
762
780
781
763782
764783
765784
// Check for errors.
if ( bb.flags.cf
|| bb.eax.rx != kMemoryMapSignature
|| bb.ecx.rx != kDescriptorSizeMin ) {
if ( bb.flags.cf || bb.eax.rx != kMemoryMapSignature || bb.ecx.rx != kDescriptorSizeMin )
{
//printf("Got an error %x %x %x\n", bb.flags.cf,
// bb.eax.rx, bb.ecx.rx);
break;
// Tally up the conventional/extended memory sizes.
if ( range->type == kMemoryRangeUsable ||
range->type == kMemoryRangeACPI ||
range->type == kMemoryRangeNVS ) {
if ( range->type == kMemoryRangeUsable || range->type == kMemoryRangeACPI || range->type == kMemoryRangeNVS ) {
// Tally the conventional memory ranges.
if ( range->base + range->length <= 0xa0000 ) {
if ( range->base + range->length <= 0xa0000 )
{
conMemSize += range->length;
}
// Record the top of extended memory.
if (range->base >= EXTENDED_ADDR) {
if (range->base >= EXTENDED_ADDR)
{
extMemSize += range->length;
}
}
// Is this the last address range?
if ( bb.ebx.rx == 0 ) {
if ( bb.ebx.rx == 0 )
{
//printf("last range\n");
break;
}
}
*conMemSizePtr = conMemSize / 1024; // size in KB
*extMemSizePtr = extMemSize / 1024; // size in KB
*conMemSizePtr = (conMemSize / 1024); // size in KB
*extMemSizePtr = (extMemSize / 1024); // size in KB
#if MEMRANGE
rerangedCount = rerangeMemoryMap(count);
range += rerangedCount - count;
getchar();
for (i = 0, range = rangeArray; i<count; i++, range++) {
for (i = 0, range = rangeArray; i<count; i++, range++)
{
printf("range: type %d, base 0x%x, length 0x%x\n",
range->type, (unsigned int)range->base, (unsigned int)range->length);
getchar();
// Return the size of memory above 1MB (extended memory) in kilobytes.
if (bb.flags.cf == 0) {
if (bb.flags.cf == 0)
{
return (bb.ebx.rr * 64 + bb.eax.rr);
}
bb.intno = 0x13;
sec += 1; // sector numbers start at 1.
for (i = 0; ;) {
for (i = 0; ;)
{
bb.ecx.r.h = cyl;
bb.ecx.r.l = ((cyl & 0x300) >> 2) | (sec & 0x3F);
bb.edx.r.h = head;
bios(&bb);
// In case of a successful call, make sure we set AH (return code) to zero.
if (bb.flags.cf == 0) {
if (bb.flags.cf == 0)
{
bb.eax.r.h = 0;
}
// Now we can really check for the return code (AH) value.
if ((bb.eax.r.h == 0x00) || (i++ >= 5)) {
if ((bb.eax.r.h == 0x00) || (i++ >= 5))
{
break;
}
bb.eax.r.h = 0x00;
bios(&bb);
}
return bb.eax.r.h;
}
{
int i;
static struct {
static struct
{
unsigned char size;
unsigned char reserved;
unsigned char numblocks;
} addrpacket __attribute__((aligned(16))) = {0};
addrpacket.size = sizeof(addrpacket);
for (i = 0; ;) {
for (i = 0; ;)
{
bb.intno = 0x13;
bb.eax.r.h = 0x42;
bb.edx.r.l = dev;
bios(&bb);
// In case of a successful call, make sure we set AH (return code) to zero.
if (bb.flags.cf == 0) {
if (bb.flags.cf == 0)
{
bb.eax.r.h = 0;
}
// Now we can really check for the return code (AH) value.
if ((bb.eax.r.h == 0x00) || (i++ >= 5)) {
if ((bb.eax.r.h == 0x00) || (i++ >= 5))
{
break;
}
void bios_putchar(int ch)
{
bb.intno = 0x10;
bb.ebx.r.h = 0x00; /* background black */
bb.ebx.r.l = 0x0F; /* foreground white */
bb.eax.r.h = 0x0e;
bb.eax.r.l = ch;
bb.intno= 0x10;
bb.ebx.r.h= 0x00; /* background black */
bb.ebx.r.l= 0x0F; /* foreground white */
bb.eax.r.h= 0x0e;
bb.eax.r.l= ch;
bios(&bb);
}
int is_no_emulation(int drive)
{
struct packet {
struct packet
{
unsigned char packet_size;
unsigned char media_type;
unsigned char drive_num;
/* Some BIOSes erroneously return cf = 1 */
/* Just check to see if the drive number is the same. */
if (pkt.drive_num == drive) {
if ((pkt.media_type & 0x0F) == 0) {
/* We are in no-emulation mode. */
return 1;
}
if (pkt.drive_num == drive && (pkt.media_type & 0x0F) == 0)
{
return 1; // We are in no-emulation mode.
}
return 0;
}
bb.ebx.rr = 0x55aa;
bios(&bb);
if ((bb.ebx.rr == 0xaa55) && (bb.flags.cf == 0)) {
if ((bb.ebx.rr == 0xaa55) && (bb.flags.cf == 0))
{
/* Get flags for supported operations. */
dp->uses_ebios = bb.ecx.r.l;
}
if (dp->uses_ebios & (EBIOS_ENHANCED_DRIVE_INFO | EBIOS_LOCKING_ACCESS | EBIOS_FIXED_DISK_ACCESS)) {
if (dp->uses_ebios & (EBIOS_ENHANCED_DRIVE_INFO | EBIOS_LOCKING_ACCESS | EBIOS_FIXED_DISK_ACCESS))
{
/* Get EBIOS drive info. */
static struct drive_params params;
bb.ds = NORMALIZED_SEGMENT((unsigned)&params);
bios(&bb);
if (bb.flags.cf != 0 /* || params.phys_sectors < 2097152 */) {
if (bb.flags.cf != 0 /* || params.phys_sectors < 2097152 */)
{
dp->uses_ebios = 0;
di->params.buf_size = 1;
} else {
}
else
{
bcopy(&params, &di->params, sizeof(params));
if (drive >= BASE_HD_DRIVE &&
(dp->uses_ebios & EBIOS_ENHANCED_DRIVE_INFO) &&
di->params.buf_size >= 30 &&
!(di->params.dpte_offset == 0xFFFF && di->params.dpte_segment == 0xFFFF)) {
!(di->params.dpte_offset == 0xFFFF && di->params.dpte_segment == 0xFFFF))
{
void *ptr = (void *)(di->params.dpte_offset + ((unsigned int)di->params.dpte_segment << 4));
bcopy(ptr, &di->dpte, sizeof(di->dpte));
}
//unsigned long cyl;
//unsigned long sec;
//unsigned long hds;
//
//
//hds = bb.edx.r.h;
//sec = bb.ecx.r.l & 0x3F;
//if ((dp->uses_ebios & EBIOS_ENHANCED_DRIVE_INFO) && (sec != 0)) {
//}
//}
if (dp->no_emulation) {
if (dp->no_emulation)
{
/* Some BIOSes give us erroneous EBIOS support information.
* Assume that if you're on a CD, then you can use
* EBIOS disk calls.
pause();
#endif
if (ret == 0) {
if (ret == 0)
{
dp->valid = 1;
}
return ret;
trunk/i386/libsaio/saio_types.h
3434
3535
3636
37
37
3838
39
39
4040
4141
4242
......
5757
5858
5959
60
60
61
6162
6263
6364
6465
6566
66
67
67
6868
6969
7070
7171
7272
7373
74
74
75
7576
7677
7778
......
8081
8182
8283
83
84
8485
8586
8687
......
123124
124125
125126
126
127
127
128128
129129
130130
......
218218
219219
220220
221
221222
222223
223224
#include "bootargs.h"
#if DEBUG
#define DEBUG_DISK(x) printf x
#define DEBUG_DISK(x) printf x
#else
#define DEBUG_DISK(x)
#define DEBUG_DISK(x)
#endif
typedef unsigned long entry_t;
int totalDrives;
};
struct Tag {
typedef struct Tag
{
longtype;
char *string;
longoffset;
struct Tag *tag;
struct Tag *tagNext;
};
typedef struct Tag Tag, *TagPtr;
} Tag, *TagPtr;
/*
* Max size fo config data array, in bytes.
*/
#define IO_CONFIG_DATA_SIZE40960 // was 4096 // was 163840
typedef struct {
typedef struct
{
charplist[IO_CONFIG_DATA_SIZE];// buffer for plist
TagPtrdictionary;// buffer for xml dictionary
boolcanOverride;// flag to mark a dictionary can be overriden
/*
* BIOS drive information.
*/
struct boot_drive_info
typedef struct boot_drive_info
{
struct drive_params
{
unsigned char revision;
unsigned char checksum;
} dpte __attribute__((packed));
} __attribute__((packed));
typedef struct boot_drive_info boot_drive_info_t;
} __attribute__((packed)) boot_drive_info_t;
struct driveInfo
enum
{
kBVFlagZero= 0x00,
kBVFlagPrimary= 0x01,
kBVFlagNativeBoot= 0x02,
kBVFlagForeignBoot= 0x04,
trunk/i386/libsaio/fake_efi.c
654654
655655
656656
657
657
658658
659659
660660
const char *boardid = getStringForKey("SMboardproduct", &bootInfo->smbiosConfig);
if (boardid)
{
DT__AddProperty(node, BOARDID_PROP, strlen(boardid)+1, (EFI_CHAR16*)boardid);
DT__AddProperty(node, BOARDID_PROP, strlen(boardid)+1, (EFI_CHAR16 *)boardid);
}
}
trunk/i386/libsaio/saio_internal.h
202202
203203
204204
205
205206
206207
207208
u_int32_t * time, FinderInfo *finderInfo, long *infoValid);
extern void flushdev(void);
extern void scanBootVolumes(int biosdev, int *count);
extern void scanDisks(int biosdev, int *count);
extern BVRef selectBootVolume(BVRef chain);
extern void getBootVolumeDescription(BVRef bvr, char *str, long strMaxLen, bool verbose);
trunk/i386/boot2/graphics.c
780780
781781
782782
783
784
785
786
787
783
788784
785
786
787
788
789
789790
790791
791792
......
810811
811812
812813
813
814
814815
815816
816817
......
828829
829830
830831
831
832
833
832
833
834
834835
835836
836837
......
878879
879880
880881
881
882
883
884
882
883
884
885
885886
886
887
887888
888889
889890
unsigned long lookUpCLUTIndex( unsigned char index, unsigned char depth )
{
long result, red, green, blue;
red = appleClut8[index * 3 + 0];
green = appleClut8[index * 3 + 1];
blue = appleClut8[index * 3 + 2];
long result;
long colorIndex = (index * 3);
long red = appleClut8[ colorIndex ];
long green = appleClut8[ colorIndex++ ];
long blue = appleClut8[ colorIndex++ ];
switch (depth) {
case 16 :
result = ((red & 0xF8) << 7) |
//==========================================================================
// drawColorRectangle
void * stosl(void * dst, long val, long len)
void *stosl(void *dst, long val, long len)
{
asm volatile ( "rep; stosl"
: "=c" (len), "=D" (dst)
unsigned short height,
unsigned char colorIndex )
{
long pixelBytes;
long color = lookUpCLUTIndex( colorIndex, VIDEO(depth) );
char * vram;
longpixelBytes;
longcolor = lookUpCLUTIndex( colorIndex, VIDEO(depth) );
char*vram;
pixelBytes = VIDEO(depth) / 8;
vram = (char *) VIDEO(baseAddr) + VIDEO(rowBytes) * y + pixelBytes * x;
void loadImageScale (void *input, int iw, int ih, int ip, void *output, int ow, int oh, int op, int or)
{
int x,y, off;
int red=0x7f, green=0x7f, blue=0x7f;
for (x=0;x<ow;x++)
for (y=0;y<oh;y++)
int x, y, off;
int red = 0x7f, green = 0x7f, blue = 0x7f;
for ( x = 0; x < ow; x++)
for ( y = 0; y < oh; y++ )
{
off=(x*iw)/ow+((y*ih)/oh)*iw;
off = ( x * iw ) / ow +( ( y * ih ) / oh ) * iw;
switch (ip)
{
case 16:
trunk/i386/boot2/gui.c
23342334
23352335
23362336
2337
2337
2338
23382339
2339
2340
2341
2342
23402343
23412344
23422345
23432346
2344
2347
2348
23452349
2346
2350
2351
2352
23472353
23482354
2349
2355
2356
2357
23502358
2351
2359
2360
2361
23522362
23532363
23542364
......
23632373
23642374
23652375
2366
2376
2377
23672378
23682379
23692380
2370
2381
2382
23712383
2372
2384
2385
2386
23732387
23742388
23752389
2376
2390
2391
2392
23772393
23782394
23792395
23802396
23812397
2382
2398
2399
2400
23832401
23842402
23852403
......
23872405
23882406
23892407
2390
2408
2409
23912410
2392
2411
2412
23932413
23942414
23952415
bool legacy_logo;
uint16_t x, y;
if (getBoolForKey("Legacy Logo", &legacy_logo, &bootInfo->chameleonConfig) && legacy_logo) {
if (getBoolForKey("Legacy Logo", &legacy_logo, &bootInfo->chameleonConfig) && legacy_logo)
{
usePngImage = false;
} else if (bootImageData == NULL) {
}
else if (bootImageData == NULL)
{
loadBootGraphics();
}
// parse screen size parameters
if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig) && pos > 0) {
if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig) && pos > 0)
{
screen_params[0] = pos;
} else {
}
else
{
screen_params[0] = DEFAULT_SCREEN_WIDTH;
}
if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig) && pos > 0) {
if (getIntForKey("boot_height", &pos, &bootInfo->themeConfig) && pos > 0)
{
screen_params[1] = pos;
} else {
}
else
{
screen_params[1] = DEFAULT_SCREEN_HEIGHT;
}
getGraphicModeParams(screen_params);
// Set graphics mode if the booter was in text mode or the screen resolution has changed.
if (bootArgs->Video.v_display == VGA_TEXT_MODE || (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) ) {
if (bootArgs->Video.v_display == VGA_TEXT_MODE || (screen_params[0] != oldScreenWidth && screen_params[1] != oldScreenHeight) )
{
setVideoMode(GRAPHICS_MODE, 0);
}
if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->chameleonConfig)) {
if (getValueForKey("-checkers", &dummyVal, &length, &bootInfo->chameleonConfig))
{
drawCheckerBoard();
} else {
}
else
{
// Fill the background to 75% grey (same as BootX).
drawColorRectangle(0, 0, screen_params[0], screen_params[1], 0x01);
}
if ((bootImageData) && (usePngImage)) {
if ((bootImageData) && (usePngImage))
{
x = (screen_params[0] - MIN(bootImageWidth, screen_params[0])) / 2;
y = (screen_params[1] - MIN(bootImageHeight, screen_params[1])) / 2;
// Draw the image in the center of the display.
blendImage(x, y, bootImageWidth, bootImageHeight, bootImageData);
} else {
}
else
{
uint8_t *appleBootPict;
bootImageData = NULL;
bootImageWidth = kAppleBootWidth;
// Prepare the data for the default Apple boot image.
appleBootPict = (uint8_t *) decodeRLE(gAppleBootPictRLE, kAppleBootRLEBlocks, bootImageWidth * bootImageHeight);
if (appleBootPict) {
if (appleBootPict)
{
convertImage(bootImageWidth, bootImageHeight, appleBootPict, &bootImageData);
if (bootImageData) {
if (bootImageData)
{
x = (screen_params[0] - MIN(kAppleBootWidth, screen_params[0])) / 2;
y = (screen_params[1] - MIN(kAppleBootHeight, screen_params[1])) / 2;
drawDataRectangle(x, y, kAppleBootWidth, kAppleBootHeight, bootImageData);
trunk/i386/libsa/string.c
117117
118118
119119
120
121
120122
121
122
123
123124
124
125
126
127
125
126
127
128
129
130
131
128132
129133
130134
131
132
135
136
137
138
133139
134
140
141
135142
136143
137144
145
138146
139147
140148
......
220228
221229
222230
231
232
233
223234
224235
225236
226237
227238
239
228240
241
229242
243
230244
231
245
246
247
248
249
250
232251
233252
234253
254
255
256
235257
236258
237259
260
238261
262
239263
240
264
265
266
267
241268
242269
243270
......
373400
374401
375402
376
377
378
403
404
405
379406
380407
381408
/*#endif*/
//==========================================================================
/* NOTE: Moved from ntfs.c */
int
memcmp(const void *p1, const void *p2, size_t len)
int memcmp(const void *p1, const void *p2, size_t len)
{
while (len--) {
if (*(const char*)(p1++) != *(const char*)(p2++))
return -1;
}
while (len--)
{
if (*(const char*)(p1++) != *(const char*)(p2++))
{
return -1;
}
}
return 0;
}
int
strcmp(const char * s1, const char * s2)
//==========================================================================
int strcmp(const char * s1, const char * s2)
{
while (*s1 && (*s1 == *s2)) {
while (*s1 && (*s1 == *s2))
{
s1++;
s2++;
}
return (*s1 - *s2);
}
return (char *) (in - 1);
}
//==========================================================================
int ptol(const char *str)
{
register int c = *str;
if (c <= '7' && c >= '0')
{
c -= '0';
}
else if (c <= 'h' && c >= 'a')
{
c -= 'a';
else c = 0;
}
else
{
c = 0;
}
return c;
}
//==========================================================================
int atoi(const char *str)
{
register int sum = 0;
while (*str == ' ' || *str == '\t')
{
str++;
while (*str >= '0' && *str <= '9') {
}
while (*str >= '0' && *str <= '9')
{
sum *= 10;
sum += *str++ - '0';
}
/* COPYRIGHT NOTICE: checksum8 from AppleSMBIOS */
uint8_t checksum8( void *start, unsigned int length )
{
uint8_t csum = 0;
uint8_t * cp = (uint8_t *) start;
unsigned int i;
uint8_tcsum = 0;
uint8_t*cp = (uint8_t *) start;
unsigned int i;
for ( i = 0; i < length; i++)
{
trunk/i386/libsa/prf.c
5656
5757
5858
59
60
59
6160
6261
6362
* Printn prints a number n in base b.
* We don't use recursion to avoid deep kernel stacks.
*/
static void
printn(n, b, flag, minwidth, putfn_p, putfn_arg)
static void printn(n, b, flag, minwidth, putfn_p, putfn_arg)
u_long n;
int b, flag, minwidth;
void (*putfn_p)();
trunk/i386/libsa/strtol.c
9797
9898
9999
100
100
101
102
101103
102104
103
105
106
107
104108
105109
106
110
111
112
107113
108114
109115
110
116
117
111118
112119
113120
114
121
122
123
115124
116125
117126
118127
119
128
129
130
120131
121132
122133
......
137148
138149
139150
151
140152
141153
142154
143
144
155
156
157
158
159
145160
146
161
162
163
147164
148
165
166
167
149168
150169
151
170
171
172
152173
153174
154
175
176
177
155178
156
179
180
181
157182
158183
159184
160185
161186
162
187
188
189
163190
164
165
191
192
193
166194
167
195
196
197
198
168199
169200
201
170202
171203
172204
......
192224
193225
194226
195
227
228
196229
197230
198
231
232
233
199234
200235
201
236
237
238
202239
203240
204
241
242
243
205244
206245
207246
208
247
248
249
209250
210251
211252
212253
213
254
255
256
214257
215258
259
216260
217261
218
219
262
263
264
265
266
220267
221
268
269
270
222271
223
272
273
274
224275
225276
226
277
278
279
227280
228281
229
282
283
284
230285
231
286
287
288
232289
233290
234291
235292
236293
237
294
295
296
238297
239
240
298
299
300
241301
242302
243
303
304
305
244306
245307
308
246309
247310
248311
......
268331
269332
270333
271
334
335
336
272337
273338
274
339
340
341
275342
276343
277
344
345
346
278347
279
348
349
350
280351
281352
282353
283
354
355
356
284357
285358
286359
287360
288
361
362
363
289364
290365
366
291367
292368
293369
294
295
370
371
372
373
374
296375
297
376
377
378
298379
299
380
381
382
300383
301384
302
385
386
387
303388
304389
305
390
391
392
306393
307
394
395
396
308397
309398
310399
311400
312401
313
402
403
404
314405
315
316
406
407
408
317409
318410
319
411
412
413
320414
321415
416
322417
323418
* If base is 0, allow 0x for hex and 0 for octal, else
* assume decimal; if base is already 16, allow 0x.
*/
do {
do
{
c = *s++;
} while (isspace(c));
if (c == '-') {
if (c == '-')
{
neg = 1;
c = *s++;
} else if (c == '+') {
}
else if (c == '+')
{
c = *s++;
}
if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')) {
if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X'))
{
c = s[1];
s += 2;
base = 16;
} else if ((base == 0 || base == 2) && c == '0' && (*s == 'b' || *s == 'B')) {
}
else if ((base == 0 || base == 2) && c == '0' && (*s == 'b' || *s == 'B'))
{
c = s[1];
s += 2;
base = 2;
}
if (base == 0) {
if (base == 0)
{
base = c == '0' ? 8 : 10;
}
* Set any if any `digits' consumed; make it negative to indicate
* overflow.
*/
cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX;
cutlim = cutoff % (unsigned long)base;
cutoff /= (unsigned long)base;
for (acc = 0, any = 0;; c = *s++) {
if (isdigit(c)) {
for (acc = 0, any = 0;; c = *s++)
{
if (isdigit(c))
{
c -= '0';
} else if (isalpha(c)) {
}
else if (isalpha(c))
{
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
} else {
}
else
{
break;
}
if (c >= base) {
if (c >= base)
{
break;
}
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) {
if ((any < 0 || acc > cutoff) || (acc == cutoff && c > cutlim))
{
any = -1;
} else {
}
else
{
any = 1;
acc *= base;
acc += c;
}
}
if (any < 0) {
if (any < 0)
{
acc = neg ? LONG_MIN : LONG_MAX;
//errno = ERANGE;
} else if (neg)
}
else if (neg)
{
acc = -acc;
if (endptr != 0) {
}
if (endptr != 0)
{
*endptr = (char *)(any ? s - 1 : nptr);
}
return (acc);
}
/*
* See strtol for comments as to the logic used.
*/
do {
do
{
c = *s++;
} while (isspace(c));
if (c == '-') {
if (c == '-')
{
neg = 1;
c = *s++;
} else if (c == '+') {
}
else if (c == '+')
{
c = *s++;
}
if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')){
if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X'))
{
c = s[1];
s += 2;
base = 16;
} else if ((base == 0 || base == 2) && c == '0' && (*s == 'b' || *s == 'B')) {
}
else if ((base == 0 || base == 2) && c == '0' && (*s == 'b' || *s == 'B'))
{
c = s[1];
s += 2;
base = 2;
}
if (base == 0) {
if (base == 0)
{
base = c == '0' ? 8 : 10;
}
cutoff = (unsigned long)ULONG_MAX / (unsigned long)base;
cutlim = (unsigned long)ULONG_MAX % (unsigned long)base;
for (acc = 0, any = 0;; c = *s++) {
if (isdigit(c)) {
for (acc = 0, any = 0;; c = *s++)
{
if (isdigit(c))
{
c -= '0';
} else if (isalpha(c)) {
}
else if (isalpha(c))
{
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
} else {
}
else
{
break;
}
if (c >= base) {
if (c >= base)
{
break;
}
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) {
if ((any < 0 || acc > cutoff) || (acc == cutoff && c > cutlim))
{
any = -1;
} else {
}
else
{
any = 1;
acc *= base;
acc += c;
}
}
if (any < 0) {
if (any < 0)
{
acc = ULONG_MAX;
//errno = ERANGE;
} else if (neg) {
}
else if (neg)
{
acc = -acc;
}
if (endptr != 0) {
if (endptr != 0)
{
*endptr = (char *)(any ? s - 1 : nptr);
}
return (acc);
}
* See strtoq for comments as to the logic used.
*/
s = nptr;
do {
do
{
c = *s++;
} while (isspace(c));
if (c == '-') {
if (c == '-')
{
neg = 1;
c = *s++;
} else {
}
else
{
neg = 0;
if (c == '+') {
if (c == '+')
{
c = *s++;
}
}
if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')) {
if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X'))
{
c = s[1];
s += 2;
base = 16;
}
if (base == 0) {
if (base == 0)
{
base = c == '0' ? 8 : 10;
}
qbase = (unsigned)base;
cutoff = (unsigned long long)UQUAD_MAX / qbase;
cutlim = (unsigned long long)UQUAD_MAX % qbase;
for (acc = 0, any = 0;; c = *s++) {
if (isdigit(c)) {
for (acc = 0, any = 0;; c = *s++)
{
if (isdigit(c))
{
c -= '0';
} else if (isalpha(c)) {
}
else if (isalpha(c))
{
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
} else {
}
else
{
break;
}
if (c >= base) {
if (c >= base)
{
break;
}
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) {
if ((any < 0 || acc > cutoff) || (acc == cutoff && c > cutlim))
{
any = -1;
} else {
}
else
{
any = 1;
acc *= qbase;
acc += c;
}
}
if (any < 0) {
if (any < 0)
{
acc = UQUAD_MAX;
//errno = ERANGE;
} else if (neg) {
}
else if (neg)
{
acc = -acc;
}
if (endptr != 0) {
if (endptr != 0)
{
*endptr = (char *)(any ? s - 1 : nptr);
}
return (acc);
}

Archive Download the corresponding diff file

Revision: 2734