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-12-10#$ 14 $Rev: 9620 $ 15 $Author: shirait $ 16 *---------------------------------------------------------------------------*/ 17 18 #ifndef _LOADER_SUBSET_H_ 19 #define _LOADER_SUBSET_H_ 20 21 #include "elf.h" 22 #include "elf_loader.h" 23 24 25 /*------------------------------------------------------ 26 Copies a veneer into a buffer 27 start: Address to jump from 28 data: Address to jump to 29 -----------------------------------------------------*/ 30 void* ELi_CopyVeneerToBuffer( ELDesc* elElfDesc, ELObject* MYObject, u32 start, u32 data, s32 threshold); 31 32 33 /*------------------------------------------------------ 34 Copies a veneer into a buffer 35 start: Caller 36 data: Jump target 37 threshold : If there is already a veneer within this range, reuse it 38 -----------------------------------------------------*/ 39 void* ELi_CopyV4tVeneerToBuffer( ELDesc* elElfDesc, ELObject* MYObject, u32 start, u32 data, s32 threshold); 40 41 42 /*------------------------------------------------------ 43 Copies a segment into a buffer 44 -----------------------------------------------------*/ 45 void* ELi_CopySegmentToBuffer( ELDesc* elElfDesc, ELObject* MYObject, Elf32_Phdr* Phdr); 46 47 48 /*------------------------------------------------------ 49 Copies a section into a buffer 50 -----------------------------------------------------*/ 51 void* ELi_CopySectionToBuffer( ELDesc* elElfDesc, ELObject* MYObject, Elf32_Shdr* Shdr); 52 53 54 /*------------------------------------------------------ 55 Allocates a section in a buffer (without copying) 56 -----------------------------------------------------*/ 57 void* ELi_AllocSectionToBuffer( ELDesc* elElfDesc, ELObject* MYObject, Elf32_Shdr* Shdr); 58 59 60 /*------------------------------------------------------ 61 Gets the program header at the specified index and puts it in a buffer 62 -----------------------------------------------------*/ 63 void ELi_GetPhdr( ELDesc* elElfDesc, u32 index, Elf32_Phdr* Phdr); 64 65 66 /*------------------------------------------------------ 67 Gets the section header at the specified index and puts it in a buffer 68 -----------------------------------------------------*/ 69 void ELi_GetShdr( ELDesc* elElfDesc, u32 index, Elf32_Shdr* Shdr); 70 71 72 /*------------------------------------------------------ 73 Gets the section entry at the specified index and puts it in a buffer 74 -----------------------------------------------------*/ 75 void ELi_GetSent( ELDesc* elElfDesc, u32 index, void* entry_buf, u32 offset, u32 size); 76 77 78 /*------------------------------------------------------ 79 Gets the entry at the specified index of a given section header and puts it in a buffer 80 (only for sections with a fixed entry size) 81 -----------------------------------------------------*/ 82 void ELi_GetEntry( ELDesc* elElfDesc, Elf32_Shdr* Shdr, u32 index, void* entry_buf); 83 84 85 /*------------------------------------------------------ 86 Gets the string at the specified index of the STR section header 87 -----------------------------------------------------*/ 88 void ELi_GetStrAdr( ELDesc* elElfDesc, u32 strsh_index, u32 ent_index, char* str, u32 len); 89 90 91 /*------------------------------------------------------ 92 Redefines a symbol 93 -----------------------------------------------------*/ 94 BOOL ELi_RelocateSym( ELDesc* elElfDesc, ELObject* MYObject, u32 relsh_index); 95 96 /*------------------------------------------------------ 97 Puts a global symbol into the address table 98 -----------------------------------------------------*/ 99 BOOL ELi_GoPublicGlobalSym( ELDesc* elElfDesc, ELObject* MYObject, u32 symtblsh_index); 100 101 /*------------------------------------------------------ 102 Releases the symbol lists created in ELi_RelocateSym and ELi_GoPublicGlobalSym 103 (After calling either one, invoke this function) 104 -----------------------------------------------------*/ 105 void ELi_FreeSymList( ELDesc* elElfDesc); 106 107 /*------------------------------------------------------ 108 Resolves a symbol based on unresolved information 109 -----------------------------------------------------*/ 110 BOOL ELi_DoRelocate( ELDesc* elElfDesc, ELObject* MYObject, ELImportEntry* UnresolvedInfo); 111 112 113 /*------------------------------------------------------ 114 Extracts an ELSymEx object from the specified index in the list 115 -----------------------------------------------------*/ 116 //ELSymEx* ELi_GetSymExfromList( ELSymEx* SymExStart, u32 index); 117 118 119 /*------------------------------------------------------ 120 Extracts an ELShdrEx object from the specified index in the list 121 -----------------------------------------------------*/ 122 ELShdrEx* ELi_GetShdrExfromList( ELShdrEx* ShdrExStart, u32 index); 123 124 125 /*------------------------------------------------------ 126 Determines whether the section at the specified index is debugging information 127 -----------------------------------------------------*/ 128 BOOL ELi_ShdrIsDebug( ELDesc* elElfDesc, u32 index); 129 130 131 /*------------------------------------------------------ 132 Inspects the SymEx table in elElfDesc and determines if the code at the specified offset from the specified index is ARM or THUMB 133 134 -----------------------------------------------------*/ 135 u32 ELi_CodeIsThumb( ELDesc* elElfDesc, u16 sh_index, u32 offset); 136 137 138 /*--------------------------------------------------------- 139 Initializes an import information entry 140 --------------------------------------------------------*/ 141 static void ELi_InitImport( ELImportEntry* ImportInfo); 142 143 144 /*------------------------------------------------------ 145 Extracts an entry from the import information table (Do not delete ImpEnt!) 146 -----------------------------------------------------*/ 147 BOOL ELi_ExtractImportEntry( ELImportEntry** StartEnt, ELImportEntry* ImpEnt); 148 149 150 /*--------------------------------------------------------- 151 Adds an entry to the import information table 152 --------------------------------------------------------*/ 153 void ELi_AddImportEntry( ELImportEntry** ELUnrEntStart, ELImportEntry* UnrEnt); 154 155 156 /*------------------------------------------------------ 157 Releases the entire import information table 158 -----------------------------------------------------*/ 159 void ELi_FreeImportTbl( ELImportEntry** ELImpEntStart); 160 161 162 /*------------------------------------------------------ 163 Releases the veneer table 164 -----------------------------------------------------*/ 165 void* ELi_FreeVenTbl( ELDesc* elElfDesc, ELObject* MYObject); 166 167 168 169 #endif /*_LOADER_SUBSET_H_*/ 170