Chameleon

Chameleon Commit Details

Date:2011-08-03 03:28:05 (8 years 2 months ago)
Author:Evan Lojewski
Commit:1255
Parents: 1254
Message:Arch folder / cleanup
Changes:
D/branches/xZen/src/arch/i386/util/bdmesg.c
D/branches/xZen/src/i386/Makefile
D/branches/xZen/src/i386/MakePaths.dir
D/branches/xZen/src/arch/i386/util/dyldsymboltool.c
D/branches/xZen/src/arch/i386/util/Makefile
D/branches/xZen/src/i386/Cconfig
D/branches/xZen/src/i386/cdboot
D/branches/xZen/src/i386/util
D/branches/xZen/src/arch/i386/util/openUp.c
D/branches/xZen/src/i386/libsaio
D/branches/xZen/src/arch/i386/config
D/branches/xZen/src/i386/boot0
D/branches/xZen/src/i386/boot1
D/branches/xZen/src/i386/boot2
D/branches/xZen/src/arch/i386/util/machOconv.c
D/branches/xZen/src/i386/libsa
D/branches/xZen/src/arch/i386/util/fdisk
D/branches/xZen/src/arch/i386/include
D/branches/xZen/src/arch/i386/util/Cconfig
D/branches/xZen/src/i386/doc
R/branches/xZen/src/i386/Make.rules → /branches/xZen/src/arch/i386/Make.rules
C/branches/xZen/src/i386 → /branches/xZen/src/arch/i386
C/branches/xZen/src/arm → /branches/xZen/src/arch/armv5
C/branches/xZen/src/ppc → /branches/xZen/src/arch/ppc
A/branches/xZen/src/arch/x86_64
A/branches/xZen/src/arch
A/branches/xZen/src/arch/x86_64/Make.rules
M/branches/xZen/src/Make.rules

File differences

