void smbios_real_run (struct SMBEntryPoint * origsmbios, struct SMBEntryPoint * newsmbios) { char *smbiostables=0; char *tablesptr, *newtablesptr; int origsmbiosnum=0; // bitmask of used handles uint8_t handles[8192]; uint16_t nexthandle=0; int i, j; int tablespresent[256]; BOOL do_auto=1; getBoolForKey("SMBIOSdefaults",&do_auto,&bootInfo->bootConfig); for (i=0;i<256;i++) tablespresent[i]=0; memset (handles,0,8192); newsmbios->dmi.tableAddress=(uint32_t)AllocateKernelMemory(newsmbios->dmi.tableLength); if (origsmbios) { smbiostables=(char *) origsmbios->dmi.tableAddress; origsmbiosnum=origsmbios->dmi.structureCount; } tablesptr=smbiostables; newtablesptr=(char *) newsmbios->dmi.tableAddress; if (smbiostables) for (i=0;i<origsmbiosnum;i++) { struct smbios_table_header *oldcur =(struct smbios_table_header *) tablesptr, *newcur=(struct smbios_table_header *) newtablesptr; char *stringsptr; int nstrings=0; handles[(oldcur->handle)/8]|=1<<((oldcur->handle)%8); memcpy (newcur,oldcur, oldcur->length); tablesptr+=oldcur->length; stringsptr=tablesptr; newtablesptr+=oldcur->length; for (;tablesptr[0]!=0 || tablesptr[1]!=0;tablesptr++) if (tablesptr[0]==0) nstrings++; if (tablesptr!=stringsptr) nstrings++; tablesptr+=2; memcpy (newtablesptr,stringsptr,tablesptr-stringsptr); //point to next possible space for a string newtablesptr+=tablesptr-stringsptr-1; if (nstrings==0) newtablesptr--; for (j=0;j<sizeof (smbios_properties)/sizeof(smbios_properties[0]); j++) { const char *str; int size; int num; char altname[40]; sprintf (altname, "%s_%d",smbios_properties[j].name, tablespresent[newcur->type]+1); if (smbios_properties[j].table_type==newcur->type) switch (smbios_properties[j].value_type) { case SMSTRING: if (getValueForKey(altname,&str, &size, &bootInfo->smbiosConfig) ||getValueForKey(smbios_properties[j].name,&str, &size, &bootInfo->smbiosConfig)) { memcpy (newtablesptr, str,size); newtablesptr[size]=0; newtablesptr+=size+1; *((uint8_t*)(((char*)newcur)+smbios_properties[j].offset))=++nstrings; } else if (do_auto && smbios_properties[j].auto_str) { str=smbios_properties[j].auto_str(smbios_properties[j].name,tablespresent[newcur->type]); size=strlen (str); memcpy (newtablesptr, str,size); newtablesptr[size]=0; newtablesptr+=size+1; *((uint8_t*)(((char*)newcur)+smbios_properties[j].offset))=++nstrings; } break; case SMOWORD: if (getValueForKey(altname,&str, &size, &bootInfo->smbiosConfig) ||getValueForKey(smbios_properties[j].name,&str, &size, &bootInfo->smbiosConfig)) { int k=0, t=0, kk=0; const char *ptr=str; memset(((char*)newcur)+smbios_properties[j].offset, 0, 16); while (ptr-str<size && *ptr && (*ptr==' ' || *ptr=='\t' || *ptr=='\n')) ptr++; if (size-(ptr-str)>=2 && ptr[0]=='0' && (ptr[1]=='x' || ptr[1]=='X')) ptr+=2; for (;ptr-str<size && *ptr && k<16;ptr++) { if (*ptr>='0' && *ptr<='9') (t=(t<<4)|(*ptr-'0')),kk++; if (*ptr>='a' && *ptr<='f') (t=(t<<4)|(*ptr-'a'+10)),kk++; if (*ptr>='A' && *ptr<='F') (t=(t<<4)|(*ptr-'A'+10)),kk++; if (kk==2) { *((uint8_t*)(((char*)newcur)+smbios_properties[j].offset+k))=t; k++; kk=0; t=0; } } } break; case SMBYTE: if (getIntForKey(altname,&num,&bootInfo->smbiosConfig) ||getIntForKey(smbios_properties[j].name,&num,&bootInfo->smbiosConfig)) *((uint8_t*)(((char*)newcur)+smbios_properties[j].offset))=num; else if (do_auto && smbios_properties[j].auto_int) *((uint8_t*)(((char*)newcur)+smbios_properties[j].offset)) =smbios_properties[j].auto_int(smbios_properties[j].name, tablespresent[newcur->type]); break; case SMWORD: if (getIntForKey(altname,&num,&bootInfo->smbiosConfig) ||getIntForKey(smbios_properties[j].name,&num,&bootInfo->smbiosConfig)) *((uint16_t*)(((char*)newcur)+smbios_properties[j].offset))=num; else if (do_auto && smbios_properties[j].auto_int) *((uint16_t*)(((char*)newcur)+smbios_properties[j].offset)) =smbios_properties[j].auto_int(smbios_properties[j].name, tablespresent[newcur->type]); break; } } if (nstrings==0) { newtablesptr[0]=0; newtablesptr++; } newtablesptr[0]=0; newtablesptr++; tablespresent[newcur->type]++; } for (i=0;i<sizeof (smbios_table_descriptions) /sizeof(smbios_table_descriptions[0]);i++) { int numnec=-1; char buffer[40]; sprintf (buffer, "SMtable%d", i); if (!getIntForKey(buffer,&numnec,&bootInfo->smbiosConfig)) numnec=-1; if (numnec==-1 && do_auto && smbios_table_descriptions[i].numfunc) numnec=smbios_table_descriptions[i].numfunc (smbios_table_descriptions[i].type); while (tablespresent[smbios_table_descriptions[i].type]<numnec) { struct smbios_table_header *newcur=(struct smbios_table_header *) newtablesptr; int nstrings=0; memset (newcur,0, smbios_table_descriptions[i].len); while (handles[(nexthandle)/8]&(1<<((nexthandle)%8))) nexthandle++; newcur->handle=nexthandle; handles[nexthandle/8]|=1<<(nexthandle%8); newcur->type=smbios_table_descriptions[i].type; newcur->length=smbios_table_descriptions[i].len; newtablesptr+=smbios_table_descriptions[i].len; for (j=0;j<sizeof (smbios_properties)/sizeof(smbios_properties[0]); j++) { const char *str; int size; int num; char altname[40]; sprintf (altname, "%s_%d",smbios_properties[j].name, tablespresent[newcur->type]+1); if (smbios_properties[j].table_type==newcur->type) switch (smbios_properties[j].value_type) { case SMSTRING: if (getValueForKey(altname,&str, &size, &bootInfo->smbiosConfig) ||getValueForKey(smbios_properties[j].name,&str, &size, &bootInfo->smbiosConfig)) { memcpy (newtablesptr, str,size); newtablesptr[size]=0; newtablesptr+=size+1; *((uint8_t*)(((char*)newcur)+smbios_properties[j].offset))=++nstrings; } else if (do_auto && smbios_properties[j].auto_str) { str=smbios_properties[j].auto_str(smbios_properties[j].name, tablespresent[newcur->type]); size=strlen (str); memcpy (newtablesptr, str,size); newtablesptr[size]=0; newtablesptr+=size+1; *((uint8_t*)(((char*)newcur)+smbios_properties[j].offset))=++nstrings; } break; case SMOWORD: if (getValueForKey(altname,&str, &size, &bootInfo->smbiosConfig) ||getValueForKey(smbios_properties[j].name,&str, &size, &bootInfo->smbiosConfig)) { int k=0, t=0, kk=0; const char *ptr=str; memset(((char*)newcur)+smbios_properties[j].offset, 0, 16); while (ptr-str<size && *ptr && (*ptr==' ' || *ptr=='\t' || *ptr=='\n')) ptr++; if (size-(ptr-str)>=2 && ptr[0]=='0' && (ptr[1]=='x' || ptr[1]=='X')) ptr+=2; for (;ptr-str<size && *ptr && k<16;ptr++) { if (*ptr>='0' && *ptr<='9') (t=(t<<4)|(*ptr-'0')),kk++; if (*ptr>='a' && *ptr<='f') (t=(t<<4)|(*ptr-'a'+10)),kk++; if (*ptr>='A' && *ptr<='F') (t=(t<<4)|(*ptr-'A'+10)),kk++; if (kk==2) { *((uint8_t*)(((char*)newcur)+smbios_properties[j].offset+k))=t; k++; kk=0; t=0; } } } break; case SMBYTE: if (getIntForKey(altname,&num,&bootInfo->smbiosConfig) ||getIntForKey(smbios_properties[j].name,&num,&bootInfo->smbiosConfig)) *((uint8_t*)(((char*)newcur)+smbios_properties[j].offset))=num; else if (do_auto && smbios_properties[j].auto_int) *((uint8_t*)(((char*)newcur)+smbios_properties[j].offset)) =smbios_properties[j].auto_int(smbios_properties[j].name, tablespresent[newcur->type]); break; case SMWORD: if (getIntForKey(altname,&num,&bootInfo->smbiosConfig) ||getIntForKey(smbios_properties[j].name,&num,&bootInfo->smbiosConfig)) *((uint16_t*)(((char*)newcur)+smbios_properties[j].offset))=num; else if (do_auto && smbios_properties[j].auto_int) *((uint16_t*)(((char*)newcur)+smbios_properties[j].offset)) =smbios_properties[j].auto_int(smbios_properties[j].name, tablespresent[newcur->type]); break; } } if (nstrings==0) { newtablesptr[0]=0; newtablesptr++; } newtablesptr[0]=0; newtablesptr++; tablespresent[smbios_table_descriptions[i].type]++; } } newsmbios->dmi.checksum=0; newsmbios->dmi.checksum=256-checksum8 (&newsmbios->dmi,sizeof (newsmbios->dmi)); newsmbios->checksum=0; newsmbios->checksum=256-checksum8 (newsmbios,sizeof (*newsmbios)); verbose("Patched DMI Table.\n"); }
int getBootOptions(bool firstRun) { int i; int key; int nextRow; int timeout; int bvCount; BVRef bvr; BVRef menuBVR; bool showPrompt, newShowPrompt, isCDROM; // Initialize default menu selection entry. gBootVolume = menuBVR = selectBootVolume(bvChain); if (biosDevIsCDROM(gBIOSDev)) { isCDROM = true; } else { isCDROM = false; } // ensure we're in graphics mode if gui is setup if (firstRun && gui.initialised && bootArgs->Video.v_display == VGA_TEXT_MODE) { setVideoMode(GRAPHICS_MODE, 0); } // Clear command line boot arguments clearBootArgs(); // Allow user to override default timeout. if (multiboot_timeout_set) { timeout = multiboot_timeout; } else if (!getIntForKey(kTimeoutKey, &timeout, &bootInfo->chameleonConfig)) { /* If there is no timeout key in the file use the default timeout which is different for CDs vs. hard disks. However, if not booting a CD and no config file could be loaded set the timeout to zero which causes the menu to display immediately. This way, if no partitions can be found, that is the disk is unpartitioned or simply cannot be read) then an empty menu is displayed. If some partitions are found, for example a Windows partition, then these will be displayed in the menu as foreign partitions. */ if (isCDROM) { timeout = kCDBootTimeout; } else { timeout = sysConfigValid ? kBootTimeout : 0; } } if (timeout < 0) { gBootMode |= kBootModeQuiet; } // If the user is holding down a modifier key, enter safe mode. if ((readKeyboardShiftFlags() & 0x0F) != 0) { gBootMode |= kBootModeSafe; } // Checking user pressed keys bool f8press = false, spress = false, vpress = false; while (readKeyboardStatus()) { key = bgetc (); if (key == 0x4200) f8press = true; if ((key & 0xff) == 's' || (key & 0xff) == 'S') spress = true; if ((key & 0xff) == 'v' || (key & 0xff) == 'V') vpress = true; } // If user typed F8, abort quiet mode, and display the menu. if (f8press) { gBootMode &= ~kBootModeQuiet; timeout = 0; } // If user typed 'v' or 'V', boot in verbose mode. if ((gBootMode & kBootModeQuiet) && firstRun && vpress) { addBootArg(kVerboseModeFlag); } // If user typed 's' or 'S', boot in single user mode. if ((gBootMode & kBootModeQuiet) && firstRun && spress) { addBootArg(kSingleUserModeFlag); } if (bootArgs->Video.v_display == VGA_TEXT_MODE) { setCursorPosition(0, 0, 0); clearScreenRows(0, kScreenLastRow); if (!(gBootMode & kBootModeQuiet)) { // Display banner and show hardware info. printf(bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024); printf(getVBEInfoString()); } changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0); verbose("Scanning device %x...", gBIOSDev); } // When booting from CD, default to hard drive boot when possible. if (isCDROM && firstRun) { const char *val; char *prompt = NULL; char *name = NULL; int cnt; int optionKey; if (getValueForKey(kCDROMPromptKey, &val, &cnt, &bootInfo->chameleonConfig)) { prompt = malloc(cnt + 1); strncat(prompt, val, cnt); } else { name = malloc(80); getBootVolumeDescription(gBootVolume, name, 79, false); prompt = malloc(256); sprintf(prompt, "Press any key to start up from %s, or press F8 to enter startup options.", name); free(name); } if (getIntForKey( kCDROMOptionKey, &optionKey, &bootInfo->chameleonConfig )) { // The key specified is a special key. } else { // Default to F8. optionKey = 0x4200; } // If the timeout is zero then it must have been set above due to the // early catch of F8 which means the user wants to set boot options // which we ought to interpret as meaning he wants to boot the CD. if (timeout != 0) { key = countdown(prompt, kMenuTopRow, timeout); } else { key = optionKey; } if (prompt != NULL) { free(prompt); } clearScreenRows( kMenuTopRow, kMenuTopRow + 2 ); // Hit the option key ? if (key == optionKey) { gBootMode &= ~kBootModeQuiet; timeout = 0; } else { key = key & 0xFF; // Try booting hard disk if user pressed 'h' if (biosDevIsCDROM(gBIOSDev) && key == 'h') { BVRef bvr; // Look at partitions hosting OS X other than the CD-ROM for (bvr = bvChain; bvr; bvr=bvr->next) { if ((bvr->flags & kBVFlagSystemVolume) && bvr->biosdev != gBIOSDev) { gBootVolume = bvr; } } } goto done; } } if (gBootMode & kBootModeQuiet) { // No input allowed from user. goto done; } if (firstRun && timeout > 0 && countdown("Press any key to enter startup options.", kMenuTopRow, timeout) == 0) { // If the user is holding down a modifier key, // enter safe mode. if ((readKeyboardShiftFlags() & 0x0F) != 0) { gBootMode |= kBootModeSafe; } goto done; } if (gDeviceCount) { // Allocate memory for an array of menu items. menuItems = malloc(sizeof(MenuItem) * gDeviceCount); if (menuItems == NULL) { goto done; } // Associate a menu item for each BVRef. for (bvr=bvChain, i=gDeviceCount-1, selectIndex=0; bvr; bvr=bvr->next) { if (bvr->visible) { getBootVolumeDescription(bvr, menuItems[i].name, sizeof(menuItems[i].name) - 1, true); menuItems[i].param = (void *) bvr; if (bvr == menuBVR) { selectIndex = i; } i--; } } } if (bootArgs->Video.v_display != VGA_TEXT_MODE) { // redraw the background buffer gui.logo.draw = true; drawBackground(); gui.devicelist.draw = true; gui.redraw = true; if (!(gBootMode & kBootModeQuiet)) { // Check if "Boot Banner"=N switch is present in config file. getBoolForKey(kBootBannerKey, &showBootBanner, &bootInfo->chameleonConfig); if (showBootBanner) { // Display banner and show hardware info. gprintf(&gui.screen, bootBanner + 1, (bootInfo->convmem + bootInfo->extmem) / 1024); } // redraw background memcpy(gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4); } } else { // Clear screen and hide the blinking cursor. clearScreenRows(kMenuTopRow, kMenuTopRow + 2); changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0); } nextRow = kMenuTopRow; showPrompt = true; if (gDeviceCount) { if( bootArgs->Video.v_display == VGA_TEXT_MODE ) { printf("Use \30\31 keys to select the startup volume."); } showMenu( menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems ); nextRow += MIN( gDeviceCount, kMenuMaxItems ) + 3; } // Show the boot prompt. showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot); showBootPrompt( nextRow, showPrompt ); do { if (bootArgs->Video.v_display != VGA_TEXT_MODE) { // redraw background memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 ); // reset cursor co-ords gui.debug.cursor = pos( gui.screen.width - 160 , 10 ); } key = getchar(); updateMenu( key, (void **) &menuBVR ); newShowPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot); if (newShowPrompt != showPrompt) { showPrompt = newShowPrompt; showBootPrompt( nextRow, showPrompt ); } if (showPrompt) { updateBootArgs(key); } switch (key) { case KEY_ENTER: if (gui.menu.draw) { key=0; break; } if (*gBootArgs == '?') { char * argPtr = gBootArgs; // Skip the leading "?" character. argPtr++; getNextArg(&argPtr, booterCommand); getNextArg(&argPtr, booterParam); /* * TODO: this needs to be refactored. */ if (strcmp( booterCommand, "video" ) == 0) { if (bootArgs->Video.v_display != VGA_TEXT_MODE) { showInfoBox(getVBEInfoString(), getVBEModeInfoString()); } else { printVBEModeInfo(); } } else if ( strcmp( booterCommand, "memory" ) == 0) { if (bootArgs->Video.v_display != VGA_TEXT_MODE ) { showInfoBox("Memory Map", getMemoryInfoString()); } else { printMemoryInfo(); } } else if (strcmp(booterCommand, "lspci") == 0) { lspci(); } else if (strcmp(booterCommand, "more") == 0) { showTextFile(booterParam); } else if (strcmp(booterCommand, "rd") == 0) { processRAMDiskCommand(&argPtr, booterParam); } else if (strcmp(booterCommand, "norescan") == 0) { if (gEnableCDROMRescan) { gEnableCDROMRescan = false; break; } } else { showHelp(); } key = 0; showBootPrompt(nextRow, showPrompt); break; } gBootVolume = menuBVR; setRootVolume(menuBVR); gBIOSDev = menuBVR->biosdev; break; case KEY_ESC: clearBootArgs(); break; case KEY_F5: // New behavior: // Clear gBootVolume to restart the loop // if the user enabled rescanning the optical drive. // Otherwise boot the default boot volume. if (gEnableCDROMRescan) { gBootVolume = NULL; clearBootArgs(); } break; case KEY_F10: gScanSingleDrive = false; scanDisks(gBIOSDev, &bvCount); gBootVolume = NULL; clearBootArgs(); break; case KEY_TAB: // New behavior: // Switch between text & graphic interfaces // Only Permitted if started in graphics interface if (useGUI) { if (bootArgs->Video.v_display != VGA_TEXT_MODE) { setVideoMode(VGA_TEXT_MODE, 0); setCursorPosition(0, 0, 0); clearScreenRows(0, kScreenLastRow); // Display banner and show hardware info. printf(bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024); printf(getVBEInfoString()); clearScreenRows(kMenuTopRow, kMenuTopRow + 2); changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0); nextRow = kMenuTopRow; showPrompt = true; if (gDeviceCount) { printf("Use \30\31 keys to select the startup volume."); showMenu(menuItems, gDeviceCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems); nextRow += MIN(gDeviceCount, kMenuMaxItems) + 3; } showPrompt = (gDeviceCount == 0) || (menuBVR->flags & kBVFlagNativeBoot); showBootPrompt(nextRow, showPrompt); //changeCursor( 0, kMenuTopRow, kCursorTypeUnderline, 0 ); } else { gui.redraw = true; setVideoMode(GRAPHICS_MODE, 0); updateVRAM(); updateGraphicBootPrompt(); } } key = 0; break; default: key = 0; break; } } while (0 == key); done: if (bootArgs->Video.v_display == VGA_TEXT_MODE) { clearScreenRows(kMenuTopRow, kScreenLastRow); changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0); } shouldboot = false; gui.menu.draw = false; if (menuItems) { free(menuItems); menuItems = NULL; } return 0; }
/** From the origsmbios detected by getAddressOfSmbiosTable() to newsmbios whose entrypoint * struct has been created by smbios_dry_run, update each table struct content of new smbios * int the new allocated table address of size newsmbios->tablelength. */ static void smbios_real_run(struct SMBEntryPoint * origsmbios, struct SMBEntryPoint * newsmbios) { char *smbiostables; char *tablesptr, *newtablesptr; int origsmbiosnum; // bitmask of used handles uint8_t handles[8192]; uint16_t nexthandle=0; int i, j; int tablespresent[256]; bool do_auto=true; extern void dumpPhysAddr(const char * title, void * a, int len); bzero(tablespresent, sizeof(tablespresent)); bzero(handles, sizeof(handles)); getBoolForKey(kSMBIOSdefaults, &do_auto, &bootInfo->bootConfig); newsmbios->dmi.tableAddress = (uint32_t)AllocateKernelMemory(newsmbios->dmi.tableLength); if (origsmbios) { smbiostables = (char *)origsmbios->dmi.tableAddress; origsmbiosnum = origsmbios->dmi.structureCount; } else { smbiostables = NULL; origsmbiosnum = 0; } tablesptr = smbiostables; newtablesptr = (char *)newsmbios->dmi.tableAddress; // if old smbios exists then update new smbios with old smbios original content first if (smbiostables) { for (i=0; i<origsmbiosnum; i++) { struct smbios_table_header *oldcur = (struct smbios_table_header *) tablesptr; struct smbios_table_header *newcur = (struct smbios_table_header *) newtablesptr; char *stringsptr; int nstrings = 0; handles[(oldcur->handle) / 8] |= 1 << ((oldcur->handle) % 8); // copy table length from old table to new table but not the old strings memcpy(newcur,oldcur, oldcur->length); tablesptr += oldcur->length; stringsptr = tablesptr; newtablesptr += oldcur->length; // calculate the number of strings in the old content for (;tablesptr[0]!=0 || tablesptr[1]!=0; tablesptr++) { if (tablesptr[0] == 0) { nstrings++; } } if (tablesptr != stringsptr) { nstrings++; } tablesptr += 2; // copy the old strings to new table memcpy(newtablesptr, stringsptr, tablesptr-stringsptr); // point to next possible space for a string (deducting the second 0 char at the end) newtablesptr += tablesptr - stringsptr - 1; if (nstrings == 0) { // if no string was found rewind to the first 0 char of the 0,0 terminator newtablesptr--; } // now for each property in the table update the overrides if any (auto or user) for (j=0; j<sizeof(smbios_properties)/sizeof(smbios_properties[0]); j++) { const char *str; int size; int num; char altname[40]; sprintf(altname, "%s_%d", smbios_properties[j].name, tablespresent[newcur->type] + 1); if (smbios_properties[j].table_type == newcur->type) { switch (smbios_properties[j].value_type) { case SMSTRING: if (getValueForKey(altname, &str, &size, &bootInfo->smbiosConfig) || getValueForKey(smbios_properties[j].name, &str, &size, &bootInfo->smbiosConfig)) { memcpy(newtablesptr, str, size); newtablesptr[size] = 0; newtablesptr += size + 1; *((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = ++nstrings; } else if (do_auto && smbios_properties[j].auto_str) { str = smbios_properties[j].auto_str(smbios_properties[j].name, tablespresent[newcur->type]); size = strlen(str); memcpy(newtablesptr, str, size); newtablesptr[size] = 0; newtablesptr += size + 1; *((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = ++nstrings; } break; case SMOWORD: if (getValueForKey(altname, &str, &size, &bootInfo->smbiosConfig) || getValueForKey(smbios_properties[j].name, &str, &size, &bootInfo->smbiosConfig)) { int k=0, t=0, kk=0; const char *ptr = str; memset(((char*)newcur) + smbios_properties[j].offset, 0, 16); while (ptr-str<size && *ptr && (*ptr==' ' || *ptr=='\t' || *ptr=='\n')) { ptr++; } if (size-(ptr-str)>=2 && ptr[0]=='0' && (ptr[1]=='x' || ptr[1]=='X')) { ptr += 2; } for (;ptr-str<size && *ptr && k<16;ptr++) { if (*ptr>='0' && *ptr<='9') { (t=(t<<4)|(*ptr-'0')),kk++; } if (*ptr>='a' && *ptr<='f') { (t=(t<<4)|(*ptr-'a'+10)),kk++; } if (*ptr>='A' && *ptr<='F') { (t=(t<<4)|(*ptr-'A'+10)),kk++; } if (kk == 2) { *((uint8_t*)(((char*)newcur) + smbios_properties[j].offset + k)) = t; k++; kk = 0; t = 0; } } } break; case SMBYTE: if (getIntForKey(altname, &num, &bootInfo->smbiosConfig) || getIntForKey(smbios_properties[j].name, &num, &bootInfo->smbiosConfig)) { *((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = num; } else if (do_auto && smbios_properties[j].auto_int) { *((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = smbios_properties[j].auto_int(smbios_properties[j].name, tablespresent[newcur->type]); } break; case SMWORD: if (getIntForKey(altname, &num, &bootInfo->smbiosConfig) || getIntForKey(smbios_properties[j].name, &num, &bootInfo->smbiosConfig)) { *((uint16_t*)(((char*)newcur) + smbios_properties[j].offset)) = num; } else if (do_auto && smbios_properties[j].auto_int) { *((uint16_t*)(((char*)newcur) + smbios_properties[j].offset)) = smbios_properties[j].auto_int(smbios_properties[j].name, tablespresent[newcur->type]); } break; } } } if (nstrings == 0) { newtablesptr[0] = 0; newtablesptr++; } newtablesptr[0] = 0; newtablesptr++; tablespresent[newcur->type]++; } } // for each eventual complementary table not present in the original smbios, do the overrides for (i=0; i<sizeof(smbios_table_descriptions)/sizeof(smbios_table_descriptions[0]); i++) { int numnec = -1; char buffer[40]; sprintf(buffer, "SMtable%d", i); if (!getIntForKey(buffer, &numnec, &bootInfo->smbiosConfig)) { numnec = -1; } if (numnec == -1 && do_auto && smbios_table_descriptions[i].numfunc) { numnec = smbios_table_descriptions[i].numfunc(smbios_table_descriptions[i].type); } while (tablespresent[smbios_table_descriptions[i].type] < numnec) { struct smbios_table_header *newcur = (struct smbios_table_header *) newtablesptr; int nstrings = 0; memset(newcur,0, smbios_table_descriptions[i].len); while (handles[(nexthandle)/8] & (1 << ((nexthandle) % 8))) { nexthandle++; } newcur->handle = nexthandle; handles[nexthandle / 8] |= 1 << (nexthandle % 8); newcur->type = smbios_table_descriptions[i].type; newcur->length = smbios_table_descriptions[i].len; newtablesptr += smbios_table_descriptions[i].len; for (j=0; j<sizeof(smbios_properties)/sizeof(smbios_properties[0]); j++) { const char *str; int size; int num; char altname[40]; sprintf(altname, "%s_%d", smbios_properties[j].name, tablespresent[newcur->type] + 1); if (smbios_properties[j].table_type == newcur->type) { switch (smbios_properties[j].value_type) { case SMSTRING: if (getValueForKey(altname, &str, &size, &bootInfo->smbiosConfig) || getValueForKey(smbios_properties[j].name, &str, &size, &bootInfo->smbiosConfig)) { memcpy(newtablesptr, str, size); newtablesptr[size] = 0; newtablesptr += size + 1; *((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = ++nstrings; } else if (do_auto && smbios_properties[j].auto_str) { str = smbios_properties[j].auto_str(smbios_properties[j].name, tablespresent[newcur->type]); size = strlen(str); memcpy(newtablesptr, str, size); newtablesptr[size] = 0; newtablesptr += size + 1; *((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = ++nstrings; } break; case SMOWORD: if (getValueForKey(altname, &str, &size, &bootInfo->smbiosConfig) || getValueForKey(smbios_properties[j].name, &str, &size, &bootInfo->smbiosConfig)) { int k=0, t=0, kk=0; const char *ptr = str; memset(((char*)newcur) + smbios_properties[j].offset, 0, 16); while (ptr-str<size && *ptr && (*ptr==' ' || *ptr=='\t' || *ptr=='\n')) { ptr++; } if (size-(ptr-str)>=2 && ptr[0]=='0' && (ptr[1]=='x' || ptr[1]=='X')) { ptr += 2; } for (;ptr-str<size && *ptr && k<16;ptr++) { if (*ptr>='0' && *ptr<='9') { (t=(t<<4)|(*ptr-'0')),kk++; } if (*ptr>='a' && *ptr<='f') { (t=(t<<4)|(*ptr-'a'+10)),kk++; } if (*ptr>='A' && *ptr<='F') { (t=(t<<4)|(*ptr-'A'+10)),kk++; } if (kk == 2) { *((uint8_t*)(((char*)newcur) + smbios_properties[j].offset + k)) = t; k++; kk = 0; t = 0; } } } break; case SMBYTE: if (getIntForKey(altname, &num, &bootInfo->smbiosConfig) || getIntForKey(smbios_properties[j].name, &num, &bootInfo->smbiosConfig)) { *((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = num; } else if (do_auto && smbios_properties[j].auto_int) { *((uint8_t*)(((char*)newcur) + smbios_properties[j].offset)) = smbios_properties[j].auto_int(smbios_properties[j].name, tablespresent[newcur->type]); } break; case SMWORD: if (getIntForKey(altname, &num, &bootInfo->smbiosConfig) || getIntForKey(smbios_properties[j].name, &num, &bootInfo->smbiosConfig)) { *((uint16_t*)(((char*)newcur) + smbios_properties[j].offset)) = num; } else if (do_auto && smbios_properties[j].auto_int) { *((uint16_t*)(((char*)newcur)+smbios_properties[j].offset)) = smbios_properties[j].auto_int(smbios_properties[j].name, tablespresent[newcur->type]); } break; } } } if (nstrings == 0) { newtablesptr[0] = 0; newtablesptr++; } newtablesptr[0] = 0; newtablesptr++; tablespresent[smbios_table_descriptions[i].type]++; } } // calculate new checksums newsmbios->dmi.checksum = 0; newsmbios->dmi.checksum = 256 - checksum8(&newsmbios->dmi, sizeof(newsmbios->dmi)); newsmbios->checksum = 0; newsmbios->checksum = 256 - checksum8(newsmbios, sizeof(*newsmbios)); verbose("Patched DMI Table\n"); }
/* Compute necessary space requirements for new smbios */ struct SMBEntryPoint * smbios_dry_run (struct SMBEntryPoint * origsmbios) { struct SMBEntryPoint *ret; char *smbiostables=0; char *tablesptr; int origsmbiosnum=0; int i, j; int tablespresent[256]; BOOL do_auto=1; getBoolForKey("SMBIOSdefaults",&do_auto,&bootInfo->bootConfig); for (i=0;i<256;i++) tablespresent[i]=0; ret=(struct SMBEntryPoint *)AllocateKernelMemory(sizeof (struct SMBEntryPoint)); if (origsmbios) { smbiostables=(char *)origsmbios->dmi.tableAddress; origsmbiosnum=origsmbios->dmi.structureCount; } // _SM_ ret->anchor[0]=0x5f; ret->anchor[1]=0x53; ret->anchor[2]=0x4d; ret->anchor[3]=0x5f; ret->entryPointLength=sizeof (*ret); ret->majorVersion=2; ret->minorVersion=1; ret->maxStructureSize=0; ret->entryPointRevision=0; for (i=0;i<5;i++) ret->formattedArea[i]=0; //_DMI_ ret->dmi.anchor[0]=0x5f; ret->dmi.anchor[1]=0x44; ret->dmi.anchor[2]=0x4d; ret->dmi.anchor[3]=0x49; ret->dmi.anchor[4]=0x5f; ret->dmi.tableLength=0; ret->dmi.tableAddress=0; ret->dmi.structureCount=0; ret->dmi.bcdRevision=0x21; tablesptr=smbiostables; if (smbiostables) for (i=0;i<origsmbiosnum;i++) { struct smbios_table_header *cur =(struct smbios_table_header *) tablesptr; char *stringsptr; int stringlen; tablesptr+=cur->length; stringsptr=tablesptr; for (;tablesptr[0]!=0 || tablesptr[1]!=0;tablesptr++); tablesptr+=2; stringlen=tablesptr-stringsptr-1; if (stringlen==1) stringlen=0; for (j=0;j<sizeof (smbios_properties)/sizeof(smbios_properties[0]); j++) { const char *str; int size; char altname[40]; sprintf (altname, "%s_%d",smbios_properties[j].name, tablespresent[cur->type]+1); if (smbios_properties[j].table_type==cur->type && smbios_properties[j].value_type==SMSTRING && (getValueForKey(smbios_properties[j].name, &str, &size, &bootInfo->smbiosConfig) || getValueForKey(altname,&str, &size, &bootInfo->smbiosConfig))) stringlen+=size+1; else if (smbios_properties[j].table_type==cur->type && smbios_properties[j].value_type==SMSTRING && do_auto && smbios_properties[j].auto_str) stringlen+=strlen(smbios_properties[j].auto_str(smbios_properties[j].name,tablespresent[cur->type]))+1; } if (stringlen==0) stringlen=1; stringlen++; if (ret->maxStructureSize<cur->length+stringlen) ret->maxStructureSize=cur->length+stringlen; ret->dmi.tableLength+=cur->length+stringlen; ret->dmi.structureCount++; tablespresent[cur->type]++; } for (i=0;i<sizeof (smbios_table_descriptions) /sizeof(smbios_table_descriptions[0]);i++) { int numnec=-1; char buffer[40]; sprintf (buffer, "SMtable%d", i); if (!getIntForKey(buffer,&numnec,&bootInfo->smbiosConfig)) numnec=-1; if (numnec==-1 && do_auto && smbios_table_descriptions[i].numfunc) numnec=smbios_table_descriptions[i].numfunc (smbios_table_descriptions[i].type); while (tablespresent[smbios_table_descriptions[i].type]<numnec) { int stringlen=0; for (j=0;j<sizeof (smbios_properties)/sizeof(smbios_properties[0]); j++) { const char *str; int size; char altname[40]; sprintf (altname, "%s_%d",smbios_properties[j].name, tablespresent[smbios_table_descriptions[i].type]+1); if (smbios_properties[j].table_type ==smbios_table_descriptions[i].type && smbios_properties[j].value_type==SMSTRING && (getValueForKey(altname,&str, &size, &bootInfo->smbiosConfig) || getValueForKey(smbios_properties[j].name,&str, &size, &bootInfo->smbiosConfig))) stringlen+=size+1; else if (smbios_properties[j].table_type ==smbios_table_descriptions[i].type && smbios_properties[j].value_type==SMSTRING && do_auto && smbios_properties[j].auto_str) stringlen+=strlen(smbios_properties[j].auto_str (smbios_properties[j].name, tablespresent[smbios_table_descriptions[i].type]))+1; } if (stringlen==0) stringlen=1; stringlen++; if (ret->maxStructureSize<smbios_table_descriptions[i].len+stringlen) ret->maxStructureSize=smbios_table_descriptions[i].len+stringlen; ret->dmi.tableLength+=smbios_table_descriptions[i].len+stringlen; ret->dmi.structureCount++; tablespresent[smbios_table_descriptions[i].type]++; } } return ret; }
bool setup_gma_devprop(pci_dt_t *gma_dev) { char *devicepath = NULL; volatile uint8_t *regs; uint32_t bar[7]; char *model = NULL; uint8_t BuiltIn = 0x00; uint16_t vendor_id = gma_dev->vendor_id; uint16_t device_id = gma_dev->device_id; uint8_t ClassFix[4] = { 0x00, 0x00, 0x03, 0x00 }; int n_igs = 0; int len; const char *value; devicepath = get_pci_dev_path(gma_dev); bar[0] = pci_config_read32(gma_dev->dev.addr, 0x10); regs = (uint8_t *) (bar[0] & ~0x0f); model = get_gma_controller_name(device_id, vendor_id); verbose("---------------------------------------------\n"); verbose("------------ INTEL DEVICE INFO --------------\n"); verbose("---------------------------------------------\n"); verbose("Class code: [%04x]\n%s [%04x:%04x] (rev %02x)\nSubsystem: [%04x:%04x] :: %s\n", gma_dev->class_id, model, gma_dev->vendor_id, gma_dev->device_id, gma_dev->revision_id, gma_dev->subsys_id.subsys.vendor_id, gma_dev->subsys_id.subsys.device_id, devicepath); if (!string) { string = devprop_create_string(); } struct DevPropDevice *device = devprop_add_device(string, devicepath); if (!device) { printf("Failed initializing dev-prop string dev-entry.\n"); pause(); return false; } devprop_add_value(device, "model", (uint8_t*)model, (strlen(model) + 1)); devprop_add_value(device, "device_type", (uint8_t*)"display", 8); switch ((device_id << 16) | vendor_id) { case GMA_IRONLAKE_D_G: // 0042 case GMA_IRONLAKE_M_G: // 0046 devprop_add_value(device, "built-in", &BuiltIn, 1); devprop_add_value(device, "class-code", ClassFix, 4); devprop_add_value(device, "hda-gfx", (uint8_t *)"onboard-1", 10); devprop_add_value(device, "AAPL,os-info", HDx000_os_info, 20); break; /* 27A2, 27AE, 27A6, A001, A011, A012, */ case GMA_I945_GM: // Mobile GMA950 Mobile GMA3150 case GMA_I945_GME: //case GMA_945GM: case GMA_PINEVIEW_G: case GMA_PINEVIEW_M: case GMA_GMA3150_M: devprop_add_value(device, "AAPL,HasPanel", reg_TRUE, 4); devprop_add_value(device, "built-in", &BuiltIn, 1); devprop_add_value(device, "class-code", ClassFix, 4); break; /* 2772 ,2776, A002 */ case GMA_I945_G: // Desktop GMA950 Desktop GMA3150 //case GMA_82945G: case GMA_GMA3150_D: BuiltIn = 0x01; devprop_add_value(device, "built-in", &BuiltIn, 1); devprop_add_value(device, "class-code", ClassFix, 4); break; /* 2A02, 2A12, 2A13, 2A42, 2A43 */ case GMA_I965_GM: // GMAX3100 case GMA_I965_GME: //case 0x80862A13: case GMA_GM45_GM: //case GMA_GM45_GM2: devprop_add_value(device, "AAPL,HasPanel", GMAX3100_vals[0], 4); devprop_add_value(device, "AAPL,SelfRefreshSupported", GMAX3100_vals[1], 4); devprop_add_value(device, "AAPL,aux-power-connected", GMAX3100_vals[2], 4); devprop_add_value(device, "AAPL,backlight-control", GMAX3100_vals[3], 4); devprop_add_value(device, "AAPL00,blackscreen-preferences", GMAX3100_vals[4], 4); devprop_add_value(device, "AAPL01,BacklightIntensity", GMAX3100_vals[5], 4); devprop_add_value(device, "AAPL01,blackscreen-preferences", GMAX3100_vals[6], 4); devprop_add_value(device, "AAPL01,DataJustify", GMAX3100_vals[7], 4); devprop_add_value(device, "AAPL01,Depth", GMAX3100_vals[8], 4); devprop_add_value(device, "AAPL01,Dither", GMAX3100_vals[9], 4); devprop_add_value(device, "AAPL01,DualLink", GMAX3100_vals[10], 4); devprop_add_value(device, "AAPL01,Height", GMAX3100_vals[11], 4); devprop_add_value(device, "AAPL01,Interlace", GMAX3100_vals[12], 4); devprop_add_value(device, "AAPL01,Inverter", GMAX3100_vals[13], 4); devprop_add_value(device, "AAPL01,InverterCurrent", GMAX3100_vals[14], 4); devprop_add_value(device, "AAPL01,InverterCurrency", GMAX3100_vals[15], 4); devprop_add_value(device, "AAPL01,LinkFormat", GMAX3100_vals[16], 4); devprop_add_value(device, "AAPL01,LinkType", GMAX3100_vals[17], 4); devprop_add_value(device, "AAPL01,Pipe", GMAX3100_vals[18], 4); devprop_add_value(device, "AAPL01,PixelFormat", GMAX3100_vals[19], 4); devprop_add_value(device, "AAPL01,Refresh", GMAX3100_vals[20], 4); devprop_add_value(device, "AAPL01,Stretch", GMAX3100_vals[21], 4); //devprop_add_value(device, "AAPL01,InverterFrequency", GMAX3100_vals[22], 4); devprop_add_value(device, "class-code", ClassFix, 4); break; /* 0106 */ case GMA_SANDYBRIDGE_M_GT1: // HD Graphics 2000 Mobile devprop_add_value(device, "class-code", ClassFix, 4); devprop_add_value(device, "hda-gfx", (uint8_t *)"onboard-1", 10); devprop_add_value(device, "AAPL00,PixelFormat", HD2000_vals[0], 4); devprop_add_value(device, "AAPL00,T1", HD2000_vals[1], 4); devprop_add_value(device, "AAPL00,T2", HD2000_vals[2], 4); devprop_add_value(device, "AAPL00,T3", HD2000_vals[3], 4); devprop_add_value(device, "AAPL00,T4", HD2000_vals[4], 4); devprop_add_value(device, "AAPL00,T5", HD2000_vals[5], 4); devprop_add_value(device, "AAPL00,T6", HD2000_vals[6], 4); devprop_add_value(device, "AAPL00,T7", HD2000_vals[7], 4); devprop_add_value(device, "AAPL00,LinkType", HD2000_vals[8], 4); devprop_add_value(device, "AAPL00,LinkFormat", HD2000_vals[9], 4); devprop_add_value(device, "AAPL00,DualLink", HD2000_vals[10], 4); devprop_add_value(device, "AAPL00,Dither", HD2000_vals[11], 4); devprop_add_value(device, "AAPL00,DataJustify", HD3000_vals[12], 4); devprop_add_value(device, "graphic-options", HD2000_vals[13], 4); devprop_add_value(device, "AAPL,tbl-info", HD2000_tbl_info, 18); devprop_add_value(device, "AAPL,os-info", HD2000_os_info, 20); break; /* 0116, 0126 */ case GMA_SANDYBRIDGE_M_GT2: // HD Graphics 3000 Mobile case GMA_SANDYBRIDGE_M_GT2_PLUS: devprop_add_value(device, "class-code", ClassFix, 4); devprop_add_value(device, "hda-gfx", (uint8_t *)"onboard-1", 10); devprop_add_value(device, "AAPL00,PixelFormat", HD3000_vals[0], 4); devprop_add_value(device, "AAPL00,T1", HD3000_vals[1], 4); devprop_add_value(device, "AAPL00,T2", HD3000_vals[2], 4); devprop_add_value(device, "AAPL00,T3", HD3000_vals[3], 4); devprop_add_value(device, "AAPL00,T4", HD3000_vals[4], 4); devprop_add_value(device, "AAPL00,T5", HD3000_vals[5], 4); devprop_add_value(device, "AAPL00,T6", HD3000_vals[6], 4); devprop_add_value(device, "AAPL00,T7", HD3000_vals[7], 4); devprop_add_value(device, "AAPL00,LinkType", HD3000_vals[8], 4); devprop_add_value(device, "AAPL00,LinkFormat", HD3000_vals[9], 4); devprop_add_value(device, "AAPL00,DualLink", HD3000_vals[10], 4); devprop_add_value(device, "AAPL00,Dither", HD3000_vals[11], 4); devprop_add_value(device, "AAPL00,DataJustify", HD3000_vals[12], 4); devprop_add_value(device, "graphic-options", HD3000_vals[13], 4); devprop_add_value(device, "AAPL,tbl-info", HD3000_tbl_info, 18); devprop_add_value(device, "AAPL,os-info", HD3000_os_info, 20); devprop_add_value(device, "AAPL,snb-platform-id", HD3000_vals[16], 4);// previusly commented break; /* 0102 */ /* HD Graphics 2000 */ case GMA_SANDYBRIDGE_GT1: // 0102 device_id = 0x00000102; // Inject a valid mobile GPU device id instead of patching kexts devprop_add_value(device, "built-in", &BuiltIn, 1); devprop_add_value(device, "class-code", ClassFix, 4); devprop_add_value(device, "device-id", (uint8_t*)&device_id, sizeof(device_id)); devprop_add_value(device, "hda-gfx", (uint8_t *)"onboard-1", 10); devprop_add_value(device, "AAPL,tbl-info", HD2000_tbl_info, 18); devprop_add_value(device, "AAPL,os-info", HD2000_os_info, 20); break; /* Sandy Bridge */ /* HD Graphics 3000 */ case GMA_SANDYBRIDGE_GT2: // 0112 case GMA_SANDYBRIDGE_GT2_PLUS: // 0122 devprop_add_value(device, "built-in", &BuiltIn, 1); devprop_add_value(device, "class-code", ClassFix, 4); device_id = 0x00000126; // Inject a valid mobile GPU device id instead of patching kexts devprop_add_value(device, "device-id", (uint8_t*)&device_id, sizeof(device_id)); devprop_add_value(device, "hda-gfx", (uint8_t *)"onboard-1", 10); devprop_add_value(device, "AAPL,tbl-info", HD3000_tbl_info, 18); devprop_add_value(device, "AAPL,os-info", HD3000_os_info, 20); break; /* Ivy Bridge */ /* HD Graphics 4000, HD Graphics 4000 Mobile, HD Graphics P4000, HD Graphics 2500 HD, Graphics 2500 Mobile */ case GMA_IVYBRIDGE_D_GT1: // 0152 case GMA_IVYBRIDGE_M_GT1: // 0156 case GMA_IVYBRIDGE_S_GT1: // 015A case GMA_IVYBRIDGE_S_GT3: // 015e case GMA_IVYBRIDGE_D_GT2: // 0162 case GMA_IVYBRIDGE_M_GT2: // 0166 case GMA_IVYBRIDGE_S_GT2: // 016A case GMA_IVYBRIDGE_S_GT4: // 0172 case GMA_IVYBRIDGE_S_GT5: // 0176 if (getValueForKey(kAAPLCustomIG, &value, &len, &bootInfo->chameleonConfig) && len == AAPL_LEN_IVY * 2) { uint8_t new_aapl0[AAPL_LEN_IVY]; if (hex2bin(value, new_aapl0, AAPL_LEN_IVY) == 0) { memcpy(default_aapl_ivy, new_aapl0, AAPL_LEN_IVY); verbose("Using user supplied AAPL,ig-platform-id\n"); verbose("AAPL,ig-platform-id: %02x%02x%02x%02x\n", default_aapl_ivy[0], default_aapl_ivy[1], default_aapl_ivy[2], default_aapl_ivy[3]); } devprop_add_value(device, "AAPL,ig-platform-id", default_aapl_ivy, AAPL_LEN_IVY); } else if (getIntForKey(kIntelCapriFB, &n_igs, &bootInfo->chameleonConfig)) { if ((n_igs >= 0) || (n_igs <= 11)) { verbose("AAPL,ig-platform-id was set in org.chameleon.Boot.plist with value %d\n", n_igs); devprop_add_value(device, "AAPL,ig-platform-id", ivy_bridge_ig_vals[n_igs], 4); } else { verbose("AAPL,ig-platform-id was set in org.chameleon.Boot.plist with bad value please choose a number between 0 and 11.\n"); } } else { uint32_t ig_platform_id; uint32_t ram = (((getVBEVideoRam() + 512) / 1024) + 512) / 1024; switch (ram) { case 96: ig_platform_id = 0x01660000; // 96mb Mobile break; case 64: ig_platform_id = 0x01660009; // 64mb Mobile break; case 32: ig_platform_id = 0x01620005; // 32mb Desktop break; default: printf("Please specify 96, 64, or 32MB RAM for the HD4000 in the bios.\n" "The selected %dMB RAM configuration is not supported for the HD4000.\n", ram); pause(); return false; // Exit early before the AAPL,ig-platform-id property is set. break; } devprop_add_value(device, "AAPL,ig-platform-id", (uint8_t *)&ig_platform_id, 4); } devprop_add_value(device, "AAPL00,DualLink", HD4000_vals[10], 4); devprop_add_value(device, "built-in", &BuiltIn, 1); devprop_add_value(device, "class-code", ClassFix, 4); devprop_add_value(device, "hda-gfx", (uint8_t *)"onboard-1", 10); break; /* Haswell */ /* HD Graphics 5000, HD Graphics 5000 Mobile, HD Graphics P5000, HD Graphics 4600, HD Graphics 4600 Mobile */ //case 0x80860090: //case 0x80860091: //case 0x80860092: case GMA_HASWELL_D_GT1: // 0402 case GMA_HASWELL_M_GT1: // 0406 case GMA_HASWELL_S_GT1: // 040a case GMA_HASWELL_D_GT2: // 0412 case GMA_HASWELL_M_GT2: // 0416 case GMA_HASWELL_S_GT2: // 041a case GMA_HASWELL_E_GT1: // 040e case GMA_HASWELL_E_GT2: // 041e case GMA_HASWELL_E_GT3: // 042e case GMA_HASWELL_D_GT3: // 0422 case GMA_HASWELL_M_GT3: // 0426 case GMA_HASWELL_S_GT3: // 042a case GMA_HASWELL_ULT_M_GT1: // 0a06 case GMA_HASWELL_ULT_E_GT1: // 0a0e case GMA_HASWELL_ULT_M_GT2: // 0a16 case GMA_HASWELL_ULT_E_GT2: // 0a1e case GMA_HASWELL_ULT_D_GT3: // 0a22 case GMA_HASWELL_ULT_M_GT3: // 0a26 case GMA_HASWELL_ULT_S_GT3: // 0a2a case GMA_HASWELL_ULT_E_GT3: // 0a2e case GMA_HASWELL_SDV_D_GT1_IG: // 0c02 case GMA_HASWELL_SDV_M_GT1_IG: // 0c06 case GMA_HASWELL_SDV_D_GT2_IG: // 0c12 case GMA_HASWELL_SDV_M_GT2_IG: // 0c16 case GMA_HASWELL_SDV_D_GT2_PLUS_IG: // 0c22 case GMA_HASWELL_SDV_M_GT2_PLUS_IG: // 0c26 case GMA_HASWELL_CRW_D_GT1: // 0d02 case GMA_HASWELL_CRW_D_GT2: // 0d12 case GMA_HASWELL_CRW_D_GT3: // 0d22 case GMA_HASWELL_CRW_M_GT1: // 0d06 case GMA_HASWELL_CRW_M_GT2: // 0d16 case GMA_HASWELL_CRW_M_GT3: // 0d26 case GMA_HASWELL_CRW_S_GT1: // 0d0a case GMA_HASWELL_CRW_S_GT2: // 0d1a case GMA_HASWELL_CRW_S_GT3: // 0d2a case GMA_HASWELL_CRW_B_GT1: // 0d0b case GMA_HASWELL_CRW_B_GT2: // 0d1b case GMA_HASWELL_CRW_B_GT3: // 0d2b case GMA_HASWELL_CRW_E_GT1: // 0d0e case GMA_HASWELL_CRW_E_GT2: // 0d1e case GMA_HASWELL_CRW_E_GT3: // 0d2e case GMA_HASWELL_CRW_M_GT2_PLUS_IG: // 0d36 if (getValueForKey(kAAPLCustomIG, &value, &len, &bootInfo->chameleonConfig) && len == AAPL_LEN_HSW * 2) { uint8_t new_aapl0[AAPL_LEN_HSW]; if (hex2bin(value, new_aapl0, AAPL_LEN_HSW) == 0) { memcpy(default_aapl_haswell, new_aapl0, AAPL_LEN_HSW); verbose("Using user supplied AAPL,ig-platform-id\n"); verbose("AAPL,ig-platform-id: %02x%02x%02x%02x\n", default_aapl_haswell[0], default_aapl_haswell[1], default_aapl_haswell[2], default_aapl_haswell[3]); } devprop_add_value(device, "AAPL,ig-platform-id", default_aapl_haswell, AAPL_LEN_HSW); } else if (getIntForKey(kIntelAzulFB, &n_igs, &bootInfo->chameleonConfig)) { if ((n_igs >= 0) || (n_igs <= 15)) { verbose("AAPL,ig-platform-id was set in org.chameleon.Boot.plist with value %d\n", n_igs); devprop_add_value(device, "AAPL,ig-platform-id", haswell_ig_vals[n_igs], 4); } else { verbose("AAPL,ig-platform-id was set in org.chameleon.Boot.plist with bad value please choose a number between 0 and 15.\n"); } } else { uint32_t ig_platform_id = 0x0000260c; // set the default platform ig devprop_add_value(device, "AAPL,ig-platform-id", (uint8_t *)&ig_platform_id, 4); } devprop_add_value(device, "AAPL00,DualLink", HD4000_vals[10], 4); devprop_add_value(device, "built-in", &BuiltIn, 1); devprop_add_value(device, "class-code", ClassFix, 4); devprop_add_value(device, "hda-gfx", (uint8_t *)"onboard-1", 10); break; default: break; } stringdata = malloc(sizeof(uint8_t) * string->length); if (!stringdata) { printf("No stringdata.\n"); pause(); return false; } verbose("---------------------------------------------\n"); memcpy(stringdata, (uint8_t*)devprop_generate_string(string), string->length); stringlength = string->length; return true; }
/** Compute necessary space requirements for new smbios */ static struct SMBEntryPoint *smbios_dry_run(struct SMBEntryPoint *origsmbios) { struct SMBEntryPoint *ret; char *smbiostables; char *tablesptr; int origsmbiosnum; int i, j; int tablespresent[256]; bool do_auto=true; bzero(tablespresent, sizeof(tablespresent)); getBoolForKey(kSMBIOSdefaults, &do_auto, &bootInfo->bootConfig); ret = (struct SMBEntryPoint *)AllocateKernelMemory(sizeof(struct SMBEntryPoint)); if (origsmbios) { smbiostables = (char *)origsmbios->dmi.tableAddress; origsmbiosnum = origsmbios->dmi.structureCount; } else { smbiostables = NULL; origsmbiosnum = 0; } // _SM_ ret->anchor[0] = 0x5f; ret->anchor[1] = 0x53; ret->anchor[2] = 0x4d; ret->anchor[3] = 0x5f; ret->entryPointLength = sizeof(*ret); ret->majorVersion = 2; ret->minorVersion = 1; ret->maxStructureSize = 0; // will be calculated later in this function ret->entryPointRevision = 0; for (i=0;i<5;i++) { ret->formattedArea[i] = 0; } //_DMI_ ret->dmi.anchor[0] = 0x5f; ret->dmi.anchor[1] = 0x44; ret->dmi.anchor[2] = 0x4d; ret->dmi.anchor[3] = 0x49; ret->dmi.anchor[4] = 0x5f; ret->dmi.tableLength = 0; // will be calculated later in this function ret->dmi.tableAddress = 0; // will be initialized in smbios_real_run() ret->dmi.structureCount = 0; // will be calculated later in this function ret->dmi.bcdRevision = 0x21; tablesptr = smbiostables; // add stringlen of overrides to original stringlen, update maxStructure size adequately, // update structure count and tablepresent[type] with count of type. if (smbiostables) { for (i=0; i<origsmbiosnum; i++) { struct smbios_table_header *cur = (struct smbios_table_header *)tablesptr; char *stringsptr; int stringlen; tablesptr += cur->length; stringsptr = tablesptr; for (; tablesptr[0]!=0 || tablesptr[1]!=0; tablesptr++); tablesptr += 2; stringlen = tablesptr - stringsptr - 1; if (stringlen == 1) { stringlen = 0; } for (j=0; j<sizeof(smbios_properties)/sizeof(smbios_properties[0]); j++) { const char *str; int size; char altname[40]; sprintf(altname, "%s_%d",smbios_properties[j].name, tablespresent[cur->type] + 1); if (smbios_properties[j].table_type == cur->type && smbios_properties[j].value_type == SMSTRING && (getValueForKey(smbios_properties[j].name, &str, &size, &bootInfo->smbiosConfig) || getValueForKey(altname,&str, &size, &bootInfo->smbiosConfig))) { stringlen += size + 1; } else if (smbios_properties[j].table_type == cur->type && smbios_properties[j].value_type == SMSTRING && do_auto && smbios_properties[j].auto_str) { stringlen += strlen(smbios_properties[j].auto_str(smbios_properties[j].name, tablespresent[cur->type])) + 1; } } if (stringlen == 0) { stringlen = 1; } stringlen++; if (ret->maxStructureSize < cur->length+stringlen) { ret->maxStructureSize=cur->length+stringlen; } ret->dmi.tableLength += cur->length+stringlen; ret->dmi.structureCount++; tablespresent[cur->type]++; } } // Add eventually table types whose detected count would be < required count, and update ret header with: // new stringlen addons, structure count, and tablepresent[type] count adequately for (i=0; i<sizeof(smbios_table_descriptions)/sizeof(smbios_table_descriptions[0]); i++) { int numnec=-1; char buffer[40]; sprintf(buffer, "SMtable%d", i); if (!getIntForKey(buffer, &numnec, &bootInfo->smbiosConfig)) { numnec = -1; } if (numnec==-1 && do_auto && smbios_table_descriptions[i].numfunc) { numnec = smbios_table_descriptions[i].numfunc(smbios_table_descriptions[i].type); } while (tablespresent[smbios_table_descriptions[i].type] < numnec) { int stringlen = 0; for (j=0; j<sizeof(smbios_properties)/sizeof(smbios_properties[0]); j++) { const char *str; int size; char altname[40]; sprintf(altname, "%s_%d",smbios_properties[j].name, tablespresent[smbios_table_descriptions[i].type] + 1); if (smbios_properties[j].table_type == smbios_table_descriptions[i].type && smbios_properties[j].value_type == SMSTRING && (getValueForKey(altname, &str, &size, &bootInfo->smbiosConfig) || getValueForKey(smbios_properties[j].name, &str, &size, &bootInfo->smbiosConfig))) { stringlen += size + 1; } else if (smbios_properties[j].table_type == smbios_table_descriptions[i].type && smbios_properties[j].value_type==SMSTRING && do_auto && smbios_properties[j].auto_str) { stringlen += strlen(smbios_properties[j].auto_str(smbios_properties[j].name, tablespresent[smbios_table_descriptions[i].type])) + 1; } } if (stringlen == 0) { stringlen = 1; } stringlen++; if (ret->maxStructureSize < smbios_table_descriptions[i].len+stringlen) { ret->maxStructureSize = smbios_table_descriptions[i].len + stringlen; } ret->dmi.tableLength += smbios_table_descriptions[i].len + stringlen; ret->dmi.structureCount++; tablespresent[smbios_table_descriptions[i].type]++; } } return ret; }
void loadThemeValues(config_file_t *theme, bool overide) { unsigned int screen_width = gui.screen.width; unsigned int screen_height = gui.screen.height; unsigned int pixel; int alpha; // transparency level 0 (obligue) - 255 (transparent) uint32_t color; // color value formatted RRGGBB int val, len; const char *string; /* * Parse screen parameters */ if(getColorForKey("screen_bgcolor", &color, theme )) gui.screen.bgcolor = (color & 0x00FFFFFF); if(getIntForKey("screen_textmargin_h", &val, theme)) gui.screen.hborder = MIN( gui.screen.width , val ); if(getIntForKey("screen_textmargin_v", &val, theme)) gui.screen.vborder = MIN( gui.screen.height , val ); /* * Parse background parameters */ if(getDimensionForKey("background_pos_x", &pixel, theme, screen_width , images[iBackground].image->width ) ) gui.background.pos.x = pixel; if(getDimensionForKey("background_pos_y", &pixel, theme, screen_height , images[iBackground].image->height ) ) gui.background.pos.y = pixel; /* * Parse logo parameters */ if(getDimensionForKey("logo_pos_x", &pixel, theme, screen_width , images[iLogo].image->width ) ) gui.logo.pos.x = pixel; if(getDimensionForKey("logo_pos_y", &pixel, theme, screen_height , images[iLogo].image->height ) ) gui.logo.pos.y = pixel; /* * Parse progress bar parameters */ if(getDimensionForKey("progressbar_pos_x", &pixel, theme, screen_width , 0 ) ) gui.progressbar.pos.x = pixel; if(getDimensionForKey("progressbar_pos_y", &pixel, theme, screen_height , 0 ) ) gui.progressbar.pos.y = pixel; /* * Parse countdown text parameters */ if(getDimensionForKey("countdown_pos_x", &pixel, theme, screen_width , 0 ) ) gui.countdown.pos.x = pixel; if(getDimensionForKey("countdown_pos_y", &pixel, theme, screen_height , 0 ) ) gui.countdown.pos.y = pixel; /* * Parse devicelist parameters */ if(getIntForKey("devices_max_visible", &val, theme )) gui.maxdevices = MIN( val, gDeviceCount ); if(getIntForKey("devices_iconspacing", &val, theme )) gui.devicelist.iconspacing = val; // check layout for horizontal or vertical gui.layout = HorizontalLayout; if(getValueForKey( "devices_layout", &string, &len, theme)) { if (!strcmp (string, "vertical")) { gui.layout = VerticalLayout; } } switch (gui.layout) { case VerticalLayout: gui.devicelist.height = ((images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing) * MIN(gui.maxdevices, gDeviceCount) + (images[iDeviceScrollPrev].image->height + images[iDeviceScrollNext].image->height) + gui.devicelist.iconspacing); gui.devicelist.width = (images[iSelection].image->width + gui.devicelist.iconspacing); if(getDimensionForKey("devices_pos_x", &pixel, theme, gui.screen.width , images[iSelection].image->width ) ) gui.devicelist.pos.x = pixel; if(getDimensionForKey("devices_pos_y", &pixel, theme, gui.screen.height , gui.devicelist.height ) ) gui.devicelist.pos.y = pixel; break; case HorizontalLayout: default: gui.devicelist.width = ((images[iSelection].image->width + gui.devicelist.iconspacing) * MIN(gui.maxdevices, gDeviceCount) + (images[iDeviceScrollPrev].image->width + images[iDeviceScrollNext].image->width) + gui.devicelist.iconspacing); gui.devicelist.height = (images[iSelection].image->height + font_console.chars[0]->height + gui.devicelist.iconspacing); if(getDimensionForKey("devices_pos_x", &pixel, theme, gui.screen.width , gui.devicelist.width ) ) gui.devicelist.pos.x = pixel; else gui.devicelist.pos.x = ( gui.screen.width - gui.devicelist.width ) / 2; if(getDimensionForKey("devices_pos_y", &pixel, theme, gui.screen.height , images[iSelection].image->height ) ) gui.devicelist.pos.y = pixel; else gui.devicelist.pos.y = ( gui.screen.height - gui.devicelist.height ) / 2; break; } if(getColorForKey("devices_bgcolor", &color, theme)) gui.devicelist.bgcolor = (color & 0x00FFFFFF); if(getIntForKey("devices_transparency", &alpha, theme)) gui.devicelist.bgcolor = gui.devicelist.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24); /* * Parse infobox parameters */ if(getIntForKey("infobox_width", &val, theme)) gui.infobox.width = MIN( screen_width , val ); if(getIntForKey("infobox_height", &val, theme)) gui.infobox.height = MIN( screen_height , val ); if(getDimensionForKey("infobox_pos_x", &pixel, theme, screen_width , gui.infobox.width ) ) gui.infobox.pos.x = pixel; if(getDimensionForKey("infobox_pos_y", &pixel, theme, screen_height , gui.infobox.height ) ) gui.infobox.pos.y = pixel; if(getIntForKey("infobox_textmargin_h", &val, theme)) gui.infobox.hborder = MIN( gui.infobox.width , val ); if(getIntForKey("infobox_textmargin_v", &val, theme)) gui.infobox.vborder = MIN( gui.infobox.height , val ); if(getColorForKey("infobox_bgcolor", &color, theme)) gui.infobox.bgcolor = (color & 0x00FFFFFF); if(getIntForKey("infobox_transparency", &alpha, theme)) gui.infobox.bgcolor = gui.infobox.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24); /* * Parse menu parameters */ if(getDimensionForKey("menu_width", &pixel, theme, gui.screen.width , 0 ) ) gui.menu.width = pixel; else gui.menu.width = images[iMenuSelection].image->width; if(getDimensionForKey("menu_height", &pixel, theme, gui.screen.height , 0 ) ) gui.menu.height = pixel; else gui.menu.height = (infoMenuItemsCount) * images[iMenuSelection].image->height; if(getDimensionForKey("menu_pos_x", &pixel, theme, screen_width , gui.menu.width ) ) gui.menu.pos.x = pixel; if(getDimensionForKey("menu_pos_y", &pixel, theme, screen_height , gui.menu.height ) ) gui.menu.pos.y = pixel; if(getIntForKey("menu_textmargin_h", &val, theme)) gui.menu.hborder = MIN( gui.menu.width , val ); if(getIntForKey("menu_textmargin_v", &val, theme)) gui.menu.vborder = MIN( gui.menu.height , val ); if(getColorForKey("menu_bgcolor", &color, theme)) gui.menu.bgcolor = (color & 0x00FFFFFF); if(getIntForKey("menu_transparency", &alpha, theme)) gui.menu.bgcolor = gui.menu.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24); /* * Parse bootprompt parameters */ if(getDimensionForKey("bootprompt_width", &pixel, theme, screen_width , 0 ) ) gui.bootprompt.width = pixel; if(getIntForKey("bootprompt_height", &val, theme)) gui.bootprompt.height = MIN( screen_height , val ); if(getDimensionForKey("bootprompt_pos_x", &pixel, theme, screen_width , gui.bootprompt.width ) ) gui.bootprompt.pos.x = pixel; if(getDimensionForKey("bootprompt_pos_y", &pixel, theme, screen_height , gui.bootprompt.height ) ) gui.bootprompt.pos.y = pixel; if(getIntForKey("bootprompt_textmargin_h", &val, theme)) gui.bootprompt.hborder = MIN( gui.bootprompt.width , val ); if(getIntForKey("bootprompt_textmargin_v", &val, theme)) gui.bootprompt.vborder = MIN( gui.bootprompt.height , val ); if(getColorForKey("bootprompt_bgcolor", &color, theme)) gui.bootprompt.bgcolor = (color & 0x00FFFFFF); if(getIntForKey("bootprompt_transparency", &alpha, theme)) gui.bootprompt.bgcolor = gui.bootprompt.bgcolor | (( 255 - ( alpha & 0xFF) ) << 24); if(getColorForKey("font_small_color", &color, theme)) gui.screen.font_small_color = (color & 0x00FFFFFF); if(getColorForKey("font_console_color", &color, theme)) gui.screen.font_console_color = (color & 0x00FFFFFF); }
int initGUI(void) { int val; #ifdef EMBED_THEME config_file_t *config; config = &bootInfo->themeConfig; if (ParseXMLFile((char *)__theme_plist, &config->dictionary) != 0) { return 1; } #else int len; char dirspec[256]; getValueForKey( "Theme", &theme_name, &len, &bootInfo->bootConfig ); if ((strlen(theme_name) + 27) > sizeof(dirspec)) { return 1; } sprintf(dirspec, "/Extra/Themes/%s/theme.plist", theme_name); if (loadConfigFile(dirspec, &bootInfo->themeConfig) != 0) { return 1; } #endif // parse display size parameters if (getIntForKey("screen_width", &val, &bootInfo->themeConfig)) { screen_params[0] = val; } if (getIntForKey("screen_height", &val, &bootInfo->themeConfig)) { screen_params[1] = val; } screen_params[2] = 32; // Initalizing GUI strucutre. bzero(&gui, sizeof(gui_t)); // find best matching vesa mode for our requested width & height getGraphicModeParams(screen_params); // set our screen structure with the mode width & height gui.screen.width = screen_params[0]; gui.screen.height = screen_params[1]; // load graphics otherwise fail and return if (loadGraphics() == 0) { loadThemeValues(&bootInfo->themeConfig, true); colorFont(&font_small, gui.screen.font_small_color); colorFont(&font_console, gui.screen.font_console_color); // create the screen & window buffers if (createBackBuffer(&gui.screen) == 0) { if (createWindowBuffer(&gui.screen) == 0) { if (createWindowBuffer(&gui.devicelist) == 0) { if (createWindowBuffer(&gui.bootprompt) == 0) { if (createWindowBuffer(&gui.infobox) == 0) { if (createWindowBuffer(&gui.menu) == 0) { drawBackground(); // lets copy the screen into the back buffer memcpy( gui.backbuffer->pixels, gui.screen.pixmap->pixels, gui.backbuffer->width * gui.backbuffer->height * 4 ); setVideoMode( GRAPHICS_MODE, 0 ); gui.initialised = true; return 0; } } } } } } } return 1; }
int getBootOptions(bool firstRun) { int i; int key; int nextRow; int timeout; #if UNUSED int bvCount; #endif BVRef bvr; BVRef menuBVR; bool showPrompt, newShowPrompt, isCDROM; int optionKey; // Initialize default menu selection entry. menuBVR = selectBootVolume(getBvChain()); safe_set_env(envgBootVolume, (uint32_t)menuBVR); if (biosDevIsCDROM((int)get_env(envgBIOSDev))) { isCDROM = true; } else { isCDROM = false; } // Clear command line boot arguments clearBootArgs(); // Allow user to override default timeout. #if UNUSED if (multiboot_timeout_set) { timeout = multiboot_timeout; } else #endif if (!getIntForKey(kTimeoutKey, &timeout, DEFAULT_BOOT_CONFIG)) { /* If there is no timeout key in the file use the default timeout which is different for CDs vs. hard disks. However, if not booting a CD and no config file could be loaded set the timeout to zero which causes the menu to display immediately. This way, if no partitions can be found, that is the disk is unpartitioned or simply cannot be read) then an empty menu is displayed. If some partitions are found, for example a Windows partition, then these will be displayed in the menu as foreign partitions. */ if (isCDROM) { timeout = kCDBootTimeout; } else { timeout = get_env(envSysConfigValid) ? kBootTimeout : 0; } } long gBootMode = (long)get_env(envgBootMode); if (timeout < 0) { gBootMode |= kBootModeQuiet; safe_set_env(envgBootMode,gBootMode); } // If the user is holding down a modifier key, enter safe mode. if ((readKeyboardShiftFlags() & 0x0F) != 0) { gBootMode |= kBootModeSafe; safe_set_env(envgBootMode,gBootMode); } // Checking user pressed keys bool f8press = false, spress = false, vpress = false; while (readKeyboardStatus()) { key = bgetc (); if (key == 0x4200) f8press = true; if ((key & 0xff) == 's' || (key & 0xff) == 'S') spress = true; if ((key & 0xff) == 'v' || (key & 0xff) == 'V') vpress = true; } // If user typed F8, abort quiet mode, and display the menu. if (f8press) { gBootMode &= ~kBootModeQuiet; safe_set_env(envgBootMode,gBootMode); timeout = 0; } // If user typed 'v' or 'V', boot in verbose mode. if ((gBootMode & kBootModeQuiet) && firstRun && vpress) { addBootArg(kVerboseModeFlag); } // If user typed 's' or 'S', boot in single user mode. if ((gBootMode & kBootModeQuiet) && firstRun && spress) { addBootArg(kSingleUserModeFlag); } setCursorPosition(0, 0, 0); clearScreenRows(0, kScreenLastRow); if (!(gBootMode & kBootModeQuiet)) { // Display banner and show hardware info. char * bootBanner = (char*)(uint32_t)get_env(envBootBanner); printf(bootBanner, (int)(get_env(envConvMem) + get_env(envExtMem)) / 1024); } changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0); msglog("Scanning device %x...", (uint32_t)get_env(envgBIOSDev)); // When booting from CD, default to hard drive boot when possible. if (isCDROM && firstRun) { const char *val; char *prompt = NULL; char *name = NULL; int cnt; if (getValueForKey(kCDROMPromptKey, &val, &cnt, DEFAULT_BOOT_CONFIG)) { prompt = calloc(cnt + 1, sizeof(char)); if (!prompt) { stop("Couldn't allocate memory for the prompt\n"); //TODO: Find a better stategie return -1; } strncat(prompt, val, cnt); } else { prompt = calloc(256, sizeof(char)); if (!prompt) { stop("Couldn't allocate memory for the prompt\n"); //TODO: Find a better stategie return -1; } BVRef bvr; if (( bvr = ((BVRef)(uint32_t)get_env(envgBootVolume)))) { name = calloc(80, sizeof(char)); if (!name) { stop("Couldn't allocate memory for the device name\n"); //TODO: Find a better stategie return -1; } getBootVolumeDescription(bvr, name, 79, false); snprintf(prompt, 256,"Press ENTER to start up from %s, or press any key to enter startup options.", name); free(name); } else snprintf(prompt, 256,"Press ENTER to start up, or press any key to enter startup options."); } if (getIntForKey( kCDROMOptionKey, &optionKey, DEFAULT_BOOT_CONFIG )) { // The key specified is a special key. } else { // Default to F8. optionKey = 0x4200; } // If the timeout is zero then it must have been set above due to the // early catch of F8 which means the user wants to set boot options // which we ought to interpret as meaning he wants to boot the CD. if (timeout != 0) { key = countdown(prompt, kMenuTopRow, timeout, &optionKey); } else { key = optionKey; } if (prompt != NULL) { free(prompt); } clearScreenRows( kMenuTopRow, kMenuTopRow + 2 ); do { // Hit the option key ? if (key == optionKey) { if (key != 0x1C0D) { gBootMode &= ~kBootModeQuiet; safe_set_env(envgBootMode,gBootMode); timeout = 0; break; } } key = key & 0xFF; // Try booting hard disk if user pressed 'h' if (biosDevIsCDROM((int)get_env(envgBIOSDev)) && key == 'h') { BVRef bvr; // Look at partitions hosting OS X other than the CD-ROM for (bvr = getBvChain(); bvr; bvr=bvr->next) { if ((bvr->flags & kBVFlagSystemVolume) && bvr->biosdev != (int)get_env(envgBIOSDev)) { safe_set_env(envgBootVolume, (uint32_t)bvr); } } } goto done; } while (0); } if (get_env(envgBootMode) & kBootModeQuiet) { // No input allowed from user. goto done; } if (firstRun && timeout > 0 ) { key = countdown("Press ENTER to start up, or press any key to enter startup options.", kMenuTopRow, timeout, &optionKey); if (key == 0x1C0D) { goto done; } else if (key == 0) { // If the user is holding down a modifier key, // enter safe mode. if ((readKeyboardShiftFlags() & 0x0F) != 0) { gBootMode |= kBootModeSafe; safe_set_env(envgBootMode,gBootMode); } goto done; } } int devcnt = (int)get_env(envgDeviceCount); if (devcnt) { // Allocate memory for an array of menu items. menuItems = calloc(devcnt,sizeof(MenuItem)); if (menuItems == NULL) { goto done; } // Associate a menu item for each BVRef. for (bvr=getBvChain(), i=devcnt-1, selectIndex=0; bvr; bvr=bvr->next) { if (bvr->visible) { getBootVolumeDescription(bvr, menuItems[i].name, sizeof(menuItems[i].name) - 1, true); menuItems[i].param = (void *) bvr; if (bvr == menuBVR) { selectIndex = i; } i--; } } } // Clear screen and hide the blinking cursor. clearScreenRows(kMenuTopRow, kMenuTopRow + 2); changeCursor(0, kMenuTopRow, kCursorTypeHidden, 0); nextRow = kMenuTopRow; /*showPrompt = true;*/ if (devcnt) { printf("Use \30\31 keys to select the startup volume."); showMenu( menuItems, devcnt, selectIndex, kMenuTopRow + 2, kMenuMaxItems ); nextRow += min( devcnt, kMenuMaxItems ) + 3; } // Show the boot prompt. showPrompt = (devcnt == 0) || (menuBVR->flags & kBVFlagNativeBoot); showBootPrompt( nextRow, showPrompt ); do { key = getc(); updateMenu( key, (void **) &menuBVR ); newShowPrompt = (devcnt == 0) || (menuBVR->flags & kBVFlagNativeBoot); if (newShowPrompt != showPrompt) { showPrompt = newShowPrompt; showBootPrompt( nextRow, showPrompt ); } if (showPrompt) { updateBootArgs(key); } switch (key) { case kReturnKey: if (*gBootArgs == '?') { char * argPtr = gBootArgs; // Skip the leading "?" character. argPtr++; getNextArg(&argPtr, booterCommand); getNextArg(&argPtr, booterParam); /* * TODO: this needs to be refactored. */ #if UNUSED if (strncmp( booterCommand, "video", sizeof("video") ) == 0) { printVBEModeInfo(); } else #endif if ( strncmp( booterCommand, "memory", sizeof("memory") ) == 0) { printMemoryInfo(); } else if (strncmp(booterCommand, "lspci", sizeof( "lspci")) == 0) { lspci(); } else if (strncmp(booterCommand, "more", sizeof("more")) == 0) { showTextFile(booterParam); } else if (strncmp(booterCommand, "rd", sizeof("rd")) == 0) { if (execute_hook("processRAMDiskCommand", (void*)argPtr, &booterParam, NULL, NULL, NULL, NULL) != EFI_SUCCESS) showMessage("ramdisk module not found, please install RamdiskLoader.dylib in /Extra/modules/"); } else if (strncmp(booterCommand, "norescan", sizeof("norescan")) == 0) { if (get_env(envgEnableCDROMRescan)) { safe_set_env(envgEnableCDROMRescan,false); break; } } else { showHelp(); } key = 0; showBootPrompt(nextRow, showPrompt); break; } safe_set_env(envgBootVolume, (uint32_t)menuBVR); setRootVolume(menuBVR); safe_set_env(envgBIOSDev,menuBVR->biosdev); break; case kEscapeKey: clearBootArgs(); break; case kF5Key: // New behavior: // Clear gBootVolume to restart the loop // if the user enabled rescanning the optical drive. // Otherwise boot the default boot volume. if (get_env(envgEnableCDROMRescan)) { //gBootVolume = NULL; safe_set_env(envgBootVolume, (uint32_t)NULL); clearBootArgs(); } break; case kF10Key: safe_set_env(envgScanSingleDrive, false); scanDisks(); //gBootVolume = NULL; safe_set_env(envgBootVolume, (uint32_t)NULL); clearBootArgs(); break; default: key = 0; break; } } while (0 == key); done: if (bootArgs->Video.v_display == VGA_TEXT_MODE) { clearScreenRows(kMenuTopRow, kScreenLastRow); changeCursor(0, kMenuTopRow, kCursorTypeUnderline, 0); } safe_set_env(envShouldboot, false); if (menuItems) { free(menuItems); menuItems = NULL; } return 0; }
int getBootOptions(BOOL firstRun) { int i; int key; int selectIndex = 0; int bvCount; int nextRow; int timeout; BVRef bvr; BVRef bvChain; BVRef menuBVR; BOOL showPrompt, newShowPrompt, isCDROM; MenuItem * menuItems = NULL; if ( diskIsCDROM(gBootVolume) ) isCDROM = TRUE; else isCDROM = FALSE; // Allow user to override default timeout. if ( getIntForKey(kTimeoutKey, &timeout) == NO ) { if ( isCDROM ) timeout = kCDBootTimeout; else timeout = kBootTimeout; } if (timeout < 0) gBootMode |= kBootModeQuiet; // If the user is holding down a modifier key, // enter safe mode. if ( ( readKeyboardShiftFlags() & 0x0F ) != 0 ) { gBootMode |= kBootModeSafe; } // If user typed F8, abort quiet mode, // and display the menu. if (flushKeyboardBuffer()) { gBootMode &= ~kBootModeQuiet; timeout = 0; } clearBootArgs(); setCursorPosition( 0, 0, 0 ); clearScreenRows( 0, kScreenLastRow ); if ( ! ( gBootMode & kBootModeQuiet ) ) { // Display banner and show hardware info. printf( bootBanner, (bootInfo->convmem + bootInfo->extmem) / 1024 ); printVBEInfo(); } changeCursor( 0, kMenuTopRow, kCursorTypeUnderline, 0 ); verbose("Scanning device %x...", gBIOSDev); // Get a list of bootable volumes on the device. bvChain = scanBootVolumes( gBIOSDev, &bvCount ); gBootVolume = menuBVR = selectBootVolume( bvChain ); // When booting from CD, default to hard // drive boot when possible. if ( isCDROM ) { const char *val; char *prompt; int cnt; int optionKey; if (getValueForKey( kCDROMPromptKey, &val, &cnt )) { cnt += 1; prompt = malloc(cnt); strlcpy(prompt, val, cnt); } else { prompt = "Press any key to start up from CD-ROM, " "or press F8 to enter startup options."; cnt = 0; } if (getIntForKey( kCDROMOptionKey, &optionKey )) { // The key specified is a special key. } else if (getValueForKey( kCDROMOptionKey, &val, &cnt) && cnt >= 1) { optionKey = val[0]; } else { // Default to F8. optionKey = 0x4200; } key = countdown(prompt, kMenuTopRow, timeout); if (cnt) free(prompt); clearScreenRows( kMenuTopRow, kMenuTopRow + 2 ); if (key == 0) { // Boot from hard disk. // Scan the original device 0x80. BVRef hd_bvr = selectBootVolume(scanBootVolumes(0x80, 0)); if ( hd_bvr->flags & kBVFlagNativeBoot ) { gBootVolume = hd_bvr; gBIOSDev = hd_bvr->biosdev; initKernBootStruct( gBIOSDev ); goto done; } } else { if (optionKey < 0x100) key = key & 0x5F; if (key != optionKey) goto done; } gBootMode &= ~kBootModeQuiet; timeout = 0; } if ( gBootMode & kBootModeQuiet ) { // No input allowed from user. goto done; } if ( firstRun && ( timeout > 0 ) && ( countdown("Press any key to enter startup options.", kMenuTopRow, timeout) == 0 ) ) { // If the user is holding down a modifier key, // enter safe mode. if ( ( readKeyboardShiftFlags() & 0x0F ) != 0 ) { gBootMode |= kBootModeSafe; } goto done; } if ( bvCount ) { // Allocate memory for an array of menu items. menuItems = (MenuItem *) malloc( sizeof(MenuItem) * bvCount ); if ( menuItems == NULL ) goto done; // Associate a menu item for each BVRef. for ( bvr = bvChain, i = bvCount - 1, selectIndex = 0; bvr; bvr = bvr->next, i-- ) { getBootVolumeDescription( bvr, menuItems[i].name, 80, YES ); menuItems[i].param = (void *) bvr; if ( bvr == menuBVR ) selectIndex = i; } } // Clear screen and hide the blinking cursor. clearScreenRows( kMenuTopRow, kMenuTopRow + 2 ); changeCursor( 0, kMenuTopRow, kCursorTypeHidden, 0 ); nextRow = kMenuTopRow; showPrompt = YES; // Show the menu. if ( bvCount ) { printf("Use \30\31 keys to select the startup volume."); showMenu( menuItems, bvCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems ); nextRow += min( bvCount, kMenuMaxItems ) + 3; } // Show the boot prompt. showPrompt = (bvCount == 0) || (menuBVR->flags & kBVFlagNativeBoot); showBootPrompt( nextRow, showPrompt ); do { key = getc(); updateMenu( key, (void **) &menuBVR ); newShowPrompt = (bvCount == 0) || (menuBVR->flags & kBVFlagNativeBoot); if ( newShowPrompt != showPrompt ) { showPrompt = newShowPrompt; showBootPrompt( nextRow, showPrompt ); } if ( showPrompt ) updateBootArgs( key ); switch ( key & kASCIIKeyMask ) { case kReturnKey: if ( *gBootArgs == '?' ) { if ( strcmp( gBootArgs, "?video" ) == 0 ) { printVBEModeInfo(); } else if ( strcmp( gBootArgs, "?memory" ) == 0 ) { printMemoryInfo(); } else { showHelp(); } key = 0; showBootPrompt( nextRow, showPrompt ); break; } gBootVolume = menuBVR; break; case kEscapeKey: clearBootArgs(); break; default: key = 0; } } while ( 0 == key ); done: firstRun = NO; clearScreenRows( kMenuTopRow, kScreenLastRow ); changeCursor( 0, kMenuTopRow, kCursorTypeUnderline, 0 ); if ( menuItems ) free(menuItems); return 0; }
int getBootOptions(BOOL firstRun) { int i; int key; int selectIndex = 0; int bvCount; int nextRow; int timeout; BVRef bvr; BVRef bvChain; BVRef menuBVR; BOOL showPrompt, newShowPrompt; MenuItem * menuItems = NULL; // Allow user to override default timeout. if ( getIntForKey(kTimeoutKey, &timeout) == NO ) { timeout = kBootTimeout; } // If the user is holding down a shift key, // abort quiet mode. if ( ( readKeyboardShiftFlags() & 0x0F ) != 0 ) { gBootMode &= ~kBootModeQuiet; } // If user typed F8, abort quiet mode, // and display the menu. if (flushKeyboardBuffer()) { gBootMode &= ~kBootModeQuiet; timeout = 0; } clearBootArgs(); setCursorPosition( 0, 0, 0 ); clearScreenRows( 0, kScreenLastRow ); if ( ! ( gBootMode & kBootModeQuiet ) ) { // Display banner and show hardware info. printf( bootBanner, (bootArgs->convmem + bootArgs->extmem) / 1024 ); printVBEInfo(); } changeCursor( 0, kMenuTopRow, kCursorTypeUnderline, 0 ); verbose("Scanning device %x...", gBIOSDev); // Get a list of bootable volumes on the device. bvChain = scanBootVolumes( gBIOSDev, &bvCount ); gBootVolume = menuBVR = selectBootVolume( bvChain ); #if 0 // When booting from CD (via HD emulation), default to hard // drive boot when possible. if ( gBootVolume->part_type == FDISK_BOOTER && gBootVolume->biosdev == 0x80 ) { // Scan the original device 0x80 that has been displaced // by the CD-ROM. BVRef hd_bvr = selectBootVolume(scanBootVolumes(0x81, 0)); if ( hd_bvr->flags & kBVFlagNativeBoot ) { int key = countdown("Press C to start up from CD-ROM.", kMenuTopRow, 5); if ( (key & 0x5f) != 'c' ) { gBootVolume = hd_bvr; gBIOSDev = hd_bvr->biosdev; initKernBootStruct( gBIOSDev ); goto done; } } } #endif if ( gBootMode & kBootModeQuiet ) { // No input allowed from user. goto done; } if ( firstRun && ( timeout > 0 ) && ( countdown("Press any key to enter startup options.", kMenuTopRow, timeout) == 0 ) ) { goto done; } if ( bvCount ) { // Allocate memory for an array of menu items. menuItems = (MenuItem *) malloc( sizeof(MenuItem) * bvCount ); if ( menuItems == NULL ) goto done; // Associate a menu item for each BVRef. for ( bvr = bvChain, i = bvCount - 1, selectIndex = 0; bvr; bvr = bvr->next, i-- ) { getBootVolumeDescription( bvr, menuItems[i].name, 80, YES ); menuItems[i].param = (void *) bvr; if ( bvr == menuBVR ) selectIndex = i; } } // Clear screen and hide the blinking cursor. clearScreenRows( kMenuTopRow, kMenuTopRow + 2 ); changeCursor( 0, kMenuTopRow, kCursorTypeHidden, 0 ); nextRow = kMenuTopRow; showPrompt = YES; // Show the menu. if ( bvCount ) { printf("Use \30\31 keys to select the startup volume."); showMenu( menuItems, bvCount, selectIndex, kMenuTopRow + 2, kMenuMaxItems ); nextRow += min( bvCount, kMenuMaxItems ) + 3; } // Show the boot prompt. showPrompt = (bvCount == 0) || (menuBVR->flags & kBVFlagNativeBoot); showBootPrompt( nextRow, showPrompt ); do { key = getc(); updateMenu( key, (void **) &menuBVR ); newShowPrompt = (bvCount == 0) || (menuBVR->flags & kBVFlagNativeBoot); if ( newShowPrompt != showPrompt ) { showPrompt = newShowPrompt; showBootPrompt( nextRow, showPrompt ); } if ( showPrompt ) updateBootArgs( key ); switch ( key & kASCIIKeyMask ) { case kReturnKey: if ( *gBootArgs == '?' ) { if ( strcmp( gBootArgs, "?video" ) == 0 ) { printVBEModeInfo(); } else if ( strcmp( gBootArgs, "?memory" ) == 0 ) { printMemoryInfo(); } else { showHelp(); } key = 0; showBootPrompt( nextRow, showPrompt ); break; } gBootVolume = menuBVR; break; case kEscapeKey: clearBootArgs(); break; default: key = 0; } } while ( 0 == key ); done: firstRun = NO; clearScreenRows( kMenuTopRow, kScreenLastRow ); changeCursor( 0, kMenuTopRow, kCursorTypeUnderline, 0 ); if ( menuItems ) free(menuItems); return 0; }
int G::getMoney(){ return getIntForKey("money", INITMONEY+MONEY_OFFSET)-MONEY_OFFSET; }
int G::getCoin(){ return getIntForKey("coin", INITCOIN+COIN_OFFSET)-COIN_OFFSET; }