Index: branches/xZenu/src/arch/i386/libsaio/xml.c =================================================================== --- branches/xZenu/src/arch/i386/libsaio/xml.c (revision 1302) +++ branches/xZenu/src/arch/i386/libsaio/xml.c (revision 1303) @@ -1,1129 +0,0 @@ -/* - * 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 -#include -#include -#include "libsaio.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) - { - printf("NULL symbol!"); - while(1); - } - - // 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) - { - printf("last guy not last!"); - while(1); - } - 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; -} Index: branches/xZenu/src/arch/i386/libsaio/xml.h =================================================================== --- branches/xZenu/src/arch/i386/libsaio/xml.h (revision 1302) +++ branches/xZenu/src/arch/i386/libsaio/xml.h (revision 1303) @@ -1,113 +0,0 @@ -/* - * 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 - -typedef char bool; -#define false 0 -#define true 1 - -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 */ Index: branches/xZenu/src/arch/i386/libsaio/efi.h =================================================================== --- branches/xZenu/src/arch/i386/libsaio/efi.h (revision 1302) +++ branches/xZenu/src/arch/i386/libsaio/efi.h (revision 1303) @@ -1,558 +0,0 @@ -/* - * 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 - -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 */ Index: branches/xZenu/src/arch/i386/libsaio/sys.c =================================================================== --- branches/xZenu/src/arch/i386/libsaio/sys.c (revision 1302) +++ branches/xZenu/src/arch/i386/libsaio/sys.c (revision 1303) @@ -1,1039 +0,0 @@ -/* - * 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.c 7.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 -//#include - -#if 0 /* No OS X release has ever included this. */ -#include -#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) -{ - int fd; - - // 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; - int fdesc; - int i; - - 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; - BVRef bvr; - - // 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; - BVRef bvr; - int i; - int len; - int unit; - int partition; - - 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; -} Index: branches/xZenu/src/arch/i386/libsaio/load.c =================================================================== --- branches/xZenu/src/arch/i386/libsaio/load.c (revision 1302) +++ branches/xZenu/src/arch/i386/libsaio/load.c (revision 1303) @@ -1,81 +0,0 @@ -/* - * 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 -#include -#include - - -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; -} \ No newline at end of file Index: branches/xZenu/src/arch/i386/libsaio/bootargs.h =================================================================== --- branches/xZenu/src/arch/i386/libsaio/bootargs.h (revision 1302) +++ branches/xZenu/src/arch/i386/libsaio/bootargs.h (revision 1303) @@ -1,193 +0,0 @@ -/* - * Copyright (c) 2000 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_BOOT_H -#define _PEXPERT_I386_BOOT_H - -#include - -/* - * What the booter leaves behind for the kernel. - */ - -/* - * Types of boot driver that may be loaded by the booter. - */ -enum { - kBootDriverTypeInvalid = 0, - kBootDriverTypeKEXT = 1, - kBootDriverTypeMKEXT = 2 -}; - -enum { - kEfiReservedMemoryType = 0, - kEfiLoaderCode = 1, - kEfiLoaderData = 2, - kEfiBootServicesCode = 3, - kEfiBootServicesData = 4, - kEfiRuntimeServicesCode = 5, - kEfiRuntimeServicesData = 6, - kEfiConventionalMemory = 7, - kEfiUnusableMemory = 8, - kEfiACPIReclaimMemory = 9, - kEfiACPIMemoryNVS = 10, - kEfiMemoryMappedIO = 11, - kEfiMemoryMappedIOPortSpace = 12, - kEfiPalCode = 13, - kEfiMaxMemoryType = 14 -}; - -/* - * Memory range descriptor. - */ -typedef struct EfiMemoryRange { - uint32_t Type; - uint32_t Pad; - uint64_t PhysicalStart; - uint64_t VirtualStart; - uint64_t NumberOfPages; - uint64_t Attribute; -} EfiMemoryRange; - -#define BOOT_LINE_LENGTH 1024 -#define BOOT_STRING_LEN BOOT_LINE_LENGTH - -/* - * Video information.. - */ - -struct Boot_Video { - uint32_t v_baseAddr; /* Base address of video memory */ - uint32_t v_display; /* Display Code (if Applicable */ - uint32_t v_rowBytes; /* Number of bytes per pixel row */ - uint32_t v_width; /* Width */ - uint32_t v_height; /* Height */ - uint32_t v_depth; /* Pixel Depth */ -}; - -typedef struct Boot_Video Boot_Video; - -/* Values for v_display */ - -#define GRAPHICS_MODE 1 -#define FB_TEXT_MODE 2 - -/* Boot argument structure - passed into Mach kernel at boot time. - * "Revision" can be incremented for compatible changes - */ -// Lion -#define kBootArgsRevision 0 -#define kBootArgsVersion 2 - -// Snow Leopard and older -#define kBootArgsPreLionRevision 6 -#define kBootArgsPreLionVersion 1 - -/* Snapshot constants of previous revisions that are supported */ - -#define kBootArgsEfiMode32 32 -#define kBootArgsEfiMode64 64 - -typedef struct boot_args { - uint16_t Revision; /* Revision of boot_args structure */ - uint16_t Version; /* Version of boot_args structure */ - - uint8_t efiMode; /* 32 = 32-bit, 64 = 64-bit */ - uint8_t debugMode; /* Bit field with behavior changes */ - uint8_t __reserved1[2]; - - char CommandLine[BOOT_LINE_LENGTH]; /* Passed in command line */ - - uint32_t MemoryMap; /* Physical address of memory map */ - uint32_t MemoryMapSize; - uint32_t MemoryMapDescriptorSize; - uint32_t MemoryMapDescriptorVersion; - - Boot_Video Video; /* Video Information */ - - uint32_t deviceTreeP; /* Physical address of flattened device tree */ - uint32_t deviceTreeLength; /* Length of flattened tree */ - - uint32_t kaddr; /* Physical address of beginning of kernel text */ - uint32_t ksize; /* Size of combined kernel text+data+efi */ - - uint32_t efiRuntimeServicesPageStart; /* physical address of defragmented runtime pages */ - uint32_t efiRuntimeServicesPageCount; - uint64_t efiRuntimeServicesVirtualPageStart; /* virtual address of defragmented runtime pages */ - - uint32_t efiSystemTable; /* physical address of system table in runtime area */ - uint32_t __reserved2; - - uint32_t performanceDataStart; /* physical address of log */ - uint32_t performanceDataSize; - - uint32_t keyStoreDataStart; /* physical address of key store data */ - uint32_t keyStoreDataSize; - uint64_t bootMemStart; - uint64_t bootMemSize; - uint64_t PhysicalMemorySize; - uint64_t FSBFrequency; - uint32_t __reserved4[734]; - -} boot_args; - -typedef struct boot_args_pre_lion { - uint16_t Revision; /* Revision of boot_args structure */ - uint16_t Version; /* Version of boot_args structure */ - - char CommandLine[BOOT_LINE_LENGTH]; /* Passed in command line */ - - uint32_t MemoryMap; /* Physical address of memory map */ - uint32_t MemoryMapSize; - uint32_t MemoryMapDescriptorSize; - uint32_t MemoryMapDescriptorVersion; - - Boot_Video Video; /* Video Information */ - - uint32_t deviceTreeP; /* Physical address of flattened device tree */ - uint32_t deviceTreeLength; /* Length of flattened tree */ - - uint32_t kaddr; /* Physical address of beginning of kernel text */ - uint32_t ksize; /* Size of combined kernel text+data+efi */ - - uint32_t efiRuntimeServicesPageStart; /* physical address of defragmented runtime pages */ - uint32_t efiRuntimeServicesPageCount; - uint32_t efiSystemTable; /* physical address of system table in runtime area */ - - uint8_t efiMode; /* 32 = 32-bit, 64 = 64-bit */ - uint8_t __reserved1[3]; - uint32_t __reserved2[1]; - uint32_t performanceDataStart; /* physical address of log */ - uint32_t performanceDataSize; - uint64_t efiRuntimeServicesVirtualPageStart; /* virtual address of defragmented runtime pages */ - uint32_t __reserved3[2]; - -} boot_args_pre_lion; - -extern char gMacOSVersion[8]; - -#endif /* _PEXPERT_I386_BOOT_H */ Index: branches/xZenu/src/arch/i386/libsaio/bios.h =================================================================== --- branches/xZenu/src/arch/i386/libsaio/bios.h (revision 1302) +++ branches/xZenu/src/arch/i386/libsaio/bios.h (revision 1303) @@ -29,7 +29,6 @@ #ifndef __LIBSAIO_BIOS_H #define __LIBSAIO_BIOS_H -#include "bootargs.h" typedef union { unsigned int rx; Index: branches/xZenu/src/arch/i386/libsaio/saio_types.h =================================================================== --- branches/xZenu/src/arch/i386/libsaio/saio_types.h (revision 1302) +++ branches/xZenu/src/arch/i386/libsaio/saio_types.h (revision 1303) @@ -30,7 +30,6 @@ #include #include #include "bios.h" -#include "bootargs.h" #if DEBUG #define DEBUG_DISK(x) printf x Index: branches/xZenu/src/arch/i386/libsaio/Makefile =================================================================== --- branches/xZenu/src/arch/i386/libsaio/Makefile (revision 1302) +++ branches/xZenu/src/arch/i386/libsaio/Makefile (revision 1303) @@ -26,7 +26,7 @@ INC = -I. -I$(SYMROOT) -I$(LIBSADIR) -I$(BOOT2DIR) -I${SRCROOT}/include OBJECTS = table asm bios biosfn \ - misc xml load console + misc console LIBS = libsaio.a LIBS := $(addprefix $(SYMROOT)/, $(LIBS))