From 0c4eed48fd7b9983ecf4a94c49cecb59de6c5556 Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Mon, 22 Jul 2013 10:18:47 +0800 Subject: Moxie Support Signed-off-by: Peng Fan --- libbsd/include/arch/moxie/machine/ansi.h | 0 libbsd/include/arch/moxie/machine/asm.h | 2 + libbsd/include/arch/moxie/machine/cdefs.h | 0 libbsd/include/arch/moxie/machine/elf_machdep.h | 15 +++++ libbsd/include/arch/moxie/machine/int_types.h | 0 libbsd/include/sys/exec_elf.h | 2 + rtems.py | 2 + rtl-mdreloc-moxie.c | 88 +++++++++++++++++++++++++ testcase/1.c | 13 ++++ testcase/wscript | 2 +- wscript | 2 +- 11 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 libbsd/include/arch/moxie/machine/ansi.h create mode 100644 libbsd/include/arch/moxie/machine/asm.h create mode 100644 libbsd/include/arch/moxie/machine/cdefs.h create mode 100644 libbsd/include/arch/moxie/machine/elf_machdep.h create mode 100644 libbsd/include/arch/moxie/machine/int_types.h create mode 100644 rtl-mdreloc-moxie.c diff --git a/libbsd/include/arch/moxie/machine/ansi.h b/libbsd/include/arch/moxie/machine/ansi.h new file mode 100644 index 0000000..e69de29 diff --git a/libbsd/include/arch/moxie/machine/asm.h b/libbsd/include/arch/moxie/machine/asm.h new file mode 100644 index 0000000..b3a7a95 --- /dev/null +++ b/libbsd/include/arch/moxie/machine/asm.h @@ -0,0 +1,2 @@ + +#define __CONCAT(x,y) x ## y diff --git a/libbsd/include/arch/moxie/machine/cdefs.h b/libbsd/include/arch/moxie/machine/cdefs.h new file mode 100644 index 0000000..e69de29 diff --git a/libbsd/include/arch/moxie/machine/elf_machdep.h b/libbsd/include/arch/moxie/machine/elf_machdep.h new file mode 100644 index 0000000..3f0df23 --- /dev/null +++ b/libbsd/include/arch/moxie/machine/elf_machdep.h @@ -0,0 +1,15 @@ +#define ELF32_MACHDEP_ENDIANNESS ELFDATA2MSB + +#define ELF32_MACHDEP_ID_CASES \ + case EM_MOXIE: \ + break; + +#define ELF32_MACHDEP_ID EM_MOXIE + +#define ARCH_ELFSIZE 32 + +#define R_MOXIE_NONE 0 +#define R_MOXIE_32 1 +#define R_MOXIE_PCREL10 2 + +#define R_TYPE(name) __CONCAT(R_MOXIE_,name) diff --git a/libbsd/include/arch/moxie/machine/int_types.h b/libbsd/include/arch/moxie/machine/int_types.h new file mode 100644 index 0000000..e69de29 diff --git a/libbsd/include/sys/exec_elf.h b/libbsd/include/sys/exec_elf.h index 19ca7f5..08da7e8 100644 --- a/libbsd/include/sys/exec_elf.h +++ b/libbsd/include/sys/exec_elf.h @@ -330,6 +330,8 @@ typedef struct { #define EM_MICROBLAZE 189 /* Xilinx MicroBlaze 32-bit RISC soft processor core */ +#define EM_MOXIE 0xFEED + /* Unofficial machine types follow */ #define EM_AVR32 6317 /* used by NetBSD/avr32 */ #define EM_ALPHA_EXP 36902 /* used by NetBSD/alpha; obsolete */ diff --git a/rtems.py b/rtems.py index 2b6fd81..1fb0b2a 100644 --- a/rtems.py +++ b/rtems.py @@ -174,6 +174,8 @@ def tweaks(conf, arch_bsp): conf.env.OBJCOPY_FLAGS = ['-I', 'binary', '-O', 'elf32-littlearm'] elif conf.env.RTEMS_ARCH in ['mips']: conf.env.OBJCOPY_FLAGS = ['-I', 'binary', '-O', 'elf32-bigmips'] + elif conf.env.RTEMS_ARCH in ['moxie']: + conf.env.OBJCOPY_FLAGS = ['-I', 'binary', '-O', 'elf32-bigmoxie'] else: conf.env.OBJCOPY_FLAGS = ['-O', 'elf32-' + conf.env.RTEMS_ARCH] diff --git a/rtl-mdreloc-moxie.c b/rtl-mdreloc-moxie.c new file mode 100644 index 0000000..c036d4a --- /dev/null +++ b/rtl-mdreloc-moxie.c @@ -0,0 +1,88 @@ + +#include + +#include +#include +#include +#include + +#include +#include "rtl-elf.h" +#include "rtl-error.h" +#include + +bool +rtems_rtl_elf_rel_resolve_sym (Elf_Word type) +{ + return true; +} + +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 *where; + Elf_Sword tmp; + + where = (Elf_Addr *)(sect->base + rela->r_offset); + + /* Handle the not 4byte aligned address carefully */ + + switch (ELF_R_TYPE(rela->r_info)) { + case R_TYPE(NONE): + break; + + case R_TYPE(32): + *(uint16_t *)where = ((symvalue + rela->r_addend) >> 16) & 0xffff; + *((uint16_t *)where + 1) = (symvalue + rela->r_addend) & 0xffff; + + if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) { + printf("*where 0x%04x%04x\n", *((uint16_t *)where + 1), *(uint16_t *)where); + } + break; + + case R_TYPE(PCREL10): + /* beq, bge, bgeu, bgt, bgtu, ble, bleu, blt, bltu, bne */ + if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) { + printf("*where %x\n", *(uint16_t *)where); + printf("symvalue - where %x\n", (int)(symvalue - (Elf_Word)where)); + } + tmp = (symvalue + rela->r_addend - ((Elf_Word)where + 2)); /* pc is the next instruction */ + tmp = (Elf_Sword)tmp >> 1; + if (((Elf32_Sword)tmp > 0x1ff) || ((Elf32_Sword)tmp < -(Elf32_Sword)0x200)){ + printf("Overflow for PCREL10: %d exceed -0x200:0x1ff\n", tmp); + return false; + } + + *(uint16_t *)where = (*(uint16_t *)where & 0xfc00) | (tmp & 0x3ff); + + if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) { + printf("*where 0x%04x\n", *(uint16_t *)where); + } + + break; + + default: + rtems_rtl_set_error (EINVAL, "rela type record not supported"); + printf("Unsupported reloc types\n"); + return false; + } + + 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; +} diff --git a/testcase/1.c b/testcase/1.c index a643d77..18e643b 100644 --- a/testcase/1.c +++ b/testcase/1.c @@ -37,6 +37,11 @@ void hello(int arg) case 13: printf("SPARC 13 'mov hello, %%l4'\n"); break; +#elif defined (__moxie__) + case 10: + printf("Just test 'beq hello, PCREL10', so just halt here\n"); + while(1); + break; #else #endif @@ -264,6 +269,14 @@ int rtems(int argc, char **argv) if (global == 22) printf("R_LM32_32 pass\n"); + +#elif defined (__moxie__) + __asm__ volatile ( + "ldi.l $r0, 10\n\t" + "ldi.l $r1, 10\n\t" + "cmp $r0, $r1\n\t" + "beq hello\n\t"); + #else /* other archs */ #endif diff --git a/testcase/wscript b/testcase/wscript index 0a42011..8698fd7 100644 --- a/testcase/wscript +++ b/testcase/wscript @@ -85,7 +85,7 @@ def build(bld): '--entry', '_my_main'], source = ['1.c', '2.c']) - elif arch == 'lm32': + elif arch == 'lm32' or arch == 'moxie': bld(target = 'test.rap', features = 'c rap', xxxx = 'hello', diff --git a/wscript b/wscript index a2876f9..a86d7ce 100644 --- a/wscript +++ b/wscript @@ -66,7 +66,7 @@ def build(bld): # # The ARM as special BSP initialise code. # - if arch == 'arm' or arch == 'powerpc' or arch == 'mips' or arch == 'bfin' or arch == 'h8300' or arch == 'lm32': + if arch == 'arm' or arch == 'powerpc' or arch == 'mips' or arch == 'bfin' or arch == 'h8300' or arch == 'lm32' or arch == 'moxie': bld(target = 'bspinit', features = 'c', includes = bld.includes, -- cgit v1.2.3