1 /*---------------------------------------------------------------------------* 2 Project: TwlSDK - ELF Loader 3 File: loader_subset.h 4 5 Copyright 2006-2008 Nintendo. All rights reserved. 6 7 These coded instructions, statements, and computer programs contain 8 proprietary information of Nintendo of America Inc. and/or Nintendo 9 Company Ltd., and are protected by Federal copyright law. They may 10 not be disclosed to third parties or copied or duplicated in any form, 11 in whole or in part, without the prior written consent of Nintendo. 12 13 $Date:: 2008-09-17#$ 14 $Rev: 8556 $ 15 $Author: okubata_ryoma $ 16 *---------------------------------------------------------------------------*/ 17 18 #ifndef _LOADER_SUBSET_H_ 19 #define _LOADER_SUBSET_H_ 20 21 #include "types.h" 22 #include "elf.h" 23 #include "elf_loader.h" 24 25 26 /*------------------------------------------------------ 27 Copies the contents of a symbol string to a buffer 28 -----------------------------------------------------*/ 29 void* ELi_CopySymStrToBuffer( ELHandle* ElfHandle, ELShdrEx* SymStrShdrEx); 30 31 32 /*------------------------------------------------------ 33 Copies the contents of a section string to a buffer 34 -----------------------------------------------------*/ 35 void* ELi_CopyShStrToBuffer( ELHandle* ElfHandle, Elf32_Shdr* Shdr); 36 37 38 /*------------------------------------------------------ 39 Copies symbol entries together into a buffer 40 -----------------------------------------------------*/ 41 void* ELi_CopySymToBuffer( ELHandle* ElfHandle); 42 43 44 /*------------------------------------------------------ 45 Copies a section into a buffer 46 -----------------------------------------------------*/ 47 void* ELi_CopySectionToBuffer( ELHandle* ElfHandle, Elf32_Shdr* Shdr); 48 49 50 /*------------------------------------------------------ 51 Allocates a section in a buffer (without copying) 52 -----------------------------------------------------*/ 53 void* ELi_AllocSectionToBuffer( ELHandle* ElfHandle, Elf32_Shdr* Shdr); 54 55 56 /*------------------------------------------------------ 57 Gets the section header at the specified index and puts it in a buffer 58 -----------------------------------------------------*/ 59 void ELi_GetShdr( ELHandle* ElfHandle, u32 index, Elf32_Shdr* Shdr); 60 61 62 /*------------------------------------------------------ 63 Gets the section entry at the specified index and puts it in a buffer 64 -----------------------------------------------------*/ 65 void ELi_GetSent( ELHandle* ElfHandle, u32 index, void* entry_buf, u32 offset, u32 size); 66 67 68 /*------------------------------------------------------ 69 Gets the entry at the specified index of a given section header and puts it in a buffer 70 (only for sections with a fixed entry size) 71 -----------------------------------------------------*/ 72 void ELi_GetEntry( ELHandle* ElfHandle, Elf32_Shdr* Shdr, u32 index, void* entry_buf); 73 74 75 /*------------------------------------------------------ 76 Gets the string at the specified index of the STR section header 77 -----------------------------------------------------*/ 78 void ELi_GetStrAdr( ELHandle* ElfHandle, u32 strsh_index, u32 ent_index, char* str, u32 len); 79 80 /*------------------------------------------------------ 81 Gets the length of the string at the specified index of the STR section header 82 -----------------------------------------------------*/ 83 u32 ELi_GetStrLen( ELHandle* ElfHandle, u32 index, u32 offset); 84 85 86 /*------------------------------------------------------ 87 Creates a symbol list 88 89 -----------------------------------------------------*/ 90 void ELi_BuildSymList( ELHandle* elElfDesc, u32 symsh_index, u32** sym_table); 91 92 93 /*------------------------------------------------------ 94 Releases a symbol list 95 96 -----------------------------------------------------*/ 97 void ELi_FreeSymList( ELHandle* elElfDesc, u32** sym_table); 98 99 100 /*------------------------------------------------------ 101 Redefines a symbol 102 -----------------------------------------------------*/ 103 void ELi_RelocateSym( ELHandle* ElfHandle, u32 relsh_index); 104 105 106 /*------------------------------------------------------ 107 Function unique to makelst 108 Registers global items from the symbol section to the address table 109 110 -----------------------------------------------------*/ 111 void ELi_DiscriminateGlobalSym( ELHandle* ElfHandle, u32 symsh_index); 112 113 114 /*------------------------------------------------------ 115 Resolves a symbol based on unresolved information 116 -----------------------------------------------------*/ 117 u32 ELi_DoRelocate( ELUnresolvedEntry* UnresolvedInfo); 118 119 120 /*------------------------------------------------------ 121 Extracts an ELSymEx object from the specified index in the list 122 -----------------------------------------------------*/ 123 ELSymEx* ELi_GetSymExfromList( ELSymEx* SymExStart, u32 index); 124 125 126 /*------------------------------------------------------ 127 Extracts an ELShdrEx object from the specified index in the list 128 -----------------------------------------------------*/ 129 ELShdrEx* ELi_GetShdrExfromList( ELShdrEx* ShdrExStart, u32 index); 130 131 132 /*------------------------------------------------------ 133 Determines whether the section at the specified index is debugging information 134 -----------------------------------------------------*/ 135 BOOL ELi_ShdrIsDebug( ELHandle* ElfHandle, u32 index); 136 137 138 /*------------------------------------------------------ 139 Inspects the SymEx table in ElfHandle and determines if the code at the specified offset from the specified index is ARM or Thumb 140 141 -----------------------------------------------------*/ 142 u32 ELi_CodeIsThumb( ELHandle* ElfHandle, u16 sh_index, u32 offset); 143 144 145 /*--------------------------------------------------------- 146 Initializes an unresolved data entry 147 --------------------------------------------------------*/ 148 void ELi_UnresolvedInfoInit( ELUnresolvedEntry* UnresolvedInfo); 149 150 151 /*------------------------------------------------------ 152 Removes an entry from the unresolved data table 153 -----------------------------------------------------*/ 154 BOOL ELi_RemoveUnresolvedEntry( ELUnresolvedEntry* UnrEnt); 155 156 157 /*--------------------------------------------------------- 158 Adds an entry to the unresolved data table 159 --------------------------------------------------------*/ 160 void ELi_AddUnresolvedEntry( ELUnresolvedEntry* UnrEnt); 161 162 163 /*------------------------------------------------------ 164 Finds the entry corresponding to the specified string from the unresolved data table 165 -----------------------------------------------------*/ 166 ELUnresolvedEntry* ELi_GetUnresolvedEntry( char* ent_name); 167 168 169 #endif /*_LOADER_SUBSET_H_*/ 170