X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/89b3af67bb32e691275bf6fa803d1834b2284115..b226f5e54a60dc81db17b1260381d7dbfea3cdf1:/pexpert/i386/pe_init.c?ds=sidebyside diff --git a/pexpert/i386/pe_init.c b/pexpert/i386/pe_init.c index f85167df9..49f9caecf 100644 --- a/pexpert/i386/pe_init.c +++ b/pexpert/i386/pe_init.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * @@ -29,8 +29,10 @@ * file: pe_init.c * i386 platform expert initialization. */ + #include #include +#include #include #include #include @@ -39,72 +41,60 @@ #include #include -#include "fakePPCStructs.h" -#include "fakePPCDeviceTree.h" +#if CONFIG_CSR +#include +#endif + #include "boot_images.h" /* extern references */ extern void pe_identify_machine(void * args); -extern void initialize_screen(void *, unsigned int); - +extern int kdb_printf(const char *format, ...) __printflike(1,2); /* private globals */ PE_state_t PE_state; -dt_data gMemoryMapNode; -dt_data gDriversProp; -dt_data gRootpathProp; -dt_data gCompatibleProp; /* Clock Frequency Info */ clock_frequency_info_t gPEClockFrequencyInfo; -void *gPEEFISystemTable = 0; -void *gPEEFIRuntimeServices = 0; +void *gPEEFISystemTable; +void *gPEEFIRuntimeServices; + +static boot_icon_element* norootIcon_lzss; +static const uint8_t* norootClut_lzss; int PE_initialize_console( PE_Video * info, int op ) { static int last_console = -1; - Boot_Video bootInfo; - Boot_Video * bInfo; - /* - * Refuse changes from outside pexpert. - * The video mode setup by the booter cannot be changed. - */ - if ( info ) - { - bootInfo.v_baseAddr = info->v_baseAddr; - bootInfo.v_rowBytes = info->v_rowBytes; - bootInfo.v_width = info->v_width; - bootInfo.v_height = info->v_height; - bootInfo.v_depth = info->v_depth; - bInfo = &bootInfo; - if (info == &PE_state.video) { - bootInfo.v_display = info->v_display; - } else { - bootInfo.v_display = GRAPHICS_MODE; - } + if (info) { + info->v_offset = 0; + info->v_length = 0; + info->v_display = GRAPHICS_MODE; } - else - bInfo = 0; switch ( op ) { case kPEDisableScreen: - initialize_screen((void *) bInfo, op); + initialize_screen(info, op); kprintf("kPEDisableScreen %d\n", last_console); if (!console_is_serial()) last_console = switch_to_serial_console(); break; case kPEEnableScreen: - initialize_screen((void *) bInfo, op); + initialize_screen(info, op); + if (info) PE_state.video = *info; kprintf("kPEEnableScreen %d\n", last_console); if( last_console != -1) switch_to_old_console( last_console); break; + case kPEBaseAddressChange: + if (info) PE_state.video = *info; + /* fall thru */ + default: - initialize_screen((void *) bInfo, op); + initialize_screen(info, op); break; } @@ -115,17 +105,16 @@ void PE_init_iokit(void) { enum { kMaxBootVar = 128 }; - typedef struct { - char name[32]; - unsigned long length; - unsigned long value[2]; - } DriversPackageProp; - boolean_t bootClutInitialized = FALSE; - boolean_t norootInitialized = FALSE; + boolean_t noroot_rle_Initialized = FALSE; + DTEntry entry; - int size; - void ** map; + unsigned int size; + uint32_t *map; + boot_progress_element *bootPict; + + norootIcon_lzss = NULL; + norootClut_lzss = NULL; PE_init_kprintf(TRUE); PE_init_printf(TRUE); @@ -135,49 +124,59 @@ void PE_init_iokit(void) /* * Fetch the CLUT and the noroot image. */ - boot_progress_element * bootPict; - if( kSuccess == DTLookupEntry(0, "/chosen/memory-map", &entry)) { - if( kSuccess == DTGetProperty(entry, "BootCLUT", (void **) &map, &size)) { - bcopy( map[0], appleClut8, sizeof(appleClut8) ); - bootClutInitialized = TRUE; + if( kSuccess == DTLookupEntry(NULL, "/chosen/memory-map", &entry)) { + if( kSuccess == DTGetProperty(entry, "BootCLUT", (void **) &map, &size)) { + if (sizeof(appleClut8) <= map[1]) { + bcopy( (void *)ml_static_ptovirt(map[0]), appleClut8, sizeof(appleClut8) ); + bootClutInitialized = TRUE; + } } - if( kSuccess == DTGetProperty(entry, "Pict-FailedBoot", (void **) &map, &size)) { - bootPict = (boot_progress_element *) map[0]; - default_noroot.width = bootPict->width; - default_noroot.height = bootPict->height; - default_noroot.dx = 0; - default_noroot.dy = bootPict->yOffset; - default_noroot_data = &bootPict->data[0]; - norootInitialized = TRUE; - } + if( kSuccess == DTGetProperty(entry, "Pict-FailedBoot", (void **) &map, &size)) { + bootPict = (boot_progress_element *) ml_static_ptovirt(map[0]); + default_noroot.width = bootPict->width; + default_noroot.height = bootPict->height; + default_noroot.dx = 0; + default_noroot.dy = bootPict->yOffset; + default_noroot_data = &bootPict->data[0]; + noroot_rle_Initialized = TRUE; + } + + if( kSuccess == DTGetProperty(entry, "FailedCLUT", (void **) &map, &size)) { + norootClut_lzss = (uint8_t*) ml_static_ptovirt(map[0]); + } + + if( kSuccess == DTGetProperty(entry, "FailedImage", (void **) &map, &size)) { + norootIcon_lzss = (boot_icon_element *) ml_static_ptovirt(map[0]); + if (norootClut_lzss == NULL) { + printf("ERROR: No FailedCLUT provided for noroot icon!\n"); + } + } } if (!bootClutInitialized) { - bcopy( (void *) (uintptr_t) bootClut, (void *) appleClut8, sizeof(appleClut8) ); + bcopy( (void *) (uintptr_t) bootClut, (void *) appleClut8, sizeof(appleClut8) ); } - if (!norootInitialized) { - default_noroot.width = kFailedBootWidth; - default_noroot.height = kFailedBootHeight; - default_noroot.dx = 0; - default_noroot.dy = kFailedBootOffset; - default_noroot_data = failedBootPict; + if (!noroot_rle_Initialized) { + default_noroot.width = kFailedBootWidth; + default_noroot.height = kFailedBootHeight; + default_noroot.dx = 0; + default_noroot.dy = kFailedBootOffset; + default_noroot_data = failedBootPict; } - /* - * Initialize the panic UI - */ - panic_ui_initialize( (unsigned char *) appleClut8 ); - /* * Initialize the spinning wheel (progress indicator). */ - vc_progress_initialize( &default_progress, default_progress_data, - (unsigned char *) appleClut8 ); + vc_progress_initialize(&default_progress, + default_progress_data1x, + default_progress_data2x, + default_progress_data3x, + (unsigned char *) appleClut8); - (void) StartIOKit( PE_state.deviceTreeHead, PE_state.bootArgs, gPEEFIRuntimeServices, 0); + StartIOKit( PE_state.deviceTreeHead, PE_state.bootArgs, gPEEFIRuntimeServices, NULL); } void PE_init_platform(boolean_t vm_initialized, void * _args) @@ -189,33 +188,47 @@ void PE_init_platform(boolean_t vm_initialized, void * _args) // New EFI-style PE_state.bootArgs = _args; - PE_state.deviceTreeHead = args->deviceTreeP; - PE_state.video.v_baseAddr = args->Video.v_baseAddr; - PE_state.video.v_rowBytes = args->Video.v_rowBytes; - PE_state.video.v_width = args->Video.v_width; - PE_state.video.v_height = args->Video.v_height; - PE_state.video.v_depth = args->Video.v_depth; - PE_state.video.v_display = args->Video.v_display; - strcpy( PE_state.video.v_pixelFormat, "PPPPPPPP"); + PE_state.deviceTreeHead = (void *) ml_static_ptovirt(args->deviceTreeP); + if (args->Video.v_baseAddr) { + PE_state.video.v_baseAddr = args->Video.v_baseAddr; // remains physical address + PE_state.video.v_rowBytes = args->Video.v_rowBytes; + PE_state.video.v_width = args->Video.v_width; + PE_state.video.v_height = args->Video.v_height; + PE_state.video.v_depth = args->Video.v_depth; + PE_state.video.v_display = args->Video.v_display; + strlcpy(PE_state.video.v_pixelFormat, "PPPPPPPP", + sizeof(PE_state.video.v_pixelFormat)); + } else { + PE_state.video.v_baseAddr = args->VideoV1.v_baseAddr; // remains physical address + PE_state.video.v_rowBytes = args->VideoV1.v_rowBytes; + PE_state.video.v_width = args->VideoV1.v_width; + PE_state.video.v_height = args->VideoV1.v_height; + PE_state.video.v_depth = args->VideoV1.v_depth; + PE_state.video.v_display = args->VideoV1.v_display; + strlcpy(PE_state.video.v_pixelFormat, "PPPPPPPP", + sizeof(PE_state.video.v_pixelFormat)); + } + +#ifdef kBootArgsFlagHiDPI + if (args->flags & kBootArgsFlagHiDPI) + PE_state.video.v_scale = kPEScaleFactor2x; + else + PE_state.video.v_scale = kPEScaleFactor1x; +#else + PE_state.video.v_scale = kPEScaleFactor1x; +#endif } if (!vm_initialized) { - /* Hack! FIXME.. */ - outb(0x21, 0xff); /* Maskout all interrupts Pic1 */ - outb(0xa1, 0xff); /* Maskout all interrupts Pic2 */ - + if (PE_state.deviceTreeHead) { DTInit(PE_state.deviceTreeHead); - } + } pe_identify_machine(args); - } else { - DTEntry entry; - void *ptr; - uint32_t size; - pe_init_debug(); } + } void PE_create_console( void ) @@ -235,11 +248,26 @@ int PE_current_console( PE_Video * info ) void PE_display_icon( __unused unsigned int flags, __unused const char * name ) { - if ( default_noroot_data ) + if ( norootIcon_lzss && norootClut_lzss ) { + uint32_t width = norootIcon_lzss->width; + uint32_t height = norootIcon_lzss->height; + uint32_t x = ((PE_state.video.v_width - width) / 2); + uint32_t y = ((PE_state.video.v_height - height) / 2) + norootIcon_lzss->y_offset_from_center; + + vc_display_lzss_icon(x, y, width, height, + &norootIcon_lzss->data[0], + norootIcon_lzss->data_size, + norootClut_lzss); + } + else if ( default_noroot_data ) { vc_display_icon( &default_noroot, default_noroot_data ); + } else { + printf("ERROR: No data found for noroot icon!\n"); + } } -extern boolean_t PE_get_hotkey( __unused unsigned char key ) +boolean_t +PE_get_hotkey(__unused unsigned char key) { return (FALSE); } @@ -296,5 +324,108 @@ PE_stub_poll_input(__unused unsigned int options, char * c) int (*PE_poll_input)(unsigned int options, char * c) = PE_stub_poll_input; +boolean_t +PE_reboot_on_panic(void) +{ + boot_args *args = (boot_args *)PE_state.bootArgs; + + if (args->flags & kBootArgsFlagRebootOnPanic) + return TRUE; + else + return FALSE; +} + +void +PE_sync_panic_buffers(void) +{ +} + +/* rdar://problem/21244753 */ +uint32_t +PE_i_can_has_debugger(uint32_t *debug_flags) +{ +#if DEVELOPMENT || DEBUG + if (debug_flags) { + assert(debug_boot_arg_inited); + } +#endif + +#if CONFIG_CSR + if (csr_check(CSR_ALLOW_KERNEL_DEBUGGER) != 0) { + if (debug_flags) + *debug_flags = 0; + return FALSE; + } +#endif + if (debug_flags) { + *debug_flags = debug_boot_arg; + } + return TRUE; +} + +uint32_t +PE_get_offset_into_panic_region(char *location) +{ + assert(panic_info != NULL); + assert(location > (char *) panic_info); + + return (uint32_t) (location - (char *) panic_info); +} +void +PE_init_panicheader() +{ + bzero(panic_info, offsetof(struct macos_panic_header, mph_data)); + panic_info->mph_panic_log_offset = PE_get_offset_into_panic_region(debug_buf_base); + + panic_info->mph_magic = MACOS_PANIC_MAGIC; + panic_info->mph_version = MACOS_PANIC_HEADER_CURRENT_VERSION; + return; +} + +/* + * Tries to update the panic header to keep it consistent on nested panics. + * + * NOTE: The purpose of this function is NOT to detect/correct corruption in the panic region, + * it is to update the panic header to make it consistent when we nest panics. + * + * We try to avoid nested panics/asserts on x86 because they are difficult to debug, so log any + * inconsistencies we find. + */ +void +PE_update_panicheader_nestedpanic() +{ + /* If the panic log offset is not set, re-init the panic header */ + if (panic_info->mph_panic_log_offset == 0) { + PE_init_panicheader(); + panic_info->mph_panic_flags |= MACOS_PANIC_HEADER_FLAG_NESTED_PANIC; + return; + } + + panic_info->mph_panic_flags |= MACOS_PANIC_HEADER_FLAG_NESTED_PANIC; + + /* Usually indicative of corruption in the panic region */ + if(!(((panic_info->mph_stackshot_offset == 0) && (panic_info->mph_stackshot_len == 0)) || + ((panic_info->mph_stackshot_offset != 0) && (panic_info->mph_stackshot_len != 0)))) { + kdb_printf("panic_info contains invalid stackshot metadata: mph_stackshot_offset 0x%x mph_stackshot_len 0x%x\n", + panic_info->mph_stackshot_offset, panic_info->mph_stackshot_len); + } + + /* + * macOS panic logs contain nested panic data, if we've already closed the panic log, + * begin the other log. + */ + if ((panic_info->mph_panic_log_len != 0) && (panic_info->mph_other_log_offset == 0)) { + panic_info->mph_other_log_offset = PE_get_offset_into_panic_region(debug_buf_ptr); + + /* Usually indicative of corruption in the panic region */ + if (panic_info->mph_other_log_len != 0) { + kdb_printf("panic_info contains invalid other log metadata (zero offset but non-zero length), length was 0x%x, zeroing value\n", + panic_info->mph_other_log_len); + panic_info->mph_other_log_len = 0; + } + } + + return; +}