23 extern void writeStr(
const char *str);
24 int StringCopyN(
char *dest,
const char *src,
int len)
34 int ByteSet(
void *buf,
int c,
size_t len)
36 unsigned char *tmp =
reinterpret_cast<unsigned char *
>(buf);
44 void MemoryCopy(
void *dest,
const void *src,
size_t len)
46 const unsigned char *sp =
reinterpret_cast<const unsigned char *
>(src);
47 unsigned char *dp =
reinterpret_cast<unsigned char *
>(dest);
48 for (; len != 0; len--)
52 int StringCompare(
const char *p1,
const char *p2)
56 while (p1[i] !=
'\0' && p2[i] !=
'\0')
66 if ((p1[i] ==
'\0' && p2[i] !=
'\0') || (p1[i] !=
'\0' && p2[i] ==
'\0'))
73 : m_pHeader(0), m_pSymbolTable(0), m_pStringTable(0), m_pShstrtab(0),
74 m_pGotTable(0), m_pRelTable(0), m_pSectionHeaders(0), m_pBuffer(0)
76 StringCopyN(m_pId, name, 127);
83 bool Elf32::load(uint8_t *pBuffer,
unsigned int nBufferLength)
86 m_pHeader =
reinterpret_cast<Elf32Header_t *
>(pBuffer);
89 if ((m_pHeader->ident[1] !=
'E') || (m_pHeader->ident[2] !=
'L') ||
90 (m_pHeader->ident[3] !=
'F') || (m_pHeader->ident[0] != 127))
98 reinterpret_cast<Elf32SectionHeader_t *
>(&pBuffer[m_pHeader->shoff]);
101 m_pStringTable = &m_pSectionHeaders[m_pHeader->shstrndx];
104 const char *pStrtab =
105 reinterpret_cast<const char *
>(&pBuffer[m_pStringTable->offset]);
108 for (
int i = 0; i < m_pHeader->shnum; i++)
110 const char *pStr = pStrtab + m_pSectionHeaders[i].name;
111 if (!StringCompare(pStr,
".symtab"))
113 m_pSymbolTable = &m_pSectionHeaders[i];
115 if (!StringCompare(pStr,
".strtab"))
116 m_pStringTable = &m_pSectionHeaders[i];
168 unsigned int physAddress = 0x1000000;
169 for (
int i = 0; i < m_pHeader->shnum; i++)
171 if (m_pSectionHeaders[i].flags & SHF_ALLOC)
173 if (m_pSectionHeaders[i].type != SHT_NOBITS)
176 physAddress, m_pSectionHeaders[i].addr,
177 m_pSectionHeaders[i].size + 0x1000);
178 physAddress += m_pSectionHeaders[i].size + 0x1000;
181 reinterpret_cast<uint8_t *>(m_pSectionHeaders[i].addr),
183 m_pSectionHeaders[i].size);
188 physAddress, m_pSectionHeaders[i].addr,
189 m_pSectionHeaders[i].size + 0x1000);
190 physAddress += m_pSectionHeaders[i].size + 0x1000;
192 reinterpret_cast<uint8_t *>(m_pSectionHeaders[i].addr), 0,
193 m_pSectionHeaders[i].size);
195 for (
unsigned int j = m_pSectionHeaders[i].addr;
196 j < m_pSectionHeaders[i].addr + m_pSectionHeaders[i].size;
199 asm volatile(
"dcbst 0, %0" ::
"r"(j));
202 asm volatile(
"sync");
203 for (
unsigned int j = m_pSectionHeaders[i].addr;
204 j < m_pSectionHeaders[i].addr + m_pSectionHeaders[i].size;
207 asm volatile(
"icbi 0, %0" ::
"r"(j));
209 asm volatile(
"sync;isync;");
222 if (!m_pSymbolTable || !m_pStringTable)
225 Elf32Symbol_t *pSymbol =
226 reinterpret_cast<Elf32Symbol_t *
>(&
m_pBuffer[m_pSymbolTable->offset]);
227 const char *pStrtab =
228 reinterpret_cast<const char *
>(&
m_pBuffer[m_pStringTable->offset]);
230 for (
size_t i = 0; i < m_pSymbolTable->size /
sizeof(Elf32Symbol_t); i++)
233 if (ELF32_ST_TYPE(pSymbol->info) != 0x2 &&
234 ELF32_ST_TYPE(pSymbol->info) != 0x0 )
242 uint32_t size = pSymbol->size;
245 if ((addr >= pSymbol->value) && (addr < (pSymbol->value + size)))
247 const char *pStr = pStrtab + pSymbol->name;
249 *startAddr = pSymbol->value;
274 return m_pHeader->entry;
unsigned int getLastAddress()
uint32_t getGlobalOffsetTable()
const char * lookupSymbol(unsigned int addr, unsigned int *startAddr=0)
char * lookupDynamicSymbolName(uint32_t off)
uint32_t lookupDynamicSymbolAddress(uint32_t off)
uint8_t * m_pBuffer
Offset of the file in memory.
bool load(uint8_t *pBuffer, unsigned int nBufferLength)