summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLogan Chien <loganchien@google.com>2011-11-22 14:03:06 +0800
committerLogan Chien <loganchien@google.com>2011-11-22 14:05:12 +0800
commitdb8ee06e529a5d3034c6f3e7f2324d918d9834a1 (patch)
treebb45cfead7a739bf83d78f4396d1f5b31cdf053f
parent422ed20c5b1e4d69cf2efd1e16a979ca42512509 (diff)
downloadlinkloader-db8ee06e529a5d3034c6f3e7f2324d918d9834a1.tar.gz
Add the stub related test cases.
Change-Id: I9f32ea4b0e26216cfc45a69f6a59f5bd247ab6e9
-rw-r--r--tests/stubs/arm-stub.c27
-rw-r--r--tests/stubs/mips-stub.c48
-rw-r--r--tests/stubs/stub-layout-test.cpp (renamed from tests/stub-test.cpp)0
3 files changed, 75 insertions, 0 deletions
diff --git a/tests/stubs/arm-stub.c b/tests/stubs/arm-stub.c
new file mode 100644
index 0000000..2138f9a
--- /dev/null
+++ b/tests/stubs/arm-stub.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+
+// Note: The first instruction stands for ldr, which loads the data from
+// memory to the specified register. Notice that due to the pipeline design,
+// when ldr is executed, the program will be advanced by 8. So, to get our
+// address we should substract it by 4.
+
+uint32_t stub[] = {
+ 0xe51ff004ul, // ldr pc, [pc, #-4]
+ 0x00000000ul // address
+};
+
+int test() {
+ printf("hello world!\n");
+ return 5;
+}
+
+int main() {
+ int (*f)() = (int (*)())stub;
+ stub[1] = (uint32_t)(uintptr_t)test;
+
+ printf("return = %d\n", f());
+ return EXIT_SUCCESS;
+}
diff --git a/tests/stubs/mips-stub.c b/tests/stubs/mips-stub.c
new file mode 100644
index 0000000..ff34d03
--- /dev/null
+++ b/tests/stubs/mips-stub.c
@@ -0,0 +1,48 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+// --------------
+// Register Usage
+// --------------
+// $0 zero
+// $1 at
+// $2-$3 function return value registers
+// $4-$7 function argument registers
+// $8-$15 temporary
+// $16-$23 saved register
+// $24-$25 temporary
+// $26-$27 os kernel
+// $28 global pointer
+// $29 stack pointer
+// $30 saved register
+// $31 return addres reigster
+
+// --------------------
+// Instruction Encoding
+// --------------------
+// lui: 0011 1100 000t tttt iiii iiii iiii iiii
+// ori: 0011 01ss ssst tttt iiii iiii iiii iiii
+// jr: 0000 00ss sss0 0000 0000 0000 0000 1000
+// nop: 0000 0000 0000 0000 0000 0000 0000 0000
+
+uint32_t stub[] = {
+ 0x3c190000ul,
+ 0x37390000ul,
+ 0x03200008ul,
+ 0x00000000ul
+};
+
+int test() {
+ printf("hello world!\n");
+ return 5;
+}
+
+int main() {
+ int (*f)() = (int (*)())stub;
+ stub[0] |= (((uint32_t)(uintptr_t)test) >> 16) & 0xffff;
+ stub[1] |= (((uint32_t)(uintptr_t)test)) & 0xffff;
+
+ printf("return = %d\n", f());
+ return EXIT_SUCCESS;
+}
diff --git a/tests/stub-test.cpp b/tests/stubs/stub-layout-test.cpp
index ba07cd2..ba07cd2 100644
--- a/tests/stub-test.cpp
+++ b/tests/stubs/stub-layout-test.cpp