[PATCH] H8/300 module support update

From: Yoshinori Sato
Date: Fri May 21 2004 - 01:36:45 EST


- add module support code
- add H8/300 ELF infomation
- fix kcore ELF format

--
Yoshinori Sato
<ysato@xxxxxxxxxxxxxxxxxxxx>

diff -Nur linux-2.6.6-bk4/arch/h8300/kernel/Makefile linux-2.6.6-h8300/arch/h8300/kernel/Makefile
--- linux-2.6.6-bk4/arch/h8300/kernel/Makefile 2004-05-11 14:30:25.000000000 +0900
+++ linux-2.6.6-h8300/arch/h8300/kernel/Makefile 2004-05-21 02:44:25.000000000 +0900
@@ -6,5 +6,6 @@

obj-y := process.o traps.o ptrace.o ints.o \
sys_h8300.o time.o semaphore.o signal.o \
- setup.o h8300_ksyms.o gpio.o init_task.o \
- syscalls.o
+ setup.o gpio.o init_task.o syscalls.o
+
+obj-$(CONFIG_MODULES) += module.o h8300_ksyms.o
diff -Nur linux-2.6.6-bk4/arch/h8300/kernel/h8300_ksyms.c linux-2.6.6-h8300/arch/h8300/kernel/h8300_ksyms.c
--- linux-2.6.6-bk4/arch/h8300/kernel/h8300_ksyms.c 2004-01-09 16:00:03.000000000 +0900
+++ linux-2.6.6-h8300/arch/h8300/kernel/h8300_ksyms.c 2004-05-21 02:44:25.000000000 +0900
@@ -17,6 +17,7 @@
#include <asm/checksum.h>
#include <asm/hardirq.h>
#include <asm/current.h>
+#include <asm/gpio.h>

//asmlinkage long long __ashrdi3 (long long, int);
//asmlinkage long long __lshrdi3 (long long, int);
@@ -38,8 +39,6 @@

EXPORT_SYMBOL(ip_fast_csum);

-EXPORT_SYMBOL(mach_enable_irq);
-EXPORT_SYMBOL(mach_disable_irq);
EXPORT_SYMBOL(kernel_thread);

/* Networking helper routines. */
@@ -103,10 +102,10 @@
EXPORT_SYMBOL_NOVERS(__umoddi3);
EXPORT_SYMBOL_NOVERS(__umodsi3);

-EXPORT_SYMBOL_NOVERS(_current_task);
-
+#ifdef MAGIC_ROM_PTR
EXPORT_SYMBOL_NOVERS(is_in_rom);
+#endif

