Chameleon

Chameleon Commit Details

Date:2015-02-21 19:13:53 (4 years 4 months ago)
Author:ErmaC
Commit:2582
Parents: 2581
Message:Typo, indent & define DEBUG.
Changes:
M/trunk/i386/modules/Keylayout/Keylayout.c
M/trunk/i386/boot2/resume.c
M/trunk/i386/boot2/graphics.c
M/trunk/i386/boot2/boot.c
M/trunk/i386/libsa/libsa.h
M/trunk/i386/libsaio/efi.h
M/trunk/i386/libsaio/nvidia_helper.c
M/trunk/i386/libsaio/nvidia.c
M/trunk/i386/boot2/boot.h
M/trunk/i386/libsaio/pci.c
M/trunk/i386/libsaio/vbe.c
M/trunk/i386/libsaio/ati.c
M/trunk/i386/libsa/string.c
M/trunk/i386/libsaio/device_tree.c
M/trunk/i386/libsaio/load.c
M/trunk/i386/libsaio/hfs.c
M/trunk/i386/boot2/drivers.c
M/trunk/i386/modules/Makefile
M/trunk/i386/libsaio/ati.h
M/trunk/i386/boot2/gui.c
M/trunk/i386/libsaio/cpu.c
M/trunk/i386/libsaio/md5c.c
M/trunk/i386/libsaio/platform.h
M/trunk/i386/libsaio/pci_setup.c
M/trunk/i386/boot2/options.c
M/trunk/i386/boot2/graphic_utils.c
M/trunk/i386/libsaio/xml.c

File differences

