summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLogan Chien <loganchien@google.com>2011-11-22 14:47:23 +0800
committerLogan Chien <loganchien@google.com>2011-11-22 14:57:01 +0800
commit81b38f9fb6d6274166df3f6c564a9553ecfb1972 (patch)
tree360f6261e4708b2723bea0e3ae006fcfae220ab4
parentdb8ee06e529a5d3034c6f3e7f2324d918d9834a1 (diff)
downloadlinkloader-81b38f9fb6d6274166df3f6c564a9553ecfb1972.tar.gz
Add mips routine for far stubs.
Change-Id: Ia78369067aa89369dabdbaeb844cfc0a08c18714
-rw-r--r--lib/StubLayout.cpp26
1 files changed, 21 insertions, 5 deletions
diff --git a/lib/StubLayout.cpp b/lib/StubLayout.cpp
index 929ee5b..733e665 100644
--- a/lib/StubLayout.cpp
+++ b/lib/StubLayout.cpp
@@ -23,8 +23,10 @@
#include <stdlib.h>
#include <sys/mman.h>
-#ifdef __arm__
-#define STUB_SIZE 8 // 8 bytes (2 words)
+#if defined(__arm__)
+#define STUB_SIZE 8
+#elif defined(__mips__)
+#define STUB_SIZE 16
#endif
StubLayout::StubLayout() : table(NULL), count(0) {
@@ -36,7 +38,7 @@ void StubLayout::initStubTable(unsigned char *table_, size_t count_) {
}
void *StubLayout::allocateStub(void *addr) {
-#ifdef __arm__
+#if defined(__arm__) || defined(__mips__)
// Check if we have created this stub or not.
std::map<void *, void *>::iterator index_iter = stub_index.find(addr);
@@ -67,7 +69,7 @@ void *StubLayout::allocateStub(void *addr) {
}
void StubLayout::setStubAddress(void *stub_, void *addr) {
-#ifdef __arm__
+#if defined(__arm__)
uint8_t *stub = (uint8_t *)stub_;
stub[0] = 0x04; // ldr pc, [pc, #-4]
stub[1] = 0xf0; // ldr pc, [pc, #-4]
@@ -76,11 +78,25 @@ void StubLayout::setStubAddress(void *stub_, void *addr) {
void **target = (void **)(stub + 4);
*target = addr;
+
+#elif defined(__mips__)
+ uint32_t addr32 = (uint32_t)(uintptr_t)addr;
+ uint16_t addr_hi16 = (addr32 >> 16) & 0xffff;
+ uint16_t addr_lo16 = addr32 & 0xffff;
+
+ uint32_t *stub = (uint32_t *)stub_;
+ stub[0] = 0x3c190000ul | addr_hi16; // lui
+ stub[1] = 0x37390000ul | addr_lo16; // ori
+ stub[2] = 0x03200008ul; // jr (jump register)
+ stub[3] = 0x00000000ul; // nop
+
+#else
+ rsl_assert(0 && "Stub is not supported on this platform");
#endif
}
size_t StubLayout::calcStubTableSize(size_t count) const {
-#ifdef __arm__
+#if defined(__arm__) || defined(__mips__)
return count * STUB_SIZE;
#else
return 0;