summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeng Fan <van.freenix@gmail.com>2013-07-22 10:56:13 +0800
committerPeng Fan <van.freenix@gmail.com>2013-09-05 13:47:39 +0800
commit42d16f6d37130a3550b537d35698977f06908234 (patch)
tree8d8bf5b713308aaa52916fe98810670f1f47a02b
parent43044399b0507b4357edeae9350751276c3b9ceb (diff)
H8300 Support
Signed-off-by: Peng Fan <van.freenix@gmail.com>
-rw-r--r--libbsd/include/arch/h8300/machine/ansi.h0
-rw-r--r--libbsd/include/arch/h8300/machine/asm.h2
-rw-r--r--libbsd/include/arch/h8300/machine/cdefs.h0
-rw-r--r--libbsd/include/arch/h8300/machine/elf_machdep.h59
-rw-r--r--libbsd/include/arch/h8300/machine/int_types.h0
-rw-r--r--rtl-mdreloc-h8300.c101
-rw-r--r--testcase/Readme8
-rw-r--r--testcase/wscript11
-rw-r--r--wscript2
9 files changed, 182 insertions, 1 deletions
diff --git a/libbsd/include/arch/h8300/machine/ansi.h b/libbsd/include/arch/h8300/machine/ansi.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/libbsd/include/arch/h8300/machine/ansi.h
diff --git a/libbsd/include/arch/h8300/machine/asm.h b/libbsd/include/arch/h8300/machine/asm.h
new file mode 100644
index 0000000..b3a7a95
--- /dev/null
+++ b/libbsd/include/arch/h8300/machine/asm.h
@@ -0,0 +1,2 @@
+
+#define __CONCAT(x,y) x ## y
diff --git a/libbsd/include/arch/h8300/machine/cdefs.h b/libbsd/include/arch/h8300/machine/cdefs.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/libbsd/include/arch/h8300/machine/cdefs.h
diff --git a/libbsd/include/arch/h8300/machine/elf_machdep.h b/libbsd/include/arch/h8300/machine/elf_machdep.h
new file mode 100644
index 0000000..3d04915
--- /dev/null
+++ b/libbsd/include/arch/h8300/machine/elf_machdep.h
@@ -0,0 +1,59 @@
+
+#define ELF32_MACHDEP_ENDIANNESS ELFDATA2MSB
+
+#define ELF32_MACHDEP_ID_CASES \
+ case EM_H8_300: \
+ case EM_H8_300H: \
+ case EM_H8S: \
+ case EM_H8_500: \
+ break;
+
+#define ELF32_MACHDEP_ID EM_H8_300
+#define ARCH_ELFSIZE 32
+
+#define R_H8_NONE 0
+#define R_H8_DIR32 1
+#define R_H8_DIR32_28 2
+#define R_H8_DIR32_24 3
+#define R_H8_DIR32_16 4
+#define R_H8_DIR32U 6
+#define R_H8_DIR32U_28 7
+#define R_H8_DIR32U_24 8
+#define R_H8_DIR32U_20 9
+#define R_H8_DIR32U_16 10
+#define R_H8_DIR24 11
+#define R_H8_DIR24_20 12
+#define R_H8_DIR24_16 13
+#define R_H8_DIR24U 14
+#define R_H8_DIR24U_20 15
+#define R_H8_DIR24U_16 16
+#define R_H8_DIR16 17
+#define R_H8_DIR16U 18
+#define R_H8_DIR16S_32 19
+#define R_H8_DIR16S_28 20
+#define R_H8_DIR16S_24 21
+#define R_H8_DIR16S_20 22
+#define R_H8_DIR16S 23
+#define R_H8_DIR8 24
+#define R_H8_DIR8U 25
+#define R_H8_DIR8Z_32 26
+#define R_H8_DIR8Z_28 27
+#define R_H8_DIR8Z_24 28
+#define R_H8_DIR8Z_20 29
+#define R_H8_DIR8Z_16 30
+#define R_H8_PCREL16 31
+#define R_H8_PCREL8 32
+#define R_H8_BPOS 33
+#define R_H8_PCREL32 34
+#define R_H8_GOT32O 35
+#define R_H8_GOT16O 36
+#define R_H8_DIR16A8 59
+#define R_H8_DIR16R8 60
+#define R_H8_DIR24A8 61
+#define R_H8_DIR24R8 62
+#define R_H8_DIR32A16 63
+#define R_H8_ABS32 65
+#define R_H8_ABS32A16 127
+
+
+#define R_TYPE(name) __CONCAT(R_H8_,name)
diff --git a/libbsd/include/arch/h8300/machine/int_types.h b/libbsd/include/arch/h8300/machine/int_types.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/libbsd/include/arch/h8300/machine/int_types.h
diff --git a/rtl-mdreloc-h8300.c b/rtl-mdreloc-h8300.c
new file mode 100644
index 0000000..e9adeda
--- /dev/null
+++ b/rtl-mdreloc-h8300.c
@@ -0,0 +1,101 @@
+#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_Word tmp;
+
+ where = (Elf_Addr *)(sect->base + rela->r_offset);
+
+ if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) {
+ printf("rela relocation type is %ld\n", ELF_R_TYPE(rela->r_info));
+ printf("relocated address 0x%08lx\n", (Elf_Addr)where);
+ }
+
+ tmp = symvalue;
+ switch (ELF_R_TYPE(rela->r_info)) {
+ case R_TYPE(NONE):
+ break;
+
+ case R_TYPE(DIR16):
+ *(uint16_t *)where += symvalue + rela->r_addend;
+ break;
+
+ case R_TYPE(DIR32):
+ case R_TYPE(DIR32A16):
+ *where += symvalue + rela->r_addend;
+ break;
+
+ case R_TYPE(DIR24A8):
+ if (ELF32_R_SYM(rela->r_info))
+ *where += symvalue + rela->r_addend;
+ break;
+
+ case R_TYPE(DIR24R8):
+ where = (uint32_t *)((uint32_t)where - 1);
+ *where = (*where & 0xff000000) | ((*where & 0xffffff) + symvalue + rela->r_addend);
+ break;
+
+ case R_TYPE(PCREL8):
+ /* bcc instruction */
+ tmp = symvalue + rela->r_addend - (Elf_Addr)where - 1;
+ if (((Elf32_Sword)tmp > 0x7f) || ((Elf32_Sword)tmp < -(Elf32_Sword)0x80)){
+ printf("PCREL8 overflow\n");
+ return false;
+ } else {
+ *(uint8_t *)where = tmp;
+ }
+ break;
+
+ case R_TYPE(PCREL16):
+ /* bcc instruction */
+ tmp = symvalue + rela->r_addend - (Elf_Addr)where - 2;
+ if (((Elf32_Sword)tmp > 0x7fff) || ((Elf32_Sword)tmp < -(Elf32_Sword)0x8000)){
+ printf("PCREL16 overflow\n");
+ return false;
+ } else {
+ *(uint16_t *)where = tmp;
+ }
+ 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/Readme b/testcase/Readme
index ee71b3e..c90ab71 100644
--- a/testcase/Readme
+++ b/testcase/Readme
@@ -27,3 +27,11 @@ bfin:
Simulator:
bf537Stamp-gdb build/bfin-rtems4.11-bf537Stamp/rtld
Note: if use gdb to run rtl, add 'rap ld './test.rap'' into shell-init
+
+h8300:
+ configure --rtems=/opt/rtems-4.11 --rtems-tools=/opt/rtems-4.11 --rtems-archs=h8300 --rtems-bsps=h8300/h8sim
+ configure --rtems=/opt/rtems-4.11 --rtems-tools=/opt/rtems-4.11 --rtems-archs=h8300 --rtems-bsps=h8300/h8sxsim
+ You should change '-B ${RTEMS_ARCH}' to '-B h8300h' for h8sim and '-B h8300sx' for h8sxsim
+
+ Simulator:
+ h8sim -i build/h8300-rtems4.11-h8sim/rtld
diff --git a/testcase/wscript b/testcase/wscript
index 130b441..1a0d0c5 100644
--- a/testcase/wscript
+++ b/testcase/wscript
@@ -74,6 +74,17 @@ def build(bld):
'--entry', '_my_main'],
source = ['1.c', '2.c'])
+ elif arch == 'h8300':
+ 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}')
diff --git a/wscript b/wscript
index 5919636..4e5974c 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':
+ if arch == 'arm' or arch == 'powerpc' or arch == 'mips' or arch == 'bfin' or arch == 'h8300':
bld(target = 'bspinit',
features = 'c',
includes = bld.includes,