trunk/i386/libsaio/xml.c
22
33
44
5
5
66
7
7
88
99
1010
1111
1212
13
13
1414
1515
1616
......
1818
1919
2020
21
21
2222
2323
2424
......
3030
3131
3232
33
33
3434
35
35
3636
3737
38
38
3939
4040
4141
......
5555
5656
5757
58
58
5959
60
60
6161
6262
6363
......
127127
128128
129129
130
131
130
132131
133132
134133
135
134
135
136136
137137
138138
......
142142
143143
144144
145
145
146
146147
147148
148149
149
150
151
150152
151153
152154
......
156158
157159
158160
159
160
161
161162
162163
163
164
164
165
166
165167
166168
167169
......
173175
174176
175177
176
178
179
177180
178181
179182
180183
181
184
185
182186
183187
184188
......
188192
189193
190194
191
195
196
192197
193198
194199
......
204209
205210
206211
207
212
213
208214
209215
210216
......
214220
215221
216222
217
223
218224
219225
220
226
227
221228
222229
223
230
224231
225232
226233
227234
228
235
229236
230237
231238
232239
233240
234
241
242
235243
236244
237245
......
243251
244252
245253
246
254
247255
248256
257
249258
250259
251
252
260
253261
254262
255
263
256264
257265
258266
......
269277
270278
271279
272
280
281
273282
274283
275284
......
277286
278287
279288
280
289
290
281291
282292
283293
284294
285295
286296
287
297
298
288299
289300
290301
291302
292
303
304
293305
294306
295307
......
303315
304316
305317
306
307318
308319
309320
......
311322
312323
313324
314
315
325
316326
317
318
319
320
327
328
329
330
321331
322332
323333
324334
335
325336
326337
327338
328339
329
330
331
332
340
341
342
343
333344
334
345
335346
336
337
338
339
340
347
348
349
350
351
352
353
354
355
356
357
358
341359
342
343
344
345
346
360
361
362
363
364
365
347366
348
349367
350368
351369
352370
353
354
371
355372
356
357
373
374
358375
376
377
378
359379
360
380
381
361382
362383
363384
364385
365
386
387
366388
367389
368390
......
371393
372394
373395
374
396
397
398
375399
376
400
401
402
377403
378404
379405
380
406
407
381408
382409
383410
384411
385
412
413
386414
387
415
416
417
388418
389
419
420
390421
391422
392423
393424
394425
395426
396
397
427
428
429
430
398431
399
432
433
434
400435
401436
402437
403438
404439
405440
406
441
407442
408
443
444
445
409446
410447
411448
412449
413450
414451
415
416
452
453
454
455
417456
418
457
458
459
419460
420461
421462
......
430471
431472
432473
433
474
434475
435476
436477
437478
438479
439480
440
481
482
441483
442
443
484
485
486
487
488
444489
445490
446491
447492
448493
449494
450
451
495
496
497
498
452499
453
500
501
502
454503
455504
456505
457506
458507
459508
460
509
461510
462
511
512
513
463514
464515
465516
466517
467518
468519
469
470
520
521
522
523
471524
472
525
526
527
473528
474529
475530
476531
477532
478533
479
534
480535
481536
482537
......
485540
486541
487542
488
543
489544
490545
491
546
547
548
492549
493550
494551
495552
496553
497554
498
555
556
499557
500558
501559
502560
503
561
562
504563
505564
506565
......
511570
512571
513572
514
573
574
515575
516
576
577
578
517579
518
580
581
582
519583
520584
521585
522586
523
587
588
524589
525590
526
591
592
527593
528594
529
595
596
530597
531
598
599
600
532601
533602
534603
535604
536
537
605
606
607
538608
539609
540610
541611
542
612
613
543614
544615
545616
......
549620
550621
551622
552
553
623
554624
555
556
625
626
627
628
629
557630
558
559
560
561
562
631
632
633
634
563635
564
636
637
565638
566639
567640
568641
569642
570643
571
644
645
572646
573647
574648
575649
576650
577651
578
652
653
579654
580655
581656
582657
583658
584659
585
660
661
586662
587663
588664
......
601677
602678
603679
604
605
680
606681
607
608
609
682
683
684
685
686
610687
611688
612
689
690
613691
614692
615693
616694
617
695
696
618697
619698
620699
621700
622
701
702
623703
624704
625705
626706
627707
628
708
709
629710
630711
631712
......
638719
639720
640721
641
722
642723
643724
644725
645726
646727
647728
648
649
729
650730
651
652
731
732
653733
654734
655
735
736
656737
657738
658739
659740
660
741
742
661743
662744
663
745
664746
665
747
748
666749
667750
668751
......
670753
671754
672755
756
673757
674
675758
676759
677760
......
680763
681764
682765
683
684
766
685767
686768
687769
......
704786
705787
706788
707
789
708790
709
791
792
710793
711794
712795
713796
714797
715
798
799
716800
717801
718802
719803
720
804
805
721806
722
723
724
807
808
809
810
725811
726
812
813
814
727815
728
816
817
818
729819
730
820
821
822
731823
732824
733825
734826
735827
736828
737
738
829
830
831
832
833
739834
740835
741836
742837
743838
744
745
746
839
840
841
842
843
844
747845
748846
749847
......
772870
773871
774872
775
776
873
777874
778
779
780
875
876
877
878
781879
782880
783
881
882
883
884
784885
785886
786
887
888
889
890
787891
788892
789893
790894
791895
792
896
793897
794898
899
795900
796901
902
797903
798904
799905
......
804910
805911
806912
807
808
913
809914
810
811
915
916
812917
813918
814
919
920
921
922
815923
816924
817
925
926
927
928
818929
819930
820931
......
822933
823934
824935
936
825937
826
827938
828939
829940
......
833944
834945
835946
836
837
947
838948
839949
840950
841951
842
952
953
954
955
843956
844957
845958
846959
960
847961
848
849962
850963
851964
......
855968
856969
857970
858
859
971
860972
861
973
974
862975
863
976
977
864978
865979
866980
867981
868982
869
870
983
984
985
986
987
988
989
871990
872991
873992
874993
875
876
994
995
996
997
998
999
1000
8771001
8781002
8791003
8801004
8811005
8821006
883
1007
1008
8841009
8851010
8861011
......
8931018
8941019
8951020
896
897
1021
8981022
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
9151048
9161049
9171050
......
9211054
9221055
9231056
924
925
1057
9261058
927
928
1059
1060
9291061
930
931
932
933
934
935
936
937
938
939
940
941
942
943
1062
1063
1064
1065
1066
1067
1068
9441069
945
946
1070
1071
1072
1073
1074
1075
1076
1077
1078
9471079
948
949
950
951
1080
1081
1082
1083
1084
1085
1086
9521087
9531088
9541089
9551090
9561091
957
958
1092
9591093
9601094
961
1095
1096
9621097
9631098
9641099
965
1100
1101
9661102
9671103
9681104
......
9921128
9931129
9941130
995
1131
9961132
9971133
9981134
9991135
10001136
10011137
1002
1003
1138
10041139
10051140
1006
10071141
1142
1143
10081144
10091145
10101146
1011
1012
1147
1148
1149
10131150
1014
1151
1152
10151153
10161154
10171155
......
10271165
10281166
10291167
1030
1168
1169
10311170
10321171
10331172
......
10381177
10391178
10401179
1041
1042
1180
10431181
10441182
10451183
10461184
10471185
10481186
1049
1187
1188
10501189
10511190
10521191
10531192
10541193
10551194
1056
1195
1196
10571197
10581198
10591199
10601200
1061
1201
1202
10621203
1063
1204
1205
1206
10641207
10651208
10661209
......
10721215
10731216
10741217
1075
1076
1218
10771219
10781220
1079
1221
10801222
10811223
10821224
1083
1084
1225
1226
1227
1228
10851229
10861230
10871231
......
10891233
10901234
10911235
1092
1236
1237
10931238
10941239
10951240
......
10981243
10991244
11001245
1101
1246
1247
11021248
11031249
11041250
......
11121258
11131259
11141260
1115
1261
1262
11161263
11171264
1118
1265
1266
1267
11191268
11201269
11211270
......
11341283
11351284
11361285
1137
1286
1287
11381288
11391289
1140
1290
1291
1292
11411293
1142
1294
1295
1296
11431297
11441298
11451299
......
11491303
11501304
11511305
1152
1306
11531307
1154
1308
1309
11551310
11561311
11571312
1158
1313
1314
11591315
11601316
11611317
11621318
11631319
11641320
1165
1321
11661322
1167
1323
1324
11681325
11691326
11701327
1171
1328
1329
11721330
11731331
11741332
......
11791337
11801338
11811339
1182
1340
1341
11831342
1184
1343
1344
1345
11851346
11861347
11871348
......
11931354
11941355
11951356
1196
1357
1358
11971359
11981360
1199
1361
1362
1363
12001364
12011365
12021366
......
12091373
12101374
12111375
1212
1376
1377
12131378
12141379
12151380
1216
1381
1382
1383
12171384
12181385
12191386
12201387
12211388
1222
1389
12231390
1224
1391
1392
12251393
12261394
12271395
......
12291397
12301398
12311399
1232
1400
1401
12331402
12341403
12351404
12361405
1237
1406
1407
12381408
12391409
12401410
......
12461416
12471417
12481418
1249
1419
1420
12501421
12511422
12521423
12531424
12541425
1255
1426
1427
12561428
12571429
12581430
* Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
*
* Portions Copyright (c) 2003 Apple Computer, Inc. All Rights
* Reserved.
* Reserved.
* The contents of this file constitute Original Code as defined in and
* are subject to the Apple Public Source License Version 2.0 (the
* "License"). You may not use this file except in compliance with the
* License. Please obtain a copy of the License at
* http://www.apple.com/publicsource and read it before using this file.
*
*
* This Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
*
*
* @APPLE_LICENSE_HEADER_END@
*/
string_ref *ref_strings = NULL;
/// TODO: remove below
static char* buffer_start = NULL;
static char *buffer_start = NULL;
// TODO: redo the next two functions
void SaveRefString(char* string, int id)
void SaveRefString(char *string, int id)
{
//printf("Adding Ref String %d (%s)\n", id, string);
string_ref* tmp = ref_strings;
string_ref *tmp = ref_strings;
while(tmp)
{
if(tmp->id == id)
ref_strings = new_ref;
}
char* GetRefString(int id)
char *GetRefString(int id)
{
string_ref* tmp = ref_strings;
string_ref *tmp = ref_strings;
while(tmp)
{
if(tmp->id == id) return tmp->string;
//==========================================================================
// XMLGetProperty
TagPtr
XMLGetProperty(TagPtr dict, const char * key)
TagPtr XMLGetProperty(TagPtr dict, const char *key)
{
TagPtr tagList, tag;
if (dict->type != kTagTypeDict) {
if (dict->type != kTagTypeDict)
{
return 0;
}
tag = tagList;
tagList = tag->tagNext;
if ((tag->type != kTagTypeKey) || (tag->string == 0)) {
if ((tag->type != kTagTypeKey) || (tag->string == 0))
{
continue;
}
if (!strcmp(tag->string, key)) {
if (!strcmp(tag->string, key))
{
return tag->tag;
}
}
//==========================================================================
// XMLGetProperty
TagPtr
XMLGetKey( TagPtr dict, int id )
TagPtr XMLGetKey( TagPtr dict, int id )
{
TagPtr tagList, tag;
if (dict->type != kTagTypeDict) {
if (dict->type != kTagTypeDict)
{
return 0;
}
tag = tagList;
tagList = tag->tagNext;
if ((tag->type != kTagTypeKey) || (tag->string == 0)) {
if ((tag->type != kTagTypeKey) || (tag->string == 0))
{
continue;
}
element++;
if(id == element) {
if(id == element)
{
return tag;
}
TagPtr XMLGetValueForKey(TagPtr key)
{
if (!key || key->type != kTagTypeKey) {
if (!key || key->type != kTagTypeKey)
{
return 0;
}
int count = 0;
TagPtr tagList, tag;
if (dict->type != kTagTypeDict && dict->type != kTagTypeArray) {
if (dict->type != kTagTypeDict && dict->type != kTagTypeArray)
{
return 0;
}
{
tag = tagList;
tagList = tag->tagNext;
if (((tag->type != kTagTypeKey) && ((tag->string == 0) || (tag->string[0] == 0)))
&& (dict->type != kTagTypeArray)// If we are an array, any element is valid
) {
)
{
continue;
}
//if(tag->type == kTagTypeKey) printf("Located key %s\n", tag->string);
count++;
}
return count;
}
TagPtr XMLGetElement( TagPtr dict, int id )
{
if(dict->type != kTagTypeArray) {
if(dict->type != kTagTypeArray)
{
return 0;
}
element++;
tmp = tmp->tagNext;
}
return tmp;
}
/* Function for basic XML character entities parsing */
char*
XMLDecode(const char* src)
char *XMLDecode(const char* src)
{
typedef const struct XMLEntity {
const char* name;
const char *name;
size_t nameLen;
char value;
} XMLEntity;
const char *s;
char *out, *o;
if ( !src || !(len = strlen(src)) || !(out = malloc(len+1)) ) {
if ( !src || !(len = strlen(src)) || !(out = malloc(len+1)) )
{
return 0;
}
s = src;
while (s <= src+len) /* Make sure the terminator is also copied */
{
if ( *s == '&' ) {
if ( *s == '&' )
{
bool entFound = false;
int i;
s++;
for ( i = 0; i < sizeof(ents)/sizeof(ents[0]); i++)
{
if ( strncmp(s, ents[i].name, ents[i].nameLen) == 0 ) {
if ( strncmp(s, ents[i].name, ents[i].nameLen) == 0 )
{
entFound = true;
break;
}
}
if ( entFound ) {
if ( entFound )
{
*o++ = ents[i].value;
s += ents[i].nameLen;
return out;
}
//#if UNUSED
//==========================================================================
// XMLParseFile
// Expects to see one dictionary in the XML file, the final pos will be returned
// Puts the first dictionary it finds in the
// tag pointer and returns the end of the dic, or returns -1 if not found.
//
long
XMLParseFile( char * buffer, TagPtr * dict )
long XMLParseFile( char * buffer, TagPtr *dict )
{
long length, pos;
TagPtr tag;
pos = 0;
char *configBuffer;
longlength;
longpos = 0;
TagPtrtag;
char*configBuffer;
int strlength = strlen(buffer);
configBuffer = malloc(strlength+1);
bcopy(buffer, configBuffer, strlength);
configBuffer[strlength] = 0;
buffer_start = configBuffer;
while (1)
{
length = XMLParseNextTag(configBuffer + pos, &tag);
if (length == -1) break;
while (1)
{
length = XMLParseNextTag(configBuffer + pos, &tag);
if (length == -1) break;
pos += length;
pos += length;
if (tag == 0) continue;
if (tag->type == kTagTypeDict) break;
XMLFreeTag(tag);
}
if (tag == 0)
{
continue;
}
if (tag->type == kTagTypeDict)
{
break;
}
XMLFreeTag(tag);
}
free(configBuffer);
if (length < 0) {
return -1;
}
*dict = tag;
return pos;
if (length < 0)
{
return -1;
}
*dict = tag;
return pos;
}
//#endif /* UNUSED */
//==========================================================================
// ParseNextTag
// TODO: cleanup
long
XMLParseNextTag( char * buffer, TagPtr * tag )
long XMLParseNextTag( char *buffer, TagPtr *tag )
{
long length, pos;
char * tagName;
longlength = 0;
longpos = 0;
char*tagName;
length = GetNextTag(buffer, &tagName, 0);
if (length == -1) {
if (length == -1)
{
return -1;
}
pos = length;
if (!strncmp(tagName, kXMLTagPList, 6)) {
if (!strncmp(tagName, kXMLTagPList, 6))
{
length = 0;
// just a header; nothing to parse
// return-via-reference tag should be left alone
else if (!strcmp(tagName, kXMLTagDict))
{
length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0);
} else if (!strncmp(tagName, kXMLTagDict, strlen(kXMLTagDict)) && tagName[strlen(tagName)-1] == '/') {
}
else if (!strncmp(tagName, kXMLTagDict, strlen(kXMLTagDict)) && tagName[strlen(tagName)-1] == '/')
{
length = ParseTagList(buffer + pos, tag, kTagTypeDict, 1);
} else if (!strncmp(tagName, kXMLTagDict " ", strlen(kXMLTagDict " "))) {
}
else if (!strncmp(tagName, kXMLTagDict " ", strlen(kXMLTagDict " ")))
{
length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0);
}
/***** key ****/
else if (!strcmp(tagName, kXMLTagKey)) {
else if (!strcmp(tagName, kXMLTagKey))
{
length = ParseTagKey(buffer + pos, tag);
}
/***** string ****/
else if (!strcmp(tagName, kXMLTagString)) {
else if (!strcmp(tagName, kXMLTagString))
{
length = ParseTagString(buffer + pos, tag);
} else if (!strncmp(tagName, kXMLTagString " ", strlen(kXMLTagString " "))) {
}
else if (!strncmp(tagName, kXMLTagString " ", strlen(kXMLTagString " ")))
{
// TODO: save tag if if found
if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringID, strlen(kXMLStringID))) {
if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringID, strlen(kXMLStringID)))
{
// ID=
int id = 0;
int cnt = strlen(kXMLTagString " " kXMLStringID "\"") + 1;
while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
tagName[cnt] = 0;
char* val = tagName + strlen(kXMLTagString " " kXMLStringID "\"");
while(*val) {
if ((*val >= '0' && *val <= '9')) { // 0 - 9
while(*val)
{
if ((*val >= '0' && *val <= '9'))// 0 - 9
{
id = (id * 10) + (*val++ - '0');
} else {
}
else
{
printf("ParseStringID error (0x%x)\n", *val);
getchar();
return -1;
}
}
length = ParseTagString(buffer + pos, tag);
SaveRefString(buffer + pos, id);
} else if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringIDRef, strlen(kXMLStringIDRef))) {
}
else if(!strncmp(tagName + strlen(kXMLTagString " "), kXMLStringIDRef, strlen(kXMLStringIDRef)))
{
// IDREF=
int id = 0;
int cnt = strlen(kXMLTagString " " kXMLStringIDRef "\"") + 1;
while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
tagName[cnt] = 0;
char* val = tagName + strlen(kXMLTagString " " kXMLStringIDRef "\"");
while(*val) {
if ((*val >= '0' && *val <= '9')) { // 0 - 9
while(*val)
{
if ((*val >= '0' && *val <= '9'))// 0 - 9
{
id = (id * 10) + (*val++ - '0');
} else {
}
else
{
printf("ParseStringIDREF error (0x%x)\n", *val);
getchar();
return -1;
tmpTag->tagNext = 0;
tmpTag->offset = buffer_start ? buffer - buffer_start + pos : 0;
*tag = tmpTag;
length = 0;
//printf("Located IDREF, id = %d, string = %s\n", id, str);
}
}
/***** integer ****/
else if (!strcmp(tagName, kXMLTagInteger)) {
else if (!strcmp(tagName, kXMLTagInteger))
{
length = ParseTagInteger(buffer + pos, tag);
} else if (!strncmp(tagName, kXMLTagInteger " ", strlen(kXMLTagInteger " "))) {
if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringID, strlen(kXMLStringID))) {
}
else if (!strncmp(tagName, kXMLTagInteger " ", strlen(kXMLTagInteger " ")))
{
if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringID, strlen(kXMLStringID)))
{
// ID=
int id = 0;
int cnt = strlen(kXMLTagInteger " " kXMLStringID "\"") + 1;
while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
tagName[cnt] = 0;
char* val = tagName + strlen(kXMLTagInteger " " kXMLStringID "\"");
while(*val) {
if ((*val >= '0' && *val <= '9')) { // 0 - 9
while(*val)
{
if ((*val >= '0' && *val <= '9'))// 0 - 9
{
id = (id * 10) + (*val++ - '0');
} else {
}
else
{
printf("ParseIntegerID error (0x%x)\n", *val);
getchar();
return -1;
}
}
length = ParseTagInteger(buffer + pos, tag);
SaveRefString((*tag)->string, id);
} else if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringIDRef, strlen(kXMLStringIDRef))) {
}
else if(!strncmp(tagName + strlen(kXMLTagInteger " "), kXMLStringIDRef, strlen(kXMLStringIDRef)))
{
// IDREF=
int id = 0;
int cnt = strlen(kXMLTagInteger " " kXMLStringIDRef "\"") + 1;
while ((tagName[cnt] != '\0') && (tagName[cnt] != '"')) cnt++;
tagName[cnt] = 0;
char* val = tagName + strlen(kXMLTagInteger " " kXMLStringIDRef "\"");
while(*val) {
if ((*val >= '0' && *val <= '9')) { // 0 - 9
while(*val)
{
if ((*val >= '0' && *val <= '9'))// 0 - 9
{
id = (id * 10) + (*val++ - '0');
} else {
}
else
{
printf("ParseStringIDREF error (0x%x)\n", *val);
getchar();
return -1;
}
}
int integer = (int)GetRefString(id);
TagPtr tmpTag = NewTag();
tmpTag->type = kTagTypeInteger;
tmpTag->string = (char*) integer;
tmpTag->offset = buffer_start ? buffer - buffer_start + pos : 0;
*tag = tmpTag;
length = 0;
//printf("Located IDREF, id = %d, string = %s\n", id, str);
} else {
}
else
{
length = ParseTagInteger(buffer + pos, tag);
}
}
/***** false ****/
else if (!strcmp(tagName, kXMLTagFalse)) {
else if (!strcmp(tagName, kXMLTagFalse))
{
length = ParseTagBoolean(buffer + pos, tag, kTagTypeFalse);
}
/***** true ****/
else if (!strcmp(tagName, kXMLTagTrue)) {
else if (!strcmp(tagName, kXMLTagTrue))
{
length = ParseTagBoolean(buffer + pos, tag, kTagTypeTrue);
}
/***** data ****/
else if (!strcmp(tagName, kXMLTagData)) {
else if (!strcmp(tagName, kXMLTagData))
{
length = ParseTagData(buffer + pos, tag);
} else if (!strncmp(tagName, kXMLTagData " ", strlen(kXMLTagData " "))) {
}
else if (!strncmp(tagName, kXMLTagData " ", strlen(kXMLTagData " ")))
{
length = ParseTagData(buffer + pos, tag);
} else if (!strcmp(tagName, kXMLTagDate)) {
}
else if (!strcmp(tagName, kXMLTagDate))
{
length = ParseTagDate(buffer + pos, tag);
}
/***** date ****/
else if (!strncmp(tagName, kXMLTagDate " ", strlen(kXMLTagDate " "))) {
else if (!strncmp(tagName, kXMLTagDate " ", strlen(kXMLTagDate " ")))
{
length = ParseTagDate(buffer + pos, tag);
}/***** array ****/
else if (!strcmp(tagName, kXMLTagArray)) {
else if (!strcmp(tagName, kXMLTagArray))
{
length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0);
}
else if (!strncmp(tagName, kXMLTagArray " ", strlen(kXMLTagArray " "))) {
else if (!strncmp(tagName, kXMLTagArray " ", strlen(kXMLTagArray " ")))
{
length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0);
} else if (!strcmp(tagName, kXMLTagArray "/")) {
}
else if (!strcmp(tagName, kXMLTagArray "/"))
{
length = ParseTagList(buffer + pos, tag, kTagTypeArray, 1);
}
/***** unknown ****/
else {
// it wasn't parsed so we consumed no additional characters
else
{
// it wasn't parsed so we consumed no additional characters
*tag = 0;
length = 0;
}
if (length == -1) {
if (length == -1)
{
return -1;
}
//==========================================================================
// ParseTagList
static long
ParseTagList( char * buffer, TagPtr * tag, long type, long empty )
static long ParseTagList( char *buffer, TagPtr *tag, long type, long empty )
{
long length, pos;
TagPtr tagList, tmpTag;
longpos = 0;
longlength = 0;
TagPtrtagList = 0;
TagPtrtmpTag;
tagList = 0;
pos = 0;
if (!empty) {
while (1) {
if (!empty)
{
while (1)
{
length = XMLParseNextTag(buffer + pos, &tmpTag);
if (length == -1) {
if (length == -1)
{
break;
}
pos += length;
// detect end of list
if (tmpTag == 0) {
if (tmpTag == 0)
{
break;
}
tmpTag->tagNext = tagList;
tagList = tmpTag;
}
if (length == -1) {
if (length == -1)
{
XMLFreeTag(tagList);
return -1;
}
}
tmpTag = NewTag();
if (tmpTag == 0) {
if (tmpTag == 0)
{
XMLFreeTag(tagList);
return -1;
}
//==========================================================================
// ParseTagKey
static long
ParseTagKey( char * buffer, TagPtr * tag )
static long ParseTagKey( char *buffer, TagPtr *tag )
{
long length, length2;
char *string;
TagPtr tmpTag, subTag;
longlength = 0;
longlength2 = 0;
char*string;
TagPtrtmpTag;
TagPtrsubTag;
length = FixDataMatchingTag(buffer, kXMLTagKey);
if (length == -1) {
if (length == -1)
{
return -1;
}
length2 = XMLParseNextTag(buffer + length, &subTag);
if (length2 == -1) {
if (length2 == -1)
{
return -1;
}
tmpTag = NewTag();
if (tmpTag == 0) {
if (tmpTag == 0)
{
XMLFreeTag(subTag);
return -1;
}
string = NewSymbol(buffer);
if (string == 0) {
if (string == 0)
{
XMLFreeTag(subTag);
XMLFreeTag(tmpTag);
return -1;
tmpTag->tagNext = 0;
*tag = tmpTag;
return length + length2;
}
//==========================================================================
// ParseTagString
static long
ParseTagString( char * buffer, TagPtr * tag )
static long ParseTagString( char *buffer, TagPtr *tag )
{
long length;
char * string;
longlength = 0;
char*string;
length = FixDataMatchingTag(buffer, kXMLTagString);
if (length == -1) {
if (length == -1)
{
return -1;
}
TagPtr tmpTag = NewTag();
if (tmpTag == 0) {
if (tmpTag == 0)
{
return -1;
}
string = NewSymbol(buffer);
if (string == 0) {
if (string == 0)
{
XMLFreeTag(tmpTag);
return -1;
}
tmpTag->type = kTagTypeString;
tmpTag->string = string;
tmpTag->tag = 0;
tmpTag->tagNext = 0;
tmpTag->offset = buffer_start ? buffer - buffer_start: 0;
tmpTag->tagNext = 0;
*tag = tmpTag;
return length;
//==========================================================================
// ParseTagInteger
static long
ParseTagInteger( char * buffer, TagPtr * tag )
static long ParseTagInteger( char *buffer, TagPtr *tag )
{
long length, integer;
bool negative = false;
return 0;
}
size = length = FixDataMatchingTag(buffer, kXMLTagInteger);
if (length == -1) {
if (length == -1)
{
return -1;
}
tmpTag = NewTag();
if (tmpTag == 0) {
if (tmpTag == 0)
{
return -1;
}
integer = 0;
if(size > 1 && (val[1] == 'x' || val[1] == 'X')) { // Hex value
if(size > 1 && (val[1] == 'x' || val[1] == 'X'))// Hex value
{
val += 2;
while(*val) {
if ((*val >= '0' && *val <= '9')) { // 0 - 9
while(*val)
{
if ((*val >= '0' && *val <= '9'))// 0 - 9
{
integer = (integer * 16) + (*val++ - '0');
} else if ((*val >= 'a' && *val <= 'f')) { // a - f
}
else if ((*val >= 'a' && *val <= 'f'))// a - f
{
integer = (integer * 16) + (*val++ - 'a' + 10);
} else if ((*val >= 'A' && *val <= 'F')) { // A - F
}
else if ((*val >= 'A' && *val <= 'F'))// A - F
{
integer = (integer * 16) + (*val++ - 'A' + 10);
} else {
}
else
{
printf("ParseTagInteger hex error (0x%x) in buffer %s\n", *val, buffer);
getchar();
XMLFreeTag(tmpTag);
return -1;
}
}
} else if ( size ) { // Decimal value
if (*val == '-') {
}
else if ( size )// Decimal value
{
if (*val == '-')
{
negative = true;
val++;
size--;
}
for (integer = 0; size > 0; size--) {
if(*val) { // UGLY HACK, fix me.
if (*val < '0' || *val > '9') {
for (integer = 0; size > 0; size--)
{
if(*val) // UGLY HACK, fix me.
{
if (*val < '0' || *val > '9')
{
printf("ParseTagInteger decimal error (0x%x) in buffer %s\n", *val, buffer);
getchar();
return -1;
//==========================================================================
// ParseTagData
static long
ParseTagData( char * buffer, TagPtr * tag )
static long ParseTagData( char *buffer, TagPtr *tag )
{
int actuallen = 0;
long length;
TagPtr tmpTag;
intactuallen = 0;
longlength = 0;
TagPtrtmpTag;
char*string;
length = FixDataMatchingTag(buffer, kXMLTagData);
if (length == -1) return -1;
if (length == -1)
{
return -1;
}
tmpTag = NewTag();
if (tmpTag == 0) return -1;
if (tmpTag == 0)
{
return -1;
}
//printf("ParseTagData unimplimented\n");
//printf("Data: %s\n", buffer);
//getchar();
char* string = BASE64Decode(buffer, strlen(buffer), &actuallen);
string = BASE64Decode(buffer, strlen(buffer), &actuallen);
tmpTag->type = kTagTypeData;
tmpTag->string = string;
tmpTag->tag = 0;
tmpTag->offset = actuallen; // buffer_start ? buffer - buffer_start: 0;
tmpTag->tagNext = 0;
*tag = tmpTag;
//==========================================================================
// ParseTagDate
static long
ParseTagDate( char * buffer, TagPtr * tag )
static long ParseTagDate( char *buffer, TagPtr *tag )
{
long length;
TagPtr tmpTag;
longlength = 0;
TagPtrtmpTag;
length = FixDataMatchingTag(buffer, kXMLTagDate);
if (length == -1) return -1;
if (length == -1)
{
return -1;
}
tmpTag = NewTag();
if (tmpTag == 0) return -1;
if (tmpTag == 0)
{
return -1;
}
printf("ParseTagDate unimplimented\n");
getchar();
tmpTag->type = kTagTypeDate;
tmpTag->string = 0;
tmpTag->tag = 0;
tmpTag->tagNext = 0;
tmpTag->offset = buffer_start ? buffer - buffer_start: 0;
tmpTag->tagNext = 0;
*tag = tmpTag;
//==========================================================================
// ParseTagBoolean
long
ParseTagBoolean( char * buffer, TagPtr * tag, long type )
long ParseTagBoolean( char *buffer, TagPtr *tag, long type )
{
TagPtr tmpTag;
tmpTag = NewTag();
if (tmpTag == 0) return -1;
if (tmpTag == 0)
{
return -1;
}
tmpTag->type = type;
tmpTag->string = 0;
tmpTag->tag = 0;
tmpTag->tagNext = 0;
tmpTag->offset = buffer_start ? buffer - buffer_start: 0;
tmpTag->tagNext = 0;
*tag = tmpTag;
//==========================================================================
// GetNextTag
static long
GetNextTag( char * buffer, char ** tag, long * start )
static long GetNextTag( char *buffer, char **tag, long *start )
{
long cnt, cnt2;
longcnt;
longcnt2;
if (tag == 0) {
if (tag == 0)
{
return -1;
}
// Find the start of the tag.
cnt = 0;
while ((buffer[cnt] != '\0') && (buffer[cnt] != '<')) cnt++;
if (buffer[cnt] == '\0') {
while ((buffer[cnt] != '\0') && (buffer[cnt] != '<'))
{
cnt++;
}
if (buffer[cnt] == '\0')
{
return -1;
}
// Find the end of the tag.
cnt2 = cnt + 1;
while ((buffer[cnt2] != '\0') && (buffer[cnt2] != '>')) cnt2++;
if (buffer[cnt2] == '\0') {
while ((buffer[cnt2] != '\0') && (buffer[cnt2] != '>'))
{
cnt2++;
}
if (buffer[cnt2] == '\0')
{
return -1;
}
// Fix the tag data.
*tag = buffer + cnt + 1;
buffer[cnt2] = '\0';
if (start) {
if (start)
{
*start = cnt;
}
// Returns the length of the data found, counting the end tag,
// or -1 if the end tag was not found.
static long
FixDataMatchingTag( char * buffer, char * tag )
static long FixDataMatchingTag( char *buffer, char *tag )
{
long length, start, stop;
char * endTag;
start = 0;
while (1)
{
length = GetNextTag(buffer + start, &endTag, &stop);
if (length == -1) return -1;
if ((*endTag == '/') && !strcmp(endTag + 1, tag)) break;
start += length;
}
buffer[start + stop] = '\0';
return start + length;
longlength;
longstart;
longstop;
char*endTag;
start = 0;
while (1)
{
length = GetNextTag(buffer + start, &endTag, &stop);
if (length == -1)
{
return -1;
}
if ((*endTag == '/') && !strcmp(endTag + 1, tag))
{
break;
}
start += length;
}
buffer[start + stop] = '\0';
return start + length;
}
//==========================================================================
static TagPtr gTagsFree;
static TagPtr
NewTag( void )
static TagPtr NewTag( void )
{
long cnt;
TagPtr tag;
longcnt;
TagPtrtag;
if (gTagsFree == 0)
{
tag = (TagPtr)malloc(kTagsPerBlock * sizeof(Tag));
if (tag == 0) return 0;
// Initalize the new tags.
for (cnt = 0; cnt < kTagsPerBlock; cnt++)
{
tag[cnt].type = kTagTypeNone;
tag[cnt].string = 0;
tag[cnt].tag = 0;
tag[cnt].tagNext = tag + cnt + 1;
}
tag[kTagsPerBlock - 1].tagNext = 0;
if (gTagsFree == 0)
{
tag = (TagPtr)malloc(kTagsPerBlock *sizeof(Tag));
if (tag == 0)
{
return 0;
}
gTagsFree = tag;
}
// Initalize the new tags.
for (cnt = 0; cnt < kTagsPerBlock; cnt++)
{
tag[cnt].type = kTagTypeNone;
tag[cnt].string = 0;
tag[cnt].tag = 0;
tag[cnt].tagNext = tag + cnt + 1;
}
tag[kTagsPerBlock - 1].tagNext = 0;
tag = gTagsFree;
gTagsFree = tag->tagNext;
return tag;
gTagsFree = tag;
}
tag = gTagsFree;
gTagsFree = tag->tagNext;
return tag;
}
//==========================================================================
// XMLFreeTag
void
XMLFreeTag( TagPtr tag )
void XMLFreeTag( TagPtr tag )
{
#if DOFREE
if (tag == 0) {
if (tag == 0)
{
return;
}
if (!XMLIsInteger(tag) && tag->string) {
if (!XMLIsInteger(tag) && tag->string)
{
FreeSymbol(tag->string);
}
};
typedef struct Symbol Symbol, *SymbolPtr;
static SymbolPtr FindSymbol(char * string, SymbolPtr * prevSymbol);
static SymbolPtr FindSymbol(char *string, SymbolPtr *prevSymbol);
static SymbolPtr gSymbolsHead;
//==========================================================================
// NewSymbol
static char *
NewSymbol( char * string )
static char *NewSymbol( char *string )
{
static SymbolPtr lastGuy = 0;
SymbolPtr symbol;
SymbolPtrsymbol;
// Look for string in the list of symbols.
symbol = FindSymbol(string, 0);
// Add the new symbol.
if (symbol == 0) {
// Add the new symbol.
if (symbol == 0)
{
symbol = (SymbolPtr)malloc(sizeof(Symbol) + 1 + strlen(string));
if (symbol == 0) { //return 0;
if (symbol == 0)
{//return 0;
stop("NULL symbol!");
}
// Update the refCount and return the string.
symbol->refCount++;
if (lastGuy && lastGuy->next != 0) {
if (lastGuy && lastGuy->next != 0)
{
stop("last guy not last!");
}
// FreeSymbol
#if DOFREE
static void
FreeSymbol( char * string )
static void FreeSymbol( char *string )
{
SymbolPtr symbol, prev;
prev = 0;
// Look for string in the list of symbols.
symbol = FindSymbol(string, &prev);
if (symbol == 0) {
if (symbol == 0)
{
return;
}
// Update the refCount.
symbol->refCount--;
if (symbol->refCount != 0) {
if (symbol->refCount != 0)
{
return;
}
// Remove the symbol from the list.
if (prev != 0) {
if (prev != 0)
{
prev->next = symbol->next;
} else {
}
else
{
gSymbolsHead = symbol->next;
}
//==========================================================================
// FindSymbol
static SymbolPtr
FindSymbol( char * string, SymbolPtr * prevSymbol )
static SymbolPtr FindSymbol( char *string, SymbolPtr *prevSymbol )
{
SymbolPtr symbol, prev;
symbol = gSymbolsHead;
prev = 0;
while (symbol != 0) {
if (!strcmp(symbol->string, string)) {
while (symbol != NULL)
{
if (!strcmp(symbol->string, string))
{
break;
}
symbol = symbol->next;
}
if ((symbol != 0) && (prevSymbol != 0)) {
if ((symbol != 0) && (prevSymbol != 0))
{
*prevSymbol = prev;
}
bool XMLIsType(TagPtr dict, enum xmltype type)
{
if(!dict) {
if(!dict)
{
return (type == kTagTypeNone);
}
return (dict->type == type);
TagPtr XMLCastArray(TagPtr dict)
{
if(!dict) {
if(!dict)
{
return NULL;
}
if(dict->type == kTagTypeArray) {
if(dict->type == kTagTypeArray)
{
return dict;
} else {
return NULL;
TagPtr XMLCastDict(TagPtr dict)
{
if(!dict) {
if(!dict)
{
return NULL;
}
if(dict->type == kTagTypeDict) {
if(dict->type == kTagTypeDict)
{
return dict;
} else {
}
else
{
return NULL;
}
}
return entry && ((entry->type == kTagTypeString) || (entry->type == kTagTypeKey));
}
char* XMLCastString(TagPtr dict)
char *XMLCastString(TagPtr dict)
{
if(!dict) {
if(!dict)
{
return NULL;
}
if((dict->type == kTagTypeString) || (dict->type == kTagTypeKey)) {
if((dict->type == kTagTypeString) || (dict->type == kTagTypeKey))
{
return dict->string;
}
return NULL;
}
char* XMLCastData(TagPtr dict, int* length)
char *XMLCastData(TagPtr dict, int* length)
{
if(!dict) {
if(!dict)
{
return NULL;
}
if((dict->type == kTagTypeData) || (dict->type == kTagTypeKey)) {
if((dict->type == kTagTypeData) || (dict->type == kTagTypeKey))
{
*length = dict->offset;
return dict->string;
}
long XMLCastStringOffset(TagPtr dict)
{
if(dict && ((dict->type == kTagTypeString) || (dict->type == kTagTypeKey))) {
if(dict && ((dict->type == kTagTypeString) || (dict->type == kTagTypeKey)))
{
return dict->offset;
} else {
}
else
{
return -1;
}
}
bool XMLCastBoolean(TagPtr dict)
{
if(!dict) {
if(!dict)
{
return false;
}
if(dict->type == kTagTypeTrue) {
if(dict->type == kTagTypeTrue)
{
return true;
}
return false;
int XMLCastInteger(TagPtr dict)
{
if(!dict) {
if(!dict)
{
//printf("XMLCastInteger: null dict\n");
return 0;
}
if(dict->type == kTagTypeInteger) {
if(dict->type == kTagTypeInteger)
{
return (int)(dict->string);
}
return 0;
}
bool XMLAddTagToDictionary(TagPtr dict, char* key, TagPtr value)
bool XMLAddTagToDictionary(TagPtr dict, char *key, TagPtr value)
{
if (!dict || dict->type != kTagTypeDict) {
if (!dict || dict->type != kTagTypeDict)
{
return false;
}
char* string;
tmpTag = NewTag();
if (tmpTag == 0) {
if (tmpTag == 0)
{
return false;
}
string = NewSymbol(key);
if (string == 0) {
if (string == 0)
{
XMLFreeTag(tmpTag);
return false;
}
tmpTag->tagNext = 0;
TagPtr tagList = dict->tag;
if(!tagList) {
if(!tagList)
{
// First tag
dict->tag = tmpTag;
return true;
}
while(tagList && tagList->tagNext) tagList = tagList->tagNext;
if(tagList) {
if(tagList)
{
tagList->tagNext = tmpTag;
return true;
}
trunk/i386/libsaio/efi.h
254254
255255
256256
257
257
258258
259259
260260
......
262262
263263
264264
265
265
266266
267267
268268
......
281281
282282
283283
284
284
285285
286286
287287
......
290290
291291
292292
293
293
294294
295295
296296
......
301301
302302
303303
304
304
305305
306306
307307
......
318318
319319
320320
321
321
322322
323323
324324
325325
326326
327327
328
328
329329
330330
331331
......
334334
335335
336336
337
337
338338
339339
340340
......
342342
343343
344344
345
345
346346
347347
348348
......
363363
364364
365365
366
366
367367
368368
369369
......
391391
392392
393393
394
394
395395
396396
397397
IN EFI_UINTN DescriptorSize,
IN EFI_UINT32 DescriptorVersion,
IN EFI_MEMORY_DESCRIPTOR * VirtualMap
);
) __attribute__((regparm(0)));
typedef
EFI_RUNTIMESERVICE
(EFIAPI *EFI_CONVERT_POINTER) (
IN EFI_UINTN DebugDisposition,
IN OUT VOID **Address
);
) __attribute__((regparm(0)));
// Variable attributes
OUT EFI_UINT32 * Attributes OPTIONAL,
IN OUT EFI_UINTN * DataSize,
OUT VOID * Data
);
) __attribute__((regparm(0)));
typedef
EFI_RUNTIMESERVICE
IN OUT EFI_UINTN * VariableNameSize,
IN OUT EFI_CHAR16 * VariableName,
IN OUT EFI_GUID * VendorGuid
);
) __attribute__((regparm(0)));
typedef
EFI_RUNTIMESERVICE
IN EFI_UINT32 Attributes,
IN EFI_UINTN DataSize,
IN VOID * Data
);
) __attribute__((regparm(0)));
// EFI Time
(EFIAPI *EFI_GET_TIME) (
OUT EFI_TIME * Time,
OUT EFI_TIME_CAPABILITIES * Capabilities OPTIONAL
);
) __attribute__((regparm(0)));
typedef
EFI_RUNTIMESERVICE
EFI_STATUS
(EFIAPI *EFI_SET_TIME) (
IN EFI_TIME * Time
);
) __attribute__((regparm(0)));
typedef
EFI_RUNTIMESERVICE
OUT EFI_BOOLEAN * Enabled,
OUT EFI_BOOLEAN * Pending,
OUT EFI_TIME * Time
);
) __attribute__((regparm(0)));
typedef
EFI_RUNTIMESERVICE
(EFIAPI *EFI_SET_WAKEUP_TIME) (
IN EFI_BOOLEAN Enable,
IN EFI_TIME * Time OPTIONAL
);
) __attribute((regparm(0)));
typedef enum {
EfiResetCold,
IN EFI_STATUS ResetStatus,
IN EFI_UINTN DataSize,
IN EFI_CHAR16 * ResetData OPTIONAL
);
) __attribute__((regparm(0)));
typedef
EFI_RUNTIMESERVICE
IN EFI_UINT32 Instance,
IN EFI_GUID * CallerId OPTIONAL,
IN EFI_STATUS_CODE_DATA * Data OPTIONAL
);
) __attribute__((regparm(0)));
#endif
//
trunk/i386/libsaio/vbe.c
129129
130130
131131
132
132
133133
134134
135135
#define kC 30.0 // C = (C'-J) * (K/256) + J
#define kM 300.0 // M = K/256 * M'
int Round(double f)
static int Round(double f)
{
return (int)(f + 0.5);
}
trunk/i386/libsaio/device_tree.c
8282
8383
8484
85
86
85
8786
8887
8988
......
143142
144143
145144
146
147
145
148146
149147
150148
......
206204
207205
208206
209
210
207
211208
212209
213210
......
215212
216213
217214
218
219
215
220216
221217
222218
......
224220
225221
226222
227
228
223
229224
230225
231226
......
246241
247242
248243
249
250
244
251245
252246
253247
......
280274
281275
282276
283
284
277
285278
286279
287280
......
325318
326319
327320
328
329
321
330322
331323
332324
......
378370
379371
380372
381
382
373
383374
384375
385376
......
400391
401392
402393
403
404
394
405395
406396
407397
......
418408
419409
420410
421
422
411
423412
424413
425414
......
486475
487476
488477
489
490
478
491479
492480
493481
......
524512
525513
526514
527
528
515
529516
530517
531518
......
539526
540527
541528
542
543
529
544530
545531
546532
......
548534
549535
550536
551
552
537
553538
554539
555540
......
580565
581566
582567
583
584
568
585569
586570
587571
......
602586
603587
604588
605
606
589
607590
608591
609592
610593
611594
612595
613
614
596
615597
616598
617599
//==============================================================================
Property *
DT__AddProperty(Node *node, const char *name, uint32_t length, void *value)
Property *DT__AddProperty(Node *node, const char *name, uint32_t length, void *value)
{
Property *prop;
//==============================================================================
Node *
DT__AddChild(Node *parent, const char *name)
Node *DT__AddChild(Node *parent, const char *name)
{
Node *node;
//==============================================================================
void
DT__FreeProperty(Property *prop)
void DT__FreeProperty(Property *prop)
{
prop->next = freeProperties;
freeProperties = prop;
//==============================================================================
void
DT__FreeNode(Node *node)
void DT__FreeNode(Node *node)
{
node->next = freeNodes;
freeNodes = node;
//==============================================================================
void
DT__Initialize(void)
void DT__Initialize(void)
{
DPRINTF("DT__Initialize\n");
/*
* Free up memory used by in-memory representation of device tree.
*/
void
DT__Finalize(void)
void DT__Finalize(void)
{
Node *node;
Property *prop;
//==============================================================================
static void *
FlattenNodes(Node *node, void *buffer)
static void *FlattenNodes(Node *node, void *buffer)
{
Property *prop;
DeviceTreeNode *flatNode;
* To use your own buffer, call with *result = &buffer.
*/
void
DT__FlattenDeviceTree(void **buffer_p, uint32_t *length)
void DT__FlattenDeviceTree(void **buffer_p, uint32_t *length)
{
uint32_t totalSize;
void * buf;
//==============================================================================
char *
DT__GetName(Node *node)
char *DT__GetName(Node *node)
{
Property *prop;
//==============================================================================
// Bungo
Property *
DT__GetProperty(Node *node, const char *name)
Property *DT__GetProperty(Node *node, const char *name)
{
Property *prop;
//==============================================================================
Node *
DT__FindNode(const char *path, bool createIfMissing)
Node *DT__FindNode(const char *path, bool createIfMissing)
{
Node *node, *child;
DTPropertyNameBuf nameBuf;
//==============================================================================
void
DT__PrintNode(Node *node, int level)
void DT__PrintNode(Node *node, int level)
{
char spaces[10], *cp = spaces;
Property *prop;
//==============================================================================
static void
_PrintTree(Node *node, int level)
static void _PrintTree(Node *node, int level)
{
DT__PrintNode(node, level);
//==============================================================================
void
DT__PrintTree(Node *node)
void DT__PrintTree(Node *node)
{
if (node == 0) node = rootNode;
_PrintTree(node, 0);
//==============================================================================
void
DT__PrintFlattenedNode(DTEntry entry, int level)
void DT__PrintFlattenedNode(DTEntry entry, int level)
{
char spaces[10], *cp = spaces;
DTPropertyIterator propIter;
//==============================================================================
static void
_PrintFlattenedTree(DTEntry entry, int level)
static void _PrintFlattenedTree(DTEntry entry, int level)
{
DTEntryIterator entryIter;
//==============================================================================
void
DT__PrintFlattenedTree(DTEntry entry)
void DT__PrintFlattenedTree(DTEntry entry)
{
_PrintFlattenedTree(entry, 0);
}
//==============================================================================
int
main(int argc, char **argv)
int main(int argc, char **argv)
{
DTEntrydtEntry;
DTPropertyIteratorpropIter;
trunk/i386/libsaio/hfs.c
295295
296296
297297
298
298
299299
300300
301301
......
647647
648648
649649
650
651
650652
651653
652654
......
920922
921923
922924
925
926
927
928
929
930
923931
924932
925933
......
10181026
10191027
10201028
1029
1030
10211031
10221032
10231033
char entry[512];
char devStr[12];
u_int32_t dirID;
long result, flags;
long result, flags = 0;
if (HFSInitPartition(ih) == -1)
{
*flags = kFileTypeUnknown;
tmpTime = 0;
break;
default:
break;
}
if (time != 0)
curNode = SWAP_BE32(gBTHeaders[btree]->rootNode);
nodeSize = SWAP_BE16(gBTHeaders[btree]->nodeSize);
nodeBuf = (char *)malloc(nodeSize);
if (!nodeBuf)
{
return -1;
}
node = (BTNodeDescriptor *)nodeBuf;
while (1)
break;
case kHFSPlusFileThreadRecord : entrySize = 264;
break;
default:
break;
}
}
else
trunk/i386/libsaio/nvidia.c
23232323
23242324
23252325
2326
2327
2328
2329
2330
2326
2327
2328
2329
2330
23312331
23322332
23332333
devprop_add_nvidia_template(device);
devprop_add_value(device, "NVCAP", default_NVCAP, NVCAP_LEN);
devprop_add_value(device, "NVPM", default_NVPM, NVPM_LEN);
devprop_add_value(device, "VRAM,totalsize", (uint8_t*)&videoRam, 4);
devprop_add_value(device, "model", (uint8_t*)model, strlen(model) + 1);
devprop_add_value(device, "rom-revision", (uint8_t*)biosVersion, strlen(biosVersion) + 1);
devprop_add_value(device, "@0,display-cfg", default_dcfg_0, DCFG0_LEN);
devprop_add_value(device, "@1,display-cfg", default_dcfg_1, DCFG1_LEN);
devprop_add_value(device, "VRAM,totalsize", (uint8_t *)&videoRam, 4);
devprop_add_value(device, "model", (uint8_t *)model, strlen(model) + 1);
devprop_add_value(device, "rom-revision", (uint8_t *)biosVersion, strlen(biosVersion) + 1);
devprop_add_value(device, "@0,display-cfg", (uint8_t *)&default_dcfg_0, DCFG0_LEN);
devprop_add_value(device, "@1,display-cfg", (uint8_t *)&default_dcfg_1, DCFG1_LEN);
/******************** Added Marchrius.**********************/
// For the AppleBacklightDisplay //
trunk/i386/libsaio/ati.c
137137
138138
139139
140
140
141
142
143
144
145
141146
142147
143148
......
15001505
15011506
15021507
1503
1508
1509
15041510
15051511
15061512
......
16411647
16421648
16431649
1644
1645
1650
1651
16461652
16471653
16481654
......
17701776
17711777
17721778
1773
1779
17741780
17751781
17761782
......
18501856
18511857
18521858
1853
1859
18541860
18551861
18561862
......
22842290
22852291
22862292
2293
2294
2295
22872296
22882297
22892298
2290
2291
22922299
22932300
22942301
......
23472354
23482355
23492356
2350
2357
23512358
23522359
23532360
{"Hamachi",4},
{"OPM", 6},
{"Ikura", 6},
{"IkuraS", 1}
{"IkuraS", 1},
/* AMD8000Controller */
{"Baladi", 5},//desktop
{"Exmoor", 4},//mobile
{"Basset", 4}
};
static radeon_card_info_t radeon_cards[] = {
//{ 0x99A2,0x00000000, CHIP_FAMILY_ARUBA,"AMD Radeon HD", kNull }, // Mobile
//{ 0x99A4,0x00000000, CHIP_FAMILY_ARUBA,"AMD Radeon HD", kNull },
{ 0x6613,0x00000000, CHIP_FAMILY_BONAIRE,"AMD Radeon R7 240",kFutomaki},
{ 0x6610,0x00000000, CHIP_FAMILY_OLAND,"AMD Radeon R7 250",kFutomaki},
{ 0x6613,0x00000000, CHIP_FAMILY_OLAND,"AMD Radeon R7 240",kFutomaki},
{ 0x665C,0x00000000, CHIP_FAMILY_BONAIRE,"AMD Radeon HD 7790",kFutomaki},
{ 0x665D,0x00000000, CHIP_FAMILY_BONAIRE,"AMD Radeon R9 260",kFutomaki},
//{ 0x67A8,0x00000000, CHIP_FAMILY_HAWAII,"AMD Radeon", kFutomaki},
//{ 0x67A9,0x00000000, CHIP_FAMILY_HAWAII,"AMD Radeon", kFutomaki},
//{ 0x67AA,0x00000000, CHIP_FAMILY_HAWAII,"AMD Radeon", kFutomaki},
{ 0x67B0,0x00000000, CHIP_FAMILY_HAWAII,"AMD Radeon R9 290X", kFutomaki},
{ 0x67B1,0x00000000, CHIP_FAMILY_HAWAII,"AMD Radeon R9 290", kFutomaki}, // CHIP_FAMILY_HAWAII
{ 0x67B0,0x00000000, CHIP_FAMILY_HAWAII,"AMD Radeon R9 290X", kBaladi},
{ 0x67B1,0x00000000, CHIP_FAMILY_HAWAII,"AMD Radeon R9 290", kBaladi}, // CHIP_FAMILY_HAWAII
//{ 0x67B8,0x00000000, CHIP_FAMILY_HAWAII,"AMD Radeon", kFutomaki},
//{ 0x67B9,0x00000000, CHIP_FAMILY_HAWAII,"AMD Radeon", kFutomaki},
//{ 0x67BA,0x00000000, CHIP_FAMILY_HAWAII,"AMD Radeon", kFutomaki},
val->type = kCst;
val->size = 4;
val->data = (uint8_t *)&v;
return true;
}
val->type = kPtr;
val->size = card->rom_size;
val->data = card->rom;
return true;
}
}
#endif
static charname[24];
static charname_parent[24];
static bool init_card(pci_dt_t *pci_dev)
{
booladd_vbios = true;
charname[24];
charname_parent[24];
inti;
intn_ports = 0;
{
read_disabled_vbios();
}
verbose("\n");
verbose("Video BIOS read from file\n");
}
}
trunk/i386/libsaio/load.c
5757
5858
5959
60
60
6161
6262
6363
6464
6565
66
66
67
6768
6869
6970
70
71
72
73
7174
7275
7376
......
7881
7982
8083
81
84
85
86
8287
8388
8489
......
258263
259264
260265
261
262
263
264
266
267
268
269
265270
266
271
272
273
267274
268275
269276
......
276283
277284
278285
279
286
280287
281288
282289
......
289296
290297
291298
292
299
300
293301
294302
295303
296
304
305
297306
298307
299308
300309
301
310
311
302312
303313
304314
305315
306
316
317
307318
308319
309320
......
317328
318329
319330
320
331
332
321333
322334
323335
......
355367
356368
357369
358
359
370
371
360372
361373
362374
struct fat_arch *fap = (struct fat_arch *)((unsigned long)*binary + sizeof(struct fat_header));
cpu_type_t fapcputype;
uint32_t fapoffset;
uint32_t fapsize;
uint32_t fapsize;
if (fhp->magic == FAT_MAGIC)/* 0xcafebabe */
{
nfat = fhp->nfat_arch;
swapped = 0;
} else if (fhp->magic == FAT_CIGAM)/* 0xbebafeca */
}
else if (fhp->magic == FAT_CIGAM)/* 0xbebafeca */
{
nfat = OSSwapInt32(fhp->nfat_arch);
swapped = 1;
} else {
}
else
{
return -1;
}
fapcputype = OSSwapInt32(fap->cputype);
fapoffset = OSSwapInt32(fap->offset);
fapsize = OSSwapInt32(fap->size);
} else {
}
else
{
fapcputype = fap->cputype;
fapoffset = fap->offset;
fapsize = fap->size;
segname = segCmd->segname;
#ifdef DEBUG
printf("segname: %s, vmaddr: %x, vmsize: %x, fileoff: %x, filesize: %x, nsects: %d, flags: %x.\n",
segCmd->segname, (unsigned)vmaddr, (unsigned)vmsize, (unsigned)fileaddr, (unsigned)filesize,
(unsigned) segCmd->nsects, (unsigned)segCmd->flags);
getchar();
printf("segname: %s, vmaddr: %x, vmsize: %x, fileoff: %x, filesize: %x, nsects: %d, flags: %x.\n",
segCmd->segname, (unsigned)vmaddr, (unsigned)vmsize, (unsigned)fileaddr, (unsigned)filesize,
(unsigned) segCmd->nsects, (unsigned)segCmd->flags);
getchar();
#endif
} else {
}
else
{
struct segment_command *segCmd;
segCmd = (struct segment_command *)cmdBase;
#ifdef DEBUG
printf("segname: %s, vmaddr: %x, vmsize: %x, fileoff: %x, filesize: %x, nsects: %d, flags: %x.\n",
segCmd->segname, (unsigned)vmaddr, (unsigned)vmsize, (unsigned)fileaddr, (unsigned)filesize, (unsigned) segCmd->nsects, (unsigned)segCmd->flags);
segCmd->segname, (unsigned)vmaddr, (unsigned)vmsize, (unsigned)fileaddr, (unsigned)filesize, (unsigned) segCmd->nsects, (unsigned)segCmd->flags);
getchar();
#endif
}
}
if (! ((vmaddr >= KERNEL_ADDR && (vmaddr + vmsize) <= (KERNEL_ADDR + KERNEL_LEN)) ||
(vmaddr >= HIB_ADDR && (vmaddr + vmsize) <= (HIB_ADDR + HIB_LEN)))) {
(vmaddr >= HIB_ADDR && (vmaddr + vmsize) <= (HIB_ADDR + HIB_LEN))))
{
stop("Kernel overflows available space");
}
if (vmsize && ((strcmp(segname, "__PRELINK_INFO") == 0) || (strcmp(segname, "__PRELINK") == 0))) {
if (vmsize && ((strcmp(segname, "__PRELINK_INFO") == 0) || (strcmp(segname, "__PRELINK") == 0)))
{
gHaveKernelCache = true;
}
// Copy from file load area.
if (vmsize>0 && filesize > 0) {
if (vmsize>0 && filesize > 0)
{
bcopy((char *)fileaddr, (char *)vmaddr, vmsize > filesize ? filesize : vmsize);
}
// Zero space at the end of the segment.
if (vmsize > filesize) {
if (vmsize > filesize)
{
bzero((char *)(vmaddr + filesize), vmsize - filesize);
}
static long DecodeUnixThread(long cmdBase, unsigned int *entry)
{
switch (archCpuType) {
switch (archCpuType)
{
case CPU_TYPE_I386:
{
i386_thread_state_t *i386ThreadState;
symTab = (struct symtab_command *)cmdBase;
#if DEBUG
printf("symoff: %x, nsyms: %x, stroff: %x, strsize: %x\n", symTab->symoff, symTab->nsyms, symTab->stroff, symTab->strsize);
printf("symoff: %x, nsyms: %x, stroff: %x, strsize: %x\n",
symTab->symoff, symTab->nsyms, symTab->stroff, symTab->strsize);
getchar();
#endif
trunk/i386/libsaio/ati.h
179179
180180
181181
182
183
184
185
182186
183187
184188
kOPM,
kIkura,
kIkuraS,
/* AMD8000Controller */
kBaladi,
kExmoor,
kBasset,
kCfgEnd
} ati_config_name_t;
trunk/i386/libsaio/cpu.c
312312
313313
314314
315
315
316316
317317
318318
319
319
320320
321321
322322
cores_per_package = 1;
}
if (p->CPU.CPUID[CPUID_0][0] >= 0x5) // Monitor/Mwait
if (p->CPU.CPUID[CPUID_0][0] >= 0x5)// Monitor/Mwait
{
do_cpuid(5, p->CPU.CPUID[CPUID_5]);
}
if (p->CPU.CPUID[CPUID_0][0] >= 6) // Thermal/Power
if (p->CPU.CPUID[CPUID_0][0] >= 6)// Thermal/Power
{
do_cpuid(6, p->CPU.CPUID[CPUID_6]);
}
trunk/i386/libsaio/platform.h
3535
3636
3737
38
38
3939
4040
4141
......
337337
338338
339339
340
340341
341342
342343
#define CPUID_MODEL_DOTHAN0x0D// Dothan Pentium M, Celeron M (90nm)
#define CPUID_MODEL_YONAH0x0E// Sossaman, Yonah
#define CPUID_MODEL_MEROM0x0F// Allendale, Conroe, Kentsfield, Woodcrest, Clovertown, Tigerton, Merom
#define CPUID_MODEL_CONROE0x0F//
#define CPUID_MODEL_CONROE0x0F//
#define CPUID_MODEL_CELERON0x16// Merom, Conroe (65nm), Celeron (45nm)
#define CPUID_MODEL_PENRYN0x17// Wolfdale, Yorkfield, Harpertown, Penryn
#define CPUID_MODEL_WOLFDALE0x17// Xeon 31xx, 33xx, 52xx, 54xx, Core 2 Quad 8xxx and 9xxx
/* Maximum number of ram slots */
#define MAX_RAM_SLOTS8
#define RAM_SLOT_ENUMERATOR{0, 2, 4, 1, 3, 5, 6, 8, 10, 7, 9, 11}
/* Maximum number of SPD bytes */
trunk/i386/libsaio/pci_setup.c
22
33
44
5
6
7
85
96
7
8
9
10
11
12
13
14
15
16
1017
1118
1219
......
3744
3845
3946
47
4048
4149
4250
4351
4452
45
53
4654
55
4756
4857
4958
......
5160
5261
5362
63
5464
5565
5666
......
95105
96106
97107
108
98109
99110
100111
......
102113
103114
104115
116
105117
106118
107119
108120
121
109122
110123
111124
......
115128
116129
117130
118
131
119132
120133
121134
#include "boot.h"
#include "bootstruct.h"
#include "pci.h"
#include "gma.h"
#include "nvidia.h"
#include "hda.h"
#include "modules.h"
#ifndef DEBUG_PCI_SETUP
#define DEBUG_PCI_SETUP 0
#endif
#if DEBUG_PCI_SETUP
#define DBG(x...)printf(x)
#else
#define DBG(x...)
#endif
extern bool setup_ati_devprop(pci_dt_t *ati_dev);
extern bool setup_nvidia_devprop(pci_dt_t *nvda_dev);
extern bool setup_gma_devprop(pci_dt_t *gma_dev);
switch (current->class_id)
{
case PCI_CLASS_BRIDGE_HOST:
DBG("Setup BRIDGE_HOST \n");
if (current->dev.addr == PCIADDR(0, 0, 0))
{
dram_controller_dev = current;
}
break; // PCI_CLASS_BRIDGE_HOST
case PCI_CLASS_NETWORK_ETHERNET:
DBG("Setup ETHERNET %s enabled\n", do_eth_devprop? "is":"is not");
if (do_eth_devprop)
{
set_eth_builtin(current);
break; // PCI_CLASS_NETWORK_ETHERNET
case PCI_CLASS_DISPLAY_VGA:
DBG("GraphicsEnabler %s enabled\n", do_gfx_devprop? "is":"is not");
if (do_gfx_devprop)
{
switch (current->vendor_id)
break; // PCI_CLASS_DISPLAY_VGA
case PCI_CLASS_MULTIMEDIA_AUDIO_DEV:
DBG("Setup HDEF %s enabled\n", do_hda_devprop? "is":"is not");
if (do_hda_devprop)
{
setup_hda_devprop(current);
break; // PCI_CLASS_MULTIMEDIA_AUDIO_DEV
case PCI_CLASS_SERIAL_USB:
DBG("USB\n");
notify_usb_dev(current);
break; // PCI_CLASS_SERIAL_USB
case PCI_CLASS_BRIDGE_ISA:
DBG("Force HPET %s enabled\n", do_enable_hpet? "is":"is not");
if (do_enable_hpet)
{
force_enable_hpet(current);
}
execute_hook("PCIDevice", current, NULL, NULL, NULL);
DBG("setup_pci_devs current device ID = [%04x:%04x]\n", current->vendor_id, current->device_id);
setup_pci_devs(current->children);
current = current->next;
}
trunk/i386/libsaio/nvidia_helper.c
5252
5353
5454
55
55
5656
57
57
5858
5959
60
60
6161
6262
6363
6464
6565
6666
67
68
69
70
67
68
69
70
7171
7272
7373
74
74
7575
76
76
7777
7878
7979
......
108108
109109
110110
111
112
113
114
111
112
113
114
115
116
117
118
115119
116
120
117121
118122
119123
......
127131
128132
129133
130
134
135
131136
132137
133138
134
139
140
135141
136142
137143
138
144
145
139146
140147
141148
*/
cardList_t* cardList = NULL;
cardList_t *cardList = NULL;
void add_card(char* model, uint32_t id, uint32_t subid, uint64_t videoRam)
void add_card(char *model, uint32_t id, uint32_t subid, uint64_t videoRam)
{
cardList_t* new_card = malloc(sizeof(cardList_t));
cardList_t *new_card = malloc(sizeof(cardList_t));
if (new_card)
{
new_card->next = cardList;
cardList = new_card;
new_card->id = id;
new_card->subid = subid;
new_card->videoRam = videoRam;
new_card->model = model;
new_card->id= id;
new_card->subid= subid;
new_card->videoRam= videoRam;
new_card->model= model;
}
}
cardList_t* FindCardWithIds(uint32_t id, uint32_t subid)
cardList_t *FindCardWithIds(uint32_t id, uint32_t subid)
{
cardList_t* entry = cardList;
cardList_t *entry = cardList;
while(entry)
{
if((entry->id == id) && (entry->subid == subid))
void fill_card_list(void)
{
unsigned inti, count;
TagPtr NVDIATag;
char *model_name = NULL, *match_id = NULL, *sub_id = NULL, *vram_size = NULL;
uint32_t dev_id = 0, subdev_id = 0;
uint64_t VramSize = 0;
TagPtrNVDIATag;
char*model_name = NULL;
char*match_id = NULL;
char*sub_id = NULL;
char*vram_size = NULL;
uint32_tdev_id = 0;
uint32_tsubdev_id = 0;
uint64_tVramSize = 0;
if ((NVDIATag = XMLCastArray(XMLGetProperty(bootInfo->chameleonConfig.dictionary, (const char*)"NVIDIA"))))
if ((NVDIATag = XMLCastArray(XMLGetProperty(bootInfo->chameleonConfig.dictionary, (const char *)"NVIDIA"))))
{
count = XMLTagCount(NVDIATag);
model_name = XMLCastString(XMLGetProperty(element, (const char*)"Chipset Name"));
vram_size = XMLCastString(XMLGetProperty(element, (const char*)"VRam Size"));
if (match_id) {
if (match_id)
{
dev_id = strtoul(match_id, NULL, 16);
}
if (sub_id) {
if (sub_id)
{
subdev_id = strtoul(sub_id, NULL, 16);
}
if (vram_size) {
if (vram_size)
{
VramSize = strtoul(vram_size, NULL, 10);
}
trunk/i386/libsaio/pci.c
1414
1515
1616
17
17
1818
1919
2020
......
213213
214214
215215
216
216
217217
218218
219219
#endif
#if DEBUG_PCI
#define DBG(x...)printf(x)
#define DBG(x...)printf(x)
#else
#define DBG(x...)
#endif
while (current) {
printf("%02x:%02x.%x [%04x%02x] [%04x:%04x] (subsys [%04x:%04x]):: %s\n",
current->dev.bits.bus, current->dev.bits.dev, current->dev.bits.func,
current->class_id, 0 /* FIXME: what should this be? */,
current->class_id, current->progif,
current->vendor_id, current->device_id,
current->subsys_id.subsys.vendor_id, current->subsys_id.subsys.device_id,
get_pci_dev_path(current));
trunk/i386/libsaio/md5c.c
166166
167167
168168
169
169
170
170171
171172
172173
173
174
175
176
174177
175178
176179
partLen);
MD5Transform (context->state, context->buffer);
for (i = partLen; i + 63 < inputLen; i += 64) {
for (i = partLen; i + 63 < inputLen; i += 64)
{
MD5Transform (context->state, &((const unsigned char *)input)[i]);
}
index = 0;
} else {
}
else
{
i = 0;
}
trunk/i386/boot2/graphics.c
11201120
11211121
11221122
1123
1124
1123
1124
11251125
11261126
11271127
unsigned long numbers[],
unsigned long maxArrayCount )
{
char*propStr;
unsigned longcount = 0;
char *propStr;
unsigned long count = 0;
propStr = newStringForKey((char *)propKey , &bootInfo->chameleonConfig);
trunk/i386/boot2/drivers.c
740740
741741
742742
743
744
743
745744
746
747
745
746
747
748
748749
749750
750751
......
798799
799800
800801
801
802
802
803803
804804
805805
......
825825
826826
827827
828
829
828
830829
831
832
833
834
835
836
830
831
832
833
834
835
837836
838837
839838
//==========================================================================
// MatchLibraries
static long
MatchLibraries( void )
static long MatchLibraries( void )
{
TagPtr prop, prop2;
ModulePtr module, module2;
TagPtr prop;
TagPtr prop2;
ModulePtr module;
ModulePtr module2;
long done;
do {
// FindModule
#if NOTDEF
static ModulePtr
FindModule( char * name )
static ModulePtr FindModule( char *name )
{
ModulePtr module;
TagPtr prop;
//==========================================================================
// ParseXML
static long
ParseXML( char * buffer, ModulePtr * module, TagPtr * personalities )
static long ParseXML( char *buffer, ModulePtr *module, TagPtr *personalities )
{
long length, pos;
TagPtr moduleDict, required;
ModulePtr tmpModule;
pos = 0;
longlength;
longpos = 0;
TagPtrmoduleDict;
TagPtrrequired;
ModulePtrtmpModule;
while (1)
{
length = XMLParseNextTag(buffer + pos, &moduleDict);
trunk/i386/boot2/resume.c
5454
5555
5656
57
5758
5859
5960
dst = (unsigned long *) (header->restore1CodePhysPage << 12);
count = header->restore1PageCount;
proc = (header->restore1CodeOffset + ((uint32_t) dst));
newSP = header->restore1StackOffset + (header->restore1CodePhysPage << 12);
src = (unsigned long *) (((u_int32_t) &header->fileExtentMap[0])
trunk/i386/boot2/boot.c
425425
426426
427427
428
429
430
428
429
430
431431
432432
433433
bool firstRun = true;
bool instantMenu;
bool rescanPrompt;
intstatus;
unsigned intallowBVFlags = kBVFlagSystemVolume | kBVFlagForeignBoot;
unsigned intdenyBVFlags = kBVFlagEFISystem;
intstatus;
unsigned intallowBVFlags = kBVFlagSystemVolume | kBVFlagForeignBoot;
unsigned intdenyBVFlags = kBVFlagEFISystem;
// Set reminder to unload the PXE base code. Neglect to unload
// the base code will result in a hang or kernel panic.
trunk/i386/boot2/boot.h
119119
120120
121121
122
122
123123
124124
125
125
126126
127127
128
128
129129
130130
131131
......
154154
155155
156156
157
157
158158
159159
160160
......
180180
181181
182182
183
183
184184
185185
186
186
187187
188188
189189
#define kEHCIhard"EHCIhard"/* usb.c */
#define kDefaultPartition"Default Partition"/* sys.c */
/* Zenith432: added this */
/* Zenith432: added this key */
#define kXHCILegacyOff"XHCILegacyOff"/* usb.c */
/* Duvel300: added this */
/* Duvel300: added this key */
#define kRestartFix"RestartFix"/* acpi_patcher.c */
/* Slice: added this */
/* Slice: added these keys */
#define kPS2RestartFix"PS2RestartFix"/* acpi_patcher.c */
#define kUseIntelHDMI"UseIntelHDMI"/* ati.c && nvidia.c && gma.c */
#define kDcfg0"display_0"/* nvidia.c */
#define kDcfg1"display_1"/* nvidia.c */
/* Marchrius: added these keys */
/* Marchrius: added this key */
#define kEnableBacklight"EnableBacklight"/* nvidia.c */
/* Kabyl: added these keys */
#define kHDEFLayoutID"HDEFLayoutID"/* hda.c */
#define kHDAULayoutID"HDAULayoutID"/* hda.c */
/* Karas: added these keys */
/* Karas: added this key */
#define kMemFullInfo"ForceFullMemInfo"/* smbios.c */
/* Bungo: added these keys */
/* Bungo: added this key */
#define kPrivateData"PrivateData"/* smbios_decode.c */
trunk/i386/boot2/gui.c
1313
1414
1515
16
17
18
19
20
21
22
23
24
25
1626
1727
1828
......
456466
457467
458468
469
470
459471
460472
461473
......
524536
525537
526538
527
539
540
541
528542
529543
544
530545
531
546
547
532548
533549
550
534551
535552
536553
......
545562
546563
547564
548
565
566
567
549568
550569
551570
552571
553
572
573
554574
555575
576
556577
557578
558579
......
566587
567588
568589
569
590
591
570592
571593
572594
573595
596
574597
575598
576599
......
620643
621644
622645
623
646
647
624648
625649
626650
627
651
652
628653
629654
630655
631656
632657
633
634
658
659
660
661
635662
636663
637664
......
756783
757784
758785
759
786
760787
761788
762789
......
907934
908935
909936
937
938
939
910940
941
911942
912943
913944
......
931962
932963
933964
934
965
966
935967
936968
937969
938970
939971
940
941
942
943
944
945
972
973
974
975
976
977
978
979
980
981
982
983
946984
947985
948986
949987
988
950989
990
951991
952992
953993
......
958998
959999
9601000
961
962
963
964
965
966
967
968
1001
9691002
1003
1004
1005
1006
1007
1008
1009
1010
1011
9701012
9711013
9721014
......
11301172
11311173
11321174
1133
1175
1176
11341177
11351178
11361179
......
11721215
11731216
11741217
1175
1218
1219
11761220
11771221
1178
1222
1223
11791224
11801225
11811226
......
12031248
12041249
12051250
1206
1251
1252
12071253
12081254
12091255
......
12451291
12461292
12471293
1248
1294
1295
12491296
1250
1251
1297
1298
1299
1300
1301
1302
12521303
1253
1254
1304
1305
1306
1307
12551308
12561309
12571310
1258
1311
1312
12591313
12601314
12611315
......
12701324
12711325
12721326
1327
1328
12731329
12741330
12751331
......
12801336
12811337
12821338
1283
1284
1339
1340
1341
1342
12851343
12861344
1287
1345
1346
12881347
12891348
1290
1291
1349
1350
1351
12921352
1293
1353
1354
12941355
12951356
12961357
12971358
12981359
12991360
1300
1361
1362
13011363
13021364
13031365
......
13161378
13171379
13181380
1319
1320
1381
1382
1383
1384
13211385
13221386
13231387
......
13331397
13341398
13351399
1336
1400
13371401
13381402
1339
1403
1404
13401405
13411406
13421407
......
13601425
13611426
13621427
1363
1428
1429
13641430
13651431
13661432
13671433
13681434
1369
1435
1436
13701437
13711438
13721439
1373
1440
1441
13741442
13751443
13761444
13771445
13781446
13791447
1380
1448
1449
13811450
13821451
13831452
13841453
1385
1454
1455
13861456
13871457
13881458
13891459
13901460
13911461
1392
1462
1463
13931464
13941465
13951466
13961467
13971468
1398
1469
1470
13991471
14001472
14011473
......
14171489
14181490
14191491
1420
1492
14211493
14221494
14231495
1424
1425
1496
1497
1498
14261499
14271500
14281501
......
14321505
14331506
14341507
1435
1508
14361509
14371510
1438
1511
14391512
14401513
14411514
......
14461519
14471520
14481521
1449
1522
1523
14501524
14511525
14521526
14531527
14541528
1455
1529
1530
14561531
14571532
14581533
1459
1534
1535
14601536
14611537
14621538
14631539
14641540
14651541
1466
1542
1543
14671544
14681545
14691546
1470
1547
1548
14711549
14721550
14731551
14741552
14751553
1476
1554
1555
14771556
14781557
14791558
14801559
14811560
1482
1561
1562
14831563
14841564
14851565
......
15091589
15101590
15111591
1512
1592
1593
15131594
15141595
15151596
......
15221603
15231604
15241605
1525
1606
1607
15261608
15271609
15281610
15291611
1530
1612
1613
15311614
15321615
1533
1616
1617
15341618
15351619
15361620
......
15401624
15411625
15421626
1543
1627
1628
15441629
15451630
15461631
15471632
15481633
15491634
1550
1635
1636
15511637
15521638
15531639
15541640
15551641
1556
1642
1643
15571644
15581645
15591646
15601647
15611648
1562
1649
1650
15631651
15641652
15651653
......
15741662
15751663
15761664
1577
1665
1666
15781667
1579
1668
1669
15801670
15811671
15821672
......
15851675
15861676
15871677
1588
1678
1679
15891680
1590
1681
1682
15911683
15921684
1593
1685
1686
1687
15941688
15951689
15961690
......
16021696
16031697
16041698
1605
1699
1700
16061701
1607
1702
1703
16081704
16091705
16101706
16111707
16121708
16131709
1614
1710
1711
16151712
16161713
16171714
......
16301727
16311728
16321729
1633
1634
1730
1731
1732
1733
16351734
16361735
1637
1736
1737
1738
16381739
1639
1740
1741
1742
16401743
1641
1744
1745
16421746
16431747
16441748
1645
1749
1750
16461751
16471752
16481753
......
16581763
16591764
16601765
1661
1662
1663
1766
1767
1768
1769
1770
1771
16641772
16651773
16661774
......
16821790
16831791
16841792
1685
1793
1794
16861795
16871796
16881797
1689
1798
1799
16901800
16911801
1692
1802
1803
16931804
16941805
1695
1696
1806
1807
1808
16971809
16981810
1699
1700
1811
1812
1813
1814
17011815
17021816
17031817
1704
1818
17051819
1706
1820
1821
17071822
17081823
17091824
17101825
1711
1826
17121827
17131828
17141829
17151830
17161831
17171832
1718
1833
1834
17191835
17201836
17211837
1722
1838
1839
17231840
17241841
17251842
......
17321849
17331850
17341851
1735
1852
1853
17361854
17371855
17381856
......
17401858
17411859
17421860
1743
1861
1862
17441863
17451864
1746
1747
1865
1866
1867
1868
17481869
1749
1870
1871
17501872
17511873
17521874
......
17811903
17821904
17831905
1784
1785
1906
1907
1908
1909
17861910
1787
1911
1912
17881913
17891914
17901915
......
18451970
18461971
18471972
1848
1973
1974
18491975
1850
1851
1976
1977
1978
1979
18521980
18531981
1854
1982
1983
1984
18551985
18561986
18571987
18581988
18591989
1860
1861
1990
1991
1992
1993
18621994
18631995
1864
1996
1997
1998
18651999
18662000
18672001
......
18852019
18862020
18872021
1888
2022
2023
18892024
18902025
18912026
18922027
1893
2028
2029
18942030
18952031
18962032
......
19022038
19032039
19042040
1905
2041
19062042
19072043
19082044
......
19402076
19412077
19422078
1943
2079
2080
19442081
19452082
19462083
......
21302267
21312268
21322269
2270
2271
21332272
21342273
21352274
......
21512290
21522291
21532292
2154
2293
2294
21552295
21562296
21572297
#include "appleboot.h"
#include "vers.h"
#ifndef DEBUG_GUI
#define DEBUG_GUI 0
#endif
#if DEBUG_GUI
#define DBG(x...)printf(x)
#else
#define DBG(x...)
#endif
#define IMG_REQUIRED -1
#define THEME_NAME_DEFAULT"Default"
static const char *theme_name = THEME_NAME_DEFAULT;
initFont( &font_console, &images[iFontConsole]);
initFont( &font_small, &images[iFontSmall]);
//DBG("Graphic objects successfully loaded !!\n",theme_name);
return 0;
}
int createBackBuffer( window_t *window )
{
gui.backbuffer = malloc(sizeof(pixmap_t));
if(!gui.backbuffer) {
if(!gui.backbuffer)
{
//DBG("Unable to allocate memory for gui.backbuffer");
return 1;
}
gui.backbuffer->pixels = malloc( window->width * window->height * 4 );
if(!gui.backbuffer->pixels) {
if(!gui.backbuffer->pixels)
{
free(gui.backbuffer);
gui.backbuffer = 0;
//DBG("Unable to allocate memory for gui.backbuffer->pixels");
return 1;
}
int createWindowBuffer( window_t *window )
{
window->pixmap = malloc(sizeof(pixmap_t));
if(!window->pixmap) {
if(!window->pixmap)
{
//DBG("Unable to allocate memory for window->pixmap");
return 1;
}
window->pixmap->pixels = malloc( window->width * window->height * 4 );
if(!window->pixmap->pixels) {
if(!window->pixmap->pixels)
{
free(window->pixmap);
window->pixmap = 0;
//DBG("Unable to allocate memory for window->pixmap->pixels");
return 1;
}
int freeWindowBuffer( window_t *window )
{
if (window->pixmap && window->pixmap->pixels) {
if (window->pixmap && window->pixmap->pixels)
{
free(window->pixmap->pixels);
free(window->pixmap);
return 0;
}
return 1;
}
int val, len;
const char *string;
if(getIntForKey("devices_max_visible", &val, theme )) {
if(getIntForKey("devices_max_visible", &val, theme ))
{
gui.maxdevices = MIN( val, gDeviceCount );
}
if(getIntForKey("devices_iconspacing", &val, theme )) {
if(getIntForKey("devices_iconspacing", &val, theme ))
{
gui.devicelist.iconspacing = val;
}
// check layout for horizontal or vertical
gui.layout = HorizontalLayout;
if(getValueForKey( "devices_layout", &string, &len, theme)) {
if (!strcmp (string, "vertical")) {
if(getValueForKey( "devices_layout", &string, &len, theme))
{
if (!strcmp (string, "vertical"))
{
gui.layout = VerticalLayout;
}
}
gui.countdown.pos.y = pixel;
}
/*
/*
* Parse devicelist parameters
*/
setupDeviceList(theme);
return 1;
}
#else
//DBG("Unable to load %s theme plist.\n",theme_name);
return 1;
#endif
}
// parse display size parameters
gui.screen.height = screen_params[1];
// load graphics otherwise fail and return
if (loadGraphics() == 0) {
if (loadGraphics() == 0)
{
loadThemeValues(&bootInfo->themeConfig);
colorFont(&font_small, gui.screen.font_small_color);
colorFont(&font_console, gui.screen.font_console_color);
// create the screen & window buffers
if (createBackBuffer(&gui.screen) == 0) {
if (createWindowBuffer(&gui.screen) == 0) {
if (createWindowBuffer(&gui.devicelist) == 0) {
if (createWindowBuffer(&gui.bootprompt) == 0) {
if (createWindowBuffer(&gui.infobox) == 0) {
if (createWindowBuffer(&gui.menu) == 0) {
if (createBackBuffer(&gui.screen) == 0)
{
if (createWindowBuffer(&gui.screen) == 0)
{
if (createWindowBuffer(&gui.devicelist) == 0)
{
if (createWindowBuffer(&gui.bootprompt) == 0)
{
if (createWindowBuffer(&gui.infobox) == 0)
{
if (createWindowBuffer(&gui.menu) == 0)
{
gui.logo.draw = true;
drawBackground();
// lets copy the screen into the back buffer
memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
setVideoMode( GRAPHICS_MODE, 0 );
gui.initialised = true;
return 0;
}
}
}
// not available memory, freeing resources
freeWindowBuffer(&gui.menu);
freeWindowBuffer(&gui.infobox);
freeWindowBuffer(&gui.bootprompt);
freeWindowBuffer(&gui.devicelist);
freeWindowBuffer(&gui.screen);
freeBackBuffer(&gui.screen);
unloadGraphics();
DBG("Loading error occurred, reseting...\n",theme_name);
// not available memory, freeing resources
freeWindowBuffer(&gui.menu);
freeWindowBuffer(&gui.infobox);
freeWindowBuffer(&gui.bootprompt);
freeWindowBuffer(&gui.devicelist);
freeWindowBuffer(&gui.screen);
freeBackBuffer(&gui.screen);
unloadGraphics();
return 1;
}
}
// draw visible device icons
for (i = 0; i < gui.maxdevices; i++) {
for (i = 0; i < gui.maxdevices; i++)
{
BVRef param = menuItems[start + i].param;
bool isSelected = ((start + i) == selection) ? true : false;
drawDeviceIcon( param, gui.devicelist.pixmap, p, isSelected);
if (gui.layout == HorizontalLayout) {
if (gui.layout == HorizontalLayout)
{
p.x += images[iSelection].image->width + gui.devicelist.iconspacing;
}
if (gui.layout == VerticalLayout) {
if (gui.layout == VerticalLayout)
{
p.y += ( images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing );
}
}
//prompt_pos=0;
if( gui.bootprompt.draw == true ) {
if(gui.bootprompt.draw == true )
{
gui.bootprompt.draw = false;
gui.redraw = true;
// this causes extra frames to be drawn
static inline
void vramwrite (void *data, int width, int height)
{
if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4) {
if (VIDEO (depth) == 32 && VIDEO (rowBytes) == gui.backbuffer->width * 4)
{
memcpy((uint8_t *)vram, gui.backbuffer->pixels, VIDEO (rowBytes)*VIDEO (height));
} else {
uint32_t r, g, b;
}
else
{
uint32_t r;
uint32_t g;
uint32_t b;
int i, j;
for (i = 0; i < VIDEO (height); i++) {
for (j = 0; j < VIDEO (width); j++) {
for (i = 0; i < VIDEO (height); i++)
{
for (j = 0; j < VIDEO (width); j++)
{
b = ((uint8_t *) data)[4*i*width + 4*j];
g = ((uint8_t *) data)[4*i*width + 4*j + 1];
r = ((uint8_t *) data)[4*i*width + 4*j + 2];
switch (VIDEO (depth)) {
switch (VIDEO (depth))
{
case 32:
*(uint32_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*4) = (b&0xff) | ((g&0xff)<<8) | ((r&0xff)<<16);
break;
case 15:
*(uint16_t *)(((uint8_t *)vram)+i*VIDEO (rowBytes) + j*2) = ((b&0xf8)>>3) | ((g&0xf8)<<2) | ((r&0xf8)<<7);
break;
default:
break;
}
}
}
void updateVRAM()
{
if (gui.redraw) {
if (gui.devicelist.draw) {
if (gui.redraw)
{
if (gui.devicelist.draw)
{
blend( gui.devicelist.pixmap, gui.backbuffer, gui.devicelist.pos );
}
if (gui.bootprompt.draw) {
if (gui.bootprompt.draw)
{
blend( gui.bootprompt.pixmap, gui.backbuffer, gui.bootprompt.pos );
}
if (gui.menu.draw) {
blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos );
if (gui.menu.draw)
{
blend( gui.menu.pixmap, gui.backbuffer, gui.menu.pos );
}
if (gui.infobox.draw) {
if (gui.infobox.draw)
{
blend( gui.infobox.pixmap, gui.backbuffer, gui.infobox.pos );
}
}
vramwrite ( gui.backbuffer->pixels, gui.backbuffer->width, gui.backbuffer->height );
if (gui.redraw) {
if (gui.redraw)
{
memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 );
gui.redraw = false;
}
static int
sputc(int c, struct putc_info * pi) //Azi: same as above
{
if (pi->last_str) {
if (pi->str == pi->last_str) {
if (pi->last_str)
{
if (pi->str == pi->last_str)
{
*(pi->str) = '\0';
return 0;
}
char *formattedtext;
va_list ap;
struct putc_info pi;
if ((formattedtext = malloc(1024)) != NULL) {
if ((formattedtext = malloc(1024)) != NULL)
{
// format the text
va_start(ap, fmt);
pi.str = formattedtext;
font_t *font = &font_console;
for( i=0; i< strlen(formattedtext); i++ ) {
for( i=0; i< strlen(formattedtext); i++ )
{
character = formattedtext[i];
character -= 32;
// newline ?
if( formattedtext[i] == '\n' ) {
if( formattedtext[i] == '\n' )
{
cursor.x = window->hborder;
cursor.y += font->height;
if ( cursor.y > bounds.y ) {
if ( cursor.y > bounds.y )
{
cursor.y = origin.y;
}
continue;
}
// tab ?
if( formattedtext[i] == '\t' ) {
if( formattedtext[i] == '\t' )
{
cursor.x += ( font->chars[0]->width * 5 );
}
// draw the character
if( font->chars[character]) {
if( font->chars[character])
{
blend(font->chars[character], window->pixmap, cursor);
}
cursor.x += font->chars[character]->width;
// check x pos and do newline
if ( cursor.x > bounds.x ) {
if ( cursor.x > bounds.x )
{
cursor.x = origin.x;
cursor.y += font->height;
}
// check y pos and reset to origin.y
if ( cursor.y > bounds.y ) {
if ( cursor.y > bounds.y )
{
cursor.y = origin.y;
}
}
char *formattedtext;
va_list ap;
//window = &gui.debug;
struct putc_info pi;
if ((formattedtext = malloc(1024)) != NULL) {
if ((formattedtext = malloc(1024)) != NULL)
{
// format the text
va_start(ap, fmt);
pi.str = formattedtext;
va_end(ap);
position_torigin, cursor, bounds;
int i;
int character;
origin.x = MAX( gui.debug.cursor.x, window->hborder );
origin.y = MAX( gui.debug.cursor.y, window->vborder );
font_t *font = &font_console;
for( i=0; i< strlen(formattedtext); i++ ) {
for( i=0; i< strlen(formattedtext); i++ )
{
character = formattedtext[i];
character -= 32;
// newline ?
if( formattedtext[i] == '\n' ) {
if( formattedtext[i] == '\n' )
{
cursor.x = window->hborder;
cursor.y += font->height;
if ( cursor.y > bounds.y ) {
if ( cursor.y > bounds.y )
{
cursor.y = origin.y;
}
continue;
}
// tab ?
if( formattedtext[i] == '\t' ) {
if( formattedtext[i] == '\t' )
{
cursor.x += ( font->chars[0]->width * 5 );
}
// draw the character
if( font->chars[character]) {
if( font->chars[character])
{
blend(font->chars[character], gui.backbuffer, cursor);
}
cursor.x += font->chars[character]->width;
// check x pos and do newline
if ( cursor.x > bounds.x ) {
if ( cursor.x > bounds.x )
{
cursor.x = origin.x;
cursor.y += font->height;
}
// check y pos and reset to origin.y
if ( cursor.y > bounds.y ) {
if ( cursor.y > bounds.y )
{
cursor.y = origin.y;
}
}
position_torigin, cursor, bounds;
font_t *font = &font_console;
if ((formattedtext = malloc(1024)) != NULL) {
if ((formattedtext = malloc(1024)) != NULL)
{
// format the text
pi.str = formattedtext;
pi.last_str = 0;
bounds.y = ( window->height - ( window->vborder * 2 ) );
cursor = origin;
for( i=0; i< strlen(formattedtext); i++ ) {
for( i=0; i< strlen(formattedtext) ; i++ )
{
character = formattedtext[i];
character -= 32;
// newline ?
if( formattedtext[i] == '\n' ) {
if( formattedtext[i] == '\n' )
{
cursor.x = window->hborder;
cursor.y += font->height;
if ( cursor.y > bounds.y ) {
if ( cursor.y > bounds.y )
{
gui.redraw = true;
updateVRAM();
cursor.y = window->vborder;
}
// tab ?
if( formattedtext[i] == '\t' ) {
if( formattedtext[i] == '\t' )
{
cursor.x = ( cursor.x / ( font->chars[0]->width * 8 ) + 1 ) * ( font->chars[0]->width * 8 );
continue;
}
cursor.x += font->chars[character]->width;
// check x pos and do newline
if ( cursor.x > bounds.x ) {
if ( cursor.x > bounds.x )
{
cursor.x = origin.x;
cursor.y += font->height;
}
// check y pos and reset to origin.y
if ( cursor.y > ( bounds.y + font->chars[0]->height) ) {
if ( cursor.y > ( bounds.y + font->chars[0]->height) )
{
gui.redraw = true;
updateVRAM();
cursor.y = window->vborder;
}
// draw the character
if( font->chars[character]) {
if( font->chars[character])
{
blend(font->chars[character], gui.backbuffer, cursor);
}
}
// ====================================================================
pixmap_t* charToPixmap(unsigned char ch, font_t *font) {
pixmap_t *charToPixmap(unsigned char ch, font_t *font)
{
unsigned int cha = (unsigned int)ch - 32;
if (cha >= font->count) {
if (cha >= font->count)
{
// return ? if the font for the char doesn't exists
cha = '?' - 32;
}
// ====================================================================
position_t drawChar(unsigned char ch, font_t *font, pixmap_t *blendInto, position_t p) {
position_t drawChar(unsigned char ch, font_t *font, pixmap_t *blendInto, position_t p)
{
pixmap_t* pm = charToPixmap(ch, font);
if (pm && ((p.x + pm->width) < blendInto->width)) {
if (pm && ((p.x + pm->width) < blendInto->width))
{
blend(pm, blendInto, p);
return pos(p.x + pm->width, p.y);
} else {
}
else
{
return p;
}
}
int i=0;
position_t current_pos = pos(p.x, p.y);
for (i=0; i < strlen(ch); i++) {
for (i=0; i < strlen(ch); i++)
{
// newline ?
if ( ch[i] == '\n' ) {
if ( ch[i] == '\n' )
{
current_pos.x = p.x;
current_pos.y += font->height;
continue;
}
// tab ?
if ( ch[i] == '\t' ) {
if ( ch[i] == '\t' )
{
current_pos.x += TAB_PIXELS_WIDTH;
continue;
}
int height = font->height;
// calculate the width in pixels
for (i=0; i < strlen(text); i++) {
if (text[i] == '\n') {
for (i=0; i < strlen(text); i++)
{
if (text[i] == '\n')
{
width = 0;
height += font->height;
} else if (text[i] == '\t') {
}
else if (text[i] == '\t')
{
width += TAB_PIXELS_WIDTH;
} else {
}
else
{
pixmap_t* pm = charToPixmap(text[i], font);
if (pm){
if (pm)
{
width += pm->width;
}
}
if (width > max_width) {
if (width > max_width)
{
max_width = width;
}
}
int destroyFont(font_t *font)
{
int i;
for (i = 0; i < CHARACTERS_COUNT; i++) {
if (font->chars[i]) {
if (font->chars[i]->pixels) {
for (i = 0; i < CHARACTERS_COUNT; i++)
{
if (font->chars[i])
{
if (font->chars[i]->pixels)
{
free (font->chars[i]->pixels);
}
free (font->chars[i]);
font->height = data->image->height;
for( x = 0; x < data->image->width && count < CHARACTERS_COUNT; x++) {
for( x = 0; x < data->image->width && count < CHARACTERS_COUNT; x++)
{
start = end;
// if the pixel is red we've reached the end of the char
if( pixel( data->image, x, 0 ).value == 0xFFFF0000) {
if( pixel( data->image, x, 0 ).value == 0xFFFF0000)
{
end = x + 1;
if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) ) {
if( (font->chars[count] = malloc(sizeof(pixmap_t)) ) )
{
font->chars[count]->width = ( end - start) - 1;
font->chars[count]->height = font->height;
if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) ) {
if ( ( font->chars[count]->pixels = malloc( font->chars[count]->width * data->image->height * 4) ) )
{
space += ( font->chars[count]->width * data->image->height * 4 );
// we skip the first line because there are just the red pixels for the char width
for( y = 1; y< (font->height); y++) {
for( x2 = start, x3 = 0; x2 < end; x2++, x3++) {
for( y = 1; y< (font->height); y++)
{
for( x2 = start, x3 = 0; x2 < end; x2++, x3++)
{
pixel( font->chars[count], x3, y ) = pixel( data->image, x2, y );
}
}
// check if font is monospaced
if( ( count > 0 ) && ( font->width != font->chars[count]->width ) ) {
if( ( count > 0 ) && ( font->width != font->chars[count]->width ) )
{
monospaced = true;
}
font->width = font->chars[count]->width;
count++;
}
}
}
}
for (x = count; x < CHARACTERS_COUNT; x++) {
for (x = count; x < CHARACTERS_COUNT; x++)
{
font->chars[x] = NULL;
}
if(monospaced) {
if(monospaced)
{
font->width = 0;
}
void colorFont(font_t *font, uint32_t color)
{
if( !color ) {
if( !color )
{
return;
}
int count = 0;
pixel_t *buff;
while( font->chars[count++] ) {
while( font->chars[count++] )
{
width = font->chars[count-1]->width;
height = font->chars[count-1]->height;
for( y = 0; y < height; y++ ) {
for( x = 0; x < width; x++ ) {
for( y = 0; y < height; y++ )
{
for( x = 0; x < width; x++ )
{
buff = &(pixel( font->chars[count-1], x, y ));
if( buff->ch.a ) {
if( buff->ch.a )
{
buff->ch.r = (color & 0xFFFF0000) >> 16;
buff->ch.g = (color & 0xFF00FF00) >> 8;
buff->ch.b = (color & 0xFF0000FF);
uint8_t alpha=0;
for( y=0; y<10; y++) {
for( x=0; x<10; x++) {
for( y=0; y<10; y++)
{
for( x=0; x<10; x++)
{
// skip if the pixel should be visible
if(roundedCorner[y][x] != 0xFF){
if(roundedCorner[y][x] != 0xFF)
{
alpha = ( roundedCorner[y][x] ? (uint8_t) (roundedCorner[y][x] * pixel(p, x, y).ch.a) / 255 : 0 );
// Upper left corner
pixel(p, x, y).ch.a = alpha;
visiblelines = ( ( gui.infobox.height - ( gui.infobox.vborder * 2 ) ) / font_console.height ) - 1;
// lets display the text and allow scroll thru using up down / arrows
while(1) {
while(1)
{
// move to current line in text
for( offset = 0, i = 0; offset < strlen(text); offset++ ) {
if( currentline == i) {
for( offset = 0, i = 0; offset < strlen(text); offset++ )
{
if( currentline == i)
{
break;
}
if( text[offset] =='\n') {
if( text[offset] =='\n')
{
i++;
}
}
// find last visible line in text and place \0
for( i = offset, cnt = 0; i < strlen(text); i++) {
if(text[i]=='\n') {
for( i = offset, cnt = 0; i < strlen(text); i++)
{
if(text[i]=='\n')
{
cnt++;
}
if ( cnt == visiblelines ) {
if ( cnt == visiblelines )
{
text[i]='\0';
break;
}
position_t pos_indicator = pos( gui.infobox.width - ( images[iTextScrollPrev].image->width - ( gui.infobox.vborder / 2) ), pos_text.y );
// draw prev indicator
if(offset) {
if(offset)
{
blend( images[iTextScrollPrev].image, gui.infobox.pixmap, centeredAt( images[iTextScrollPrev].image, pos_indicator ));
}
// draw next indicator
if( lines > ( currentline + visiblelines ) ) {
if( lines > ( currentline + visiblelines ) )
{
pos_indicator.y = ( gui.infobox.height - ( ( images[iTextScrollNext].image->width + gui.infobox.vborder ) / 2 ) );
blend( images[iTextScrollNext].image, gui.infobox.pixmap, centeredAt( images[iTextScrollNext].image, pos_indicator ) );
}
updateVRAM();
key = getchar();
if( key == KEY_UP ) {
if( currentline > 0 ) {
currentline--;
{
int y;
if( time18() > lasttime) {
if( time18() > lasttime)
{
lasttime = time18();
pixmap_t *buffBar = images[iProgressBar].image;
return buff;
}
break;
default:
break;
}
return DO_NOT_BOOT;
}
char dirspec[256];
if ((strlen(theme_name) + 24) > sizeof(dirspec)) {
if ((strlen(theme_name) + 24) > sizeof(dirspec))
{
usePngImage = false;
return;
}
trunk/i386/boot2/options.c
194194
195195
196196
197
197
198198
199199
200200
......
413413
414414
415415
416
416
417417
418418
419419
......
451451
452452
453453
454
454
455455
456
457
458
459
460
461
462
463
464
465
456
457
458
459
460
461
462
463
464
465
466466
467
467
468468
469469
470470
471471
472472
473
473
474474
475475
476476
477
478
477
478
479479
480480
481481
482482
483483
484484
485
485
486486
487487
488488
......
490490
491491
492492
493
493
494494
495495
496496
......
518518
519519
520520
521
521
522522
523523
524524
......
528528
529529
530530
531
531
532532
533533
534534
535535
536536
537
537
538538
539539
540540
541541
542542
543
543
544544
545545
546546
547547
548548
549549
550
550
551551
552
553
554
555
552
553
554
555
556
557
556558
557559
558560
......
571573
572574
573575
574
575
576
577
578
579
576
577
578
579
580
581
580582
581
582
583
584
583585
584
585
586
587
588
589
590
586
587
588
589
590
591
592
591593
592
593
594
594
595
595596
596597
597598
598
599
599600
600601
601602
......
610611
611612
612613
613
614
615
616
614
615
616
617617
618
619
618
619
620
621
622
623
620624
621
622625
623
624
625
626
627
626
627
628
629
630
628631
629
632
633
634
635
636
637
630638
631
632
639
640
633641
634642
635
636
637
638
639643
640644
641645
......
750754
751755
752756
753
757
758
754759
755760
756761
......
760765
761766
762767
763
768
769
764770
765771
766772
......
11561162
11571163
11581164
1165
11591166
11601167
11611168
......
12001207
12011208
12021209
1210
12031211
12041212
12051213
......
12431251
12441252
12451253
1246
1247
1248
1249
1250
1251
1252
1253
1254
1254
1255
1256
1257
1258
1259
1260
1261
1262
12551263
12561264
12571265
{
multi--;
lasttime=time18();
}
}
if ( (ch = readKeyboardStatus()) )
break;
gMenuStart= 0;
gMenuEnd = MIN( count, gui.maxdevices ) - 1;
// If the selected item is not visible, shift the list down.
if ( gMenuSelection > gMenuBottom )
static int updateMenu( int key, void ** paramPtr )
{
int moved = 0;
int moved = 0;
union {
struct {
unsigned int
selectionUp : 1,
selectionDown : 1,
scrollUp : 1,
scrollDown : 1;
} f;
unsigned int w;
} draw = {{0}};
union {
struct {
unsigned int
selectionUp : 1,
selectionDown : 1,
scrollUp : 1,
scrollDown : 1;
} f;
unsigned int w;
} draw = {{0}};
if ( gMenuItems == NULL )
if ( gMenuItems == NULL )
return 0;
if( bootArgs->Video.v_display != VGA_TEXT_MODE )
{
int res;
// set navigation keys for horizontal layout as defaults
int previous= 0x4B00;// left arrow
int subsequent= 0x4D00;// right arrow
int menu= 0x5000;// down arrow
int menu= 0x5000;// down arrow
if ( gui.layout == VerticalLayout )
{
// set navigation keys for vertical layout
previous= 0x4800;// up arrow
subsequent= 0x5000;// down arrow
menu= 0x4B00;// right arrow
}
}
if ( key == previous )
{
draw.f.selectionUp = 1;
else if ( gMenuTop > 0 )
draw.f.scrollDown = 1;
}
else if ( key == subsequent )
else
{
shouldboot = ( res != DO_NOT_BOOT );
if ( shouldboot )
gui.menu.draw = false;
gVerboseMode = false;
gBootMode = kBootModeNormal;
break;
case BOOT_VERBOSE:
gVerboseMode = true;
gBootMode = kBootModeNormal;
addBootArg(kVerboseModeFlag);
break;
case BOOT_IGNORECACHE:
gVerboseMode = false;
gBootMode = kBootModeNormal;
addBootArg(kIgnoreCachesFlag);
break;
case BOOT_SINGLEUSER:
gVerboseMode = true;
gBootMode = kBootModeNormal;
addBootArg(kSingleUserModeFlag);
break;
}
}
}
} else {
}
}
else
{
switch ( key )
{
case 0x4800: // Up Arrow
}
}
if ( draw.w )
{
if ( draw.f.scrollUp )
{
scollPage(0, gMenuRow, 40, gMenuRow + gMenuHeight - 1, 0x07, 1, 1);
gMenuTop++; gMenuBottom++;
if ( draw.w )
{
if ( draw.f.scrollUp )
{
scollPage(0, gMenuRow, 40, gMenuRow + gMenuHeight - 1, 0x07, 1, 1);
gMenuTop++; gMenuBottom++;
gMenuStart++; gMenuEnd++;
draw.f.selectionDown = 1;
}
draw.f.selectionDown = 1;
}
if ( draw.f.scrollDown )
{
scollPage(0, gMenuRow, 40, gMenuRow + gMenuHeight - 1, 0x07, 1, -1);
gMenuTop--; gMenuBottom--;
gMenuStart--; gMenuEnd--;
draw.f.selectionUp = 1;
}
if ( draw.f.scrollDown )
{
scollPage(0, gMenuRow, 40, gMenuRow + gMenuHeight - 1, 0x07, 1, -1);
gMenuTop--; gMenuBottom--;
gMenuStart--; gMenuEnd--;
draw.f.selectionUp = 1;
}
if ( draw.f.selectionUp || draw.f.selectionDown )
{
if ( draw.f.selectionUp || draw.f.selectionDown )
{
CursorState cursorState;
// Set cursor at current position, and clear inverse video.
if( bootArgs->Video.v_display == VGA_TEXT_MODE )
{
changeCursor( 0, gMenuRow + gMenuSelection - gMenuTop, kCursorTypeHidden, &cursorState );
gMenuStart--;
gMenuEnd--;
}
} else {
gMenuSelection++;
if(( gMenuSelection - ( gui.maxdevices - 1) - gMenuStart) > 0 )
}
else
{
gMenuStart++;
gMenuEnd++;
gMenuSelection++;
if(( gMenuSelection - ( gui.maxdevices - 1) - gMenuStart) > 0 )
{
gMenuStart++;
gMenuEnd++;
}
}
}
if( bootArgs->Video.v_display == VGA_TEXT_MODE )
{
moveCursor( 0, gMenuRow + gMenuSelection - gMenuTop );
printMenuItem( &gMenuItems[gMenuSelection], 1 );
restoreCursor( &cursorState );
if( bootArgs->Video.v_display == VGA_TEXT_MODE )
{
moveCursor( 0, gMenuRow + gMenuSelection - gMenuTop );
printMenuItem( &gMenuItems[gMenuSelection], 1 );
restoreCursor( &cursorState );
} else
}
else
{
drawDeviceList (gMenuStart, gMenuEnd, gMenuSelection);
}
}
drawDeviceList (gMenuStart, gMenuEnd, gMenuSelection);
*paramPtr = gMenuItems[gMenuSelection].param;
moved = 1;
}
*paramPtr = gMenuItems[gMenuSelection].param;
moved = 1;
}
return moved;
}
void lspci(void)
{
if (bootArgs->Video.v_display == VGA_TEXT_MODE) {
if (bootArgs->Video.v_display == VGA_TEXT_MODE)
{
setActiveDisplayPage(1);
clearScreenRows(0, 24);
setCursorPosition(0, 0, 1);
pause();
if (bootArgs->Video.v_display == VGA_TEXT_MODE) {
if (bootArgs->Video.v_display == VGA_TEXT_MODE)
{
setActiveDisplayPage(0);
}
}
clearScreenRows(kMenuTopRow, kScreenLastRow);
changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0);
}
shouldboot = false;
gui.menu.draw = false;
if (menuItems) {
*argP += cnt;
*argP[0] = ' ';
(*argP)++;
*cntRemainingP -= len;
return true;
int processBootOptions()
{
const char *cp = gBootArgs;
const char *val = 0;
const char *kernel;
int cnt;
int userCnt;
int cntRemaining;
char *argP;
char *configKernelFlags;
char *valueBuffer;
const char*cp = gBootArgs;
const char*val = 0;
const char*kernel;
intcnt;
intuserCnt;
intcntRemaining;
char*argP;
char*configKernelFlags;
char*valueBuffer;
valueBuffer = malloc(VALUE_SIZE);
trunk/i386/boot2/graphic_utils.c
7878
7979
8080
81
81
82
8283
8384
8485
uint32_t x;
register uint8_t tempB;
for (x = 0; x < (p->height) * (p->width) ; x++) {
for (x = 0; x < (p->height) * (p->width) ; x++)
{
tempB = (p->pixels[x]).ch.b;
(p->pixels[x]).ch.b = (p->pixels[x]).ch.r;
(p->pixels[x]).ch.r = tempB;
trunk/i386/modules/Keylayout/Keylayout.c
1313
1414
1515
16
17
18
19
20
21
22
23
24
25
1626
1727
1828
29
1930
2031
2132
......
5061
5162
5263
53
64
65
5466
5567
5668
5769
58
70
71
5972
6073
6174
62
75
76
6377
6478
6579
6680
67
81
82
6883
6984
70
85
7186
72
87
88
7389
7490
7591
7692
77
93
94
7895
79
96
8097
8198
8299
83100
101
84102
85
103
104
86105
87106
107
88108
109
89110
90111
91112
92
113
114
93115
94116
95117
......
97119
98120
99121
100
101
122
123
102124
103
125
126
104127
105128
106129
......
113136
114137
115138
116
139
140
117141
118142
119143
120144
121145
122
123
146
147
148
124149
125150
126
151
152
153
127154
128155
129156
#include "Keylayout.h"
#include "bootstruct.h"
#ifndef DEBUG_KLAYOUT
#define DEBUG_KLAYOUT 0
#endif
#if DEBUG_KLAYOUT
#define DBG(x...)printf(x)
#else
#define DBG(x...)
#endif
#define kKeyboardLayout "KeyboardLayout"
struct keyboard_layout *current_layout = NULL;
int getchar_replacement();
int getchar_replacement() {
int code = bgetc();
return (code);
}
static uint32_t load_keyboard_layout_file(const char *filename) {
static uint32_t load_keyboard_layout_file(const char *filename)
{
int fd;
char magic[KEYBOARD_LAYOUTS_MAGIC_SIZE];
uint32_t version;
if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0) {
if ((fd = open_bvdev("bt(0,0)", filename, 0)) < 0)
{
goto fail; // fail
}
if (read(fd, magic, sizeof(magic)) != sizeof(magic)) {
if (read(fd, magic, sizeof(magic)) != sizeof(magic))
{
printf("Can't find magic in keyboard layout file: %s\n", filename);
goto fail;
}
if (memcmp (magic, KEYBOARD_LAYOUTS_MAGIC, KEYBOARD_LAYOUTS_MAGIC_SIZE) != 0) {
if (memcmp (magic, KEYBOARD_LAYOUTS_MAGIC, KEYBOARD_LAYOUTS_MAGIC_SIZE) != 0)
{
printf("Invalid magic code in keyboard layout file: %s\n", filename);
goto fail;
}
}
if (read(fd, (char*) &version, sizeof(version)) != sizeof(version)) {
if (read(fd, (char*) &version, sizeof(version)) != sizeof(version))
{
printf("Can't get version of keyboard layout file: %s\n", filename);
goto fail;
}
if (version != KEYBOARD_LAYOUTS_VERSION) {
if (version != KEYBOARD_LAYOUTS_VERSION)
{
verbose("Bad version for keyboard layout file %s expected v%d found v%d\n",
filename, KEYBOARD_LAYOUTS_VERSION, version);
filename, KEYBOARD_LAYOUTS_VERSION, version);
goto fail;
}
if (current_layout)
{
free(current_layout);
}
current_layout = malloc(sizeof(*current_layout));
if (!current_layout)
{
goto fail;
}
b_lseek(fd, KEYBOARD_LAYOUTS_MAP_OFFSET, 0);
if (read(fd, (char*) current_layout, sizeof(*current_layout)) != sizeof(*current_layout)) {
if (read(fd, (char*) current_layout, sizeof(*current_layout)) != sizeof(*current_layout))
{
printf("Wrong keyboard layout file %s size\n", filename);
goto fail;
}
close(fd);
return 1;
fail:
fail:
if (current_layout) {
if (current_layout)
{
free(current_layout);
current_layout = NULL;
}
const char*val;
intlen;
if (getValueForKey("KeyLayout", &val, &len, &bootInfo->chameleonConfig)) {
if (getValueForKey("KeyLayout", &val, &len, &bootInfo->chameleonConfig))
{
sprintf(layoutPath, "/Extra/Keymaps/%s", val);
// Add the extension if needed
if (len <= 4 || strcmp(val+len-4,".lyt") != 0)
strncat(layoutPath, ".lyt", sizeof(layoutPath) - strlen(layoutPath) - 1);
if (!load_keyboard_layout_file(layoutPath)) {
printf("Can't load %s keyboard layout file. Keylayout will not be used !\n",
if (!load_keyboard_layout_file(layoutPath))
{
DBG("Can't load %s keyboard layout file. Keylayout will not be used !\n",
layoutPath);
sleep(2);
} else if (!replace_function("_getchar", &getchar_replacement)) {
}
else if (!replace_function("_getchar", &getchar_replacement))
{
printf("Can't replace function getchar: Keylayout module can't be used !\n");
sleep(2);
}
trunk/i386/modules/Makefile
5757
5858
5959
60
61
62
63
6064
6165
6266
#SUBDIRS += HDAEnabler
#endif
#ifdef CONFIG_GRAPHICSENABLER_MODULE
#SUBDIRS += GraphicsEnabler
#endif
CFLAGS= -O3 $(MORECPP) -arch i386 -g -static
DEFINES=
CONFIG = hd
trunk/i386/libsa/libsa.h
22
33
44
5
5
66
77
88
......
1010
1111
1212
13
13
1414
1515
1616
......
1818
1919
2020
21
21
2222
2323
2424
......
8888
8989
9090
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108108
109109
110110
111111
112112
113
114
113
114
115115
116116
117117
118118
119119
120120
121
122
121
122
123123
124124
125125
126126
127
128
129
127
128
129
130130
131131
132132
133133
134
134
135135
136136
137137
138138
139
140
141
139
140
141
142142
143143
144144
145145
146146
147
148
149
150
147
148
149
150
151151
152152
153153
154154
155
155
156156
157157
* Copyright (c) 1999-2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
*
* Portions Copyright (c) 1999-2003 Apple Computer, Inc. All Rights
* Reserved. This file contains Original Code and/or Modifications of
* Original Code as defined in and that are subject to the Apple Public
* except in compliance with the License. Please obtain a copy of the
* License at http://www.apple.com/publicsource and read it before using
* this file.
*
*
* The Original Code and all software distributed under the License are
* distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
* License for the specific language governing rights and limitations
* under the License.
*
*
* @APPLE_LICENSE_HEADER_END@
*/
#error bzero is defined.
#endif
extern void * memset(void * dst, int c, size_t n);
extern void * memcpy(void * dst, const void * src, size_t len);
extern int memcmp(const void * p1, const void * p2, size_t len);
extern int strcmp(const char * s1, const char * s2);
extern int strncmp(const char * s1, const char * s2, size_t n);
extern char * strcpy(char * s1, const char * s2);
extern char * stpcpy(char * s1, const char * s2);
extern char * strncpy(char * s1, const char * s2, size_t n);
extern char * strpcpy(char * s1, const char * s2, size_t n);
extern size_t strlcpy(char * s1, const char * s2, size_t n);
extern char * strstr(const char *in, const char *str);
extern int atoi(const char * str);
extern int ptol(const char * str);
extern size_t strlen(const char * str);
extern char * strcat(char * s1, const char * s2);
extern char * strncat(char * s1, const char * s2, size_t n);
extern char * strdup(const char *s1);
extern void*memset(void * dst, int c, size_t n);
extern void*memcpy(void * dst, const void * src, size_t len);
extern intmemcmp(const void * p1, const void * p2, size_t len);
extern intstrcmp(const char * s1, const char * s2);
extern intstrncmp(const char * s1, const char * s2, size_t n);
extern char*strcpy(char * s1, const char * s2);
extern char*stpcpy(char * s1, const char * s2);
extern char*strncpy(char * s1, const char * s2, size_t n);
extern char*strpcpy(char * s1, const char * s2, size_t n);
extern size_tstrlcpy(char * s1, const char * s2, size_t n);
extern char*strstr(const char *in, const char *str);
extern intatoi(const char * str);
extern intptol(const char * str);
extern size_tstrlen(const char * str);
extern char*strcat(char * s1, const char * s2);
extern char*strncat(char * s1, const char * s2, size_t n);
extern char*strdup(const char *s1);
#if STRNCASECMP
extern int strncasecmp(const char *s1, const char *s2, size_t n);
#endif
extern char * strchr(const char *str, int c);
extern char * strbreak(const char *str, char **next, long *len);
extern char *strchr(const char *str, int c);
extern char *strbreak(const char *str, char **next, long *len);
extern uint8_t checksum8( void * start, unsigned int length );
/*
* error.c
*/
extern int errno;
extern char * strerror(int errnum);
extern interrno;
extern char*strerror(int errnum);
/*
* strtol.c
*/
extern long strtol(const char * nptr, char ** endptr, int base);
extern unsigned long strtoul(const char * nptr, char ** endptr, int base);
extern unsigned long long strtouq(const char *nptr, char ** endptr, int base);
extern long strtol(const char *nptr, char **endptr, int base);
extern unsigned long strtoul(const char *nptr, char **endptr, int base);
extern unsigned long long strtouq(const char *nptr, char **endptr, int base);
/*
* prf.c
*/
extern void prf(const char * fmt, va_list ap, int (*putfn_p)(), void * putfn_arg);
extern void prf(const char *fmt, va_list ap, int (*putfn_p)(), void *putfn_arg);
/*
* printf.c
*/
extern int sprintf(char *s, const char * format, ...);
extern int snprintf(char *s, size_t size, const char * format, ...);
extern int slvprintf(char * buffer, int len, const char * fmt, va_list arg);
extern int sprintf(char *s, const char *format, ...);
extern int snprintf(char *s, size_t size, const char *format, ...);
extern int slvprintf(char *buffer, int len, const char *fmt, va_list arg);
/*
* zalloc.c
*/
#define malloc(size) safe_malloc(size, __FILE__, __LINE__)
extern void malloc_init(char * start, int size, int nodes, void (*malloc_error)(char *, size_t, const char *, int));
extern void * safe_malloc(size_t size,const char *file, int line);
extern void free(void * start);
extern void * realloc(void * ptr, size_t size);
extern voidmalloc_init(char *start, int size, int nodes, void (*malloc_error)(char *, size_t, const char *, int));
extern void*safe_malloc(size_t size,const char *file, int line);
extern voidfree(void *start);
extern void*realloc(void *ptr, size_t size);
/*
* getsegbyname.c
*/
extern struct segment_command * getsegbynamefromheader(struct mach_header * mhp, char * segname);
extern struct segment_command *getsegbynamefromheader(struct mach_header *mhp, char *segname);
#endif /* !__BOOT_LIBSA_H */
trunk/i386/libsa/string.c
2525
2626
2727
28
28
2929
30
31
32
33
30
31
32
33
3434
35
35
3636
3737
3838
3939
4040
41
42
43
44
41
42
43
44
4545
46
46
4747
4848
4949
......
5353
5454
5555
56
56
5757
5858
5959
6060
6161
62
63
64
65
66
67
68
69
70
71
62
63
64
65
66
67
68
69
70
71
7272
73
73
7474
7575
7676
7777
78
79
80
81
82
83
84
85
86
87
78
79
80
81
82
83
84
85
86
87
8888
8989
9090
9191
92
93
94
95
96
97
98
99
100
101
102
92
93
94
95
96
97
98
99
100
101
102
103103
104104
105105
......
157157
158158
159159
160
161
160
162161
163162
164163
......
166165
167166
168167
169
170
168
171169
172170
173171
......
176174
177175
178176
179
180
177
181178
182179
183180
......
189186
190187
191188
192
193
189
194190
195191
196192
......
201197
202198
203199
204
205
200
206201
207202
208203
......
225220
226221
227222
228
229
223
230224
231225
232226
......
238232
239233
240234
241
242
235
243236
244237
245238
......
287280
288281
289282
290
283
291284
292285
293286
......
297290
298291
299292
300
301
302
293
294
295
303296
304297
305298
......
337330
338331
339332
340
333
341334
342335
343336
344337
345338
346
339
340
347341
348342
349343
#include "libsa.h"
void * memset(void * dst, int val, size_t len)
void *memset(void * dst, int val, size_t len)
{
asm volatile ( "rep; stosb"
: "=c" (len), "=D" (dst)
: "0" (len), "1" (dst), "a" (val)
: "memory" );
asm volatile ( "rep; stosb"
: "=c" (len), "=D" (dst)
: "0" (len), "1" (dst), "a" (val)
: "memory" );
return dst;
return dst;
}
#if 0
void * memcpy(void * dst, const void * src, size_t len)
{
asm volatile ( "rep; movsb"
: "=c" (len), "=D" (dst), "=S" (src)
: "0" (len), "1" (dst), "2" (src)
: "memory" );
asm volatile ( "rep; movsb"
: "=c" (len), "=D" (dst), "=S" (src)
: "0" (len), "1" (dst), "2" (src)
: "memory" );
return dst;
return dst;
}
void bcopy(const void * src, void * dst, size_t len)
void bzero(void * dst, size_t len)
{
memset(dst, 0, len);
memset(dst, 0, len);
}
#else
void * memcpy(void * dst, const void * src, size_t len)
{
asm volatile ( "cld \n\t"
"movl %%ecx, %%edx \n\t"
"shrl $2, %%ecx \n\t"
"rep; movsl \n\t"
"movl %%edx, %%ecx \n\t"
"andl $3, %%ecx \n\t"
"rep; movsb \n\t"
: "=D" (dst)
: "c" (len), "D" (dst), "S" (src)
: "memory", "%edx" );
asm volatile ( "cld \n\t"
"movl %%ecx, %%edx \n\t"
"shrl $2, %%ecx \n\t"
"rep; movsl \n\t"
"movl %%edx, %%ecx \n\t"
"andl $3, %%ecx \n\t"
"rep; movsb \n\t"
: "=D" (dst)
: "c" (len), "D" (dst), "S" (src)
: "memory", "%edx" );
return dst;
return dst;
}
void bcopy(const void * src, void * dst, size_t len)
{
asm volatile ( "cld \n\t"
"movl %%ecx, %%edx \n\t"
"shrl $2, %%ecx \n\t"
"rep; movsl \n\t"
"movl %%edx, %%ecx \n\t"
"andl $3, %%ecx \n\t"
"rep; movsb \n\t"
:
: "c" (len), "D" (dst), "S" (src)
: "memory", "%edx" );
asm volatile ( "cld \n\t"
"movl %%ecx, %%edx \n\t"
"shrl $2, %%ecx \n\t"
"rep; movsl \n\t"
"movl %%edx, %%ecx \n\t"
"andl $3, %%ecx \n\t"
"rep; movsb \n\t"
:
: "c" (len), "D" (dst), "S" (src)
: "memory", "%edx" );
}
void bzero(void * dst, size_t len)
{
asm volatile ( "xorl %%eax, %%eax \n\t"
"cld \n\t"
"movl %%ecx, %%edx \n\t"
"shrl $2, %%ecx \n\t"
"rep; stosl \n\t"
"movl %%edx, %%ecx \n\t"
"andl $3, %%ecx \n\t"
"rep; stosb \n\t"
:
: "c" (len), "D" (dst)
: "memory", "%eax" );
asm volatile ( "xorl %%eax, %%eax \n\t"
"cld \n\t"
"movl %%ecx, %%edx \n\t"
"shrl $2, %%ecx \n\t"
"rep; stosl \n\t"
"movl %%edx, %%ecx \n\t"
"andl $3, %%ecx \n\t"
"rep; stosb \n\t"
:
: "c" (len), "D" (dst)
: "memory", "%eax" );
}
#endif
return 0;
}
char *
strcpy(char * s1, const char * s2)
char *strcpy(char *s1, const char *s2)
{
register char *ret = s1;
while ((*s1++ = *s2++))
return ret;
}
char *
stpcpy(char * s1, const char * s2)
char *stpcpy(char *s1, const char *s2)
{
while ((*s1++ = *s2++))
{
return --s1;
}
char *
strncpy(char * s1, const char * s2, size_t n)
char *strncpy(char *s1, const char *s2, size_t n)
{
register char *ret = s1;
while (n && (*s1++ = *s2++))
return ret;
}
char *
stpncpy(char * s1, const char * s2, size_t n)
char *stpncpy(char *s1, const char *s2, size_t n)
{
while (n && (*s1++ = *s2++))
--n;
return s1;
}
char *
strstr(const char *in, const char *str)
char *strstr(const char *in, const char *str)
{
char c;
size_t len;
return (char *) (in - 1);
}
int
ptol(const char *str)
int ptol(const char *str)
{
register int c = *str;
return c;
}
int
atoi(const char *str)
int atoi(const char *str)
{
register int sum = 0;
while (*str == ' ' || *str == '\t')
}
#endif
char* strchr(const char *str, int c)
char *strchr(const char *str, int c)
{
do
{
while(*(str++));
return 0;
}
char* strbreak(const char *str, char **next, long *len)
}
char *strbreak(const char *str, char **next, long *len)
{
char *start = (char*)str, *end;
bool quoted = false;
}
/* COPYRIGHT NOTICE: checksum8 from AppleSMBIOS */
uint8_t checksum8( void * start, unsigned int length )
uint8_t checksum8( void *start, unsigned int length )
{
uint8_t csum = 0;
uint8_t * cp = (uint8_t *) start;
unsigned int i;
for ( i = 0; i < length; i++) {
for ( i = 0; i < length; i++)
{
csum += *cp++;
}
return csum;

Archive Download the corresponding diff file

Revision: 2582