-EXPORT_SYMBOL_NOVERS(h8300_reserved_gpio)
-EXPORT_SYMBOL_NOVERS(h8300_free_gpio)
-EXPORT_SYMBOL_NOVERS(h8300_set_gpio_dir)
+EXPORT_SYMBOL_NOVERS(h8300_reserved_gpio);
+EXPORT_SYMBOL_NOVERS(h8300_free_gpio);
+EXPORT_SYMBOL_NOVERS(h8300_set_gpio_dir);
diff -Nur linux-2.6.6-bk4/arch/h8300/kernel/module.c linux-2.6.6-h8300/arch/h8300/kernel/module.c
--- linux-2.6.6-bk4/arch/h8300/kernel/module.c 1970-01-01 09:00:00.000000000 +0900
+++ linux-2.6.6-h8300/arch/h8300/kernel/module.c 2004-05-21 02:44:25.000000000 +0900
@@ -0,0 +1,122 @@
+#include <linux/moduleloader.h>
+#include <linux/elf.h>
+#include <linux/vmalloc.h>
+#include <linux/fs.h>
+#include <linux/string.h>
+#include <linux/kernel.h>
+
+#if 0
+#define DEBUGP printk
+#else
+#define DEBUGP(fmt...)
+#endif
+
+void *module_alloc(unsigned long size)
+{
+ if (size == 0)
+ return NULL;
+ return vmalloc(size);
+}
+
+
+/* Free memory returned from module_alloc */
+void module_free(struct module *mod, void *module_region)
+{
+ vfree(module_region);
+ /* FIXME: If module_region == mod->init_region, trim exception
+ table entries. */
+}
+
+/* We don't need anything special. */
+int module_frob_arch_sections(Elf_Ehdr *hdr,
+ Elf_Shdr *sechdrs,
+ char *secstrings,
+ struct module *mod)
+{
+ return 0;
+}
+
+int apply_relocate(Elf32_Shdr *sechdrs,
+ const char *strtab,
+ unsigned int symindex,
+ unsigned int relsec,
+ struct module *me)
+{
+ printk(KERN_ERR "module %s: RELOCATION unsupported\n",
+ me->name);
+ return -ENOEXEC;
+}
+
+int apply_relocate_add(Elf32_Shdr *sechdrs,
+ const char *strtab,
+ unsigned int symindex,
+ unsigned int relsec,
+ struct module *me)
+{
+ unsigned int i;
+ Elf32_Rela *rela = (void *)sechdrs[relsec].sh_addr;
+
+ DEBUGP("Applying relocate section %u to %u\n", relsec,
+ sechdrs[relsec].sh_info);
+ for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rela); i++) {
+ /* This is where to make the change */
+ uint32_t *loc = (uint32_t *)(sechdrs[sechdrs[relsec].sh_info].sh_addr
+ + rela[i].r_offset);
+ /* This is the symbol it is referring to. Note that all
+ undefined symbols have been resolved. */
+ Elf32_Sym *sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
+ + ELF32_R_SYM(rela[i].r_info);
+ uint32_t v = sym->st_value + rela[i].r_addend;
+ uint32_t dot = sechdrs[symindex].sh_addr + rela[i].r_offset;
+
+ switch (ELF32_R_TYPE(rela[i].r_info)) {
+ case R_H8_DIR24R8:
+ loc = (uint32_t *)((uint32_t)loc - 1);
+ *loc = (*loc & 0xff000000) | ((*loc & 0xffffff) + v);
+ break;
+ case R_H8_DIR24A8:
+ *loc += v;
+ break;
+ case R_H8_DIR32:
+ case R_H8_DIR32A16:
+ *loc += v;
+ break;
+ case R_H8_PCREL16:
+ v -= dot + 2;
+ if ((Elf32_Sword)v > 0x7fff ||
+ (Elf32_Sword)v < -(Elf32_Sword)0x8000)
+ goto overflow;
+ else
+ *(unsigned short *)loc = v;
+ break;
+ case R_H8_PCREL8:
+ v -= dot + 1;
+ if ((Elf32_Sword)v > 0x7f ||
+ (Elf32_Sword)v < -(Elf32_Sword)0x80)
+ goto overflow;
+ else
+ *(unsigned char *)loc = v;
+ break;
+ default:
+ printk(KERN_ERR "module %s: Unknown relocation: %u\n",
+ me->name, ELF32_R_TYPE(rela[i].r_info));
+ return -ENOEXEC;
+ }
+ }
+ return 0;
+ overflow:
+ printk(KERN_ERR "module %s: relocation offset overflow: %p\n",
+ me->name, rela[i].r_offset);
+ return -ENOEXEC;
+}
+
+int module_finalize(const Elf_Ehdr *hdr,
+ const Elf_Shdr *sechdrs,
+ struct module *me)
+{
+ return 0;
+}
+
+void module_arch_cleanup(struct module *mod)
+{
+}
diff -Nur linux-2.6.6-bk4/arch/h8300/kernel/vmlinux.lds.S linux-2.6.6-h8300/arch/h8300/kernel/vmlinux.lds.S
--- linux-2.6.6-bk4/arch/h8300/kernel/vmlinux.lds.S 2004-05-21 02:17:15.000000000 +0900
+++ linux-2.6.6-h8300/arch/h8300/kernel/vmlinux.lds.S 2004-05-21 02:44:25.000000000 +0900
@@ -104,6 +104,21 @@
*(__ksymtab)
___stop___ksymtab = .;

