diff options
author | Peng Fan <van.freenix@gmail.com> | 2013-09-05 09:58:35 +0800 |
---|---|---|
committer | Peng Fan <van.freenix@gmail.com> | 2013-09-05 13:47:39 +0800 |
commit | 43044399b0507b4357edeae9350751276c3b9ceb (patch) | |
tree | 4d70faaf0bf4c5cde1e7239666891abd2c491837 | |
parent | 07d14d4e3239188e4f0ee407d7ae3e49fc71741b (diff) |
Bfin support
Signed-off-by: Peng Fan <van.freenix@gmail.com>
-rw-r--r-- | libbsd/include/arch/bfin/machine/ansi.h | 0 | ||||
-rw-r--r-- | libbsd/include/arch/bfin/machine/asm.h | 1 | ||||
-rw-r--r-- | libbsd/include/arch/bfin/machine/cdefs.h | 0 | ||||
-rw-r--r-- | libbsd/include/arch/bfin/machine/elf_machdep.h | 28 | ||||
-rw-r--r-- | libbsd/include/arch/bfin/machine/int_types.h | 0 | ||||
-rw-r--r-- | rtl-mdreloc-bfin.c | 115 | ||||
-rw-r--r-- | shell-init | 2 | ||||
-rw-r--r-- | testcase/1.c | 16 | ||||
-rw-r--r-- | testcase/Readme | 10 | ||||
-rw-r--r-- | testcase/wscript | 12 | ||||
-rw-r--r-- | wscript | 2 |
11 files changed, 185 insertions, 1 deletions
diff --git a/libbsd/include/arch/bfin/machine/ansi.h b/libbsd/include/arch/bfin/machine/ansi.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/libbsd/include/arch/bfin/machine/ansi.h diff --git a/libbsd/include/arch/bfin/machine/asm.h b/libbsd/include/arch/bfin/machine/asm.h new file mode 100644 index 0000000..68ab8da --- /dev/null +++ b/libbsd/include/arch/bfin/machine/asm.h @@ -0,0 +1 @@ +#define __CONCAT(x,y) x ## y diff --git a/libbsd/include/arch/bfin/machine/cdefs.h b/libbsd/include/arch/bfin/machine/cdefs.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/libbsd/include/arch/bfin/machine/cdefs.h diff --git a/libbsd/include/arch/bfin/machine/elf_machdep.h b/libbsd/include/arch/bfin/machine/elf_machdep.h new file mode 100644 index 0000000..cf0dc19 --- /dev/null +++ b/libbsd/include/arch/bfin/machine/elf_machdep.h @@ -0,0 +1,28 @@ +#define ELF32_MACHDEP_ENDIANNESS ELFDATA2LSB + +#define ELF32_MACHDEP_ID_CASES \ + case EM_BLACKFIN: \ + break; + +#define ELF32_MACHDEP_ID EM_BLACKFIN + +#define ARCH_ELFSIZE 32 + +#define R_BFIN_UNUSED0 0 + +#define R_BFIN_RIMM16 5 +#define R_BFIN_LUIMM16 6 +#define R_BFIN_HUIMM16 7 +#define R_BFIN_PCREL12_JUMP_S 8 +#define R_BFIN_PCREL24_JUMP_X 9 +#define R_BFIN_PCREL24 10 +#define R_BFIN_PCREL24_JU 13 +#define R_BFIN_PCREL24_CALL_X 14 + +#define R_BFIN_BYTE_DATA 16 +#define R_BFIN_BYTE2_DATA 17 +#define R_BFIN_BYTE4_DATA 18 + + + +#define R_TYPE(name) __CONCAT(R_BFIN_,name) diff --git a/libbsd/include/arch/bfin/machine/int_types.h b/libbsd/include/arch/bfin/machine/int_types.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/libbsd/include/arch/bfin/machine/int_types.h diff --git a/rtl-mdreloc-bfin.c b/rtl-mdreloc-bfin.c new file mode 100644 index 0000000..419f6a0 --- /dev/null +++ b/rtl-mdreloc-bfin.c @@ -0,0 +1,115 @@ +#include <sys/cdefs.h> + +#include <stdio.h> +#include <rtl.h> +#include <errno.h> +#include "rtl-elf.h" +#include "rtl-error.h" +#include <rtl-trace.h> + +bool +rtems_rtl_elf_rel_resolve_sym (Elf_Word type) +{ + return true; +} + +static inline Elf_Addr +load_ptr(void *where) +{ + Elf_Addr res; + + memcpy(&res, where, sizeof(res)); + + return (res); +} + +bool +rtems_rtl_elf_relocate_rela (const rtems_rtl_obj_t* obj, + const Elf_Rela* rela, + const rtems_rtl_obj_sect_t* sect, + const char* symname, + const Elf_Byte syminfo, + const Elf_Word symvalue) +{ + Elf_Addr target = 0; + Elf_Addr *where; + Elf_Word tmp; + Elf_Word size; //byte + + where = (Elf_Addr *)(sect->base + rela->r_offset); + + if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) { + printf("rela relocation type is %d relocated address 0x%08x", + ELF_R_TYPE(rela->r_info), where); + } + + tmp = symvalue; + switch (ELF_R_TYPE(rela->r_info)) { + case R_TYPE(UNUSED0): + break; + + case R_TYPE(HUIMM16): + tmp = symvalue >> 16; + case R_TYPE(LUIMM16): + case R_TYPE(RIMM16): + size = 2; + break; + + case R_TYPE(BYTE4_DATA): + size = 4; + break; + + case R_TYPE(PCREL24): + case R_TYPE(PCREL24_JU): + where = (Elf_Addr*)((Elf_Addr)where - 2); /* Back 2 bytes */ + tmp = symvalue - (Elf_Addr)where; + tmp >>= 1; + if ((tmp & 0x20000000) == 0x20000000) + tmp |= 0xc0000000; + + if ((tmp & 0xff000000) && (~tmp & 0xff800000)) { + printf("PCREL24/PCREL24_JU Overflow\n"); + return false; + } + + tmp = (load_ptr(where) & 0x0000ff00) | ((tmp & 0x0000ffff) << 16) | + ((tmp & 0x00ff0000) >> 16); + size = 4; + break; + + case R_TYPE(PCREL12_JUMP_S): + tmp = symvalue - (Elf_Addr)where; + tmp >>= 1; + if ((tmp & 0x20000000) == 0x20000000) + tmp |= 0xc0000000; + + if ((tmp & 0xfffff000) && (~tmp & 0xfffff800)) { + printf("PCREL12_JUMP_S Overflow\n"); + return false; + } + + tmp = ((*(uint16_t *)where) & 0xf000) | (tmp & 0xfff); + size = 2; + break; + + default: + printf("Unspported rela type\n"); + return false; + } + + memcpy((void*)where, &tmp, size); + + return true; +} + +bool +rtems_rtl_elf_relocate_rel (const rtems_rtl_obj_t* obj, + const Elf_Rel* rel, + const rtems_rtl_obj_sect_t* sect, + const char* symname, + const Elf_Byte syminfo, + const Elf_Word symvalue) +{ + rtems_rtl_set_error (EINVAL, "rel type record not supported"); + return false; +} @@ -11,3 +11,5 @@ rap ld ./bsdport.rap rap ls + +rap ld ./test.rap diff --git a/testcase/1.c b/testcase/1.c index 91cae0f..14f6da2 100644 --- a/testcase/1.c +++ b/testcase/1.c @@ -1,6 +1,16 @@ int global; static char local; +#if defined (__bfin__) +void bfin_test(void) +{ + printf("PCREL12_JUMP_S: JUMP.S _bfin_test\n"); + printf("Do not have a good idea about how to" + "return from here, thus just halt here\n"); + while(1); +} +#endif + void hello(int arg) { switch (arg) { @@ -226,6 +236,12 @@ int rtems(int argc, char **argv) "nop\n\t": : : ); +#elif defined (__bfin__) + __asm__ volatile ( + "JUMP.S _bfin_test\n\t" + "1:\n\t" + "nop\n\t" + ); #else /* other archs */ #endif diff --git a/testcase/Readme b/testcase/Readme index 81a7559..ee71b3e 100644 --- a/testcase/Readme +++ b/testcase/Readme @@ -17,3 +17,13 @@ powerpc: Configuration: waf configure --rtems=/opt/rtems-4.11 --rtems-tools=/opt/rtems-4.11 --rtems-archs=powerpc --rtems-bsps=powerpc/psim "-fno-common" are add to cflags to avoid common section problem. + +bfin: + Because the simulator does not respond to the input keys, use the automatic shell-init to load test.rap + Also you should modify the + rtems_linkflags = ['--base', 'rtld.prelink', + '--entry', '_my_main'], + "-mlong-calls" can generate fewer reloc types. One can use this option to see what it affects. + Simulator: + bf537Stamp-gdb build/bfin-rtems4.11-bf537Stamp/rtld + Note: if use gdb to run rtl, add 'rap ld './test.rap'' into shell-init diff --git a/testcase/wscript b/testcase/wscript index 2064bb6..130b441 100644 --- a/testcase/wscript +++ b/testcase/wscript @@ -62,6 +62,18 @@ def build(bld): source = ['1.c', '2.c']) + elif arch == 'bfin': +# cflags = '-fno-common -mlong-calls' + bld(target = 'test.rap', + features = 'c rap', + xxxx = 'hello', + + cflags = '-fno-common', + + rtems_linkflags = ['--base', 'rtld.prelink', + '--entry', '_my_main'], + source = ['1.c', '2.c']) + bld(target = '../test.rap', source = ['test.rap'], rule = 'cp ${SRC} ${TGT}') @@ -66,7 +66,7 @@ def build(bld): # # The ARM as special BSP initialise code. # - if arch == 'arm' or arch == 'powerpc' or arch == 'mips': + if arch == 'arm' or arch == 'powerpc' or arch == 'mips' or arch == 'bfin': bld(target = 'bspinit', features = 'c', includes = bld.includes, |