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-18#$
14   $Rev: 8573 $
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 a section into a buffer
28  -----------------------------------------------------*/
29 void* ELi_CopySectionToBuffer( ELHandle* ElfHandle, Elf32_Shdr* Shdr);
30 
31 
32 /*------------------------------------------------------
33   Allocates a section in a buffer (without copying)
34  -----------------------------------------------------*/
35 void* ELi_AllocSectionToBuffer( ELHandle* ElfHandle, Elf32_Shdr* Shdr);
36 
37 
38 /*------------------------------------------------------
39   Gets the section header at the specified index and puts it in a buffer
40  -----------------------------------------------------*/
41 void ELi_GetShdr( ELHandle* ElfHandle, u32 index, Elf32_Shdr* Shdr);
42 
43 
44 /*------------------------------------------------------
45   Gets the section entry at the specified index and puts it in a buffer
46  -----------------------------------------------------*/
47 void ELi_GetSent( ELHandle* ElfHandle, u32 index, void* entry_buf, u32 offset, u32 size);
48 
49 
50 /*------------------------------------------------------
51   Gets the entry at the specified index of a given section header and puts it in a buffer
52 	(only for sections with a fixed entry size)
53  -----------------------------------------------------*/
54 void ELi_GetEntry( ELHandle* ElfHandle, Elf32_Shdr* Shdr, u32 index, void* entry_buf);
55 
56 
57 /*------------------------------------------------------
58   Gets the string at the specified index of the STR section header
59  -----------------------------------------------------*/
60 void ELi_GetStrAdr( ELHandle* ElfHandle, u32 strsh_index, u32 ent_index, char* str, u32 len);
61 
62 
63 /*------------------------------------------------------
64   Redefines a symbol
65  -----------------------------------------------------*/
66 void ELi_RelocateSym( ELHandle* ElfHandle, u32 relsh_index);
67 
68 
69 /*------------------------------------------------------
70     Function unique to makelst
71     Registers global items from the symbol section to the address table
72 
73  -----------------------------------------------------*/
74 void ELi_DiscriminateGlobalSym( ELHandle* ElfHandle, u32 symsh_index);
75 
76 
77 /*------------------------------------------------------
78   Resolves a symbol based on unresolved information
79  -----------------------------------------------------*/
80 u32	ELi_DoRelocate( ELUnresolvedEntry* UnresolvedInfo);
81 
82 
83 /*------------------------------------------------------
84   Extracts an ELSymEx object from the specified index in the list
85  -----------------------------------------------------*/
86 ELSymEx* ELi_GetSymExfromList( ELSymEx* SymExStart, u32 index);
87 
88 
89 /*------------------------------------------------------
90   Extracts an ELShdrEx object from the specified index in the list
91  -----------------------------------------------------*/
92 ELShdrEx* ELi_GetShdrExfromList( ELShdrEx* ShdrExStart, u32 index);
93 
94 
95 /*------------------------------------------------------
96   Determines whether the section at the specified index is debugging information
97  -----------------------------------------------------*/
98 BOOL ELi_ShdrIsDebug( ELHandle* ElfHandle, u32 index);
99 
100 
101 /*------------------------------------------------------
102   Inspects the SymEx table in ElfHandle and determines if the code at the specified offset from the specified index is ARM or Thumb
103 
104  -----------------------------------------------------*/
105 u32 ELi_CodeIsThumb( ELHandle* ElfHandle, u16 sh_index, u32 offset);
106 
107 
108 /*---------------------------------------------------------
109  Initializes an unresolved data entry
110  --------------------------------------------------------*/
111 void ELi_UnresolvedInfoInit( ELUnresolvedEntry* UnresolvedInfo);
112 
113 
114 /*------------------------------------------------------
115   Removes an entry from the unresolved data table
116  -----------------------------------------------------*/
117 BOOL ELi_RemoveUnresolvedEntry( ELUnresolvedEntry* UnrEnt);
118 
119 
120 /*---------------------------------------------------------
121  Adds an entry to the unresolved data table
122  --------------------------------------------------------*/
123 void ELi_AddUnresolvedEntry( ELUnresolvedEntry* UnrEnt);
124 
125 
126 /*------------------------------------------------------
127   Finds the entry corresponding to the specified string from the unresolved data table
128  -----------------------------------------------------*/
129 ELUnresolvedEntry* ELi_GetUnresolvedEntry( char* ent_name);
130 
131 
132 #endif	/*_LOADER_SUBSET_H_*/
133