+ ___start___ksymtab_gpl = .; /* Kernel symbol table: GPL-only symbols */
+
+ *(__ksymtab_gpl)
+ ___stop___ksymtab_gpl = .;
+
+ ___start___kcrctab = .; /* Kernel symbol table: Normal symbols */
+ *(__kcrctab)
+ ___stop___kcrctab = .;
+
+ ___start___kcrctab_gpl = .; /* Kernel symbol table: GPL-only symbols */
+ *(__kcrctab_gpl)
+ ___stop___kcrctab_gpl = .;
+
+ *(__ksymtab_strings) /* Kernel symbol table: strings */
+
. = ALIGN(0x4) ;
__etext = . ;
#if defined(CONFIG_ROMKERNEL)
diff -ur linux-2.6.6-bk4/fs/proc/kcore.c linux-2.6.6-h8300/fs/proc/kcore.c
--- linux-2.6.6-bk4/fs/proc/kcore.c 2004-01-09 15:59:43.000000000 +0900
+++ linux-2.6.6-h8300/fs/proc/kcore.c 2004-05-21 13:59:18.000000000 +0900
@@ -183,7 +183,11 @@
elf->e_entry = 0;
elf->e_phoff = sizeof(struct elfhdr);
elf->e_shoff = 0;
+#if defined(CONFIG_H8300)
+ elf->e_flags = ELF_FLAGS;
+#else
elf->e_flags = 0;
+#endif
elf->e_ehsize = sizeof(struct elfhdr);
elf->e_phentsize= sizeof(struct elf_phdr);
elf->e_phnum = nphdr;
diff -ur linux-2.6.6-bk4/include/asm-h8300/elf.h linux-2.6.6-h8300/include/asm-h8300/elf.h
--- linux-2.6.6-bk4/include/asm-h8300/elf.h 2004-01-09 15:59:43.000000000 +0900
+++ linux-2.6.6-h8300/include/asm-h8300/elf.h 2004-05-21 13:59:17.000000000 +0900
@@ -13,26 +13,30 @@

#define ELF_NGREG (sizeof(struct user_regs_struct) / sizeof(elf_greg_t))
typedef elf_greg_t elf_gregset_t[ELF_NGREG];
-
-typedef struct user_m68kfp_struct elf_fpregset_t;
+typedef unsigned long elf_fpregset_t;

/*
* This is used to ensure we don't load something for the wrong architecture.
*/
-#define elf_check_arch(x) ((x)->e_machine == EM_68K)
+#define elf_check_arch(x) ((x)->e_machine == EM_H8_300)

/*
* These are used to set parameters in the core dumps.
*/
#define ELF_CLASS ELFCLASS32
#define ELF_DATA ELFDATA2MSB
-#define ELF_ARCH EM_H8_300H
+#define ELF_ARCH EM_H8_300
+#if defined(__H8300H__)
+#define ELF_FLAGS 0x810000
+#endif
+#if defined(__H8300S__)
+#define ELF_FLAGS 0x820000
+#endif

#define ELF_PLAT_INIT(_r) _r->er1 = 0

#define USE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 4096
-#endif

/* This is the location that an ET_DYN program is loaded if exec'ed. Typical
use of this is to invoke "./ld.so someprog" to test out a new version of
@@ -55,3 +59,49 @@
#ifdef __KERNEL__
#define SET_PERSONALITY(ex, ibcs2) set_personality(PER_LINUX)
#endif
+
+#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
+
+#endif
diff -ur linux-2.6.6-bk4/include/asm-h8300/module.h linux-2.6.6-h8300/include/asm-h8300/module.h
--- linux-2.6.6-bk4/include/asm-h8300/module.h 2004-05-11 14:30:12.000000000 +0900
+++ linux-2.6.6-h8300/include/asm-h8300/module.h 2004-05-21 02:07:48.000000000 +0900
@@ -3,5 +3,9 @@
/*
* This file contains the H8/300 architecture specific module code.
*/
+struct mod_arch_specific { };
+#define Elf_Shdr Elf32_Shdr
+#define Elf_Sym Elf32_Sym
+#define Elf_Ehdr Elf32_Ehdr

#endif /* _ASM_H8/300_MODULE_H */
diff -ur linux-2.6.6-bk4/include/linux/elf.h linux-2.6.6-h8300/include/linux/elf.h
--- linux-2.6.6-bk4/include/linux/elf.h 2004-05-11 14:30:47.000000000 +0900
+++ linux-2.6.6-h8300/include/linux/elf.h 2004-05-21 02:55:24.000000000 +0900
@@ -81,8 +81,7 @@

#define EM_V850 87 /* NEC v850 */

-#define EM_H8_300H 47 /* Hitachi H8/300H */
-#define EM_H8S 48 /* Hitachi H8S */
+#define EM_H8_300 46 /* Hitachi H8/300,300H,H8S */

/*
* This is an interim value that we will use until the committee comes
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/