branches/xZen/src/Make.rules
11
22
3
4
5
36
4
5
6
7
8
9
107
118
129
-include $(SRCROOT)/auto.conf
ifneq ($(ARCH),)
include ${SRCROOT}/${ARCH}/Make.rules
endif
-include ${SRCROOT}/i386/Make.rules
#-include ${SRCROOT}/x86_64/Make.rules
-include ${SRCROOT}/ppc/Make.rules
-include ${SRCROOT}/arm/Make.rules
#print transformed OBJECTS
#$(warning ${ACTUAL_OBJECTS})
branches/xZen/src/i386/Make.rules
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
X86_AS = /usr/bin/as
X86_LD = /usr/bin/ld
X86_CC = /usr/bin/gcc-4.2
X86_CPP = /usr/bin/g++-4.2
##### i386 Rules #####
$(OBJROOT)/%.i386o: %.c $(OBJROOT)
@echo "\t[CC:I386] $<"
@$(X86_CC) -arch i386 $(CFLAGS) $(DEFINES) -c $(INC) $< -o $@ \
-MD -dependency-file $(OBJROOT)/$*.d
@md -u $(OBJROOT)/Makedep -f -d $(OBJROOT)/$*.d
$(OBJROOT)/%.i386o: %.m $(OBJROOT)
@echo "\t[M:I386] $<"
@$(X86_CC) -arch i386 $(CFLAGS) $(DEFINES) -c $(INC) $< -o $@ \
-MD -dependency-file $(OBJROOT)/$*.d
@md -u $(OBJROOT)/Makedep -f -d $(OBJROOT)/$*.d
$(OBJROOT)/%.i386o: %.cpp $(OBJROOT)
@echo "\t[CPP:I386] $<"
@$(X86_CPP) -arch i386 $(CPPFLAGS) $(CFLAGS) -c "$<" $(INC) -o $@ \
-MD -dependency-file $(OBJROOT)/$*.d
@md -u $(OBJROOT)/Makedep -f -d $(OBJROOT)/$*.d
$(OBJROOT)/%.i386o: %.s
@echo "\t[AS:I386] $<"
@$(X86_CC) $(CPPFLAGS) -c $(INC) -arch i386 -o $@ $< \
-MD -dependency-file $*.d
@md -u $(OBJROOT)/Makedep -f -d $*.d
ACTUAL_OBJECTS := ${ACTUAL_OBJECTS} $(addsuffix .i386o , $(addprefix $(OBJROOT)/, $(OBJECTS)))
MODULE_OBJECTS := ${MODULE_OBJECTS} $(addsuffix .i386o, $(addprefix $(OBJROOT)/, $(MODULE_OBJS)))
branches/xZen/src/i386/Cconfig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#
# Chameleon Utilities
#
config OPTIMIZATION_LEVEL
string "Optimization Level"
default "-Oz"
---help---
Specify the level to compile chameleon with.
source "i386/boot0/Cconfig"
source "i386/boot1/Cconfig"
source "i386/boot2/Cconfig"
source "i386/libsa/Cconfig"
source "i386/libsaio/Cconfig"
branches/xZen/src/i386/MakePaths.dir
1
2
3
4
5
6
7
8
9
#
# Default paths for subdirectories.
#
OBJROOT=../../obj/i386/$(DIR)
SYMROOT=../../sym/i386
DSTROOT=../../dst/i386
SRCROOT=/tmp
branches/xZen/src/i386/Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#Makefile for i386 boot program
#
# these paths are only valid in subdirectories of this directory
#
ROOT = $(shell pwd)/../../
SRCROOT = ${ROOT}/src
OBJROOT = $(ROOT)/obj/i386
SYMROOT = $(ROOT)/sym/i386
DSTROOT = $(ROOT)/dst/usr/standalone/i386
DOCROOT = $(ROOT)/doc
include ${ROOT}/Make.rules
# The order of building is important.
SUBDIRS = libsa libsaio boot0 boot1 boot2 cdboot modules
all: ${OBJROOT} ${SYMROOT}
@#cd modules; ${MAKE} BUILT_IN=yes $@
@for i in ${SUBDIRS}; \
do \
echo ================= make $@ for $$i =================; \
( ROOT=$(ROOT); \
cd $$i; ${MAKE} \
$@ \
) || exit $$?; \
done
branches/xZen/src/arch/ppc/Make.rules
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
PPC_AS = /usr/bin/as -arch ppc
PPC_LD = /usr/bin/ld -arch ppc
PPC_CC = /usr/bin/gcc-4.2
PPC_CPP = /usr/bin/g++-4.2
PPC_SDK = /Developer/SDKs/MacOSX10.5.sdk/
PPC_CFLAGS += -I"$(PPC_SDK)/usr/include"
PPC_LDFLAGS += -L"$(PPC_SDK)/usr/lib"
PPC_LDFLAGS += -L"$(PPC_SDK)/usr/lib/system/"
PPC_LDFLAGS += -F"$(PPC_SDK)/System/Library/Frameworks"
PPC_LDFLAGS += -F"$(PPC_SDK)/System/Library/PrivateFrameworks"
##### PPC Rules #####
$(OBJROOT)/%.ppco: %.c $(OBJROOT)
@echo "\t[CC:PPC] $<"
@$(PPC_CC) -arch ppc $(PPC_CFLAGS) $(CFLAGS) $(DEFINES) -c $(INC) $< -o $@ \
-MD -dependency-file $(OBJROOT)/$*.d
@md -u $(OBJROOT)/Makedep -f -d $(OBJROOT)/$*.d
$(OBJROOT)/%.ppco: %.m $(OBJROOT)
@echo "\t[M:PPC] $<"
@$(PPC_CC) -arch ppc $(PPC_CFLAGS) $(CFLAGS) $(DEFINES) -c $(INC) $< -o $@ \
-MD -dependency-file $(OBJROOT)/$*.d
@md -u $(OBJROOT)/Makedep -f -d $(OBJROOT)/$*.d
$(OBJROOT)/%.ppco: %.cpp $(OBJROOT)
@echo "\t[CPP:PPC] $<"
@$(PPC_CPP) -arch ppc $(PPC_CFLAGS) $(CPPFLAGS) $(CFLAGS) -c "$<" $(INC) -o $@ \
-MD -dependency-file $(OBJROOT)/$*.d
@md -u $(OBJROOT)/Makedep -f -d $(OBJROOT)/$*.d
$(OBJROOT)/%.ppco: %.s
@echo "\t[AS:PPC] $<"
@$(PPC_CC) $(CPPFLAGS) -c $(INC) -arch ppc -o $@ $< \
-MD -dependency-file $*.d
@md -u $(OBJROOT)/Makedep -f -d $*.d
ACTUAL_OBJECTS := ${ACTUAL_OBJECTS} $(addsuffix .ppco, $(addprefix $(OBJROOT)/, $(OBJECTS)))
MODULE_OBJECTS := ${MODULE_OBJECTS} $(addsuffix .ppco, $(addprefix $(OBJROOT)/, $(MODULE_OBJS)))
branches/xZen/src/arch/i386/libsaio/xml.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
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
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
/*
* Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* Portions Copyright (c) 2003 Apple Computer, Inc. All Rights
* 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,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* 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@
*/
#include "libsaio.h"
#include "sl.h"
#include "xml.h"
string_ref *ref_strings = NULL;
/// TODO: remove below
static char* buffer_start = NULL;
// TODO: redo the next two functions
void SaveRefString(char* string, int id)
{
//printf("Adding Ref String %d (%s)\n", id, string);
string_ref* tmp = ref_strings;
while(tmp)
{
if(tmp->id == id)
{
tmp->string = malloc(strlen(string)+1);
sprintf(tmp->string, "%s", string);
return;
}
tmp = tmp->next;
}
string_ref* new_ref = malloc(sizeof(string_ref));
new_ref->string = malloc(strlen(string)+1);
sprintf(new_ref->string, "%s", string);
new_ref->id = id;
new_ref->next = ref_strings;
ref_strings = new_ref;
}
char* GetRefString(int id)
{
string_ref* tmp = ref_strings;
while(tmp)
{
if(tmp->id == id) return tmp->string;
tmp = tmp->next;
}
//verbose("Unable to locate Ref String %d\n", id);
return "";
}
struct Module {
struct Module *nextModule;
long willLoad;
TagPtr dict;
char *plistAddr;
long plistLength;
char *driverPath;
};
typedef struct Module Module, *ModulePtr;
struct DriverInfo {
char *plistAddr;
long plistLength;
void *moduleAddr;
long moduleLength;
};
typedef struct DriverInfo DriverInfo, *DriverInfoPtr;
#define kDriverPackageSignature1 'MKXT'
#define kDriverPackageSignature2 'MOSX'
struct DriversPackage {
unsigned long signature1;
unsigned long signature2;
unsigned long length;
unsigned long adler32;
unsigned long version;
unsigned long numDrivers;
unsigned long reserved1;
unsigned long reserved2;
};
typedef struct DriversPackage DriversPackage;
enum {
kCFBundleType2,
kCFBundleType3
};
#define DOFREE 1
static long ParseTagList(char *buffer, TagPtr *tag, long type, long empty);
static long ParseTagKey(char *buffer, TagPtr *tag);
static long ParseTagString(char *buffer, TagPtr *tag);
static long ParseTagInteger(char *buffer, TagPtr *tag);
static long ParseTagData(char *buffer, TagPtr *tag);
static long ParseTagDate(char *buffer, TagPtr *tag);
static long ParseTagBoolean(char *buffer, TagPtr *tag, long type);
static long GetNextTag(char *buffer, char **tag, long *start);
static long FixDataMatchingTag(char *buffer, char *tag);
static TagPtr NewTag(void);
static char *NewSymbol(char *string);
#if DOFREE
static void FreeSymbol(char *string);
#endif
//==========================================================================
// XMLGetProperty
TagPtr
XMLGetProperty( TagPtr dict, const char * key )
{
TagPtr tagList, tag;
if (dict->type != kTagTypeDict) return 0;
tag = 0;
tagList = dict->tag;
while (tagList)
{
tag = tagList;
tagList = tag->tagNext;
if ((tag->type != kTagTypeKey) || (tag->string == 0)) continue;
if (!strcmp(tag->string, key)) return tag->tag;
}
return 0;
}
// XMLGetTag(int index)
// XMLTagCount( TagPtr dict )
int XMLTagCount( TagPtr dict )
{
int count = 0;
TagPtr tagList, tag;
if (dict->type != kTagTypeDict && dict->type != kTagTypeArray) return 0;
tag = 0;
tagList = dict->tag;
while (tagList)
{
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) return 0;
int element = 0;
TagPtr tmp = dict->tag;
while(element < id)
{
element++;
tmp = tmp->tagNext;
}
return tmp;
}
/* Function for basic XML character entities parsing */
char*
XMLDecode(const char* src)
{
typedef const struct XMLEntity {
const char* name;
size_t nameLen;
char value;
} XMLEntity;
/* This is ugly, but better than specifying the lengths by hand */
#define _e(str,c) {str,sizeof(str)-1,c}
const XMLEntity ents[] = {
_e("quot;",'"'), _e("apos;",'\''),
_e("lt;", '<'), _e("gt;", '>'),
_e("amp;", '&')
};
size_t len;
const char *s;
char *out, *o;
if ( !src || !(len = strlen(src)) || !(out = malloc(len+1)) )
return 0;
o = out;
s = src;
while (s <= src+len) /* Make sure the terminator is also copied */
{
if ( *s == '&' )
{
bool entFound = false;
int i;
s++;
for ( i = 0; i < sizeof(ents); i++)
{
if ( strncmp(s, ents[i].name, ents[i].nameLen) == 0 )
{
entFound = true;
break;
}
}
if ( entFound )
{
*o++ = ents[i].value;
s += ents[i].nameLen;
continue;
}
}
*o++ = *s++;
}
return out;
}
//#if UNUSED
//==========================================================================
// XMLParseFile
// Expects to see one dictionary in the XML file, the final pos will be returned
// If the pos is not equal to the strlen, then there are multiple dicts
// 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 length, pos;
TagPtr tag;
pos = 0;
char *configBuffer;
configBuffer = malloc(strlen(buffer)+1);
strcpy(configBuffer, buffer);
buffer_start = configBuffer;
while (1)
{
length = XMLParseNextTag(configBuffer + pos, &tag);
if (length == -1) break;
pos += length;
if (tag == 0) continue;
if (tag->type == kTagTypeDict) break;
XMLFreeTag(tag);
}
free(configBuffer);
if (length < 0) {
return -1;
}
*dict = tag;
return pos;
}
//#endif /* UNUSED */
//==========================================================================
// ParseNextTag
// TODO: cleanup
long
XMLParseNextTag( char * buffer, TagPtr * tag )
{
long length, pos;
char * tagName;
length = GetNextTag(buffer, &tagName, 0);
if (length == -1) return -1;
pos = length;
if (!strncmp(tagName, kXMLTagPList, 6))
{
length = 0;
}
/***** dict ****/
else if (!strcmp(tagName, kXMLTagDict))
{
length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0);
}
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 " ")))
{
length = ParseTagList(buffer + pos, tag, kTagTypeDict, 0);
}
/***** key ****/
else if (!strcmp(tagName, kXMLTagKey))
{
length = ParseTagKey(buffer + pos, tag);
}
/***** string ****/
else if (!strcmp(tagName, kXMLTagString))
{
length = ParseTagString(buffer + pos, tag);
}
else if (!strncmp(tagName, kXMLTagString " ", strlen(kXMLTagString " ")))
{
// TODO: save tag if if found
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
{
id = (id * 10) + (*val++ - '0');
}
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)))
{
// 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
{
id = (id * 10) + (*val++ - '0');
}
else
{
printf("ParseStringIDREF error (0x%x)\n", *val);
getchar();
return -1;
}
}
char* str = GetRefString(id);
TagPtr tmpTag = NewTag();
tmpTag->type = kTagTypeString;
tmpTag->string = str;
tmpTag->tag = 0;
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))
{
length = ParseTagInteger(buffer + pos, tag);
}
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
{
id = (id * 10) + (*val++ - '0');
}
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)))
{
// 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
{
id = (id * 10) + (*val++ - '0');
}
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->tag = 0;
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);
}
else
{
length = ParseTagInteger(buffer + pos, tag);
}
}
/***** data ****/
else if (!strcmp(tagName, kXMLTagData))
{
length = ParseTagData(buffer + pos, tag);
}
else if (!strncmp(tagName, kXMLTagData " ", strlen(kXMLTagData " ")))
{
length = ParseTagData(buffer + pos, tag);
}
else if (!strcmp(tagName, kXMLTagDate))
{
length = ParseTagDate(buffer + pos, tag);
}
/***** date ****/
else if (!strncmp(tagName, kXMLTagDate " ", strlen(kXMLTagDate " ")))
{
length = ParseTagDate(buffer + pos, tag);
}
/***** false ****/
else if (!strcmp(tagName, kXMLTagFalse))
{
length = ParseTagBoolean(buffer + pos, tag, kTagTypeFalse);
}
/***** true ****/
else if (!strcmp(tagName, kXMLTagTrue))
{
length = ParseTagBoolean(buffer + pos, tag, kTagTypeTrue);
}
/***** array ****/
else if (!strcmp(tagName, kXMLTagArray))
{
length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0);
}
else if (!strncmp(tagName, kXMLTagArray " ", strlen(kXMLTagArray " ")))
{
length = ParseTagList(buffer + pos, tag, kTagTypeArray, 0);
}
else if (!strcmp(tagName, kXMLTagArray "/"))
{
length = ParseTagList(buffer + pos, tag, kTagTypeArray, 1);
}
/***** unknown ****/
else
{
*tag = 0;
length = 0;
}
if (length == -1) return -1;
return pos + length;
}
//==========================================================================
// ParseTagList
static long
ParseTagList( char * buffer, TagPtr * tag, long type, long empty )
{
long length, pos;
TagPtr tagList, tmpTag;
tagList = 0;
pos = 0;
if (!empty)
{
while (1)
{
length = XMLParseNextTag(buffer + pos, &tmpTag);
if (length == -1) break;
pos += length;
if (tmpTag == 0) break;
tmpTag->tagNext = tagList;
tagList = tmpTag;
}
if (length == -1)
{
XMLFreeTag(tagList);
return -1;
}
}
tmpTag = NewTag();
if (tmpTag == 0)
{
XMLFreeTag(tagList);
return -1;
}
tmpTag->type = type;
tmpTag->string = 0;
tmpTag->offset = buffer_start ? buffer - buffer_start : 0;
tmpTag->tag = tagList;
tmpTag->tagNext = 0;
*tag = tmpTag;
return pos;
}
//==========================================================================
// ParseTagKey
static long
ParseTagKey( char * buffer, TagPtr * tag )
{
long length, length2;
char *string;
TagPtr tmpTag, subTag;
length = FixDataMatchingTag(buffer, kXMLTagKey);
if (length == -1) return -1;
length2 = XMLParseNextTag(buffer + length, &subTag);
if (length2 == -1) return -1;
tmpTag = NewTag();
if (tmpTag == 0)
{
XMLFreeTag(subTag);
return -1;
}
string = NewSymbol(buffer);
if (string == 0)
{
XMLFreeTag(subTag);
XMLFreeTag(tmpTag);
return -1;
}
tmpTag->type = kTagTypeKey;
tmpTag->string = string;
tmpTag->tag = subTag;
tmpTag->offset = buffer_start ? buffer - buffer_start: 0;
tmpTag->tagNext = 0;
*tag = tmpTag;
return length + length2;
}
//==========================================================================
// ParseTagString
static long
ParseTagString( char * buffer, TagPtr * tag )
{
long length;
char * string;
length = FixDataMatchingTag(buffer, kXMLTagString);
if (length == -1) return -1;
TagPtr tmpTag = NewTag();
if (tmpTag == 0) return -1;
string = NewSymbol(buffer);
if (string == 0)
{
XMLFreeTag(tmpTag);
return -1;
}
tmpTag->type = kTagTypeString;
tmpTag->string = string;
tmpTag->tag = 0;
tmpTag->offset = buffer_start ? buffer - buffer_start: 0;
tmpTag->tagNext = 0;
*tag = tmpTag;
return length;
}
//==========================================================================
// ParseTagInteger
static long
ParseTagInteger( char * buffer, TagPtr * tag )
{
long length, integer;
bool negative = false;
TagPtr tmpTag;
char* val = buffer;
int size;
if(buffer[0] == '<')
{
printf("Warning integer is non existant\n");
getchar();
tmpTag = NewTag();
tmpTag->type = kTagTypeInteger;
tmpTag->string = 0;
tmpTag->tag = 0;
tmpTag->offset = 0;
tmpTag->tagNext = 0;
*tag = tmpTag;
return 0;
}
size = length = FixDataMatchingTag(buffer, kXMLTagInteger);
if (length == -1) return -1;
tmpTag = NewTag();
if (tmpTag == 0) return -1;
integer = 0;
if(size > 1 && (val[1] == 'x' || val[1] == 'X'))// Hex value
{
val += 2;
while(*val)
{
if ((*val >= '0' && *val <= '9'))// 0 - 9
{
integer = (integer * 16) + (*val++ - '0');
}
else if ((*val >= 'a' && *val <= 'f'))// a - f
{
integer = (integer * 16) + (*val++ - 'a' + 10);
}
else if ((*val >= 'A' && *val <= 'F'))// A - F
{
integer = (integer * 16) + (*val++ - 'a' + 10);
}
else
{
printf("ParseTagInteger hex error (0x%x) in buffer %s\n", *val, buffer);
getchar();
return -1;
}
}
}
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')
{
printf("ParseTagInteger decimal error (0x%x) in buffer %s\n", *val, buffer);
getchar();
return -1;
}
integer = (integer * 10) + (*val++ - '0');
}
}
if (negative)
integer = -integer;
}
tmpTag->type = kTagTypeInteger;
tmpTag->string = (char *)integer;
tmpTag->tag = 0;
tmpTag->offset = buffer_start ? buffer - buffer_start: 0;
tmpTag->tagNext = 0;
*tag = tmpTag;
return length;
}
//==========================================================================
// ParseTagData
static long
ParseTagData( char * buffer, TagPtr * tag )
{
long length;
TagPtr tmpTag;
length = FixDataMatchingTag(buffer, kXMLTagData);
if (length == -1) return -1;
tmpTag = NewTag();
if (tmpTag == 0) return -1;
//printf("ParseTagData unimplimented\n");
//printf("Data: %s\n", buffer);
//getchar();
// TODO: base64 decode
char* string = NewSymbol(buffer);
tmpTag->type = kTagTypeData;
tmpTag->string = string;
tmpTag->tag = 0;
tmpTag->offset = buffer_start ? buffer - buffer_start: 0;
tmpTag->tagNext = 0;
*tag = tmpTag;
return length;
}
//==========================================================================
// ParseTagDate
static long
ParseTagDate( char * buffer, TagPtr * tag )
{
long length;
TagPtr tmpTag;
length = FixDataMatchingTag(buffer, kXMLTagDate);
if (length == -1) return -1;
tmpTag = NewTag();
if (tmpTag == 0) return -1;
printf("ParseTagDate unimplimented\n");
getchar();
tmpTag->type = kTagTypeDate;
tmpTag->string = 0;
tmpTag->tag = 0;
tmpTag->offset = buffer_start ? buffer - buffer_start: 0;
tmpTag->tagNext = 0;
*tag = tmpTag;
return length;
}
//==========================================================================
// ParseTagBoolean
static long
ParseTagBoolean( char * buffer, TagPtr * tag, long type )
{
TagPtr tmpTag;
tmpTag = NewTag();
if (tmpTag == 0) return -1;
tmpTag->type = type;
tmpTag->string = 0;
tmpTag->tag = 0;
tmpTag->offset = buffer_start ? buffer - buffer_start: 0;
tmpTag->tagNext = 0;
*tag = tmpTag;
return 0;
}
//==========================================================================
// GetNextTag
static long
GetNextTag( char * buffer, char ** tag, long * start )
{
long cnt, cnt2;
if (tag == 0) return -1;
// Find the start of the tag.
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') return -1;
// Fix the tag data.
*tag = buffer + cnt + 1;
buffer[cnt2] = '\0';
if (start) *start = cnt;
return cnt2 + 1;
}
//==========================================================================
// FixDataMatchingTag
// Modifies 'buffer' to add a '\0' at the end of the tag matching 'tag'.
// 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 )
{
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;
}
//==========================================================================
// NewTag
#define kTagsPerBlock (0x1000)
static TagPtr gTagsFree;
static TagPtr
NewTag( void )
{
long cnt;
TagPtr tag;
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;
gTagsFree = tag;
}
tag = gTagsFree;
gTagsFree = tag->tagNext;
return tag;
}
//==========================================================================
// XMLFreeTag
void
XMLFreeTag( TagPtr tag )
{
#if DOFREE
if (tag == 0) return;
if (tag->string) FreeSymbol(tag->string);
XMLFreeTag(tag->tag);
XMLFreeTag(tag->tagNext);
// Clear and free the tag.
tag->type = kTagTypeNone;
tag->string = 0;
tag->tag = 0;
tag->offset = 0;
tag->tagNext = gTagsFree;
gTagsFree = tag;
#else
return;
#endif
}
//==========================================================================
// Symbol object.
struct Symbol
{
long refCount;
struct Symbol *next;
char string[];
};
typedef struct Symbol Symbol, *SymbolPtr;
static SymbolPtr FindSymbol(char * string, SymbolPtr * prevSymbol);
static SymbolPtr gSymbolsHead;
//==========================================================================
// NewSymbol
static char *
NewSymbol( char * string )
{
static SymbolPtr lastGuy = 0;
SymbolPtr symbol;
// Look for string in the list of symbols.
symbol = FindSymbol(string, 0);
// Add the new symbol.
if (symbol == 0)
{
symbol = (SymbolPtr)malloc(sizeof(Symbol) + 1 + strlen(string));
if (symbol == 0) //return 0;
stop("NULL symbol!");
// Set the symbol's data.
symbol->refCount = 0;
strcpy(symbol->string, string);
// Add the symbol to the list.
symbol->next = gSymbolsHead;
gSymbolsHead = symbol;
}
// Update the refCount and return the string.
symbol->refCount++;
if (lastGuy && lastGuy->next != 0) stop("last guy not last!");
return symbol->string;
}
//==========================================================================
// FreeSymbol
#if DOFREE
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) return;
// Update the refCount.
symbol->refCount--;
if (symbol->refCount != 0) return;
// Remove the symbol from the list.
if (prev != 0) prev->next = symbol->next;
else gSymbolsHead = symbol->next;
// Free the symbol's memory.
free(symbol);
}
#endif
//==========================================================================
// FindSymbol
static SymbolPtr
FindSymbol( char * string, SymbolPtr * prevSymbol )
{
SymbolPtr symbol, prev;
symbol = gSymbolsHead;
prev = 0;
while (symbol != 0) {
if (!strcmp(symbol->string, string)) break;
prev = symbol;
symbol = symbol->next;
}
if ((symbol != 0) && (prevSymbol != 0)) *prevSymbol = prev;
return symbol;
}
bool XMLIsType(TagPtr dict, enum xmltype type)
{
if(!dict) return (type == kTagTypeNone);
return (dict->type == type);
}
/*** Cast functions ***/
TagPtr XMLCastArray(TagPtr dict)
{
if(!dict) return NULL;
if(dict->type == kTagTypeArray) return dict;
else return NULL;
}
TagPtr XMLCastDict(TagPtr dict)
{
if(!dict) return NULL;
if(dict->type == kTagTypeDict) return dict;
else return NULL;
}
char* XMLCastString(TagPtr dict)
{
if(!dict) return NULL;
if((dict->type == kTagTypeString) ||
(dict->type == kTagTypeKey)) return dict->string;
return NULL;
}
long XMLCastStringOffset(TagPtr dict)
{
if(dict &&
((dict->type == kTagTypeString) ||
(dict->type == kTagTypeKey)))
{
return dict->offset;
}
else
{
return -1;
}
}
bool XMLCastBoolean(TagPtr dict)
{
if(!dict) return false;
if(dict->type == kTagTypeTrue) return true;
return false;
}
int XMLCastInteger(TagPtr dict)
{
if(!dict)
{
printf("XMLCastInteger: null dict\n");
return 0;
}
if(dict->type == kTagTypeInteger) return (int)(dict->string);
return 0;
}
branches/xZen/src/arch/i386/libsaio/asm.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
/*
* 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
* 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.
*
* 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,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* 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@
*/
/*
* Mach Operating System
* Copyright (c) 1990 Carnegie-Mellon University
* Copyright (c) 1989 Carnegie-Mellon University
* All rights reserved. The CMU software License Agreement specifies
* the terms and conditions for use and redistribution.
*/
/*
* HISTORY
* $Log: asm.s,v $
* Revision 1.8 2005/06/24 22:47:12 curtisg
* Merging changes for 4159531 to pass data to the kernel in EFI format.
*
* Revision 1.7 2004/05/13 17:58:38 curtisg
* Integrating:
* <rdar://problem/3094680>: (Silent boot)
* <rdar://problem/3363893>: (5 sec boot timeout is too short)
* <rdar://problem/3533781>: (Boot option to display graphics modes)
* <rdar://problem/3545539>: (Default graphics mode should be 32-bit)
* <rdar://problem/3643065>: (Booter should always find a video mode)
* <rdar://problem/3643815>: (Booter displays "0MB" VRAM)
*
* Revision 1.6 2003/11/05 20:51:02 curtisg
* Integrated 3069695,3331770,3370488,3371823
*
* Revision 1.5.26.1 2003/10/27 23:57:59 curtisg
* Added printing of volume names, better handling of extended
* partitions, and updated Apple license strings.
* New chain booter should work better with foreign operating
* systems.
*
* Revision 1.5 2002/11/05 20:34:26 jliu
* Integrating:
* 3051234 boot shouldnt require Graphics = Yes
* 3091627 Need support for refresh rate adjustment
*
* Revision 1.4 2002/10/02 00:06:18 curtisg
* Integrating PR-3032510.
*
* Revision 1.3.6.1 2002/08/30 21:16:29 curtisg
* KERNBOOTSTRUCT is going away in favor of KernelBootArgs_t in <pexpert/i386/boot.h>.
*
* Revision 1.3 2002/07/09 14:06:21 jliu
* Merging changes from PR-2954224 branch in boot/i386.
*
* Revision 1.2.30.1 2002/07/05 16:24:51 jliu
* Merged UFS/HFS/HFS+ filesystem support from BootX.
* Moved boot2 load address due to increased size. boot0/boot1 also changed.
* Updated boot graphics and CLUT.
* Added support to chain load foreign booters.
* Fixed param passing bug in network loader.
* Misc cleanup in libsaio.
*
* Revision 1.2 2000/05/23 23:01:11 lindak
* Merged PR-2309530 into Kodiak (liu i386 booter: does not support label-less
* ufs partitions)
*
* Revision 1.1.1.2.4.1 2000/05/13 17:07:39 jliu
* New boot0 (boot1 has been deprecated). Booter must now reside in its own partition, no disk label required.
*
* Revision 1.1.1.2 1999/08/04 21:16:57 wsanchez
* Impoort of boot-66
*
* Revision 1.3 1999/08/04 21:12:12 wsanchez
* Update APSL
*
* Revision 1.2 1999/03/25 05:48:30 wsanchez
* Add APL.
* Remove unused gzip code.
* Remove unused Adobe fonts.
*
* Revision 1.1.1.1.66.2 1999/03/16 16:08:54 wsanchez
* Substitute License
*
* Revision 1.1.1.1.66.1 1999/03/16 07:33:21 wsanchez
* Add APL
*
* Revision 1.1.1.1 1997/12/05 21:57:57 wsanchez
* Import of boot-25 (~mwatson)
*
* Revision 2.1.1.2 90//03//22 17:59:50 rvb
* Added _sp() => where is the stack at. [kupfer]
*
* Revision 2.1.1.1 90//02//09 17:25:04 rvb
* Add Intel copyright
* [90//02//09 rvb]
*
*/
// INTEL CORPORATION PROPRIETARY INFORMATION
//
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Intel Corporation and may not be copied
// nor disclosed except in accordance with the terms of that agreement.
//
// Copyright 1988 Intel Corporation
// Copyright 1988, 1989 by Intel Corporation
//
#include <architecture/i386/asm_help.h>
#include "memory.h"
#define data32 .byte 0x66
#define addr32 .byte 0x67
.file "asm.s"
CR0_PE_ON = 0x1
#ifdef BOOT1
CR0_PE_OFF = 0x7ffffffe
#else
CR0_PE_OFF = 0x7ffffff0
#endif
STACK32_BASE = ADDR32(STACK_SEG, 0)
STACK16_SEG = STACK_SEG
CODE32_BASE = ADDR32(BASE_SEG, 0)
CODE16_SEG = BASE_SEG
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Pointer to 6-bytes in memory that contains the base address and the limit
// (size of GDT table in bytes) of the GDT. The LGDT is the only instruction
// that directly loads a linear address (not a segment relative address) and
// a limit in protected mode.
.globl _Gdtr
//.data
.section __INIT,__data// turbo - Data that must be in the first segment
.align 2, 0x90
_Gdtr:
.word GDTLIMIT
.long vtop(_Gdt)
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// IDTR representing real-mode IVT. The values are constant.
//.const
.section __INIT,__data// turbo - Data that must be in the first segment
// Real mode IDT
.align 2
.globl _Idtr_real
_Idtr_real:
.word 0x03ff
.long 0x00000000
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// IDTR representing protected-mode IDT. It is initially NULL which tells the
// procesor that no IDT is available. After we get into protected mode we can
// allocate memory for a proper IDT and update this IDTR to point to it.
//.data
.section __INIT,__data// turbo - Data that must be in the first segment
.align 2
.globl _Idtr_prot
_Idtr_prot:
.word 0
.long 0
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Data area for __switch_stack.
//
save_sp: .long STACK_OFS
save_ss: .long STACK_SEG
//.text
.section __INIT,__text // turbo - This code must reside within the first segment
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// real_to_prot()
//
// Transfer from real mode to protected mode.
// Preserves all registers except EAX.
//
LABEL(__real_to_prot)
// Interrupts are disabled in protected mode.
cli
// Load the Global Descriptor Table Register (GDTR).
addr32
data32
lgdt OFFSET16(_Gdtr)
// Enter protected mode by setting the PE bit in CR0.
mov %cr0, %eax
data32
or $CR0_PE_ON, %eax
mov %eax, %cr0
// Make intrasegment jump to flush the processor pipeline and
// reload CS register.
data32
ljmp $0x08, $xprot
xprot:
// we are in USE32 mode now
// set up the protected mode segment registers : DS, SS, ES, FS, GS
mov $0x10, %eax
movw %ax, %ds
movw %ax, %ss
movw %ax, %es
movw %ax, %fs
movw %ax, %gs
// set up the PM IDT
lidt _Idtr_prot
// Convert STACK_SEG:SP to 32-bit linear stack pointer.
movzwl %sp, %eax
addl $STACK32_BASE, %eax
movl %eax, %esp
// Convert STACK_SEG:BP to 32-bit linear base pointer.
movzwl %bp, %eax
addl $STACK32_BASE, %eax
movl %eax, %ebp
// Modify the caller's return address on the stack from
// segment offset to linear address.
popl %eax
addl $CODE32_BASE, %eax
pushl %eax
ret
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// prot_to_real()
//
// Transfer from protected mode to real mode.
// Preserves all registers except EAX.
//
LABEL(__prot_to_real)
// Load real-mode IDT while we're still in USE32 mode so we don't need
// 32-bit addressing prefixes.
lidt _Idtr_real
// Set up segment registers appropriate for real mode.
movw $0x30, %ax
movw %ax, %ds
movw %ax, %es
movw %ax, %fs
movw %ax, %gs
movw %ax, %ss
ljmp $0x18, $x16 // change to USE16 mode
x16:
mov %cr0, %eax // clear the PE bit of CR0
data32
and $CR0_PE_OFF, %eax
mov %eax, %cr0
// make intersegment jmp to flush the processor pipeline
// and reload CS register
data32
ljmp $CODE16_SEG, $xreal - CODE32_BASE
xreal:
// we are in real mode now
// set up the real mode segment registers : DS, DS, ES, FS, GS
movw %cs, %ax
movw %ax, %ds
movw %ax, %es
movw %ax, %fs
movw %ax, %gs
// load stack segment register SS.
data32
movl $STACK16_SEG, %eax
movw %ax, %ss
// clear top 16-bits of ESP and EBP.
data32
movzwl %sp, %esp
data32
movzwl %bp, %ebp
// Modify caller's return address on the stack
// from linear address to segment offset.
data32
popl %eax
data32
movzwl %ax, %eax
data32
pushl %eax
// Reenable maskable interrupts.
sti
data32
ret
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// halt()
//
LABEL(_halt)
#ifdef BOOT1
hlt
#else
call _bgetc
#endif
jmp _halt
#ifndef BOOT1
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// startprog(phyaddr, arg)
// Start the program on protected mode where phyaddr is the entry point.
// Passes arg to the program in %eax.
//
LABEL(_startprog)
push %ebp
mov %esp, %ebp
mov 0xc(%ebp), %eax // argument to program
mov 0x8(%ebp), %ecx // entry offset
mov $0x28, %ebx // segment
push %ebx
push %ecx
// set up %ds and %es
mov $0x20, %ebx
movw %bx, %ds
movw %bx, %es
lret
#endif
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Returns the current stack pointer.
//
LABEL(__sp)
mov %esp, %eax
ret
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// Returns the current frame pointer.
//
LABEL(__bp)
mov %ebp, %eax
ret
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// switch_stack()
//
// Switches stack pointer between SS:SP and memory save_ss:save_sp.
// Call this function from real mode only!!!
//
// AX, DI, and SI are clobbered.
//
LABEL(__switch_stack)
popl %eax # save return address
popl %edi # discard upper 16-bit
data32
addr32
movl OFFSET16(save_ss), %esi # new SS to SI
data32
addr32
movl OFFSET16(save_sp), %edi # new SP to DI
addr32
mov %ss, OFFSET16(save_ss) # save current SS to memory
data32
addr32
movl %esp, OFFSET16(save_sp) # save current SP to memory
cli
mov %si, %ss # switch stack
mov %di, %sp
sti
pushl %eax # push IP of caller onto the new stack
xorl %eax, %eax
xorl %esi, %esi
xorl %edi, %edi
ret
#ifndef BOOT1
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// loader()
//
// Issue a request to the network loader.
//
LABEL(_loader)
enter $0, $0
pushal
#
# Pass a far pointer to the command structure
# to the INT call through DX:CX.
#
# The command code is in BX.
#
movw 8(%ebp), %bx # 8[EBP] = command code
movw 12(%ebp), %cx # 12[EBP] = command structure offset
movw 14(%ebp), %dx # 14[EBP] = command structure segment
call __prot_to_real # Revert to real mode
###### Real Mode Begin ######
data32
call __switch_stack # Switch to NBP stack
int $0x2b # Call NBP
data32
call __switch_stack # Restore stack
data32
call __real_to_prot # Back to protected mode
###### Real Mode End ######
popal
leave
ret
#endif
#if UNUSED
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// pcpy(src, dst, cnt)
// where src is a virtual address and dst is a physical address
//
LABEL(_pcpy)
push %ebp
mov %esp, %ebp
push %es
push %esi
push %edi
push %ecx
cld
// set %es to point at the flat segment
mov $0x20, %eax
movw %ax , %es
mov 0x8(%ebp), %esi // source
mov 0xc(%ebp), %edi // destination
mov 0x10(%ebp), %ecx // count
rep
movsb
pop %ecx
pop %edi
pop %esi
pop %es
pop %ebp
ret
#endif
branches/xZen/src/arch/i386/libsaio/bios.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* 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
* 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.
*
* 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,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* 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@
*/
/*
* Copyright 1994 NeXT Computer, Inc.
* All rights reserved.
*/
#ifndef __LIBSAIO_BIOS_H
#define __LIBSAIO_BIOS_H
#include "bootargs.h"
typedef union {
unsigned int rx;
unsigned short rr;
struct {
unsigned char l;
unsigned char h;
} r;
} machineRegister_t;
typedef struct {
unsigned short cf :1;
unsigned short :1;
unsigned short pf :1;
unsigned short :1;
unsigned short af :1;
unsigned short :1;
unsigned short zf :1;
unsigned short sf :1;
unsigned short tf :1;
unsigned short _if :1;
unsigned short df :1;
unsigned short of :1;
unsigned short iopl:2;
unsigned short nt :1;
} machineFlags_t;
typedef struct {
unsigned int intno;
machineRegister_t eax;
machineRegister_t ebx;
machineRegister_t ecx;
machineRegister_t edx;
machineRegister_t edi;
machineRegister_t esi;
machineRegister_t ebp;
unsigned short cs;
unsigned short ds;
unsigned short es;
machineFlags_t flags;
} biosBuf_t;
#define EBIOS_FIXED_DISK_ACCESS 0x01
#define EBIOS_LOCKING_ACCESS 0x02
#define EBIOS_ENHANCED_DRIVE_INFO 0x04
#define BASE_HD_DRIVE 0x80
#if 0
/*
* ACPI defined memory range types.
*/
enum {
kMemoryRangeUsable = 1, // RAM usable by the OS.
kMemoryRangeReserved = 2, // Reserved. (Do not use)
kMemoryRangeACPI = 3, // ACPI tables. Can be reclaimed.
kMemoryRangeNVS = 4, // ACPI NVS memory. (Do not use)
/* Undefined types should be treated as kMemoryRangeReserved */
};
#endif
/*
* Memory range descriptor.
*/
typedef struct MemoryRange {
unsigned long long base; // 64-bit base address
unsigned long long length; // 64-bit length in bytes
unsigned long type; // type of memory range
unsigned long reserved;
} MemoryRange;
/*
* ACPI defined memory range types.
*/
enum {
kMemoryRangeUsable = 1, // RAM usable by the OS.
kMemoryRangeReserved = 2, // Reserved. (Do not use)
kMemoryRangeACPI = 3, // ACPI tables. Can be reclaimed.
kMemoryRangeNVS = 4, // ACPI NVS memory. (Do not use)
/* Undefined types should be treated as kMemoryRangeReserved */
};
#endif /* !__LIBSAIO_BIOS_H */
branches/xZen/src/arch/i386/libsaio/console.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
* 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
* 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.
*
* 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,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* 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@
*/
/*
* Mach Operating System
* Copyright (c) 1990 Carnegie-Mellon University
* Copyright (c) 1989 Carnegie-Mellon University
* All rights reserved. The CMU software License Agreement specifies
* the terms and conditions for use and redistribution.
*/
/*
* INTEL CORPORATION PROPRIETARY INFORMATION
*
*This software is supplied under the terms of a license agreement or
*nondisclosure agreement with Intel Corporation and may not be copied
*nor disclosed except in accordance with the terms of that agreement.
*
*Copyright 1988, 1989 Intel Corporation
*/
/*
* Copyright 1993 NeXT, Inc.
* All rights reserved.
*/
#include "libsaio.h"
#include <vers.h>
bool gVerboseMode;
bool gErrors;
/*
* Azi: Doubled available log size; this seems to fix some hangs and instant reboots caused by
* booting with -f (ignore caches). 96kb are enough to hold full log, booting with -f; even so,
* this depends on how much we "play" at the boot prompt and with what patches we're playing,
* depending on how much they print to the log.
*
* Kabyl: BooterLog
*/
#define BOOTER_LOG_SIZE(128 * 1024)
#define SAFE_LOG_SIZE134
char *msgbuf = 0;
char *cursor = 0;
struct putc_info //Azi: exists on gui.c & printf.c
{
char * str;
char * last_str;
};
static int
sputc(int c, struct putc_info * pi) //Azi: same as above
{
if (pi->last_str)
if (pi->str == pi->last_str)
{
*(pi->str) = '\0';
return 0;
}
*(pi->str)++ = c;
return c;
}
void initBooterLog(void)
{
msgbuf = malloc(BOOTER_LOG_SIZE);
bzero(msgbuf, BOOTER_LOG_SIZE);
cursor = msgbuf;
msglog("%s\n", "Chameleon " I386BOOT_CHAMELEONVERSION " (svn-r" I386BOOT_CHAMELEONREVISION ")" " [" I386BOOT_BUILDDATE "]");
}
void msglog(const char * fmt, ...)
{
va_list ap;
struct putc_info pi;
if (!msgbuf)
return;
if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
return;
va_start(ap, fmt);
pi.str = cursor;
pi.last_str = 0;
prf(fmt, ap, sputc, &pi);
va_end(ap);
cursor += strlen((char *)cursor);
}
void setupBooterLog(void)
{
if (!msgbuf)
return;
}
/* Kabyl: !BooterLog */
/*
* write one character to console
*/
int putchar(int c)
{
if ( c == '\t' )
{
for (c = 0; c < 8; c++) bios_putchar(' ');
return c;
}
if ( c == '\n' )
{
bios_putchar('\r');
}
bios_putchar(c);
return c;
}
int getc()
{
int c = bgetc();
if ((c & 0xff) == 0)
return c;
else
return (c & 0xff);
}
// Read and echo a character from console. This doesn't echo backspace
// since that screws up higher level handling
int getchar()
{
register int c = getc();
//if ( c == '\r' ) c = '\n';
//if ( c >= ' ' && c < 0x7f) putchar(c);
return (c);
}
int verbose(const char * fmt, ...)
{
va_list ap;
va_start(ap, fmt);
if (gVerboseMode)
{
prf(fmt, ap, putchar, 0);
}
{
// Kabyl: BooterLog
struct putc_info pi;
if (!msgbuf)
return 0;
if (((cursor - msgbuf) > (BOOTER_LOG_SIZE - SAFE_LOG_SIZE)))
return 0;
pi.str = cursor;
pi.last_str = 0;
prf(fmt, ap, sputc, &pi);
cursor += strlen((char *)cursor);
}
va_end(ap);
return(0);
}
int error(const char * fmt, ...)
{
va_list ap;
gErrors = true;
va_start(ap, fmt);
prf(fmt, ap, putchar, 0);
va_end(ap);
return(0);
}
void stop(const char * fmt, ...)
{
va_list ap;
printf("\n");
va_start(ap, fmt);
prf(fmt, ap, putchar, 0);
va_end(ap);
printf("\nThis is a non recoverable error! System HALTED!!!");
halt();
while (1);
}
/** Print a "Press a key to continue..." message and wait for a key press. */
void pause()
{
printf("Press a key to continue...\n");
getchar(); // replace getchar() by pause() ?? were useful...?
}
branches/xZen/src/arch/i386/libsaio/xml.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* Portions Copyright (c) 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
* 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.
*
* 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,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* 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@
*/
#ifndef __LIBSAIO_XML_H
#define __LIBSAIO_XML_H
enum xmltype {
kTagTypeNone = 0,
kTagTypeDict,
kTagTypeKey,
kTagTypeString,
kTagTypeInteger,
kTagTypeData,
kTagTypeDate,
kTagTypeFalse,
kTagTypeTrue,
kTagTypeArray
};
struct string_ref
{
char* string;
int id;
struct string_ref* next;
};
typedef struct string_ref string_ref;
extern string_ref* ref_strings;
#define kXMLTagPList "plist "
#define kXMLTagDict "dict"
#define kXMLTagKey "key"
#define kXMLTagString "string"
#define kXMLTagInteger "integer"
#define kXMLTagData "data"
#define kXMLTagDate "date"
#define kXMLTagFalse "false/"
#define kXMLTagTrue "true/"
#define kXMLTagArray "array"
#define kXMLStringID"ID="
#define kXMLStringIDRef "IDREF="
#define kPropCFBundleIdentifier ("CFBundleIdentifier")
#define kPropCFBundleExecutable ("CFBundleExecutable")
#define kPropOSBundleRequired ("OSBundleRequired")
#define kPropOSBundleLibraries ("OSBundleLibraries")
#define kPropIOKitPersonalities ("IOKitPersonalities")
#define kPropIONameMatch ("IONameMatch")
/*
struct Tag {
long type;
char *string;
struct Tag *tag;
struct Tag *tagNext;
};
typedef struct Tag Tag, *TagPtr;
*/
extern long gImageFirstBootXAddr;
extern long gImageLastKernelAddr;
TagPtr XMLGetProperty( TagPtr dict, const char * key );
TagPtr XMLGetElement( TagPtr dict, int id );
int XMLTagCount( TagPtr dict );
bool XMLIsType(TagPtr dict, enum xmltype type);
bool XMLCastBoolean( TagPtr dict );
char* XMLCastString( TagPtr dict );
long XMLCastStringOffset(TagPtr dict);
int XMLCastInteger ( TagPtr dict );
TagPtr XMLCastDict ( TagPtr dict );
TagPtr XMLCastArray( TagPtr dict );
long XMLParseNextTag(char *buffer, TagPtr *tag);
void XMLFreeTag(TagPtr tag);
char* XMLDecode(const char *in);
//==========================================================================
// XMLParseFile
// Expects to see one dictionary in the XML file.
// Puts the first dictionary it finds in the
// tag pointer and returns 0, or returns -1 if not found.
//
long XMLParseFile( char * buffer, TagPtr * dict );
#endif /* __LIBSAIO_XML_H */
branches/xZen/src/arch/i386/libsaio/fdisk.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* 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
* 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.
*
* 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,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* 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@
*/
/*
* Copyright (c) 1992 NeXT Computer, Inc.
*
* IBM PC disk partitioning data structures.
*
* HISTORY
*
* 8 July 1992 David E. Bohman at NeXT
* Created.
*/
#ifndef __LIBSAIO_FDISK_H
#define __LIBSAIO_FDISK_H
#define DISK_BLK00/* blkno of boot block */
#define DISK_BLK0SZ512/* size of boot block */
#define DISK_BOOTSZ446/* size of boot code in boot block */
#define DISK_SIGNATURE0xAA55/* signature of the boot record */
#define FDISK_NPART4/* number of entries in fdisk table */
#define FDISK_ACTIVE0x80/* indicator of active partition */
#define FDISK_NEXTNAME0xA7/* indicator of NeXT partition */
#define FDISK_DOS120x01/* 12-bit fat < 10MB dos partition */
#define FDISK_DOS16S0x04/* 16-bit fat < 32MB dos partition */
#define FDISK_DOSEXT0x05/* extended dos partition */
#define FDISK_DOS16B0x06/* 16-bit fat >= 32MB dos partition */
#define FDISK_NTFS0x07/* NTFS partition */
#define FDISK_SMALLFAT320x0b /* FAT32 partition */
#define FDISK_FAT320x0c/* FAT32 partition */
#define FDISK_DOS16SLBA 0x0e
#define FDISK_LINUX0x83
#define FDISK_UFS0xa8/* Apple UFS partition */
#define FDISK_HFS0xaf/* Apple HFS partition */
#define FDISK_BOOTER0xab/* Apple booter partition */
/*
* Format of fdisk partion entry (if present).
*/
struct fdisk_part {
unsigned char bootid; /* bootable or not */
unsigned char beghead; /* begining head, sector, cylinder */
unsigned char begsect; /* begcyl is a 10-bit number */
unsigned char begcyl; /* High 2 bits are in begsect */
unsigned char systid; /* OS type */
unsigned char endhead; /* ending head, sector, cylinder */
unsigned char endsect; /* endcyl is a 10-bit number */
unsigned char endcyl; /* High 2 bits are in endsect */
unsigned long relsect; /* partion physical offset on disk */
unsigned long numsect; /* number of sectors in partition */
} __attribute__((packed));
/*
* Format of boot block.
*/
struct disk_blk0 {
unsigned char bootcode[DISK_BOOTSZ];
unsigned char parts[FDISK_NPART][sizeof (struct fdisk_part)];
unsigned short signature;
};
struct REAL_disk_blk0 {
unsigned char bootcode[DISK_BOOTSZ];
struct fdisk_part parts[FDISK_NPART];
unsigned short signature;
} __attribute__((packed));
#endif /* !__LIBSAIO_FDISK_H */
branches/xZen/src/arch/i386/libsaio/efi.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
/*
* Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that 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. The rights granted to you under the License
* may not be used to create, or enable the creation or redistribution of,
* unlawful or unlicensed copies of an Apple operating system, or to
* circumvent, violate, or enable the circumvention or violation of, any
* terms of an Apple operating system software license agreement.
*
* Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ 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,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_END@
*/
#ifndef _PEXPERT_I386_EFI_H
#define _PEXPERT_I386_EFI_H
#include <stdint.h>
typedef uint8_t EFI_UINT8;
typedef uint16_t EFI_UINT16;
typedef uint32_t EFI_UINT32;
typedef uint64_t EFI_UINT64;
typedef uint32_t EFI_UINTN; /* natural size for firmware, not kernel */
typedef int8_t EFI_INT8;
typedef int16_t EFI_INT16;
typedef int32_t EFI_INT32;
typedef int64_t EFI_INT64;
typedef int8_t EFI_CHAR8;
typedef int16_t EFI_CHAR16;
typedef int32_t EFI_CHAR32;
typedef int64_t EFI_CHAR64;
typedef uint32_t EFI_STATUS;
typedef uint8_t EFI_BOOLEAN;
typedef void VOID;
typedef uint32_t EFI_PTR32;
typedef uint32_t EFI_HANDLE32;
typedef uint64_t EFI_PTR64;
typedef uint64_t EFI_HANDLE64;
/*
Portions Copyright 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
*/
//
// Modifiers for EFI Runtime and Boot Services
//
#define EFI_RUNTIMESERVICE
#define EFIAPI
#define IN
#define OUT
#define OPTIONAL
#define EFI_MAX_BIT 0x80000000
//
// Set the upper bit to indicate EFI Error.
//
#define EFIERR(a) (EFI_MAX_BIT | (a))
#define EFIWARN(a) (a)
#define EFI_ERROR(a) (((INTN) (a)) < 0)
#define EFI_SUCCESS 0
#define EFI_LOAD_ERROR EFIERR (1)
#define EFI_INVALID_PARAMETER EFIERR (2)
#define EFI_UNSUPPORTED EFIERR (3)
#define EFI_BAD_BUFFER_SIZE EFIERR (4)
#define EFI_BUFFER_TOO_SMALL EFIERR (5)
#define EFI_NOT_READY EFIERR (6)
#define EFI_DEVICE_ERROR EFIERR (7)
#define EFI_WRITE_PROTECTED EFIERR (8)
#define EFI_OUT_OF_RESOURCES EFIERR (9)
#define EFI_VOLUME_CORRUPTED EFIERR (10)
#define EFI_VOLUME_FULL EFIERR (11)
#define EFI_NO_MEDIA EFIERR (12)
#define EFI_MEDIA_CHANGED EFIERR (13)
#define EFI_NOT_FOUND EFIERR (14)
#define EFI_ACCESS_DENIED EFIERR (15)
#define EFI_NO_RESPONSE EFIERR (16)
#define EFI_NO_MAPPING EFIERR (17)
#define EFI_TIMEOUT EFIERR (18)
#define EFI_NOT_STARTED EFIERR (19)
#define EFI_ALREADY_STARTED EFIERR (20)
#define EFI_ABORTED EFIERR (21)
#define EFI_ICMP_ERROR EFIERR (22)
#define EFI_TFTP_ERROR EFIERR (23)
#define EFI_PROTOCOL_ERROR EFIERR (24)
#define EFI_INCOMPATIBLE_VERSION EFIERR (25)
#define EFI_SECURITY_VIOLATION EFIERR (26)
#define EFI_CRC_ERROR EFIERR (27)
#define EFI_WARN_UNKNOWN_GLYPH EFIWARN (1)
#define EFI_WARN_DELETE_FAILURE EFIWARN (2)
#define EFI_WARN_WRITE_FAILURE EFIWARN (3)
#define EFI_WARN_BUFFER_TOO_SMALL EFIWARN (4)
//
// EFI Specification Revision information
//
#define EFI_SPECIFICATION_MAJOR_REVISION 1
#define EFI_SPECIFICATION_MINOR_REVISION 10
typedef struct {
EFI_UINT32 Data1;
EFI_UINT16 Data2;
EFI_UINT16 Data3;
EFI_UINT8 Data4[8];
} EFI_GUID;
#define APPLE_VENDOR_GUID \
{0xAC39C713, 0x7E50, 0x423D, {0x88, 0x9D, 0x27,0x8F, 0xCC, 0x34, 0x22, 0xB6} }
#define EFI_GLOBAL_VARIABLE_GUID \
{0x8BE4DF61, 0x93CA, 0x11d2, {0xAA, 0x0D, 0x00, 0xE0, 0x98, 0x03, 0x2B, 0x8C} }
typedef union {
EFI_GUID Guid;
EFI_UINT8 Raw[16];
} EFI_GUID_UNION;
//
// EFI Time Abstraction:
// Year: 2000 - 20XX
// Month: 1 - 12
// Day: 1 - 31
// Hour: 0 - 23
// Minute: 0 - 59
// Second: 0 - 59
// Nanosecond: 0 - 999,999,999
// TimeZone: -1440 to 1440 or 2047
//
typedef struct {
EFI_UINT16 Year;
EFI_UINT8 Month;
EFI_UINT8 Day;
EFI_UINT8 Hour;
EFI_UINT8 Minute;
EFI_UINT8 Second;
EFI_UINT8 Pad1;
EFI_UINT32 Nanosecond;
EFI_INT16 TimeZone;
EFI_UINT8 Daylight;
EFI_UINT8 Pad2;
} EFI_TIME;
//
// Bit definitions for EFI_TIME.Daylight
//
#define EFI_TIME_ADJUST_DAYLIGHT 0x01
#define EFI_TIME_IN_DAYLIGHT 0x02
//
// Value definition for EFI_TIME.TimeZone
//
#define EFI_UNSPECIFIED_TIMEZONE 0x07FF
typedef enum {
EfiReservedMemoryType,
EfiLoaderCode,
EfiLoaderData,
EfiBootServicesCode,
EfiBootServicesData,
EfiRuntimeServicesCode,
EfiRuntimeServicesData,
EfiConventionalMemory,
EfiUnusableMemory,
EfiACPIReclaimMemory,
EfiACPIMemoryNVS,
EfiMemoryMappedIO,
EfiMemoryMappedIOPortSpace,
EfiPalCode,
EfiMaxMemoryType
} EFI_MEMORY_TYPE;
typedef struct {
EFI_UINT64 Signature;
EFI_UINT32 Revision;
EFI_UINT32 HeaderSize;
EFI_UINT32 CRC32;
EFI_UINT32 Reserved;
} __attribute__((aligned(8))) EFI_TABLE_HEADER;
//
// possible caching types for the memory range
//
#define EFI_MEMORY_UC 0x0000000000000001ULL
#define EFI_MEMORY_WC 0x0000000000000002ULL
#define EFI_MEMORY_WT 0x0000000000000004ULL
#define EFI_MEMORY_WB 0x0000000000000008ULL
#define EFI_MEMORY_UCE 0x0000000000000010ULL
//
// physical memory protection on range
//
#define EFI_MEMORY_WP 0x0000000000001000ULL
#define EFI_MEMORY_RP 0x0000000000002000ULL
#define EFI_MEMORY_XP 0x0000000000004000ULL
//
// range requires a runtime mapping
//
#define EFI_MEMORY_RUNTIME 0x8000000000000000ULL
typedef EFI_UINT64 EFI_PHYSICAL_ADDRESS;
typedef EFI_UINT64 EFI_VIRTUAL_ADDRESS;
#define EFI_MEMORY_DESCRIPTOR_VERSION 1
typedef struct {
EFI_UINT32 Type;
EFI_UINT32 Pad;
EFI_PHYSICAL_ADDRESS PhysicalStart;
EFI_VIRTUAL_ADDRESS VirtualStart;
EFI_UINT64 NumberOfPages;
EFI_UINT64 Attribute;
} __attribute__((aligned(8))) EFI_MEMORY_DESCRIPTOR;
typedef
EFI_RUNTIMESERVICE
EFI_STATUS
(EFIAPI *EFI_SET_VIRTUAL_ADDRESS_MAP) (
IN EFI_UINTN MemoryMapSize,
IN EFI_UINTN DescriptorSize,
IN EFI_UINT32 DescriptorVersion,
IN EFI_MEMORY_DESCRIPTOR * VirtualMap
) __attribute__((regparm(0)));
typedef
EFI_RUNTIMESERVICE
EFI_STATUS
(EFIAPI *EFI_CONVERT_POINTER) (
IN EFI_UINTN DebugDisposition,
IN OUT VOID **Address
) __attribute__((regparm(0)));
//
// Variable attributes
//
#define EFI_VARIABLE_NON_VOLATILE 0x00000001
#define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x00000002
#define EFI_VARIABLE_RUNTIME_ACCESS 0x00000004
#define EFI_VARIABLE_READ_ONLY 0x00000008
typedef
EFI_RUNTIMESERVICE
EFI_STATUS
(EFIAPI *EFI_GET_VARIABLE) (
IN EFI_CHAR16 * VariableName,
IN EFI_GUID * VendorGuid,
OUT EFI_UINT32 * Attributes OPTIONAL,
IN OUT EFI_UINTN * DataSize,
OUT VOID * Data
) __attribute__((regparm(0)));
typedef
EFI_RUNTIMESERVICE
EFI_STATUS
(EFIAPI *EFI_GET_NEXT_VARIABLE_NAME) (
IN OUT EFI_UINTN * VariableNameSize,
IN OUT EFI_CHAR16 * VariableName,
IN OUT EFI_GUID * VendorGuid
) __attribute__((regparm(0)));
typedef
EFI_RUNTIMESERVICE
EFI_STATUS
(EFIAPI *EFI_SET_VARIABLE) (
IN EFI_CHAR16 * VariableName,
IN EFI_GUID * VendorGuid,
IN EFI_UINT32 Attributes,
IN EFI_UINTN DataSize,
IN VOID * Data
) __attribute__((regparm(0)));
//
// EFI Time
//
typedef struct {
EFI_UINT32 Resolution;
EFI_UINT32 Accuracy;
EFI_BOOLEAN SetsToZero;
} __attribute__((aligned(4))) EFI_TIME_CAPABILITIES;
typedef
EFI_RUNTIMESERVICE
EFI_STATUS
(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
EFI_STATUS
(EFIAPI *EFI_GET_WAKEUP_TIME) (
OUT EFI_BOOLEAN * Enabled,
OUT EFI_BOOLEAN * Pending,
OUT EFI_TIME * Time
) __attribute__((regparm(0)));
typedef
EFI_RUNTIMESERVICE
EFI_STATUS
(EFIAPI *EFI_SET_WAKEUP_TIME) (
IN EFI_BOOLEAN Enable,
IN EFI_TIME * Time OPTIONAL
) __attribute((regparm(0)));
typedef enum {
EfiResetCold,
EfiResetWarm,
EfiResetShutdown,
#ifdef TIANO_EXTENSION_FLAG
EfiResetUpdate
#endif
} EFI_RESET_TYPE;
typedef
EFI_RUNTIMESERVICE
VOID
(EFIAPI *EFI_RESET_SYSTEM) (
IN EFI_RESET_TYPE ResetType,
IN EFI_STATUS ResetStatus,
IN EFI_UINTN DataSize,
IN EFI_CHAR16 * ResetData OPTIONAL
) __attribute__((regparm(0)));
typedef
EFI_RUNTIMESERVICE
EFI_STATUS
(EFIAPI *EFI_GET_NEXT_HIGH_MONO_COUNT) (
OUT EFI_UINT32 * HighCount
) __attribute__((regparm(0)));
//
// Definition of Status Code extended data header
//
// HeaderSize The size of the architecture. This is specified to enable
// the future expansion
//
// Size The size of the data in bytes. This does not include the size
// of the header structure.
//
// Type A GUID defining the type of the data
//
//
#ifdef TIANO_EXTENSION_FLAG
typedef
EFI_RUNTIMESERVICE
EFI_STATUS
(EFIAPI *EFI_REPORT_STATUS_CODE) (
IN EFI_STATUS_CODE_TYPE Type,
IN EFI_STATUS_CODE_VALUE Value,
IN EFI_UINT32 Instance,
IN EFI_GUID * CallerId OPTIONAL,
IN EFI_STATUS_CODE_DATA * Data OPTIONAL
) __attribute__((regparm(0)));
#endif
//
// EFI Runtime Services Table
//
#define EFI_RUNTIME_SERVICES_SIGNATURE 0x56524553544e5552ULL
#define EFI_RUNTIME_SERVICES_REVISION ((EFI_SPECIFICATION_MAJOR_REVISION << 16) | (EFI_SPECIFICATION_MINOR_REVISION))
typedef struct {
EFI_TABLE_HEADER Hdr;
//
// Time services
//
EFI_PTR32 GetTime;
EFI_PTR32 SetTime;
EFI_PTR32 GetWakeupTime;
EFI_PTR32 SetWakeupTime;
//
// Virtual memory services
//
EFI_PTR32 SetVirtualAddressMap;
EFI_PTR32 ConvertPointer;
//
// Variable services
//
EFI_PTR32 GetVariable;
EFI_PTR32 GetNextVariableName;
EFI_PTR32 SetVariable;
//
// Misc
//
EFI_PTR32 GetNextHighMonotonicCount;
EFI_PTR32 ResetSystem;
#ifdef TIANO_EXTENSION_FLAG
//
// ////////////////////////////////////////////////////
// Extended EFI Services
//////////////////////////////////////////////////////
//
EFI_PTR32 ReportStatusCode;
#endif
} __attribute__((aligned(8))) EFI_RUNTIME_SERVICES_32;
typedef struct {
EFI_TABLE_HEADER Hdr;
//
// Time services
//
EFI_PTR64 GetTime;
EFI_PTR64 SetTime;
EFI_PTR64 GetWakeupTime;
EFI_PTR64 SetWakeupTime;
//
// Virtual memory services
//
EFI_PTR64 SetVirtualAddressMap;
EFI_PTR64 ConvertPointer;
//
// Variable services
//
EFI_PTR64 GetVariable;
EFI_PTR64 GetNextVariableName;
EFI_PTR64 SetVariable;
//
// Misc
//
EFI_PTR64 GetNextHighMonotonicCount;
EFI_PTR64 ResetSystem;
#ifdef TIANO_EXTENSION_FLAG
//
// ////////////////////////////////////////////////////
// Extended EFI Services
//////////////////////////////////////////////////////
//
EFI_PTR64 ReportStatusCode;
#endif
} __attribute__((aligned(8))) EFI_RUNTIME_SERVICES_64;
//
// EFI Configuration Table
//
typedef struct {
EFI_GUID VendorGuid;
EFI_PTR32 VendorTable;
} EFI_CONFIGURATION_TABLE_32;
typedef struct {
EFI_GUID VendorGuid;
EFI_PTR64 VendorTable;
} __attribute__((aligned(8))) EFI_CONFIGURATION_TABLE_64;
//
// EFI System Table
//
#define EFI_SYSTEM_TABLE_SIGNATURE 0x5453595320494249ULL
#define EFI_SYSTEM_TABLE_REVISION ((EFI_SPECIFICATION_MAJOR_REVISION << 16) | (EFI_SPECIFICATION_MINOR_REVISION))
#define EFI_2_00_SYSTEM_TABLE_REVISION ((2 << 16) | 00)
#define EFI_1_02_SYSTEM_TABLE_REVISION ((1 << 16) | 02)
#define EFI_1_10_SYSTEM_TABLE_REVISION ((1 << 16) | 10)
typedef struct EFI_SYSTEM_TABLE_32 {
EFI_TABLE_HEADER Hdr;
EFI_PTR32 FirmwareVendor;
EFI_UINT32 FirmwareRevision;
EFI_HANDLE32 ConsoleInHandle;
EFI_PTR32 ConIn;
EFI_HANDLE32 ConsoleOutHandle;
EFI_PTR32 ConOut;
EFI_HANDLE32 StandardErrorHandle;
EFI_PTR32 StdErr;
EFI_PTR32 RuntimeServices;
EFI_PTR32 BootServices;
EFI_UINT32 NumberOfTableEntries;
EFI_PTR32 ConfigurationTable;
} __attribute__((aligned(8))) EFI_SYSTEM_TABLE_32;
typedef struct EFI_SYSTEM_TABLE_64 {
EFI_TABLE_HEADER Hdr;
EFI_PTR64 FirmwareVendor;
EFI_UINT32 FirmwareRevision;
EFI_UINT32 __pad;
EFI_HANDLE64 ConsoleInHandle;
EFI_PTR64 ConIn;
EFI_HANDLE64 ConsoleOutHandle;
EFI_PTR64 ConOut;
EFI_HANDLE64 StandardErrorHandle;
EFI_PTR64 StdErr;
EFI_PTR64 RuntimeServices;
EFI_PTR64 BootServices;
EFI_UINT64 NumberOfTableEntries;
EFI_PTR64 ConfigurationTable;
} __attribute__((aligned(8))) EFI_SYSTEM_TABLE_64;
#endif /* _PEXPERT_I386_EFI_H */
branches/xZen/src/arch/i386/libsaio/io_inline.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
* 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
* 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.
*
* 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,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* 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@
*/
/*
* Copyright (c) 1992 NeXT Computer, Inc.
*
* Inlines for io space access.
*
* HISTORY
*
* 20 May 1992 ? at NeXT
*Created.
*/
#ifndef __LIBSAIO_IO_INLINE_H
#define __LIBSAIO_IO_INLINE_H
/*
*############################################################################
*
* x86 IN/OUT I/O inline functions.
*
* IN : inb, inw, inl
* IN(port)
*
* OUT: outb, outw, outl
* OUT(port, data)
*
*############################################################################
*/
#define __IN(s, u) \
static inline unsigned u \
in##s(unsigned short port) \
{ \
unsigned u data; \
asm volatile ( \
"in" #s " %1,%0" \
: "=a" (data) \
: "d" (port)); \
return (data); \
}
#define __OUT(s, u) \
static inline void \
out##s(unsigned short port, unsigned u data) \
{ \
asm volatile ( \
"out" #s " %1,%0" \
: \
: "d" (port), "a" (data)); \
}
__IN(b, char) /* inb() */
__IN(w, short) /* inw() */
__IN(l, long) /* inl() */
__OUT(b, char) /* outb() */
__OUT(w, short) /* outw() */
__OUT(l, long) /* outl() */
#endif /* !__LIBSAIO_IO_INLINE_H */
branches/xZen/src/arch/i386/libsaio/bios.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
* 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
* 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.
*
* 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,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* 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@
*/
/*
* Copyright 1993 NeXT Computer, Inc.
* All rights reserved.
*
* Harness for calling real-mode BIOS functions.
*/
/* Copyright 2007 David Elliott
2007-12-30 dfe
- Enhanced code to use specified DS register when doing BIOS interrupt
- Fixed movl %ax,new_es bug which assembler was interpreting as
movl %eax,new_es which was overwriting the next word.
*/
#include <architecture/i386/asm_help.h>
#include "memory.h"
#define data32 .byte 0x66
#define addr32 .byte 0x67
#define O_INT 0
#define O_EAX 4
#define O_EBX 8
#define O_ECX 12
#define O_EDX 16
#define O_EDI 20
#define O_ESI 24
#define O_EBP 28
#define O_CS 32
#define O_DS 34
#define O_ES 36
#define O_FLG 38
.section __INIT,__data// turbo - Data that must be in the first segment
/* Saved registers:
These used to be (and in theory ought to be) located in __DATA,__bss.
The problem is that the larger the binary grows, more of the BSS gets
pushed into the next real-mode segment. Doing it this way we waste 24
bytes in the binary that our loader (e.g. boot1) must now load. But the
advantage is that we relocate this data to ensure it stays in the first
real-mode segment. Therefore, depending on link order, quite a lot of
new data, and possibly a lot of new executable code can be added to the
binary since with this change the BSS and most of the DATA is now only
accessed from protected mode where real-mode segment limits don't apply.
With this change, plus the earlier change to respect DS (e.g. use huge
pointers), the binary can grow much larger, currently up to exactly 63.5k
which is the maximum that the first-stage bootsectors can handle. To get
more than that more changes are needed. In that case we would have to
play with Mach-O segments to ensure real-mode code and data got stuffed
well within the first 63.5k. Furthermore, we'd have to adjust the boot
sectors to allow them to span segments.
Since this change alone only gains us about 4k more than where we're at
now (which is not anything to scoff at) it won't be very long before we
need to start using Mach-O segments to force the linker to locate certain
bits of code and data within the first 63.5k and modify the loaders to
be able to load more than 63.5k.
*/
.align 2
save_eax: .space 4
.align 2
save_edx: .space 4
.align 1
save_es: .space 2
.align 1
save_flag: .space 2
.align 2
new_eax: .space 4
.align 2
new_edx: .space 4
.align 1
new_es: .space 2
.align 1
new_ds: .space 2
.section __INIT,__text // turbo - This code must reside within the first segment
/*============================================================================
* Call real-mode BIOS INT functions.
*
*/
LABEL(_bios)
enter $0, $0
pushal
movl 8(%ebp), %edx // address of save area
movb O_INT(%edx), %al // save int number
movb %al, do_int+1
movl O_EBX(%edx), %ebx
movl O_ECX(%edx), %ecx
movl O_EDI(%edx), %edi
movl O_ESI(%edx), %esi
movl O_EBP(%edx), %ebp
movl %edx, save_edx
movl O_EAX(%edx), %eax
movl %eax, new_eax
movl O_EDX(%edx), %eax
movl %eax, new_edx
movw O_ES(%edx), %ax
movw %ax, new_es
movw O_DS(%edx), %ax
movw %ax, new_ds
call __prot_to_real
data32
addr32
mov OFFSET16(new_eax), %eax
data32
addr32
mov OFFSET16(new_edx), %edx
data32
addr32
mov OFFSET16(new_es), %es
push %ds // Save DS
// Replace DS. WARNING: Don't access data until it's restored!
addr32
data32
mov OFFSET16(new_ds), %ds
do_int:
int $0x00
pop %ds // Restore DS before we do anything else
pushf
data32
addr32
movl %eax, OFFSET16(save_eax)
popl %eax // actually pop %ax
addr32
movl %eax, OFFSET16(save_flag) // actually movw
mov %es, %ax
addr32
movl %eax, OFFSET16(save_es) // actually movw
data32
call __real_to_prot
movl %edx, new_edx // save new edx before clobbering
movl save_edx, %edx
movl new_edx, %eax // now move it into buffer
movl %eax, O_EDX(%edx)
movl save_eax, %eax
movl %eax, O_EAX(%edx)
movw save_es, %ax
movw %ax, O_ES(%edx)
movw save_flag, %ax
movw %ax, O_FLG(%edx)
movl %ebx, O_EBX(%edx)
movl %ecx, O_ECX(%edx)
movl %edi, O_EDI(%edx)
movl %esi, O_ESI(%edx)
movl %ebp, O_EBP(%edx)
popal
leave
ret
branches/xZen/src/arch/i386/libsaio/sys.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
/*
* 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
* 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.
*
* 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,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* 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@
*/
/*
* Mach Operating System
* Copyright (c) 1990 Carnegie-Mellon University
* Copyright (c) 1989 Carnegie-Mellon University
* Copyright (c) 1988 Carnegie-Mellon University
* Copyright (c) 1987 Carnegie-Mellon University
* All rights reserved. The CMU software License Agreement specifies
* the terms and conditions for use and redistribution.
*
*/
/*
* HISTORY
* Revision 2.3 88/08/08 13:47:07 rvb
* Allocate buffers dynamically vs statically.
* Now b[i] and i_fs and i_buf, are allocated dynamically.
* boot_calloc(size) allocates and zeros a buffer rounded to a NPG
* boundary.
* Generalize boot spec to allow, xx()/mach, xx(n,[a..h])/mach,
* xx([a..h])/mach, ...
* Also default "xx" if unspecified and alloc just "/mach",
* where everything is defaulted
* Add routine, ptol(), to parse partition letters.
*
*/
/*
* Copyright (c) 1982, 1986 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
*
*@(#)sys.c7.1 (Berkeley) 6/5/86
*/
/* Copyright 2007 VMware Inc.
"Preboot" ramdisk support added by David Elliott
*/
#include "libsaio.h"
#include "boot.h"
#include "disk.h"
#include "xml.h"
#include <libkern/crypto/md5.h>
//#include <uuid/uuid.h>
#if 0 /* No OS X release has ever included this. */
#include <Kernel/uuid/namespace.h>
#else
// from our uuid/namespace.h (UFS and HFS uuids can live in the same space?)
static unsigned char kFSUUIDNamespaceSHA1[] = {0xB3,0xE2,0x0F,0x39,0xF2,0x92,0x11,0xD6,0x97,0xA4,0x00,0x30,0x65,0x43,0xEC,0xAC};
#endif
extern int multiboot_partition;
extern int multiboot_partition_set;
struct devsw {
const char * name;
// size increased from char to short to handle non-BIOS internal devices
unsigned short biosdev;
int type;
};
// Device entries must be ordered by bios device numbers.
static struct devsw devsw[] =
{
{ "hd", 0x80, kBIOSDevTypeHardDrive }, /* DEV_HD */
{ "en", 0xE0, kBIOSDevTypeNetwork }, /* DEV_EN */
{ "rd", 0x100, kBIOSDevTypeHardDrive },
{ "bt", 0x101, kBIOSDevTypeHardDrive }, // turbo - type for booter partition
{ 0, 0 }
};
// Pseudo BIOS devices
enum {
kPseudoBIOSDevRAMDisk = 0x100,
kPseudoBIOSDevBooter = 0x101
};
/*
* Max number of file descriptors.
*/
#define NFILES 6
static struct iob iob[NFILES];
void * gFSLoadAddress = 0;
// Turbo - save what we think is our original BIOS boot volume if we have one 0xab
BVRef gBIOSBootVolume = NULL;
BVRef gBootVolume;
//static BVRef getBootVolumeRef( const char * path, const char ** outPath );
static BVRef newBootVolumeRef( int biosdev, int partno );
//==========================================================================
// LoadVolumeFile - LOW-LEVEL FILESYSTEM FUNCTION.
// Load the specified file from the specified volume
// to the load buffer at LOAD_ADDR.
// If the file is fat, load only the i386 portion.
long LoadVolumeFile(BVRef bvr, const char *filePath)
{
long fileSize;
// Read file into load buffer. The data in the load buffer will be
// overwritten by the next LoadFile() call.
gFSLoadAddress = (void *) LOAD_ADDR;
fileSize = bvr->fs_loadfile(bvr, (char *)filePath);
// Return the size of the file, or -1 if load failed.
return fileSize;
}
//==========================================================================
// LoadFile - LOW-LEVEL FILESYSTEM FUNCTION.
// Load the specified file to the load buffer at LOAD_ADDR.
// If the file is fat, load only the i386 portion.
long LoadFile(const char * fileSpec)
{
const char * filePath;
BVRef bvr;
// Resolve the boot volume from the file spec.
if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL)
return -1;
return LoadVolumeFile(bvr, filePath);
}
long ReadFileAtOffset(const char * fileSpec, void *buffer, uint64_t offset, uint64_t length)
{
const char *filePath;
BVRef bvr;
if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL)
return -1;
if (bvr->fs_readfile == NULL)
return -1;
return bvr->fs_readfile(bvr, (char *)filePath, buffer, offset, length);
}
long LoadThinFatFile(const char *fileSpec, void **binary)
{
const char *filePath;
FSReadFile readFile;
BVRef bvr;
unsigned long length, length2;
// Resolve the boot volume from the file spec.
if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL)
return -1;
*binary = (void *)kLoadAddr;
// Read file into load buffer. The data in the load buffer will be
// overwritten by the next LoadFile() call.
gFSLoadAddress = (void *) LOAD_ADDR;
readFile = bvr->fs_readfile;
if (readFile != NULL) {
// Read the first 4096 bytes (fat header)
length = readFile(bvr, (char *)filePath, *binary, 0, 0x1000);
if (length > 0) {
if (ThinFatFile(binary, &length) == 0) {
if (length == 0)
return 0;
// We found a fat binary; read only the thin part
length = readFile(bvr, (char *)filePath,
(void *)kLoadAddr, (unsigned long)(*binary) - kLoadAddr, length);
*binary = (void *)kLoadAddr;
} else {
// Not a fat binary; read the rest of the file
length2 = readFile(bvr, (char *)filePath, (void *)(kLoadAddr + length), length, 0);
if (length2 == -1) return -1;
length += length2;
}
}
} else {
length = bvr->fs_loadfile(bvr, (char *)filePath);
if (length > 0) {
ThinFatFile(binary, &length);
}
}
return length;
}
#if UNUSED
long GetFSUUID(char *spec, char *uuidStr)
{
BVRef bvr;
long rval = -1;
const char *devSpec;
if ((bvr = getBootVolumeRef(spec, &devSpec)) == NULL)
return -1;
if(bvr->fs_getuuid)
rval = bvr->fs_getuuid(bvr, uuidStr);
return rval;
}
#endif
// filesystem-specific getUUID functions call this shared string generator
long CreateUUIDString(uint8_t uubytes[], int nbytes, char *uuidStr)
{
unsigned fmtbase, fmtidx, i;
uint8_t uuidfmt[] = { 4, 2, 2, 2, 6 };
char *p = uuidStr;
MD5_CTX md5c;
uint8_t mdresult[16];
bzero(mdresult, sizeof(mdresult));
// just like AppleFileSystemDriver
MD5Init(&md5c);
MD5Update(&md5c, kFSUUIDNamespaceSHA1, sizeof(kFSUUIDNamespaceSHA1));
MD5Update(&md5c, uubytes, nbytes);
MD5Final(mdresult, &md5c);
// this UUID has been made version 3 style (i.e. via namespace)
// see "-uuid-urn-" IETF draft (which otherwise copies byte for byte)
mdresult[6] = 0x30 | ( mdresult[6] & 0x0F );
mdresult[8] = 0x80 | ( mdresult[8] & 0x3F );
// generate the text: e.g. 5EB1869F-C4FA-3502-BDEB-3B8ED5D87292
i = 0; fmtbase = 0;
for(fmtidx = 0; fmtidx < sizeof(uuidfmt); fmtidx++) {
for(i=0; i < uuidfmt[fmtidx]; i++) {
uint8_t byte = mdresult[fmtbase+i];
char nib;
nib = byte >> 4;
*p = nib + '0'; // 0x4 -> '4'
if(*p > '9') *p = (nib - 9 + ('A'-1)); // 0xB -> 'B'
p++;
nib = byte & 0xf;
*p = nib + '0'; // 0x4 -> '4'
if(*p > '9') *p = (nib - 9 + ('A'-1)); // 0xB -> 'B'
p++;
}
fmtbase += i;
if(fmtidx < sizeof(uuidfmt)-1)
*(p++) = '-';
else
*p = '\0';
}
return 0;
}
//==========================================================================
// GetDirEntry - LOW-LEVEL FILESYSTEM FUNCTION.
// Fetch the next directory entry for the given directory.
long GetDirEntry(const char * dirSpec, long long * dirIndex, const char ** name,
long * flags, long * time)
{
const char * dirPath;
BVRef bvr;
// Resolve the boot volume from the dir spec.
if ((bvr = getBootVolumeRef(dirSpec, &dirPath)) == NULL)
return -1;
// Return 0 on success, or -1 if there are no additional entries.
return bvr->fs_getdirentry( bvr,
/* dirPath */ (char *)dirPath,
/* dirIndex */ dirIndex,
/* dirEntry */ (char **)name, flags, time, 0, 0 );
}
//==========================================================================
// GetFileInfo - LOW-LEVEL FILESYSTEM FUNCTION.
// Get attributes for the specified file.
static char* gMakeDirSpec;
long GetFileInfo(const char * dirSpec, const char * name,
long * flags, long * time)
{
long long index = 0;
const char * entryName;
if (gMakeDirSpec == 0)
gMakeDirSpec = (char *)malloc(1024);
if (!dirSpec) {
long idx, len;
len = strlen(name);
for (idx = len; idx && (name[idx] != '/' && name[idx] != '\\'); idx--) {}
if (idx == 0) {
gMakeDirSpec[0] = '/';
gMakeDirSpec[1] = '\0';
} else {
idx++;
strncpy(gMakeDirSpec, name, idx);
name += idx;
}
dirSpec = gMakeDirSpec;
}
while (GetDirEntry(dirSpec, &index, &entryName, flags, time) == 0)
{
if (strcmp(entryName, name) == 0)
return 0; // success
}
return -1; // file not found
}
long GetFileBlock(const char *fileSpec, unsigned long long *firstBlock)
{
const char * filePath;
BVRef bvr;
// Resolve the boot volume from the file spec.
if ((bvr = getBootVolumeRef(fileSpec, &filePath)) == NULL) {
printf("Boot volume for '%s' is bogus\n", fileSpec);
return -1;
}
return bvr->fs_getfileblock(bvr, (char *)filePath, firstBlock);
}
//==========================================================================
// GetFreeFD()
static int GetFreeFd(void)
{
intfd;
// Locate a free descriptor slot.
for (fd = 0; fd < NFILES; fd++) {
if (iob[fd].i_flgs == 0) {
return fd;
}
}
stop("Out of file descriptors");
// not reached
return -1;
}
//==========================================================================
// iob_from_fdesc()
//
// Return a pointer to an allocated 'iob' based on the file descriptor
// provided. Returns NULL if the file descriptor given is invalid.
static struct iob * iob_from_fdesc(int fdesc)
{
register struct iob * io;
if (fdesc < 0 || fdesc >= NFILES ||
((io = &iob[fdesc])->i_flgs & F_ALLOC) == 0)
return NULL;
else
return io;
}
//==========================================================================
// openmem()
int openmem(char * buf, int len)
{
int fdesc;
struct iob * io;
fdesc = GetFreeFd();
io = &iob[fdesc];
bzero(io, sizeof(*io));
// Mark the descriptor as taken. Set the F_MEM flag to indicate
// that the file buffer is provided by the caller.
io->i_flgs = F_ALLOC | F_MEM;
io->i_buf = buf;
io->i_filesize = len;
return fdesc;
}
//==========================================================================
// open() - Open the file specified by 'path' for reading.
static int open_bvr(BVRef bvr, const char *filePath, int flags)
{
struct iob*io;
intfdesc;
inti;
if (bvr == NULL) {
return -1;
}
fdesc = GetFreeFd();
io = &iob[fdesc];
bzero(io, sizeof(*io));
// Mark the descriptor as taken.
io->i_flgs = F_ALLOC;
// Find the next available memory block in the download buffer.
io->i_buf = (char *) LOAD_ADDR;
for (i = 0; i < NFILES; i++) {
if ((iob[i].i_flgs != F_ALLOC) || (i == fdesc)) {
continue;
}
io->i_buf = MAX(iob[i].i_filesize + iob[i].i_buf, io->i_buf);
}
// Load entire file into memory. Unnecessary open() calls must be avoided.
gFSLoadAddress = io->i_buf;
io->i_filesize = bvr->fs_loadfile(bvr, (char *)filePath);
if (io->i_filesize < 0) {
close(fdesc);
return -1;
}
return fdesc;
}
int open(const char *path, int flags)
{
const char*filepath;
BVRefbvr;
// Resolve the boot volume from the file spec.
if ((bvr = getBootVolumeRef(path, &filepath)) != NULL) {
return open_bvr(bvr, filepath, flags);
}
return -1;
}
int open_bvdev(const char *bvd, const char *path, int flags)
{
const struct devsw*dp;
const char*cp;
BVRefbvr;
inti;
intlen;
intunit;
intpartition;
if ((i = open(path, flags)) >= 0) {
return i;
}
if (bvd == NULL || (len = strlen(bvd)) < 2) {
return -1;
}
for (dp=devsw; dp->name; dp++) {
if (bvd[0] == dp->name[0] && bvd[1] == dp->name[1]) {
unit = 0;
partition = 0;
/* get optional unit and partition */
if (len >= 5 && bvd[2] == '(') { /* min must be present xx(0) */
cp = &bvd[3];
i = 0;
while ((cp - path) < len && isdigit(*cp)) {
i = i * 10 + *cp++ - '0';
unit = i;
}
if (*cp++ == ',') {
i = 0;
while ((cp - path) < len && isdigit(*cp)) {
i = i * 10 + *cp++ - '0';
partition = i;
}
}
}
bvr = newBootVolumeRef(dp->biosdev + unit, partition);
return open_bvr(bvr, path, flags);
}
}
return -1;
}
//==========================================================================
// close() - Close a file descriptor.
int close(int fdesc)
{
struct iob * io;
if ((io = iob_from_fdesc(fdesc)) == NULL)
return (-1);
io->i_flgs = 0;
return 0;
}
//==========================================================================
// lseek() - Reposition the byte offset of the file descriptor from the
// beginning of the file. Returns the relocated offset.
int b_lseek(int fdesc, int offset, int ptr)
{
struct iob * io;
if ((io = iob_from_fdesc(fdesc)) == NULL)
return (-1);
io->i_offset = offset;
return offset;
}
//==========================================================================
// tell() - Returns the byte offset of the file descriptor.
int tell(int fdesc)
{
struct iob * io;
if ((io = iob_from_fdesc(fdesc)) == NULL)
return 0;
return io->i_offset;
}
//==========================================================================
// read() - Read up to 'count' bytes of data from the file descriptor
// into the buffer pointed to by buf.
int read(int fdesc, char * buf, int count)
{
struct iob * io;
if ((io = iob_from_fdesc(fdesc)) == NULL)
return (-1);
if ((io->i_offset + count) > (unsigned int)io->i_filesize)
count = io->i_filesize - io->i_offset;
if (count <= 0)
return 0; // end of file
bcopy(io->i_buf + io->i_offset, buf, count);
io->i_offset += count;
return count;
}
//==========================================================================
// write() - Write up to 'count' bytes of data to the file descriptor
// from the buffer pointed to by buf.
int write(int fdesc, const char * buf, int count)
{
struct iob * io;
if ((io = iob_from_fdesc(fdesc)) == NULL)
return (-1);
if ((io->i_offset + count) > (unsigned int)io->i_filesize)
count = io->i_filesize - io->i_offset;
if (count <= 0)
return 0; // end of file
bcopy(buf, io->i_buf + io->i_offset, count);
io->i_offset += count;
return count;
}
int writebyte(int fdesc, char value)
{
struct iob * io;
if ((io = iob_from_fdesc(fdesc)) == NULL)
return (-1);
if ((io->i_offset + 1) > (unsigned int)io->i_filesize)
return 0; // end of file
io->i_buf[io->i_offset++] = value;
return 1;
}
int writeint(int fdesc, int value)
{
struct iob * io;
if ((io = iob_from_fdesc(fdesc)) == NULL)
return (-1);
if ((io->i_offset + 4) > (unsigned int)io->i_filesize)
return 0; // end of file
bcopy(&value, io->i_buf + io->i_offset, 4);
io->i_offset += 4;
return 4;
}
//==========================================================================
// file_size() - Returns the size of the file described by the file
// descriptor.
int file_size(int fdesc)
{
struct iob * io;
if ((io = iob_from_fdesc(fdesc)) == 0)
return 0;
return io->i_filesize;
}
//==========================================================================
struct dirstuff * vol_opendir(BVRef bvr, const char * path)
{
struct dirstuff * dirp = 0;
dirp = (struct dirstuff *) malloc(sizeof(struct dirstuff));
if (dirp == NULL)
goto error;
dirp->dir_path = newString(path);
if (dirp->dir_path == NULL)
goto error;
dirp->dir_bvr = bvr;
return dirp;
error:
closedir(dirp);
return NULL;
}
//==========================================================================
struct dirstuff * opendir(const char * path)
{
struct dirstuff * dirp = 0;
const char * dirPath;
BVRef bvr;
if ((bvr = getBootVolumeRef(path, &dirPath)) == NULL)
goto error;
dirp = (struct dirstuff *) malloc(sizeof(struct dirstuff));
if (dirp == NULL)
goto error;
dirp->dir_path = newString(dirPath);
if (dirp->dir_path == NULL)
goto error;
dirp->dir_bvr = bvr;
return dirp;
error:
closedir(dirp);
return NULL;
}
//==========================================================================
int closedir(struct dirstuff * dirp)
{
if (dirp) {
if (dirp->dir_path) free(dirp->dir_path);
free(dirp);
}
return 0;
}
//==========================================================================
int readdir(struct dirstuff * dirp, const char ** name, long * flags,
long * time)
{
return dirp->dir_bvr->fs_getdirentry( dirp->dir_bvr,
/* dirPath */ dirp->dir_path,
/* dirIndex */ &dirp->dir_index,
/* dirEntry */ (char **)name, flags, time,
0, 0);
}
//==========================================================================
int readdir_ext(struct dirstuff * dirp, const char ** name, long * flags,
long * time, FinderInfo *finderInfo, long *infoValid)
{
return dirp->dir_bvr->fs_getdirentry( dirp->dir_bvr,
/* dirPath */ dirp->dir_path,
/* dirIndex */ &dirp->dir_index,
/* dirEntry */ (char **)name,
flags, time,
finderInfo, infoValid);
}
//==========================================================================
const char * systemConfigDir()
{
if (gBootFileType == kNetworkDeviceType)
return "";
return "/Library/Preferences/SystemConfiguration";
}
//==========================================================================
int gBootFileType;
void scanBootVolumes( int biosdev, int * count )
{
BVRef bvr = 0;
bvr = diskScanBootVolumes(biosdev, count);
if (bvr != NULL)
{
gBootFileType = kBlockDeviceType;
}
}
//==========================================================================
void scanDisks(int biosdev, int *count)
{
#define MAX_HDD_COUNT 32
int bvCount;
int hd = 0;
// Testing up to MAX_HDD_COUNT hard drives.
while(!testBiosread(0x80 + hd, 0) && hd < MAX_HDD_COUNT)
{
bvCount = 0;
scanBootVolumes(0x80 + hd, &bvCount);
hd++;
}
}
//==========================================================================
BVRef selectBootVolume( BVRef chain )
{
bool filteredChain = false;
bool foundPrimary = false;
BVRef bvr, bvr1 = 0, bvr2 = 0;
if (chain->filtered) filteredChain = true;
if (multiboot_partition_set)
for ( bvr = chain; bvr; bvr = bvr->next )
if ( bvr->part_no == multiboot_partition && bvr->biosdev == gBIOSDev )
return bvr;
/*
* Scannig the volume chain backwards and trying to find
* a HFS+ volume with valid boot record signature.
* If not found any active partition then we will
* select this volume as the boot volume.
*/
for ( bvr = chain; bvr; bvr = bvr->next )
{
if ( bvr->flags & kBVFlagPrimary && bvr->biosdev == gBIOSDev ) foundPrimary = true;
// zhell -- Undo a regression that was introduced from r491 to 492.
// if gBIOSBootVolume is set already, no change is required
if ( bvr->flags & (kBVFlagBootable|kBVFlagSystemVolume)
&& gBIOSBootVolume
&& (!filteredChain || (filteredChain && bvr->visible))
&& bvr->biosdev == gBIOSDev )
bvr2 = bvr;
// zhell -- if gBIOSBootVolume is NOT set, we use the "if" statement
// from r491,
if ( bvr->flags & kBVFlagBootable
&& ! gBIOSBootVolume
&& bvr->biosdev == gBIOSDev )
bvr2 = bvr;
}
/*
* Use the standrad method for selecting the boot volume.
*/
if (foundPrimary)
{
for ( bvr = chain; bvr; bvr = bvr->next )
{
if ( bvr->flags & kBVFlagNativeBoot && bvr->biosdev == gBIOSDev ) bvr1 = bvr;
if ( bvr->flags & kBVFlagPrimary && bvr->biosdev == gBIOSDev ) bvr2 = bvr;
}
}
bvr = bvr2 ? bvr2 :
bvr1 ? bvr1 : chain;
return bvr;
}
//==========================================================================
#define LP '('
#define RP ')'
int gBIOSDev;
/*!
This is like boot2's gBootVolume except it is for the internal use of
libsaio to track which volume an unqualified path should be relative to.
This replaces bootInfo->kernDev as the carrier of this information.
*/
static BVRef gRootVolume;
void setRootVolume(BVRef volume)
{
gRootVolume = volume;
// Veto non-native FS. Basically that means don't allow the root volume to
// be set to a volume we can't read files from.
if(gRootVolume != NULL && ((gRootVolume->flags & kBVFlagNativeBoot) == 0))
gRootVolume = NULL;
}
void setBootGlobals(BVRef chain)
{
// Record default boot device.
gBootVolume = selectBootVolume(chain);
// turbo - Save the ORIGINAL boot volume too for loading our mkext
if (!gBIOSBootVolume) gBIOSBootVolume = gBootVolume;
setRootVolume(gBootVolume);
}
/*!
Extracts the volume selector from the pathname, returns the selected
BVRef, and sets *outPath to the remainder of the path.
If the path did not include a volume selector then the current volume
is used. When called with a volume selector the current volume
is changed to the selected volume unless the volume selector is
that of a ramdisk.
*/
BVRef getBootVolumeRef( const char * path, const char ** outPath )
{
const char * cp;
BVRef bvr = gRootVolume;
int biosdev = gBIOSDev;
// Search for left parenthesis in the path specification.
for (cp = path; *cp; cp++) {
if (*cp == LP || *cp == '/') break;
}
if (*cp != LP) // no left paren found
{
// Path is using the implicit current device so if there is
// no current device, then we must fail.
cp = path;
if ( gRootVolume == NULL )
return NULL;
}
else if ((cp - path) == 2) // found "xx("
{
const struct devsw * dp;
const char * xp = path;
int i;
int unit = -1;
int part = -1;
cp++;
// Check the 2 character device name pointed by 'xp'.
for (dp = devsw; dp->name; dp++)
{
if ((xp[0] == dp->name[0]) && (xp[1] == dp->name[1]))
break; // found matching entry
}
if (dp->name == NULL)
{
error("Unknown device '%c%c'\n", xp[0], xp[1]);
return NULL;
}
// Extract the optional unit number from the specification.
// hd(unit) or hd(unit, part).
i = 0;
while (*cp >= '0' && *cp <= '9')
{
i = i * 10 + *cp++ - '0';
unit = i;
}
// Unit is no longer optional and never really was.
// If the user failed to specify it then the unit number from the previous kernDev
// would have been used which makes little sense anyway.
// For example, if the user did fd()/foobar and the current root device was the
// second hard disk (i.e. unit 1) then fd() would select the second floppy drive!
if(unit == -1)
return NULL;
// Extract the optional partition number from the specification.
if (*cp == ',')
part = atoi(++cp);
// If part is not specified part will be -1 whereas before it would have been
// whatever the last partition was which makes about zero sense if the device
// has been switched.
// Skip past the right paren.
for ( ; *cp && *cp != RP; cp++) /* LOOP */;
if (*cp == RP) cp++;
biosdev = dp->biosdev + unit;
bvr = newBootVolumeRef(biosdev, part);
if(bvr == NULL)
return NULL;
}
else
{
// Bad device specifier, skip past the right paren.
for ( cp++; *cp && *cp != RP; cp++) /* LOOP */;
if (*cp == RP) cp++;
// If gRootVolume was NULL, then bvr will be NULL as well which
// should be caught by the caller.
}
// Returns the file path following the device spec.
// e.g. 'hd(1,b)mach_kernel' is reduced to 'mach_kernel'.
*outPath = cp;
return bvr;
}
//==========================================================================
// Function name is a misnomer as scanBootVolumes usually calls diskScanBootVolumes
// which caches the information. So it's only allocated on the first run.
static BVRef newBootVolumeRef( int biosdev, int partno )
{
BVRef bvr, bvr1, bvrChain;
bvr = bvr1 = NULL;
{
// Fetch the volume list from the device.
scanBootVolumes( biosdev, NULL );
bvrChain = getBVChainForBIOSDev(biosdev);
// Look for a perfect match based on device and partition number.
for ( bvr1 = NULL, bvr = bvrChain; bvr; bvr = bvr->next )
{
if ( ( bvr->flags & kBVFlagNativeBoot ) == 0 ) continue;
bvr1 = bvr;
if ( bvr->part_no == partno ) break;
}
}
return bvr ? bvr : bvr1;
}
//==========================================================================
// getDeviceDescription() - Extracts unit number and partition number
// from bvr structure into "dw(u,p)" format.
// Returns length of the out string
int getDeviceDescription(BVRef bvr, char *str)
{
if(!str)
return 0;
*str = '\0';
if (bvr)
{
const struct devsw *dp = devsw;
while(dp->name && bvr->biosdev >= dp->biosdev)
dp++;
dp--;
if (dp->name)
return sprintf(str, "%s(%d,%d)", dp->name, bvr->biosdev - dp->biosdev, bvr->part_no);
}
return 0;
}
branches/xZen/src/arch/i386/libsaio/load.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
/*
* Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* 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,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* 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@
*/
/*
* load.c - Functions for decoding a Mach-o Kernel.
*
* Copyright (c) 1998-2003 Apple Computer, Inc.
*
*/
#include <mach-o/fat.h>
#include <mach-o/loader.h>
#include <mach/machine/thread_status.h>
#include <sl.h>
static long DecodeSegment(long cmdBase, unsigned int*load_addr, unsigned int *load_size);
static long DecodeUnixThread(long cmdBase, unsigned int *entry);
static long DecodeSymbolTable(long cmdBase);
static unsigned long gBinaryAddress;
bool gHaveKernelCache;/* XXX aserebln: uninitialized? and only set to true, never to false */
cpu_type_t archCpuType=CPU_TYPE_I386;
// Public Functions
long ThinFatFile(void **binary, unsigned long *length)
{
unsigned long nfat, swapped, size = 0;
struct fat_header *fhp = (struct fat_header *)*binary;
struct fat_arch *fap =
(struct fat_arch *)((unsigned long)*binary + sizeof(struct fat_header));
cpu_type_t fapcputype;
uint32_t fapoffset;
uint32_t fapsize;
if (fhp->magic == FAT_MAGIC) {
nfat = fhp->nfat_arch;
swapped = 0;
} else if (fhp->magic == FAT_CIGAM) {
nfat = OSSwapInt32(fhp->nfat_arch);
swapped = 1;
} else {
return -1;
}
for (; nfat > 0; nfat--, fap++) {
if (swapped) {
fapcputype = OSSwapInt32(fap->cputype);
fapoffset = OSSwapInt32(fap->offset);
fapsize = OSSwapInt32(fap->size);
}
else
{
fapcputype = fap->cputype;
fapoffset = fap->offset;
fapsize = fap->size;
}
if (fapcputype == archCpuType) {
*binary = (void *) ((unsigned long)*binary + fapoffset);
size = fapsize;
break;
}
}
if (length != 0) *length = size;
return 0;
}
long DecodeMachO(void *binary, entry_t *rentry, char **raddr, int *rsize)
{
struct mach_header *mH;
unsigned long ncmds, cmdBase, cmd, cmdsize, cmdstart;
// long headerBase, headerAddr, headerSize;
unsigned int vmaddr = ~0;
unsigned int vmend = 0;
unsigned long cnt;
long ret = -1;
unsigned int entry = 0;
gBinaryAddress = (unsigned long)binary;
mH = (struct mach_header *)(gBinaryAddress);
switch (archCpuType)
{
case CPU_TYPE_I386:
if (mH->magic != MH_MAGIC) {
error("Mach-O file has bad magic number\n");
return -1;
}
cmdstart = (unsigned long)gBinaryAddress + sizeof(struct mach_header);
break;
case CPU_TYPE_X86_64:
if (mH->magic != MH_MAGIC_64 && mH->magic == MH_MAGIC)
return -1;
if (mH->magic != MH_MAGIC_64) {
error("Mach-O file has bad magic number\n");
return -1;
}
cmdstart = (unsigned long)gBinaryAddress + sizeof(struct mach_header_64);
break;
default:
error("Unknown CPU type\n");
return -1;
}
cmdBase = cmdstart;
#if DEBUG
printf("magic: %x\n", (unsigned)mH->magic);
printf("cputype: %x\n", (unsigned)mH->cputype);
printf("cpusubtype: %x\n", (unsigned)mH->cpusubtype);
printf("filetype: %x\n", (unsigned)mH->filetype);
printf("ncmds: %x\n", (unsigned)mH->ncmds);
printf("sizeofcmds: %x\n", (unsigned)mH->sizeofcmds);
printf("flags: %x\n", (unsigned)mH->flags);
getchar();
#endif
ncmds = mH->ncmds;
for (cnt = 0; cnt < ncmds; cnt++) {
cmd = ((long *)cmdBase)[0];
cmdsize = ((long *)cmdBase)[1];
unsigned int load_addr;
unsigned int load_size;
switch (cmd) {
case LC_SEGMENT_64:
case LC_SEGMENT:
ret = DecodeSegment(cmdBase, &load_addr, &load_size);
if (ret == 0 && load_size != 0 && load_addr >= KERNEL_ADDR) {
vmaddr = MIN(vmaddr, load_addr);
vmend = MAX(vmend, load_addr + load_size);
}
break;
case LC_UNIXTHREAD:
ret = DecodeUnixThread(cmdBase, &entry);
break;
case LC_SYMTAB:
break;
default:
#if NOTDEF
printf("Ignoring cmd type %d.\n", (unsigned)cmd);
#endif
break;
}
if (ret != 0) return -1;
cmdBase += cmdsize;
}
*rentry = (entry_t)( (unsigned long) entry & 0x3fffffff );
*rsize = vmend - vmaddr;
*raddr = (char *)vmaddr;
cmdBase = cmdstart;
for (cnt = 0; cnt < ncmds; cnt++) {
cmd = ((long *)cmdBase)[0];
cmdsize = ((long *)cmdBase)[1];
if(cmd==LC_SYMTAB)
if (DecodeSymbolTable(cmdBase)!=0)
return -1;
cmdBase += cmdsize;
}
return ret;
}
// Private Functions
static long DecodeSegment(long cmdBase, unsigned int *load_addr, unsigned int *load_size)
{
unsigned long vmaddr, fileaddr;
long vmsize, filesize;
char *segname;
if (((long *)cmdBase)[0]==LC_SEGMENT_64)
{
struct segment_command_64 *segCmd;
segCmd = (struct segment_command_64 *)cmdBase;
vmaddr = (segCmd->vmaddr & 0x3fffffff);
vmsize = segCmd->vmsize;
fileaddr = (gBinaryAddress + segCmd->fileoff);
filesize = segCmd->filesize;
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();
#endif
}
else
{
struct segment_command *segCmd;
segCmd = (struct segment_command *)cmdBase;
vmaddr = (segCmd->vmaddr & 0x3fffffff);
vmsize = segCmd->vmsize;
fileaddr = (gBinaryAddress + segCmd->fileoff);
filesize = segCmd->filesize;
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();
#endif
}
if (vmsize == 0 || filesize == 0) {
*load_addr = ~0;
*load_size = 0;
return 0;
}
if (! ((vmaddr >= KERNEL_ADDR &&
(vmaddr + vmsize) <= (KERNEL_ADDR + KERNEL_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)))
gHaveKernelCache = true;
// Copy from file load area.
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)
bzero((char *)(vmaddr + filesize), vmsize - filesize);
*load_addr = vmaddr;
*load_size = vmsize;
return 0;
}
static long DecodeUnixThread(long cmdBase, unsigned int *entry)
{
switch (archCpuType)
{
case CPU_TYPE_I386:
{
i386_thread_state_t *i386ThreadState;
i386ThreadState = (i386_thread_state_t *)
(cmdBase + sizeof(struct thread_command) + 8);
*entry = i386ThreadState->eip;
return 0;
}
case CPU_TYPE_X86_64:
{
x86_thread_state64_t *x86_64ThreadState;
x86_64ThreadState = (x86_thread_state64_t *)
(cmdBase + sizeof(struct thread_command) + 8);
*entry = x86_64ThreadState->rip;
return 0;
}
default:
error("Unknown CPU type\n");
return -1;
}
}
static long DecodeSymbolTable(long cmdBase)
{
struct symtab_command *symTab, *symTableSave;
long tmpAddr, symsSize, totalSize;
long gSymbolTableAddr;
long gSymbolTableSize;
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);
getchar();
#endif
symsSize = symTab->stroff - symTab->symoff;
totalSize = symsSize + symTab->strsize;
gSymbolTableSize = totalSize + sizeof(struct symtab_command);
// gSymbolTableAddr = AllocateKernelMemory(gSymbolTableSize);
// Add the SymTab to the memory-map.
// AllocateMemoryRange("Kernel-__SYMTAB", gSymbolTableAddr, gSymbolTableSize, -1);
symTableSave = (struct symtab_command *)gSymbolTableAddr;
tmpAddr = gSymbolTableAddr + sizeof(struct symtab_command);
symTableSave->symoff = tmpAddr;
symTableSave->nsyms = symTab->nsyms;
symTableSave->stroff = tmpAddr + symsSize;
symTableSave->strsize = symTab->strsize;
bcopy((char *)(gBinaryAddress + symTab->symoff),
(char *)tmpAddr, totalSize);
return 0;
}
branches/xZen/src/arch/i386/libsaio/biosfn.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
/*
* 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
* 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.
*
* 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,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* 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@
*/
/*
* Copyright 1993 NeXT Computer, Inc.
* All rights reserved.
*/
/* Copyright 2007 David Elliott
2007-12-30 dfe
- Enhanced code to normalize segment/offset to huge pointers so that any
linear address within the first MB of memory can be passed to BIOS
functions. This allows some of the __DATA sections to span into the
next segment and also allows stack variables to be used whereas the
old code could only operate on static data in the first 64k.
NOTE: Requires bios.s change to respect DS.
*/
/* Copyright 2007 VMware Inc.
2007-12-29 dfe
- Added ebiosEjectMedia
*/
#include "libsaio.h"
#define MAX_DRIVES 8
static biosBuf_t bb;
int bgetc(void)
{
/* Poll for the next character. Most real BIOS do not need this as the
INT 16h,AH=0h function will block until one is received.
Unfortunately, Apple's EFI CSM will never wake up. This idea is lifted
from the grub-a20.patch to GRUB's stage2/asm.S file.
*/
while(!readKeyboardStatus())
;
bb.intno = 0x16;
bb.eax.r.h = 0x00;
bios(&bb);
return bb.eax.rr;
}
int readKeyboardStatus(void)
{
bb.intno = 0x16;
bb.eax.r.h = 0x01;
bios(&bb);
if (bb.flags.zf) {
return 0;
} else {
return bb.eax.rr;
}
}
int readKeyboardShiftFlags(void)
{
bb.intno = 0x16;
bb.eax.r.h = 0x02;
bios(&bb);
return bb.eax.r.l;
}
unsigned int time18(void)
{
union {
struct {
unsigned int low:16;
unsigned int high:16;
} s;
unsigned int i;
} time;
bb.intno = 0x1a;
bb.eax.r.h = 0x00;
bios(&bb);
time.s.low = bb.edx.rr;
time.s.high = bb.ecx.rr;
return time.i;
}
#if 0
static unsigned long rerangeMemoryMap(unsigned long count)
{
int i, still_changing, newcount = count;
MemoryRange * range = (MemoryRange *)BIOS_ADDR;
struct MemoryRange change_tmp;
/* sort map list by memory addresses (low -> high) */
still_changing = 1;
while (still_changing) {
still_changing = 0;
for (i=1; i<count; i++) {
/* if <current_addr> > <last_addr>, swap */
if (range[i].base < range[i-1].base) {
change_tmp.base = range[i].base;
change_tmp.length = range[i].length;
change_tmp.type = range[i].type;
range[i].base = range[i-1].base;
range[i].length = range[i-1].length;
range[i].type = range[i-1].type;
range[i-1].base = change_tmp.base;
range[i-1].length = change_tmp.length;
range[i-1].type = change_tmp.type;
still_changing=1;
}
}
}
/* clear overlaps */
/* linux's arch/i386/kern/setup.c may have better algorithm */
for (i=1; i<count; i++) {
if ( range[i-1].base + range[i-1].length > range[i].base ) {
range[newcount].base = range[i].base + range[i].length;
range[newcount].length = range[i-1].base + range[i-1].length - range[newcount].base;
range[newcount].type = range[i-1].type;
newcount++;
range[i-1].length = range[i].base - range[i-1].base;
}
}
/*
* 0xb0000000 : 0x10000000 NG
* 0xc0000400 NG
* 0xf2000000 NG
*/
range[newcount].base = 0xb0000000;
range[newcount].length = 0x0f000000;
range[newcount].type = kMemoryRangeUsable;
newcount++;
return newcount;
}
#endif
unsigned long getMemoryMap( MemoryRange * rangeArray,
unsigned long maxRangeCount,
unsigned long * conMemSizePtr,
unsigned long * extMemSizePtr )
{
#define kMemoryMapSignature 'SMAP'
#define kDescriptorSizeMin 20
MemoryRange *range = (MemoryRange *)BIOS_ADDR;
unsigned longcount = 0;
// unsigned longrerangedCount;
unsigned long longconMemSize = 0;
unsigned long longextMemSize = 0;
// Prepare for the INT15 E820h call. Each call returns a single
// memory range. A continuation value is returned that must be
// provided on a subsequent call to fetch the next range.
//
// Certain BIOSes (Award 6.00PG) expect the upper word in EAX
// to be cleared on entry, otherwise only a single range will
// be reported.
//
// Some BIOSes will simply ignore the value of ECX on entry.
// Probably best to keep its value at 20 to avoid surprises.
//printf("Get memory map 0x%x, %d\n", rangeArray); getchar();
if (maxRangeCount > (BIOS_LEN / sizeof(MemoryRange))) {
maxRangeCount = (BIOS_LEN / sizeof(MemoryRange));
}
bb.ebx.rx = 0; // Initial continuation value must be zero.
while ( count < maxRangeCount )
{
bb.intno = 0x15;
bb.eax.rx = 0xe820;
bb.ecx.rx = kDescriptorSizeMin;
bb.edx.rx = kMemoryMapSignature;
bb.edi.rr = NORMALIZED_OFFSET( (unsigned long) range );
bb.es = NORMALIZED_SEGMENT( (unsigned long) range );
bios(&bb);
// Check for errors.
if ( bb.flags.cf
|| bb.eax.rx != kMemoryMapSignature
|| bb.ecx.rx != kDescriptorSizeMin ) {
//printf("Got an error %x %x %x\n", bb.flags.cf,
// bb.eax.rx, bb.ecx.rx);
break;
}
// Tally up the conventional/extended memory sizes.
if ( range->type == kMemoryRangeUsable ||
range->type == kMemoryRangeACPI ||
range->type == kMemoryRangeNVS )
{
// Tally the conventional memory ranges.
if ( range->base + range->length <= 0xa0000 ) {
conMemSize += range->length;
}
// Record the top of extended memory.
if ( range->base >= EXTENDED_ADDR ) {
extMemSize += range->length;
}
}
range++;
count++;
// Is this the last address range?
if ( bb.ebx.rx == 0 ) {
//printf("last range\n");
break;
}
}
*conMemSizePtr = conMemSize / 1024; // size in KB
*extMemSizePtr = extMemSize / 1024; // size in KB
#if 0
rerangedCount = rerangeMemoryMap(count);
range += rerangedCount - count;
#endif
// Copy out data
bcopy((char *)BIOS_ADDR, rangeArray, ((char *)range - (char *)BIOS_ADDR));
#if DEBUG
{
int i;
printf("%d total ranges\n", count); getchar();
for (i=0, range = rangeArray; i<count; i++, range++) {
printf("range: type %d, base 0x%x, length 0x%x\n",
range->type, (unsigned int)range->base, (unsigned int)range->length); getchar();
}
}
#endif
return count;
}
unsigned long getExtendedMemorySize()
{
// Get extended memory size for large configurations. Not used unless
// the INT15, E820H call (Get System Address Map) failed.
//
// Input:
//
// AX Function Code E801h
//
// Outputs:
//
// CF Carry Flag Carry cleared indicates no error.
// AX Extended 1 Number of contiguous KB between 1 and 16 MB,
// maximum 0x3C00 = 15 MB.
// BX Extended 2 Number of contiguous 64 KB blocks between
// 16 MB and 4 GB.
// CX Configured 1 Number of contiguous KB between 1 and 16 MB,
// maximum 0x3C00 = 15 MB.
// DX Configured 2 Number of contiguous 64 KB blocks between
// 16 MB and 4 GB.
bb.intno = 0x15;
bb.eax.rx = 0xe801;
bios(&bb);
// Return the size of memory above 1MB (extended memory) in kilobytes.
if ( bb.flags.cf == 0 ) return (bb.ebx.rr * 64 + bb.eax.rr);
// Get Extended memory size. Called on last resort since the return
// value is limited to 16-bits (a little less than 64MB max). May
// not be supported by modern BIOSes.
//
// Input:
//
// AX Function Code E801h
//
// Outputs:
//
// CF Carry Flag Carry cleared indicates no error.
// AX Memory Count Number of contiguous KB above 1MB.
bb.intno = 0x15;
bb.eax.rx = 0x88;
bios(&bb);
// Return the size of memory above 1MB (extended memory) in kilobytes.
return bb.flags.cf ? 0 : bb.eax.rr;
}
unsigned long getConventionalMemorySize()
{
bb.intno = 0x12;
bios(&bb);
return bb.eax.rr; // kilobytes
}
void video_mode(int mode)
{
bb.intno = 0x10;
bb.eax.r.h = 0x00;
bb.eax.r.l = mode;
bios(&bb);
}
int biosread(int dev, int cyl, int head, int sec, int num)
{
int i;
bb.intno = 0x13;
sec += 1; /* sector numbers start at 1 */
for (i=0;;) {
bb.ecx.r.h = cyl;
bb.ecx.r.l = ((cyl & 0x300) >> 2) | (sec & 0x3F);
bb.edx.r.h = head;
bb.edx.r.l = dev;
bb.eax.r.l = num;
bb.ebx.rr = OFFSET(ptov(BIOS_ADDR));
bb.es = SEGMENT(ptov(BIOS_ADDR));
bb.eax.r.h = 0x02;
bios(&bb);
/* In case of a successful call, make sure we set AH (return code) to zero. */
if (bb.flags.cf == 0)
bb.eax.r.h = 0;
/* Now we can really check for the return code (AH) value. */
if ((bb.eax.r.h == 0x00) || (i++ >= 5))
break;
/* reset disk subsystem and try again */
bb.eax.r.h = 0x00;
bios(&bb);
}
return bb.eax.r.h;
}
int ebiosread(int dev, unsigned long long sec, int count)
{
int i;
static struct {
unsigned char size;
unsigned char reserved;
unsigned char numblocks;
unsigned char reserved2;
unsigned short bufferOffset;
unsigned short bufferSegment;
unsigned long long startblock;
} addrpacket __attribute__((aligned(16))) = {0};
addrpacket.size = sizeof(addrpacket);
for (i=0;;) {
bb.intno = 0x13;
bb.eax.r.h = 0x42;
bb.edx.r.l = dev;
bb.esi.rr = NORMALIZED_OFFSET((unsigned)&addrpacket);
bb.ds = NORMALIZED_SEGMENT((unsigned)&addrpacket);
addrpacket.reserved = addrpacket.reserved2 = 0;
addrpacket.numblocks = count;
addrpacket.bufferOffset = OFFSET(ptov(BIOS_ADDR));
addrpacket.bufferSegment = SEGMENT(ptov(BIOS_ADDR));
addrpacket.startblock = sec;
bios(&bb);
/* In case of a successful call, make sure we set AH (return code) to zero. */
if (bb.flags.cf == 0)
bb.eax.r.h = 0;
/* Now we can really check for the return code (AH) value. */
if ((bb.eax.r.h == 0x00) || (i++ >= 5))
break;
/* reset disk subsystem and try again */
bb.eax.r.h = 0x00;
bios(&bb);
}
return bb.eax.r.h;
}
int ebioswrite(int dev, long sec, int count)
{
int i;
static struct {
unsigned char size;
unsigned char reserved;
unsigned char numblocks;
unsigned char reserved2;
unsigned short bufferOffset;
unsigned short bufferSegment;
unsigned long long startblock;
} addrpacket __attribute__((aligned(16))) = {0};
addrpacket.size = sizeof(addrpacket);
for (i=0;;) {
bb.intno = 0x13;
bb.eax.r.l = 0; /* Don't verify */
bb.eax.r.h = 0x43;
bb.edx.r.l = dev;
bb.esi.rr = NORMALIZED_OFFSET((unsigned)&addrpacket);
bb.ds = NORMALIZED_SEGMENT((unsigned)&addrpacket);
addrpacket.reserved = addrpacket.reserved2 = 0;
addrpacket.numblocks = count;
addrpacket.bufferOffset = OFFSET(ptov(BIOS_ADDR));
addrpacket.bufferSegment = SEGMENT(ptov(BIOS_ADDR));
addrpacket.startblock = sec;
bios(&bb);
/* In case of a successful call, make sure we set AH (return code) to zero. */
if (bb.flags.cf == 0)
bb.eax.r.h = 0;
/* Now we can really check for the return code (AH) value. */
if ((bb.eax.r.h == 0x00) || (i++ >= 5))
break;
/* reset disk subsystem and try again */
bb.eax.r.h = 0x00;
bios(&bb);
}
return bb.eax.r.h;
}
void bios_putchar(int ch)
{
bb.intno = 0x10;
bb.ebx.r.h = 0x00; /* background black */
bb.ebx.r.l = 0x0F; /* foreground white */
bb.eax.r.h = 0x0e;
bb.eax.r.l = ch;
bios(&bb);
}
void putca(int ch, int attr, int repeat)
{
bb.intno = 0x10;
bb.ebx.r.h = 0x00; /* page number */
bb.ebx.r.l = attr; /* attribute */
bb.eax.r.h = 0x9;
bb.eax.r.l = ch;
bb.ecx.rx = repeat; /* repeat count */
bios(&bb);
}
/* Check to see if the passed-in drive is in El Torito no-emulation mode. */
int is_no_emulation(int drive)
{
struct packet {
unsigned char packet_size;
unsigned char media_type;
unsigned char drive_num;
unsigned char ctrlr_index;
unsigned long lba;
unsigned short device_spec;
unsigned short buffer_segment;
unsigned short load_segment;
unsigned short sector_count;
unsigned char cyl_count;
unsigned char sec_count;
unsigned char head_count;
unsigned char reseved;
} __attribute__((packed));
static struct packet pkt;
bzero(&pkt, sizeof(pkt));
pkt.packet_size = 0x13;
bb.intno= 0x13;
bb.eax.r.h= 0x4b;
bb.eax.r.l= 0x01; // subfunc: get info
bb.edx.r.l= drive;
bb.esi.rr= NORMALIZED_OFFSET((unsigned)&pkt);
bb.ds= NORMALIZED_SEGMENT((unsigned)&pkt);
bios(&bb);
#if DEBUG
printf("el_torito info drive %x\n", drive);
printf("--> cf %x, eax %x\n", bb.flags.cf, bb.eax.rr);
printf("pkt_size: %x\n", pkt.packet_size);
printf("media_type: %x\n", pkt.media_type);
printf("drive_num: %x\n", pkt.drive_num);
printf("device_spec: %x\n", pkt.device_spec);
pause();
#endif
/* Some BIOSes erroneously return cf = 1 */
/* Just check to see if the drive number is the same. */
if (pkt.drive_num == drive) {
if ((pkt.media_type & 0x0F) == 0) {
/* We are in no-emulation mode. */
return 1;
}
}
return 0;
}
#if DEBUG
/*
* BIOS drive information.
*/
void print_drive_info(boot_drive_info_t *dp)
{
//printf("buf_size = %x\n", dp->params.buf_size);
printf("info_flags = %x\n", dp->params.info_flags);
printf("phys_cyls = %lx\n", dp->params. phys_cyls);
printf("phys_heads = %lx\n", dp->params. phys_heads);
printf("phys_spt = %lx\n", dp->params. phys_spt);
printf("phys_sectors = %lx%lx\n", ((unsigned long *)(&dp->params.phys_sectors))[1],
((unsigned long *)(&dp->params.phys_sectors))[0]);
printf("phys_nbps = %x\n", dp->params.phys_nbps);
//printf("dpte_offset = %x\n", dp->params.dpte_offset);
//printf("dpte_segment = %x\n", dp->params.dpte_segment);
//printf("key = %x\n", dp->params.key);
//printf("path_len = %x\n", dp->params. path_len);
//printf("reserved1 = %x\n", dp->params. reserved1);
//printf("reserved2 = %x\n", dp->params.reserved2);
//printf("bus_type[4] = %x\n", dp->params. bus_type[4]);
//printf("interface_type[8] = %x\n", dp->params. interface_type[8]);
//printf("interface_path[8] = %x\n", dp->params. interface_path[8]);
//printf("dev_path[8] = %x\n", dp->params. dev_path[8]);
//printf("reserved3 = %x\n", dp->params. reserved3);
//printf("checksum = %x\n", dp->params. checksum);
printf("io_port_base = %x\n", dp->dpte.io_port_base);
printf("control_port_base = %x\n", dp->dpte.control_port_base);
printf("head_flags = %x\n", dp->dpte. head_flags);
printf("vendor_info = %x\n", dp->dpte. vendor_info);
printf("irq = %x\n", dp->dpte. irq);
//printf("irq_unused = %x\n", dp->dpte. irq_unused);
printf("block_count = %x\n", dp->dpte. block_count);
printf("dma_channe = %x\n", dp->dpte. dma_channel);
printf("dma_type = %x\n", dp->dpte. dma_type);
printf("pio_type = %x\n", dp->dpte. pio_type);
printf("pio_unused = %x\n", dp->dpte. pio_unused);
printf("option_flags = %x\n", dp->dpte.option_flags);
//printf("reserved = %x\n", dp->dpte.reserved);
printf("revision = %x\n", dp->dpte. revision);
//printf("checksum = %x\n", dp->dpte. checksum);
}
#endif
int ebiosEjectMedia(int biosdev)
{
bb.intno = 0x13;
bb.eax.r.h = 0x46;