diff options
author | Michael Brown <mcb30@ipxe.org> | 2015-08-27 10:36:52 +0100 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2015-08-27 15:54:25 +0100 |
commit | c522c11c7b7adedf0bf339b954e30951f02d568f (patch) | |
tree | 64321865214f4fcb02113d93b4925724e9efad83 | |
parent | e08d7ccc95cf85563053f6cf1e6d4b979e32b7f1 (diff) | |
download | ipxe-c522c11c7b7adedf0bf339b954e30951f02d568f.zip ipxe-c522c11c7b7adedf0bf339b954e30951f02d568f.tar.gz ipxe-c522c11c7b7adedf0bf339b954e30951f02d568f.tar.bz2 |
[efi] Improve efi_wrap debugging
Add debug wrappers for more boot services functions, and print
symbolic values rather than raw numbers where possible.
Signed-off-by: Michael Brown <mcb30@ipxe.org>
-rw-r--r-- | src/include/ipxe/efi/efi.h | 4 | ||||
-rw-r--r-- | src/interface/efi/efi_debug.c | 23 | ||||
-rw-r--r-- | src/interface/efi/efi_wrap.c | 330 |
3 files changed, 344 insertions, 13 deletions
diff --git a/src/include/ipxe/efi/efi.h b/src/include/ipxe/efi/efi.h index f3f1d1a..ced8828 100644 --- a/src/include/ipxe/efi/efi.h +++ b/src/include/ipxe/efi/efi.h @@ -202,6 +202,10 @@ extern EFI_SYSTEM_TABLE *efi_systab; extern const __attribute__ (( pure )) char * efi_guid_ntoa ( EFI_GUID *guid ); extern const __attribute__ (( pure )) char * +efi_locate_search_type_name ( EFI_LOCATE_SEARCH_TYPE search_type ); +extern const __attribute__ (( pure )) char * +efi_open_attributes_name ( unsigned int attributes ); +extern const __attribute__ (( pure )) char * efi_devpath_text ( EFI_DEVICE_PATH_PROTOCOL *path ); extern const __attribute__ (( pure )) char * efi_handle_name ( EFI_HANDLE handle ); diff --git a/src/interface/efi/efi_debug.c b/src/interface/efi/efi_debug.c index ed88181..bcf45cf 100644 --- a/src/interface/efi/efi_debug.c +++ b/src/interface/efi/efi_debug.c @@ -190,6 +190,26 @@ const __attribute__ (( pure )) char * efi_guid_ntoa ( EFI_GUID *guid ) { } /** + * Name locate search type + * + * @v search_type Locate search type + * @ret name Locate search type name + */ +const __attribute__ (( pure )) char * +efi_locate_search_type_name ( EFI_LOCATE_SEARCH_TYPE search_type ) { + static char buf[16]; + + switch ( search_type ) { + case AllHandles : return "AllHandles"; + case ByRegisterNotify: return "ByRegisterNotify"; + case ByProtocol: return "ByProtocol"; + default: + snprintf ( buf, sizeof ( buf ), "UNKNOWN<%d>", search_type ); + return buf; + } +} + +/** * Name protocol open attributes * * @v attributes Protocol open attributes @@ -200,7 +220,8 @@ const __attribute__ (( pure )) char * efi_guid_ntoa ( EFI_GUID *guid ) { * (T)EST_PROTOCOL, BY_(C)HILD_CONTROLLER, BY_(D)RIVER, and * E(X)CLUSIVE. */ -static const char * efi_open_attributes_name ( unsigned int attributes ) { +const __attribute__ (( pure )) char * +efi_open_attributes_name ( unsigned int attributes ) { static char attribute_chars[] = "HGTCDX"; static char name[ sizeof ( attribute_chars ) ]; char *tmp = name; diff --git a/src/interface/efi/efi_wrap.c b/src/interface/efi/efi_wrap.c index e94e8d9..c0c40ee 100644 --- a/src/interface/efi/efi_wrap.c +++ b/src/interface/efi/efi_wrap.c @@ -101,6 +101,81 @@ static const char * efi_status ( EFI_STATUS efirc ) { } /** + * Convert EFI boolean to text + * + * @v boolean Boolean value + * @ret text Boolean value text + */ +static const char * efi_boolean ( BOOLEAN boolean ) { + + return ( boolean ? "TRUE" : "FALSE" ); +} + +/** + * Wrap InstallProtocolInterface() + * + */ +static EFI_STATUS EFIAPI +efi_install_protocol_interface_wrapper ( EFI_HANDLE *handle, EFI_GUID *protocol, + EFI_INTERFACE_TYPE interface_type, + VOID *interface ) { + EFI_BOOT_SERVICES *bs = efi_systab->BootServices; + void *retaddr = __builtin_return_address ( 0 ); + EFI_STATUS efirc; + + DBGC ( colour, "InstallProtocolInterface ( %s, %s, %d, %p ) ", + efi_handle_name ( *handle ), efi_guid_ntoa ( protocol ), + interface_type, interface ); + efirc = bs->InstallProtocolInterface ( handle, protocol, interface_type, + interface ); + DBGC ( colour, "= %s ( %s ) -> %p\n", + efi_status ( efirc ), efi_handle_name ( *handle ), retaddr ); + return efirc; +} + +/** + * Wrap ReinstallProtocolInterface() + * + */ +static EFI_STATUS EFIAPI +efi_reinstall_protocol_interface_wrapper ( EFI_HANDLE handle, + EFI_GUID *protocol, + VOID *old_interface, + VOID *new_interface ) { + EFI_BOOT_SERVICES *bs = efi_systab->BootServices; + void *retaddr = __builtin_return_address ( 0 ); + EFI_STATUS efirc; + + DBGC ( colour, "ReinstallProtocolInterface ( %s, %s, %p, %p ) ", + efi_handle_name ( handle ), efi_guid_ntoa ( protocol ), + old_interface, new_interface ); + efirc = bs->ReinstallProtocolInterface ( handle, protocol, + old_interface, new_interface ); + DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr ); + return efirc; +} + +/** + * Wrap UninstallProtocolInterface() + * + */ +static EFI_STATUS EFIAPI +efi_uninstall_protocol_interface_wrapper ( EFI_HANDLE handle, + EFI_GUID *protocol, + VOID *interface ) { + EFI_BOOT_SERVICES *bs = efi_systab->BootServices; + void *retaddr = __builtin_return_address ( 0 ); + EFI_STATUS efirc; + + DBGC ( colour, "UninstallProtocolInterface ( %s, %s, %p ) ", + efi_handle_name ( handle ), efi_guid_ntoa ( protocol ), + interface ); + efirc = bs->UninstallProtocolInterface ( handle, protocol, interface ); + DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr ); + return efirc; +} + +/** * Wrap HandleProtocol() * */ @@ -111,7 +186,7 @@ efi_handle_protocol_wrapper ( EFI_HANDLE handle, EFI_GUID *protocol, void *retaddr = __builtin_return_address ( 0 ); EFI_STATUS efirc; - DBGC ( colour, "HandleProtocol ( %s, %s, ... ) ", + DBGC ( colour, "HandleProtocol ( %s, %s ) ", efi_handle_name ( handle ), efi_guid_ntoa ( protocol ) ); efirc = bs->HandleProtocol ( handle, protocol, interface ); DBGC ( colour, "= %s ( %p ) -> %p\n", @@ -129,14 +204,26 @@ efi_locate_handle_wrapper ( EFI_LOCATE_SEARCH_TYPE search_type, UINTN *buffer_size, EFI_HANDLE *buffer ) { EFI_BOOT_SERVICES *bs = efi_systab->BootServices; void *retaddr = __builtin_return_address ( 0 ); + unsigned int i; EFI_STATUS efirc; - DBGC ( colour, "LocateHandle ( %d, %s, ..., %zd, ... ) ", search_type, - efi_guid_ntoa ( protocol ), ( ( size_t ) *buffer_size ) ); + DBGC ( colour, "LocateHandle ( %s, %s, %p, %zd ) ", + efi_locate_search_type_name ( search_type ), + efi_guid_ntoa ( protocol ), search_key, + ( ( size_t ) *buffer_size ) ); efirc = bs->LocateHandle ( search_type, protocol, search_key, buffer_size, buffer ); - DBGC ( colour, "= %s ( %zd ) -> %p\n", - efi_status ( efirc ), ( ( size_t ) *buffer_size ), retaddr ); + DBGC ( colour, "= %s ( %zd", efi_status ( efirc ), + ( ( size_t ) *buffer_size ) ); + if ( efirc == 0 ) { + DBGC ( colour, ", {" ); + for ( i = 0; i < ( *buffer_size / sizeof ( buffer[0] ) ); i++ ){ + DBGC ( colour, "%s%s", ( i ? ", " : " " ), + efi_handle_name ( buffer[i] ) ); + } + DBGC ( colour, " }" ); + } + DBGC ( colour, " ) -> %p\n", retaddr ); return efirc; } @@ -152,7 +239,7 @@ efi_locate_device_path_wrapper ( EFI_GUID *protocol, void *retaddr = __builtin_return_address ( 0 ); EFI_STATUS efirc; - DBGC ( colour, "LocateDevicePath ( %s, %s, ... ) ", + DBGC ( colour, "LocateDevicePath ( %s, %s ) ", efi_guid_ntoa ( protocol ), efi_devpath_text ( *device_path ) ); efirc = bs->LocateDevicePath ( protocol, device_path, device ); DBGC ( colour, "= %s ( %s, ", @@ -174,9 +261,9 @@ efi_load_image_wrapper ( BOOLEAN boot_policy, EFI_HANDLE parent_image_handle, void *retaddr = __builtin_return_address ( 0 ); EFI_STATUS efirc; - DBGC ( colour, "LoadImage ( %d, %s, ", boot_policy, + DBGC ( colour, "LoadImage ( %s, %s, ", efi_boolean ( boot_policy ), efi_handle_name ( parent_image_handle ) ); - DBGC ( colour, "%s, %p, %#llx, ... ) ", + DBGC ( colour, "%s, %p, %#llx ) ", efi_devpath_text ( device_path ), source_buffer, ( ( unsigned long long ) source_size ) ); efirc = bs->LoadImage ( boot_policy, parent_image_handle, device_path, @@ -194,6 +281,69 @@ efi_load_image_wrapper ( BOOLEAN boot_policy, EFI_HANDLE parent_image_handle, } /** + * Wrap StartImage() + * + */ +static EFI_STATUS EFIAPI +efi_start_image_wrapper ( EFI_HANDLE image_handle, UINTN *exit_data_size, + CHAR16 **exit_data ) { + EFI_BOOT_SERVICES *bs = efi_systab->BootServices; + void *retaddr = __builtin_return_address ( 0 ); + EFI_STATUS efirc; + + DBGC ( colour, "StartImage ( %s ) ", efi_handle_name ( image_handle ) ); + efirc = bs->StartImage ( image_handle, exit_data_size, exit_data ); + DBGC ( colour, "= %s", efi_status ( efirc ) ); + if ( ( efirc != 0 ) && exit_data && *exit_data_size ) + DBGC ( colour, " ( \"%ls\" )", *exit_data ); + DBGC ( colour, " -> %p\n", retaddr ); + if ( ( efirc != 0 ) && exit_data && *exit_data_size ) + DBGC_HD ( colour, *exit_data, *exit_data_size ); + return efirc; +} + +/** + * Wrap Exit() + * + */ +static EFI_STATUS EFIAPI +efi_exit_wrapper ( EFI_HANDLE image_handle, EFI_STATUS exit_status, + UINTN exit_data_size, CHAR16 *exit_data ) { + EFI_BOOT_SERVICES *bs = efi_systab->BootServices; + void *retaddr = __builtin_return_address ( 0 ); + EFI_STATUS efirc; + + if ( ( exit_status != 0 ) && exit_data && exit_data_size ) + DBGC_HD ( colour, exit_data, exit_data_size ); + DBGC ( colour, "Exit ( %s, %s", + efi_handle_name ( image_handle ), efi_status ( exit_status ) ); + if ( ( exit_status != 0 ) && exit_data && exit_data_size ) + DBGC ( colour, ", \"%ls\"", exit_data ); + DBGC ( colour, " ) " ); + efirc = bs->Exit ( image_handle, exit_status, exit_data_size, + exit_data ); + DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr ); + return efirc; +} + +/** + * Wrap UnloadImage() + * + */ +static EFI_STATUS EFIAPI +efi_unload_image_wrapper ( EFI_HANDLE image_handle ) { + EFI_BOOT_SERVICES *bs = efi_systab->BootServices; + void *retaddr = __builtin_return_address ( 0 ); + EFI_STATUS efirc; + + DBGC ( colour, "UnloadImage ( %s ) ", + efi_handle_name ( image_handle ) ); + efirc = bs->UnloadImage ( image_handle ); + DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr ); + return efirc; +} + +/** * Wrap ExitBootServices() * */ @@ -212,6 +362,60 @@ efi_exit_boot_services_wrapper ( EFI_HANDLE image_handle, UINTN map_key ) { } /** + * Wrap ConnectController() + * + */ +static EFI_STATUS EFIAPI +efi_connect_controller_wrapper ( EFI_HANDLE controller_handle, + EFI_HANDLE *driver_image_handle, + EFI_DEVICE_PATH_PROTOCOL *remaining_path, + BOOLEAN recursive ) { + EFI_BOOT_SERVICES *bs = efi_systab->BootServices; + void *retaddr = __builtin_return_address ( 0 ); + EFI_HANDLE *tmp; + EFI_STATUS efirc; + + DBGC ( colour, "ConnectController ( %s, {", + efi_handle_name ( controller_handle ) ); + if ( driver_image_handle ) { + for ( tmp = driver_image_handle ; *tmp ; tmp++ ) { + DBGC ( colour, "%s%s", + ( ( tmp == driver_image_handle ) ? " " : ", " ), + efi_handle_name ( *tmp ) ); + } + } + DBGC ( colour, " }, %s, %s ) ", efi_devpath_text ( remaining_path ), + efi_boolean ( recursive ) ); + efirc = bs->ConnectController ( controller_handle, driver_image_handle, + remaining_path, recursive ); + DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr ); + return efirc; +} + +/** + * Wrap DisconnectController() + * + */ +static EFI_STATUS EFIAPI +efi_disconnect_controller_wrapper ( EFI_HANDLE controller_handle, + EFI_HANDLE driver_image_handle, + EFI_HANDLE child_handle ) { + EFI_BOOT_SERVICES *bs = efi_systab->BootServices; + void *retaddr = __builtin_return_address ( 0 ); + EFI_STATUS efirc; + + DBGC ( colour, "DisconnectController ( %s", + efi_handle_name ( controller_handle ) ); + DBGC ( colour, ", %s", efi_handle_name ( driver_image_handle ) ); + DBGC ( colour, ", %s ) ", efi_handle_name ( child_handle ) ); + efirc = bs->DisconnectController ( controller_handle, + driver_image_handle, + child_handle ); + DBGC ( colour, "= %s -> %p\n", efi_status ( efirc ), retaddr ); + return efirc; +} + +/** * Wrap OpenProtocol() * */ @@ -223,11 +427,11 @@ efi_open_protocol_wrapper ( EFI_HANDLE handle, EFI_GUID *protocol, void *retaddr = __builtin_return_address ( 0 ); EFI_STATUS efirc; - DBGC ( colour, "OpenProtocol ( %s, %s, ..., ", + DBGC ( colour, "OpenProtocol ( %s, %s, ", efi_handle_name ( handle ), efi_guid_ntoa ( protocol ) ); DBGC ( colour, "%s, ", efi_handle_name ( agent_handle ) ); - DBGC ( colour, "%s, %#x ) ", - efi_handle_name ( controller_handle ), attributes ); + DBGC ( colour, "%s, %s ) ", efi_handle_name ( controller_handle ), + efi_open_attributes_name ( attributes ) ); efirc = bs->OpenProtocol ( handle, protocol, interface, agent_handle, controller_handle, attributes ); DBGC ( colour, "= %s ( %p ) -> %p\n", @@ -236,6 +440,90 @@ efi_open_protocol_wrapper ( EFI_HANDLE handle, EFI_GUID *protocol, } /** + * Wrap CloseProtocol() + * + */ +static EFI_STATUS EFIAPI +efi_close_protocol_wrapper ( EFI_HANDLE handle, EFI_GUID *protocol, + EFI_HANDLE agent_handle, + EFI_HANDLE controller_handle ) { + EFI_BOOT_SERVICES *bs = efi_systab->BootServices; + void *retaddr = __builtin_return_address ( 0 ); + EFI_STATUS efirc; + + DBGC ( colour, "CloseProtocol ( %s, %s, ", + efi_handle_name ( handle ), efi_guid_ntoa ( protocol ) ); + DBGC ( colour, "%s, ", efi_handle_name ( agent_handle ) ); + DBGC ( colour, "%s ) ", efi_handle_name ( controller_handle ) ); + efirc = bs->CloseProtocol ( handle, protocol, agent_handle, + controller_handle ); + DBGC ( colour, "= %s -> %p\n", + efi_status ( efirc ), retaddr ); + return efirc; +} + +/** + * Wrap ProtocolsPerHandle() + * + */ +static EFI_STATUS EFIAPI +efi_protocols_per_handle_wrapper ( EFI_HANDLE handle, + EFI_GUID ***protocol_buffer, + UINTN *protocol_buffer_count ) { + EFI_BOOT_SERVICES *bs = efi_systab->BootServices; + void *retaddr = __builtin_return_address ( 0 ); + unsigned int i; + EFI_STATUS efirc; + + DBGC ( colour, "ProtocolsPerHandle ( %s ) ", + efi_handle_name ( handle ) ); + efirc = bs->ProtocolsPerHandle ( handle, protocol_buffer, + protocol_buffer_count ); + DBGC ( colour, "= %s", efi_status ( efirc ) ); + if ( efirc == 0 ) { + DBGC ( colour, " ( {" ); + for ( i = 0 ; i < *protocol_buffer_count ; i++ ) { + DBGC ( colour, "%s%s", ( i ? ", " : " " ), + efi_guid_ntoa ( (*protocol_buffer)[i] ) ); + } + DBGC ( colour, " } )" ); + } + DBGC ( colour, " -> %p\n", retaddr ); + return efirc; +} + +/** + * Wrap LocateHandleBuffer() + * + */ +static EFI_STATUS EFIAPI +efi_locate_handle_buffer_wrapper ( EFI_LOCATE_SEARCH_TYPE search_type, + EFI_GUID *protocol, VOID *search_key, + UINTN *no_handles, EFI_HANDLE **buffer ) { + EFI_BOOT_SERVICES *bs = efi_systab->BootServices; + void *retaddr = __builtin_return_address ( 0 ); + unsigned int i; + EFI_STATUS efirc; + + DBGC ( colour, "LocateHandleBuffer ( %s, %s, %p ) ", + efi_locate_search_type_name ( search_type ), + efi_guid_ntoa ( protocol ), search_key ); + efirc = bs->LocateHandleBuffer ( search_type, protocol, search_key, + no_handles, buffer ); + DBGC ( colour, "= %s", efi_status ( efirc ) ); + if ( efirc == 0 ) { + DBGC ( colour, " ( %d, {", ( ( unsigned int ) *no_handles ) ); + for ( i = 0 ; i < *no_handles ; i++ ) { + DBGC ( colour, "%s%s", ( i ? ", " : " " ), + efi_handle_name ( (*buffer)[i] ) ); + } + DBGC ( colour, " } )" ); + } + DBGC ( colour, " -> %p\n", retaddr ); + return efirc; +} + +/** * Wrap LocateProtocol() * */ @@ -246,7 +534,7 @@ efi_locate_protocol_wrapper ( EFI_GUID *protocol, VOID *registration, void *retaddr = __builtin_return_address ( 0 ); EFI_STATUS efirc; - DBGC ( colour, "LocateProtocol ( %s, %p, ... ) ", + DBGC ( colour, "LocateProtocol ( %s, %p ) ", efi_guid_ntoa ( protocol ), registration ); efirc = bs->LocateProtocol ( protocol, registration, interface ); DBGC ( colour, "= %s ( %p ) -> %p\n", @@ -277,12 +565,30 @@ efi_locate_protocol_wrapper ( EFI_GUID *protocol, VOID *registration, sizeof ( efi_systab_wrapper ) ); memcpy ( &efi_bs_wrapper, bs, sizeof ( efi_bs_wrapper ) ); efi_systab_wrapper.BootServices = &efi_bs_wrapper; + efi_bs_wrapper.InstallProtocolInterface + = efi_install_protocol_interface_wrapper; + efi_bs_wrapper.ReinstallProtocolInterface + = efi_reinstall_protocol_interface_wrapper; + efi_bs_wrapper.UninstallProtocolInterface + = efi_uninstall_protocol_interface_wrapper; efi_bs_wrapper.HandleProtocol = efi_handle_protocol_wrapper; efi_bs_wrapper.LocateHandle = efi_locate_handle_wrapper; efi_bs_wrapper.LocateDevicePath = efi_locate_device_path_wrapper; efi_bs_wrapper.LoadImage = efi_load_image_wrapper; + efi_bs_wrapper.StartImage = efi_start_image_wrapper; + efi_bs_wrapper.Exit = efi_exit_wrapper; + efi_bs_wrapper.UnloadImage = efi_unload_image_wrapper; efi_bs_wrapper.ExitBootServices = efi_exit_boot_services_wrapper; + efi_bs_wrapper.ConnectController + = efi_connect_controller_wrapper; + efi_bs_wrapper.DisconnectController + = efi_disconnect_controller_wrapper; efi_bs_wrapper.OpenProtocol = efi_open_protocol_wrapper; + efi_bs_wrapper.CloseProtocol = efi_close_protocol_wrapper; + efi_bs_wrapper.ProtocolsPerHandle + = efi_protocols_per_handle_wrapper; + efi_bs_wrapper.LocateHandleBuffer + = efi_locate_handle_buffer_wrapper; efi_bs_wrapper.LocateProtocol = efi_locate_protocol_wrapper; /* Open loaded image protocol */ |