]> git.hungrycats.org Git - linux/commitdiff
[PATCH] H8/300 module support update
authorYoshinori Sato <ysato@users.sourceforge.jp>
Fri, 21 May 2004 07:09:43 +0000 (00:09 -0700)
committerLinus Torvalds <torvalds@ppc970.osdl.org>
Fri, 21 May 2004 07:09:43 +0000 (00:09 -0700)
- add module support code
- add H8/300 ELF infomation
- fix kcore ELF format

arch/h8300/kernel/Makefile
arch/h8300/kernel/h8300_ksyms.c
arch/h8300/kernel/module.c [new file with mode: 0644]
arch/h8300/kernel/vmlinux.lds.S
fs/proc/kcore.c
include/asm-h8300/elf.h
include/asm-h8300/module.h
include/linux/elf.h

index 2aae3e9c62d4dd1134208dd12b87b254adbd8c2a..1f4ef89b53d2897623cf3944d32c5a9bc5c8e813 100644 (file)
@@ -6,5 +6,6 @@ extra-y := vmlinux.lds.s
 
 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 
index 3b69d453317a9cbaf7ba01a79552ebdef298e04f..590415dc2f303cdef20140eabd81c92cc8589791 100644 (file)
@@ -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(strncmp);
 
 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(__udivsi3);
 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 --git a/arch/h8300/kernel/module.c b/arch/h8300/kernel/module.c
new file mode 100644 (file)
index 0000000..433e922
--- /dev/null
@@ -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)
+{
+}
index 7898e13468d5907a1fbad69d62a31167f8c1b0dc..7a6009cf26d244ca49d97afede962d3c93951821 100644 (file)
@@ -104,6 +104,21 @@ SECTIONS
                 *(__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)
index f6e81e9007e3798b6ca43a2e7513c47b5ae01c91..1f55db799b51e039221261de87254d1504b375b3 100644 (file)
@@ -183,7 +183,11 @@ static void elf_kcore_store_hdr(char *bufp, int nphdr, int dataoff)
        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;
index 8af8df06f23cab37f4aac14780733dfac4988117..f4af1553a55fcc4c0829a27fe65c48987fea3f01 100644 (file)
@@ -13,26 +13,30 @@ typedef unsigned long elf_greg_t;
 
 #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 @@ typedef struct user_m68kfp_struct elf_fpregset_t;
 #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
index 2573cfb4ad1600c6c6609100d17bdd9927f3261b..8e46724b7c09a92f26c36dabb3fc2285a9ee428b 100644 (file)
@@ -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 */
index 7f21bfaa2e712e3b3298161b702ea730ea6ce5d7..f8115ac02b51765992e2e733aeb930f4fed38cc0 100644 (file)
@@ -81,8 +81,7 @@ typedef __s64 Elf64_Sxword;
 
 #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