Skip to content

Instantly share code, notes, and snippets.

@MrVan
Created April 23, 2013 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrVan/5440197 to your computer and use it in GitHub Desktop.
Save MrVan/5440197 to your computer and use it in GitHub Desktop.
1. modify relocation code 2. modify global symbol adding code. 3. There is something wrong when using rtems arm gcc on s3c6410, so I did this on 4.10
From e2f8e650c0a70374daea61c118268b2c91bdda94 Mon Sep 17 00:00:00 2001
From: Peng Fan <van.freenix@gmail.com>
Date: Tue, 23 Apr 2013 09:41:41 +0800
Subject: [PATCH] ARM
---
.gitignore | 4 +++
libbsd/include/arch/arm/machine/elf_machdep.h | 5 +++
main.c | 3 ++
rtems.py | 4 ++-
rtl-mdreloc-arm.c | 37 ++++++++++++++++++++
rtl-sym.c | 40 ++++++++++++++++++++--
shell-init | 4 +--
wscript | 11 +++---
x-long-name-to-create-gnu-extension-in-archive.c | 6 ++++
xa.c | 11 ++++++
10 files changed, 115 insertions(+), 10 deletions(-)
mode change 100644 => 100755 wscript
diff --git a/.gitignore b/.gitignore
index 60089a0..56e23ab 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,7 @@
.lock-waf*
build
*.pyc
+*.sh
+./tags
+cscope.*
+./debug-rld
diff --git a/libbsd/include/arch/arm/machine/elf_machdep.h b/libbsd/include/arch/arm/machine/elf_machdep.h
index 963ff64..7d9442a 100644
--- a/libbsd/include/arch/arm/machine/elf_machdep.h
+++ b/libbsd/include/arch/arm/machine/elf_machdep.h
@@ -69,6 +69,11 @@
#define R_ARM_GOT32 26
#define R_ARM_PLT32 27
+#define R_ARM_CALL 28
+#define R_ARM_JUMP24 29
+
+#define R_ARM_BASE_ABS 31
+
#define R_ARM_ALU_PCREL_7_0 32
#define R_ARM_ALU_PCREL_15_8 33
#define R_ARM_ALU_PCREL_23_15 34
diff --git a/main.c b/main.c
index a8f8640..d0397ce 100644
--- a/main.c
+++ b/main.c
@@ -375,6 +375,9 @@ main (int argc, char* argv[])
{
struct termios term;
int ret;
+ printf("%s\n", __func__);
+ //__asm__ __volatile__ ("ldr r3, [r1], #4");
+ printf("%s\n", __func__);
#if pc586
int arg;
diff --git a/rtems.py b/rtems.py
index 5558f84..e8b1c25 100644
--- a/rtems.py
+++ b/rtems.py
@@ -9,7 +9,9 @@ import pkgconfig
import re
import subprocess
-default_version = '4.11'
+#freenix
+default_version = '4.10'
+#default_version = '4.11'
default_label = 'rtems-' + default_version
default_path = '/opt/' + default_label
default_postfix = 'rtems' + default_version
diff --git a/rtl-mdreloc-arm.c b/rtl-mdreloc-arm.c
index e55da1f..f31d1ef 100644
--- a/rtl-mdreloc-arm.c
+++ b/rtl-mdreloc-arm.c
@@ -71,11 +71,47 @@ rtems_rtl_elf_relocate_rel (const rtems_rtl_obj_t* obj,
where = (Elf_Addr *)(sect->base + rel->r_offset);
+ int i;
+
switch (ELF_R_TYPE(rel->r_info)) {
case R_TYPE(NONE):
break;
#if 1 /* XXX should not occur */
+
+ case R_TYPE(CALL):{
+ /* word32 ((S+A)|T-P)*/
+ /* fall through */
+ }
+
+ case R_TYPE(PC24): {
+ /* word32 ((S+A)|T-P)*/
+ /* fall through */
+ }
+
+ case R_TYPE(JUMP24): {
+ Elf32_Sword addend;
+
+ /*
+ * Extract addend and sign-extend if needed.
+ */
+ addend = *where;
+ if (addend & 0x00800000)
+ addend |= 0xff000000; //sign extended
+
+ tmp = symvalue + (addend << 2) - (Elf_Addr)where;
+
+
+ tmp >>= 2;
+ *where = (*where & 0xff000000) | (tmp & 0x00ffffff);
+ if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
+ printf ("rtl: JUMP24/PC24/CALL %p @ %p in %s",
+ (void *)*where, where, rtems_rtl_obj_oname (obj));
+ break;
+
+ }
+
+#if 0
case R_TYPE(PC24): { /* word32 S - P + A */
Elf32_Sword addend;
@@ -106,6 +142,7 @@ rtems_rtl_elf_relocate_rel (const rtems_rtl_obj_t* obj,
break;
}
#endif
+#endif
case R_TYPE(ABS32): /* word32 B + S + A */
case R_TYPE(GLOB_DAT): /* word32 B + S */
diff --git a/rtl-sym.c b/rtl-sym.c
index 0e29693..2724c49 100644
--- a/rtl-sym.c
+++ b/rtl-sym.c
@@ -86,6 +86,7 @@ rtems_rtl_symbol_global_add (rtems_rtl_obj_t* obj,
const unsigned char* esyms,
unsigned int size)
{
+ printf("%s size %d\n", __func__, size);
rtems_rtl_symbols_t* symbols;
rtems_rtl_obj_sym_t* sym;
size_t count;
@@ -94,21 +95,42 @@ rtems_rtl_symbol_global_add (rtems_rtl_obj_t* obj,
count = 0;
s = 0;
+ int i = 0;
+#if 0
+ for(i = 0; i< 1024; i++) {
+ if (i%32==0)
+ printf("\n");
+ printf("%02x ", *(esyms+i));
+ }
+ printf("\n");
+#endif
while ((s < size) && (esyms[s] != 0))
{
int l = strlen ((char*) &esyms[s]);
+#if 0
+ printf("%d s %d length %d | ", count,s,l);
+ for (i=0; i< l; i++)
+ {
+ printf("%02x ", *(esyms+s+i));
+ }
+#endif
+ //printf("count %d s %d %s\n",count,s, esyms+s);
+
if ((esyms[s + l] != '\0') || ((s + l) > size))
{
rtems_rtl_set_error (EINVAL, "invalid exported symbol table");
return false;
}
++count;
- s += l + sizeof (unsigned long) + 1;
+ //s += l + sizeof (unsigned long) + 1;
+ s += ((l+1+3)&(~3)) + sizeof (unsigned long);
}
/*
* Check this is the correct end of the table.
*/
+ s=(s+4); //align for arm
+#if 0
marker = esyms[s + 1];
marker <<= 8;
marker |= esyms[s + 2];
@@ -116,6 +138,16 @@ rtems_rtl_symbol_global_add (rtems_rtl_obj_t* obj,
marker |= esyms[s + 3];
marker <<= 8;
marker |= esyms[s + 4];
+#endif
+#if 1
+ marker = esyms[s + 0];
+ marker <<= 8;
+ marker |= esyms[s + 1];
+ marker <<= 8;
+ marker |= esyms[s + 2];
+ marker <<= 8;
+ marker |= esyms[s + 3];
+#endif
if (marker != 0xdeadbeefUL)
{
@@ -155,7 +187,8 @@ rtems_rtl_symbol_global_add (rtems_rtl_obj_t* obj,
int b;
sym->name = (const char*) &esyms[s];
- s += strlen (sym->name) + 1;
+ //s += strlen (sym->name) + 1;
+ s += ((strlen(sym->name)+1+3)&(~3));
for (b = 0; b < sizeof (void*); ++b, ++s)
copy_voidp.data[b] = esyms[s];
sym->value = copy_voidp.value;
@@ -208,9 +241,10 @@ rtems_rtl_symbol_obj_find (rtems_rtl_obj_t* obj, const char* name)
* Check the object file's symbols first. If not found search the
* global symbol table.
*/
- for (s = 0, sym = obj->global_table; s < obj->global_syms; ++s, ++sym)
+ for (s = 0, sym = obj->global_table; s < obj->global_syms; ++s, ++sym){
if (strcmp (name, sym->name) == 0)
return sym;
+ }
return rtems_rtl_symbol_global_find (name);
}
diff --git a/shell-init b/shell-init
index fcc9784..d0c9dbd 100644
--- a/shell-init
+++ b/shell-init
@@ -9,5 +9,5 @@
#dlo c/bsdport.rap
#dlo bsdport.rap
-rap ld ./bsdport.rap
-rap ls
+#rap ld ./x.rap
+#rap ls
diff --git a/wscript b/wscript
old mode 100644
new mode 100755
index 9f9417a..cc9162b
--- a/wscript
+++ b/wscript
@@ -52,7 +52,8 @@ def build(bld):
bld.defines = ['PACKAGE_VERSION="' + version + '"',
'RTEMS_RTL_ELF_LOADER=1',
'RTEMS_RTL_RAP_LOADER=1']
- bld.cflags = ['-g', '-O']
+ #bld.cflags = ['-g', '-O', '-DRTEMS_RTL_TRACE=1']
+ bld.cflags = ['-g', '-DRTEMS_RTL_TRACE=1']
if re.match('pc[3456]86', bsp) is not None:
bld.defines += ['RTEMS_APP_IDEDISK=1']
@@ -141,11 +142,12 @@ def build(bld):
# finally the second link occurs with the global symbol table to create the
# executable to install.
#
- # Create the root file system for the prelink.
+ # Create the root file system for the prelink format=gnu fanpeng.
+ # rule = 'tar cf - ${SRC} > ${TGT} --format=gnu')
#
bld(target = 'fs-root.tar',
source = ['shell-init', 'libx.a'],
- rule = 'tar cf - ${SRC} > ${TGT}')
+ rule = 'tar --format=ustar -cf ${TGT} ${SRC}')
bld.objects(name = 'rootfs.prelink',
target = 'fs-root-tarfile.o',
source = 'fs-root.tar',
@@ -186,10 +188,11 @@ def build(bld):
else:
raps = []
+ # rule = 'tar cf - ${SRC} > ${TGT}')
bld(target = 'fs-root.tar',
name = 'fs',
source = ['shell-init', 'libx.a', 'x.rap'] + raps,
- rule = 'tar cf - ${SRC} > ${TGT}')
+ rule = 'tar --format=ustar -cf ${TGT} ${SRC} ')
bld.objects(name = 'rootfs',
target = 'fs-root-tarfile.o',
source = 'fs-root.tar',
diff --git a/x-long-name-to-create-gnu-extension-in-archive.c b/x-long-name-to-create-gnu-extension-in-archive.c
index 4c53d72..c0e764d 100644
--- a/x-long-name-to-create-gnu-extension-in-archive.c
+++ b/x-long-name-to-create-gnu-extension-in-archive.c
@@ -42,6 +42,12 @@ z_writeln(int argc, const char* argv[])
return 123;
}
+void
+test_led(void)
+{
+ led_on();
+}
+
int
my_main (int argc, char* argv[])
{
diff --git a/xa.c b/xa.c
index 20c927b..f6e7f81 100644
--- a/xa.c
+++ b/xa.c
@@ -9,3 +9,14 @@ hello (void)
{
x_writeln ("hello world");
}
+
+int rtems(int argc, char **argv)
+{
+ test_led();
+#if 0
+ *(volatile unsigned int *)0x7F008800 = 0x11110000;
+ *(volatile unsigned int *)0x7F008808 = ~(0xf<<4);
+#endif
+ return 0;
+}
+
--
1.7.10.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment