Commit 4e82b2d8 authored by Yoshinori Sato's avatar Yoshinori Sato Committed by Linus Torvalds

[PATCH] H8/300 module support update

- add module support code
- add H8/300 ELF infomation
- fix kcore ELF format
parent 13bea95f
...@@ -6,5 +6,6 @@ extra-y := vmlinux.lds.s ...@@ -6,5 +6,6 @@ extra-y := vmlinux.lds.s
obj-y := process.o traps.o ptrace.o ints.o \ obj-y := process.o traps.o ptrace.o ints.o \
sys_h8300.o time.o semaphore.o signal.o \ sys_h8300.o time.o semaphore.o signal.o \
setup.o h8300_ksyms.o gpio.o init_task.o \ setup.o gpio.o init_task.o syscalls.o
syscalls.o
obj-$(CONFIG_MODULES) += module.o h8300_ksyms.o
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <asm/checksum.h> #include <asm/checksum.h>
#include <asm/hardirq.h> #include <asm/hardirq.h>
#include <asm/current.h> #include <asm/current.h>
#include <asm/gpio.h>
//asmlinkage long long __ashrdi3 (long long, int); //asmlinkage long long __ashrdi3 (long long, int);
//asmlinkage long long __lshrdi3 (long long, int); //asmlinkage long long __lshrdi3 (long long, int);
...@@ -38,8 +39,6 @@ EXPORT_SYMBOL(strncmp); ...@@ -38,8 +39,6 @@ EXPORT_SYMBOL(strncmp);
EXPORT_SYMBOL(ip_fast_csum); EXPORT_SYMBOL(ip_fast_csum);
EXPORT_SYMBOL(mach_enable_irq);
EXPORT_SYMBOL(mach_disable_irq);
EXPORT_SYMBOL(kernel_thread); EXPORT_SYMBOL(kernel_thread);
/* Networking helper routines. */ /* Networking helper routines. */
...@@ -103,10 +102,10 @@ EXPORT_SYMBOL_NOVERS(__udivsi3); ...@@ -103,10 +102,10 @@ EXPORT_SYMBOL_NOVERS(__udivsi3);
EXPORT_SYMBOL_NOVERS(__umoddi3); EXPORT_SYMBOL_NOVERS(__umoddi3);
EXPORT_SYMBOL_NOVERS(__umodsi3); EXPORT_SYMBOL_NOVERS(__umodsi3);
EXPORT_SYMBOL_NOVERS(_current_task); #ifdef MAGIC_ROM_PTR
EXPORT_SYMBOL_NOVERS(is_in_rom); EXPORT_SYMBOL_NOVERS(is_in_rom);
#endif
EXPORT_SYMBOL_NOVERS(h8300_reserved_gpio) EXPORT_SYMBOL_NOVERS(h8300_reserved_gpio);
EXPORT_SYMBOL_NOVERS(h8300_free_gpio) EXPORT_SYMBOL_NOVERS(h8300_free_gpio);
EXPORT_SYMBOL_NOVERS(h8300_set_gpio_dir) EXPORT_SYMBOL_NOVERS(h8300_set_gpio_dir);
#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)
{
}
...@@ -104,6 +104,21 @@ SECTIONS ...@@ -104,6 +104,21 @@ SECTIONS
*(__ksymtab) *(__ksymtab)
___stop___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) ; . = ALIGN(0x4) ;
__etext = . ; __etext = . ;
#if defined(CONFIG_ROMKERNEL) #if defined(CONFIG_ROMKERNEL)
......
...@@ -183,7 +183,11 @@ static void elf_kcore_store_hdr(char *bufp, int nphdr, int dataoff) ...@@ -183,7 +183,11 @@ static void elf_kcore_store_hdr(char *bufp, int nphdr, int dataoff)
elf->e_entry = 0; elf->e_entry = 0;
elf->e_phoff = sizeof(struct elfhdr); elf->e_phoff = sizeof(struct elfhdr);
elf->e_shoff = 0; elf->e_shoff = 0;
#if defined(CONFIG_H8300)
elf->e_flags = ELF_FLAGS;
#else
elf->e_flags = 0; elf->e_flags = 0;
#endif
elf->e_ehsize = sizeof(struct elfhdr); elf->e_ehsize = sizeof(struct elfhdr);
elf->e_phentsize= sizeof(struct elf_phdr); elf->e_phentsize= sizeof(struct elf_phdr);
elf->e_phnum = nphdr; elf->e_phnum = nphdr;
......
...@@ -13,26 +13,30 @@ typedef unsigned long elf_greg_t; ...@@ -13,26 +13,30 @@ typedef unsigned long elf_greg_t;
#define ELF_NGREG (sizeof(struct user_regs_struct) / sizeof(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 elf_greg_t elf_gregset_t[ELF_NGREG];
typedef unsigned long elf_fpregset_t;
typedef struct user_m68kfp_struct elf_fpregset_t;
/* /*
* This is used to ensure we don't load something for the wrong architecture. * 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. * These are used to set parameters in the core dumps.
*/ */
#define ELF_CLASS ELFCLASS32 #define ELF_CLASS ELFCLASS32
#define ELF_DATA ELFDATA2MSB #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 ELF_PLAT_INIT(_r) _r->er1 = 0
#define USE_ELF_CORE_DUMP #define USE_ELF_CORE_DUMP
#define ELF_EXEC_PAGESIZE 4096 #define ELF_EXEC_PAGESIZE 4096
#endif
/* This is the location that an ET_DYN program is loaded if exec'ed. Typical /* 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 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; ...@@ -55,3 +59,49 @@ typedef struct user_m68kfp_struct elf_fpregset_t;
#ifdef __KERNEL__ #ifdef __KERNEL__
#define SET_PERSONALITY(ex, ibcs2) set_personality(PER_LINUX) #define SET_PERSONALITY(ex, ibcs2) set_personality(PER_LINUX)
#endif #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
...@@ -3,5 +3,9 @@ ...@@ -3,5 +3,9 @@
/* /*
* This file contains the H8/300 architecture specific module code. * 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 */ #endif /* _ASM_H8/300_MODULE_H */
...@@ -81,8 +81,7 @@ typedef __s64 Elf64_Sxword; ...@@ -81,8 +81,7 @@ typedef __s64 Elf64_Sxword;
#define EM_V850 87 /* NEC v850 */ #define EM_V850 87 /* NEC v850 */
#define EM_H8_300H 47 /* Hitachi H8/300H */ #define EM_H8_300 46 /* Hitachi H8/300,300H,H8S */
#define EM_H8S 48 /* Hitachi H8S */
/* /*
* This is an interim value that we will use until the committee comes * This is an interim value that we will use until the committee comes
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment