summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeng Fan <van.freenix@gmail.com>2013-07-22 10:18:47 +0800
committerPeng Fan <van.freenix@gmail.com>2013-09-05 13:47:39 +0800
commit0c4eed48fd7b9983ecf4a94c49cecb59de6c5556 (patch)
tree486bb1e920879a2d041f79845e3c1d3b55d1e0f0
parent400bce45a8532b2377c5692da80666196ce09c64 (diff)
Moxie Support
Signed-off-by: Peng Fan <van.freenix@gmail.com>
-rw-r--r--libbsd/include/arch/moxie/machine/ansi.h0
-rw-r--r--libbsd/include/arch/moxie/machine/asm.h2
-rw-r--r--libbsd/include/arch/moxie/machine/cdefs.h0
-rw-r--r--libbsd/include/arch/moxie/machine/elf_machdep.h15
-rw-r--r--libbsd/include/arch/moxie/machine/int_types.h0
-rw-r--r--libbsd/include/sys/exec_elf.h2
-rw-r--r--rtems.py2
-rw-r--r--rtl-mdreloc-moxie.c88
-rw-r--r--testcase/1.c13
-rw-r--r--testcase/wscript2
-rw-r--r--wscript2
11 files changed, 124 insertions, 2 deletions
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
--- /dev/null
+++ b/libbsd/include/arch/moxie/machine/ansi.h
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
--- /dev/null
+++ b/libbsd/include/arch/moxie/machine/cdefs.h
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
--- /dev/null
+++ b/libbsd/include/arch/moxie/machine/int_types.h
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 <sys/cdefs.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include <rtl.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;
+}
+
+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,